Commits

Armin Rigo committed 5d5dcaf

Patch by vpelletier: add @builtinify to all public _ctypes functions.
Add a test.

Comments (0)

Files changed (6)

lib_pypy/_ctypes/__init__.py

     from _rawffi import FormatError
     from _rawffi import check_HRESULT as _check_HRESULT
 
+    try: from __pypy__ import builtinify
+    except ImportError: builtinify = lambda f: f
+
+    @builtinify
     def CopyComPointer(src, dst):
         from ctypes import c_void_p, cast
         if src:
         dst[0] = cast(src, c_void_p).value
         return 0
 
+    del builtinify
+
     LoadLibrary = dlopen
 
 from _rawffi import FUNCFLAG_STDCALL, FUNCFLAG_CDECL, FUNCFLAG_PYTHONAPI

lib_pypy/_ctypes/basics.py

 import _ffi
 import sys
 
+try: from __pypy__ import builtinify
+except ImportError: builtinify = lambda f: f
+
 keepalive_key = str # XXX fix this when provided with test
 
 def ensure_objects(where):
     _b_base_ = property(_get_b_base)
     _b_needsfree_ = False
 
+@builtinify
 def sizeof(tp):
     if not isinstance(tp, _CDataMeta):
         if isinstance(tp, _CData):
                 type(tp).__name__,))
     return tp._sizeofinstances()
 
+@builtinify
 def alignment(tp):
     if not isinstance(tp, _CDataMeta):
         if isinstance(tp, _CData):
                 type(tp).__name__,))
     return tp._alignmentofinstances()
 
+@builtinify
 def byref(cdata):
     # "pointer" is imported at the end of this module to avoid circular
     # imports
     return pointer(cdata)
 
+@builtinify
 def cdata_from_address(self, address):
     # fix the address: turn it into as unsigned, in case it's a negative number
     address = address & (sys.maxint * 2 + 1)
     instance._buffer = self._ffiarray.fromaddress(address, lgt)
     return instance
 
+@builtinify
 def addressof(tp):
     return tp._buffer.buffer
 

lib_pypy/_ctypes/dll.py

 import _rawffi
 
+try: from __pypy__ import builtinify
+except ImportError: builtinify = lambda f: f
+
+@builtinify
 def dlopen(name, mode):
     # XXX mode is ignored
     return _rawffi.CDLL(name)

lib_pypy/_ctypes/function.py

 import traceback
 import warnings
 
+try: from __pypy__ import builtinify
+except ImportError: builtinify = lambda f: f
 
 # XXX this file needs huge refactoring I fear
 
     from _ctypes import COMError
     return COMError(errcode, None, None)
 
+@builtinify
 def call_function(func, args):
     "Only for debugging so far: So that we can call CFunction instances"
     funcptr = CFuncPtr(func)

lib_pypy/_ctypes/pointer.py

 from _ctypes.array import Array, array_get_slice_params, array_slice_getitem,\
      array_slice_setitem
 
+try: from __pypy__ import builtinify
+except ImportError: builtinify = lambda f: f
+
 # This cache maps types to pointers to them.
 _pointer_type_cache = {}
 
 
     return result
 
+@builtinify
 def POINTER(cls):
     try:
         return _pointer_type_cache[cls]
         _pointer_type_cache[cls] = klass
     return klass
 
+@builtinify
 def pointer(inst):
     return POINTER(type(inst))(inst)
 

pypy/module/test_lib_pypy/ctypes_tests/test_pointers.py

         TwoOutArgs(a, byref(b), c, byref(d))
         assert b.value == 7
         assert d.value == 11
+
+    def test_byref_cannot_be_bound(self):
+        class A(object):
+            _byref = byref
+        A._byref(c_int(5))