Author: Armin Rigo <[email protected]>
Branch: cffi-1.0
Changeset: r77195:8ea3cb12052f
Date: 2015-05-08 10:02 +0200
http://bitbucket.org/pypy/pypy/changeset/8ea3cb12052f/

Log:    in-progress

diff --git a/pypy/module/_cffi_backend/lib_obj.py 
b/pypy/module/_cffi_backend/lib_obj.py
--- a/pypy/module/_cffi_backend/lib_obj.py
+++ b/pypy/module/_cffi_backend/lib_obj.py
@@ -66,6 +66,12 @@
                 ptr = rffi.cast(rffi.CCHARP, g.c_address)
                 w_result = cglob.W_GlobSupport(space, w_ct, ptr)
                 #
+            elif (op == cffi_opcode.OP_CONSTANT_INT or
+                  op == cffi_opcode.OP_ENUM):
+                # A constant integer whose value, in an "unsigned long long",
+                # is obtained by calling the function at g->address
+                w_result = realize_c_type.realize_global_int(self.ffi, g)
+                #
             else:
                 raise oefmt(space.w_NotImplementedError,
                             "in lib_build_attr: op=%d", op)
diff --git a/pypy/module/_cffi_backend/realize_c_type.py 
b/pypy/module/_cffi_backend/realize_c_type.py
--- a/pypy/module/_cffi_backend/realize_c_type.py
+++ b/pypy/module/_cffi_backend/realize_c_type.py
@@ -1,4 +1,6 @@
-from rpython.rtyper.lltypesystem import rffi
+import sys
+from rpython.rlib.rarithmetic import intmask
+from rpython.rtyper.lltypesystem import lltype, rffi
 from pypy.interpreter.error import oefmt
 from pypy.interpreter.baseobjspace import W_Root
 from pypy.module._cffi_backend.ctypeobj import W_CType
@@ -85,13 +87,33 @@
     return newtype._new_array_type(ffi.space, w_ctitemptr, length)
 
 
+FUNCPTR_FETCH_LONGLONG = lltype.Ptr(lltype.FuncType([rffi.ULONGLONGP],
+                                                    rffi.INT))
+def realize_global_int(ffi, g):
+    fetch_fnptr = rffi.cast(FUNCPTR_FETCH_LONGLONG, g.c_address)
+    with lltype.scoped_alloc(rffi.ULONGLONGP.TO, 1) as p_value:
+        neg = fetch_fnptr(p_value)
+        value = p_value[0]
+    neg = rffi.cast(lltype.Signed, neg)
+
+    if neg == 0:     # positive
+        if value <= sys.maxint:
+            return ffi.space.wrap(intmask(value))
+        else:
+            return ffi.space.wrap(value)
+    elif neg == 1:   # negative
+        if value >= -sys.maxint-1:
+            return ffi.space.wrap(intmask(value))
+        else:
+            return ffi.space.wrap(rffi.cast(rffi.LONGLONG, value))
+    xxxx
+
+
 class W_RawFuncType(W_Root):
     """Temporary: represents a C function type (not a function pointer)"""
     def __init__(self, w_ctfuncptr):
         self.w_ctfuncptr = w_ctfuncptr
 
-
-
 def unwrap_fn_as_fnptr(x):
     assert isinstance(x, W_RawFuncType)
     return x.w_ctfuncptr
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to