[pypy-commit] pypy default: Patch by vpelletier: add @builtinify to all public _ctypes functions.
arigo
noreply at buildbot.pypy.org
Sat Aug 25 16:16:57 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r56849:5d5dcafd00dd
Date: 2012-08-25 16:16 +0200
http://bitbucket.org/pypy/pypy/changeset/5d5dcafd00dd/
Log: Patch by vpelletier: add @builtinify to all public _ctypes
functions. Add a test.
diff --git a/lib_pypy/_ctypes/__init__.py b/lib_pypy/_ctypes/__init__.py
--- a/lib_pypy/_ctypes/__init__.py
+++ b/lib_pypy/_ctypes/__init__.py
@@ -19,6 +19,10 @@
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:
@@ -28,6 +32,8 @@
dst[0] = cast(src, c_void_p).value
return 0
+ del builtinify
+
LoadLibrary = dlopen
from _rawffi import FUNCFLAG_STDCALL, FUNCFLAG_CDECL, FUNCFLAG_PYTHONAPI
diff --git a/lib_pypy/_ctypes/basics.py b/lib_pypy/_ctypes/basics.py
--- a/lib_pypy/_ctypes/basics.py
+++ b/lib_pypy/_ctypes/basics.py
@@ -3,6 +3,9 @@
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):
@@ -145,6 +148,7 @@
_b_base_ = property(_get_b_base)
_b_needsfree_ = False
+ at builtinify
def sizeof(tp):
if not isinstance(tp, _CDataMeta):
if isinstance(tp, _CData):
@@ -154,6 +158,7 @@
type(tp).__name__,))
return tp._sizeofinstances()
+ at builtinify
def alignment(tp):
if not isinstance(tp, _CDataMeta):
if isinstance(tp, _CData):
@@ -163,11 +168,13 @@
type(tp).__name__,))
return tp._alignmentofinstances()
+ at builtinify
def byref(cdata):
# "pointer" is imported at the end of this module to avoid circular
# imports
return pointer(cdata)
+ at 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)
@@ -176,6 +183,7 @@
instance._buffer = self._ffiarray.fromaddress(address, lgt)
return instance
+ at builtinify
def addressof(tp):
return tp._buffer.buffer
diff --git a/lib_pypy/_ctypes/dll.py b/lib_pypy/_ctypes/dll.py
--- a/lib_pypy/_ctypes/dll.py
+++ b/lib_pypy/_ctypes/dll.py
@@ -1,5 +1,9 @@
import _rawffi
+try: from __pypy__ import builtinify
+except ImportError: builtinify = lambda f: f
+
+ at builtinify
def dlopen(name, mode):
# XXX mode is ignored
return _rawffi.CDLL(name)
diff --git a/lib_pypy/_ctypes/function.py b/lib_pypy/_ctypes/function.py
--- a/lib_pypy/_ctypes/function.py
+++ b/lib_pypy/_ctypes/function.py
@@ -10,6 +10,8 @@
import traceback
import warnings
+try: from __pypy__ import builtinify
+except ImportError: builtinify = lambda f: f
# XXX this file needs huge refactoring I fear
@@ -34,6 +36,7 @@
from _ctypes import COMError
return COMError(errcode, None, None)
+ at builtinify
def call_function(func, args):
"Only for debugging so far: So that we can call CFunction instances"
funcptr = CFuncPtr(func)
diff --git a/lib_pypy/_ctypes/pointer.py b/lib_pypy/_ctypes/pointer.py
--- a/lib_pypy/_ctypes/pointer.py
+++ b/lib_pypy/_ctypes/pointer.py
@@ -7,6 +7,9 @@
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 = {}
@@ -154,6 +157,7 @@
return result
+ at builtinify
def POINTER(cls):
try:
return _pointer_type_cache[cls]
@@ -173,6 +177,7 @@
_pointer_type_cache[cls] = klass
return klass
+ at builtinify
def pointer(inst):
return POINTER(type(inst))(inst)
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_pointers.py b/pypy/module/test_lib_pypy/ctypes_tests/test_pointers.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_pointers.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_pointers.py
@@ -253,3 +253,8 @@
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))
More information about the pypy-commit
mailing list