[pypy-svn] r61680 - in pypy/trunk/pypy: lib/_ctypes module/_rawffi rlib

afa at codespeak.net afa at codespeak.net
Tue Feb 10 01:25:00 CET 2009


Author: afa
Date: Tue Feb 10 01:24:57 2009
New Revision: 61680

Modified:
   pypy/trunk/pypy/lib/_ctypes/function.py
   pypy/trunk/pypy/module/_rawffi/interp_rawffi.py
   pypy/trunk/pypy/rlib/libffi.py
Log:
Really use the _FuncPtr._flags_ attribute, and pass it to the libffi layer.
More win32 tests pass


Modified: pypy/trunk/pypy/lib/_ctypes/function.py
==============================================================================
--- pypy/trunk/pypy/lib/_ctypes/function.py	(original)
+++ pypy/trunk/pypy/lib/_ctypes/function.py	Tue Feb 10 01:24:57 2009
@@ -23,6 +23,7 @@
 
     _argtypes_ = None
     _restype_ = None
+    _flags_ = 0
     _ffiargshape = 'P'
     _ffishape = 'P'
     _fficompositesize = None
@@ -60,13 +61,18 @@
             restype = 'O' # void
         return argtypes, restype
 
-    def __init__(self, argument=None):
+    def __init__(self, *args):
         self.name = None
         self._objects = {keepalive_key(0):self}
         self._needs_free = True
+        argument = None
+        if len(args) == 1:
+            argument = args[0]
+
         if isinstance(argument, (int, long)):
             ffiargs, ffires = self._ffishapes(self._argtypes_, self._restype_)
-            self._ptr = _rawffi.FuncPtr(argument, ffiargs, ffires)
+            self._ptr = _rawffi.FuncPtr(argument, ffiargs, ffires,
+                                        self._flags_)
             self._buffer = self._ptr.byptr()
         elif callable(argument):
             self.callable = argument
@@ -83,7 +89,8 @@
             # we need to check dll anyway
             ptr = self._getfuncptr([], ctypes.c_int)
             self._buffer = ptr.byptr()
-        elif argument is None:
+
+        elif len(args) == 0:
             # this is needed for casts
             self._buffer = _rawffi.Array('P')(1)
             return
@@ -138,11 +145,13 @@
         argshapes = [arg._ffiargshape for arg in argtypes]
         resshape = restype._ffiargshape
         if self._buffer is not None:
-            self._ptr = _rawffi.FuncPtr(self._buffer[0], argshapes, resshape)
+            self._ptr = _rawffi.FuncPtr(self._buffer[0], argshapes, resshape,
+                                        self._flags_)
             return self._ptr
+
         cdll = self.dll._handle
         try:
-            return cdll.ptr(self.name, argshapes, resshape)
+            return cdll.ptr(self.name, argshapes, resshape, self._flags_)
         except AttributeError:
             if self._flags_ & _rawffi.FUNCFLAG_CDECL:
                 raise
@@ -153,7 +162,8 @@
             for i in range(32):
                 mangled_name = "_%s@%d" % (self.name, i*4)
                 try:
-                    return cdll.ptr(mangled_name, argshapes, resshape)
+                    return cdll.ptr(mangled_name, argshapes, resshape,
+                                    self._flags_)
                 except AttributeError:
                     pass
             raise

Modified: pypy/trunk/pypy/module/_rawffi/interp_rawffi.py
==============================================================================
--- pypy/trunk/pypy/module/_rawffi/interp_rawffi.py	(original)
+++ pypy/trunk/pypy/module/_rawffi/interp_rawffi.py	Tue Feb 10 01:24:57 2009
@@ -142,7 +142,7 @@
         self.w_cache = space.newdict()
         self.space = space
 
-    def ptr(self, space, name, w_argtypes, w_restype):
+    def ptr(self, space, name, w_argtypes, w_restype, flags=0):
         """ Get a pointer for function name with provided argtypes
         and restype
         """
@@ -160,14 +160,15 @@
                 raise
         ffi_argtypes, argletters = unpack_argshapes(space, w_argtypes)
         try:
-            ptr = self.cdll.getrawpointer(name, ffi_argtypes, ffi_restype)
+            ptr = self.cdll.getrawpointer(name, ffi_argtypes, ffi_restype,
+                                          flags)
             w_funcptr = W_FuncPtr(space, ptr, argletters, resshape)
             space.setitem(self.w_cache, w_key, w_funcptr)
             return w_funcptr
         except KeyError:
             raise OperationError(space.w_AttributeError, space.wrap(
                 "No symbol %s found in library %s" % (name, self.name)))
-    ptr.unwrap_spec = ['self', ObjSpace, str, W_Root, W_Root]
+    ptr.unwrap_spec = ['self', ObjSpace, str, W_Root, W_Root, int]
 
     def getaddressindll(self, space, name):
         try:
@@ -411,12 +412,13 @@
             return space.w_None
     call.unwrap_spec = ['self', ObjSpace, 'args_w']
 
-def descr_new_funcptr(space, w_tp, addr, w_args, w_res):
+def descr_new_funcptr(space, w_tp, addr, w_args, w_res, flags=0):
     ffi_args, args = unpack_argshapes(space, w_args)
     ffi_res, res = unpack_resshape(space, w_res)
-    ptr = RawFuncPtr('???', ffi_args, ffi_res, rffi.cast(rffi.VOIDP, addr))
+    ptr = RawFuncPtr('???', ffi_args, ffi_res, rffi.cast(rffi.VOIDP, addr),
+                     flags)
     return space.wrap(W_FuncPtr(space, ptr, args, res))
-descr_new_funcptr.unwrap_spec = [ObjSpace, W_Root, r_uint, W_Root, W_Root]
+descr_new_funcptr.unwrap_spec = [ObjSpace, W_Root, r_uint, W_Root, W_Root, int]
 
 W_FuncPtr.typedef = TypeDef(
     'FuncPtr',

Modified: pypy/trunk/pypy/rlib/libffi.py
==============================================================================
--- pypy/trunk/pypy/rlib/libffi.py	(original)
+++ pypy/trunk/pypy/rlib/libffi.py	Tue Feb 10 01:24:57 2009
@@ -549,8 +549,6 @@
         AbstractFuncPtr.__del__(self)
 
 class CDLL:
-    flags = FUNCFLAG_CDECL
-
     def __init__(self, libname, unload_on_finalization=True):
         self.unload_on_finalization = unload_on_finalization
         self.lib = lltype.nullptr(rffi.CCHARP.TO)
@@ -563,17 +561,17 @@
             dlclose(self.lib)
             self.lib = lltype.nullptr(rffi.CCHARP.TO)
 
-    def getpointer(self, name, argtypes, restype):
+    def getpointer(self, name, argtypes, restype, flags):
         # these arguments are already casted to proper ffi
         # structures!
         return FuncPtr(name, argtypes, restype, dlsym(self.lib, name),
-                       flags=self.flags)
+                       flags=flags)
 
-    def getrawpointer(self, name, argtypes, restype):
+    def getrawpointer(self, name, argtypes, restype, flags):
         # these arguments are already casted to proper ffi
         # structures!
         return RawFuncPtr(name, argtypes, restype, dlsym(self.lib, name),
-                          flags=self.flags)
+                          flags=flags)
 
     def getaddressindll(self, name):
         return dlsym(self.lib, name)



More information about the Pypy-commit mailing list