Author: Armin Rigo <ar...@tunes.org>
Branch: cffi-1.0
Changeset: r77201:567a6f1771b2
Date: 2015-05-08 11:08 +0200
http://bitbucket.org/pypy/pypy/changeset/567a6f1771b2/

Log:    use ClassAttr

diff --git a/pypy/module/_cffi_backend/__init__.py 
b/pypy/module/_cffi_backend/__init__.py
--- a/pypy/module/_cffi_backend/__init__.py
+++ b/pypy/module/_cffi_backend/__init__.py
@@ -53,10 +53,6 @@
     if sys.platform == 'win32':
         interpleveldefs['getwinerror'] = 'cerrno.getwinerror'
 
-    def startup(self, space):
-        from pypy.module._cffi_backend import ffi_obj
-        ffi_obj._startup(space)
-
 for _name in ["RTLD_LAZY", "RTLD_NOW", "RTLD_GLOBAL", "RTLD_LOCAL",
               "RTLD_NODELETE", "RTLD_NOLOAD", "RTLD_DEEPBIND"]:
     if getattr(rdynload.cConfig, _name) is not None:
diff --git a/pypy/module/_cffi_backend/ffi_obj.py 
b/pypy/module/_cffi_backend/ffi_obj.py
--- a/pypy/module/_cffi_backend/ffi_obj.py
+++ b/pypy/module/_cffi_backend/ffi_obj.py
@@ -1,6 +1,6 @@
 from pypy.interpreter.error import oefmt
 from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter.typedef import TypeDef, GetSetProperty
+from pypy.interpreter.typedef import TypeDef, GetSetProperty, ClassAttr
 from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
 from rpython.rlib import jit, rgc
 from rpython.rtyper.lltypesystem import rffi
@@ -295,10 +295,21 @@
     r.__init__(space)
     return space.wrap(r)
 
+def make_NULL(space):
+    ctvoidp = newtype.new_voidp_type(space)
+    w_NULL = ctvoidp.cast(space.wrap(0))
+    return w_NULL
+
+def make_error(space):
+    return space.appexec([], """():
+        return type('error', (Exception,), {'__module__': 'ffi'})""")
+
 W_FFIObject.typedef = TypeDef(
         'CompiledFFI',
         __new__     = interp2app(W_FFIObject___new__),
         __init__    = interp2app(W_FFIObject.descr_init),
+        NULL        = ClassAttr(make_NULL),
+        error       = ClassAttr(make_error),
         errno       = GetSetProperty(W_FFIObject.get_errno,
                                      W_FFIObject.set_errno,
                                      doc=W_FFIObject.doc_errno,
@@ -315,11 +326,3 @@
         string      = interp2app(W_FFIObject.descr_string),
         typeof      = interp2app(W_FFIObject.descr_typeof),
         )
-
-def _startup(space):
-    ctvoidp = newtype.new_voidp_type(space)
-    w_NULL = ctvoidp.cast(space.wrap(0))
-    w_ffitype = space.gettypefor(W_FFIObject)
-    w_ffitype.dict_w['NULL'] = w_NULL
-    w_ffitype.dict_w['error'] = space.appexec([], """():
-        return type('error', (Exception,), {'__module__': 'ffi'})""")
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to