[pypy-svn] r72858 - pypy/branch/cpython-extension/pypy/module/cpyext

xoraxax at codespeak.net xoraxax at codespeak.net
Thu Mar 25 22:44:09 CET 2010


Author: xoraxax
Date: Thu Mar 25 22:44:08 2010
New Revision: 72858

Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/api.py
   pypy/branch/cpython-extension/pypy/module/cpyext/macros.py
   pypy/branch/cpython-extension/pypy/module/cpyext/typeobject.py
Log:
Do not use ctypes anymore for retrieval of the address.

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/api.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/api.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/api.py	Thu Mar 25 22:44:08 2010
@@ -22,6 +22,7 @@
 
 
 Py_ssize_t = lltype.Signed
+ADDR = lltype.Signed
 
 include_dir = py.path.local(autopath.pypydir) / 'module' / 'cpyext' / 'include'
 include_dirs = [
@@ -101,6 +102,8 @@
             error = lltype.nullptr(PyObject.TO)
         elif restype is lltype.Void:
             error = CANNOT_FAIL
+    if type(error) is int:
+        error = rffi.cast(restype, error)
 
     def decorate(func):
         api_function = ApiFunction(argtypes, restype, func, borrowed, error)
@@ -267,7 +270,7 @@
             state.borrowed_objects[ptr] = None
     elif not steal:
         if borrowed:
-            py_obj_addr = ctypes.addressof(py_obj._obj._storage)
+            py_obj_addr = rffi.cast(ADDR, py_obj)
             if py_obj_addr not in state.borrowed_objects:
                 Py_INCREF(space, py_obj)
                 state.borrowed_objects[py_obj_addr] = None
@@ -292,7 +295,7 @@
     if not ref:
         return None
     state = space.fromcache(State)
-    ptr = ctypes.addressof(ref._obj._storage)
+    ptr = rffi.cast(ADDR, ref)
     try:
         obj = state.py_objects_r2w[ptr]
     except KeyError:
@@ -307,11 +310,11 @@
 @cpython_api([PyObject, PyObject], lltype.Void, external=False)
 def add_borrowed_object(space, container, obj):
     state = space.fromcache(State)
-    container_ptr = ctypes.addressof(container._obj._storage)
+    container_ptr = rffi.cast(ADDR, container)
     borrowees = state.borrow_mapping.get(container_ptr)
     if borrowees is None:
         state.borrow_mapping[container_ptr] = borrowees = {}
-    obj_ptr = ctypes.addressof(obj._obj._storage)
+    obj_ptr = rffi.cast(ADDR, obj)
     borrowees[obj_ptr] = None
 
 

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/macros.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/macros.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/macros.py	Thu Mar 25 22:44:08 2010
@@ -1,8 +1,8 @@
-import ctypes
 import sys
 
 from pypy.rpython.lltypesystem import rffi, lltype
-from pypy.module.cpyext.api import cpython_api, PyObject, make_ref, from_ref
+from pypy.module.cpyext.api import cpython_api, PyObject, make_ref, from_ref, \
+        ADDR
 from pypy.module.cpyext.state import State
 
 DEBUG_REFCOUNT = False
@@ -16,7 +16,7 @@
         print >>sys.stderr, "DECREF", obj, obj.c_obj_refcnt
     if obj.c_obj_refcnt == 0:
         state = space.fromcache(State)
-        ptr = ctypes.addressof(obj._obj._storage)
+        ptr = rffi.cast(ADDR, obj)
         if ptr not in state.py_objects_r2w and \
             space.is_w(from_ref(space, obj.c_obj_type), space.w_str):
             # this is a half-allocated string, lets call the deallocator
@@ -32,7 +32,7 @@
                 if w_containee is not None:
                     containee = state.py_objects_w2r[w_containee]
                     Py_DECREF(space, w_containee)
-                    containee_ptr = ctypes.addressof(containee._obj._storage)
+                    containee_ptr = rffi.cast(ADDR, containee)
                     try:
                         del state.borrowed_objects[containee_ptr]
                     except KeyError:

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/typeobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/typeobject.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/typeobject.py	Thu Mar 25 22:44:08 2010
@@ -1,4 +1,3 @@
-import ctypes
 import sys
 
 from pypy.rpython.lltypesystem import rffi, lltype
@@ -13,7 +12,7 @@
 from pypy.module.cpyext.api import cpython_api, cpython_api_c, cpython_struct, \
     PyObject, PyVarObjectFields, Py_ssize_t, Py_TPFLAGS_READYING, \
     Py_TPFLAGS_READY, Py_TPFLAGS_HEAPTYPE, make_ref, \
-    PyStringObject
+    PyStringObject, ADDR
 from pypy.interpreter.module import Module
 from pypy.module.cpyext.modsupport import PyMethodDef, convert_method_defs
 from pypy.module.cpyext.state import State
@@ -298,7 +297,7 @@
 @cpython_api([PyTypeObjectPtr], rffi.INT_real, error=-1)
 def PyPyType_Register(space, pto):
     state = space.fromcache(State)
-    ptr = ctypes.addressof(pto._obj._storage)
+    ptr = rffi.cast(ADDR, pto)
     if ptr not in state.py_objects_r2w:
         w_obj = space.allocate_instance(W_PyCTypeObject,
                 space.gettypeobject(W_PyCTypeObject.typedef))



More information about the Pypy-commit mailing list