Author: Armin Rigo <[email protected]>
Branch: static-callback
Changeset: r2387:9f653200584c
Date: 2015-11-13 15:55 +0100
http://bitbucket.org/cffi/cffi/changeset/9f653200584c/

Log:    in-progress

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -6306,6 +6306,9 @@
 }
 #endif
 
+struct _cffi_callpy_s;      /* forward declaration */
+static void _cffi_call_python(struct _cffi_callpy_s *callpy, char *args);
+
 static void *cffi_exports[] = {
     NULL,
     _cffi_to_c_i8,
@@ -6337,6 +6340,7 @@
     _cffi_to_c__Bool,
     _prepare_pointer_call_argument,
     convert_array_from_object,
+    _cffi_call_python,
 };
 
 static struct { const char *name; int value; } all_dlopen_flags[] = {
diff --git a/c/call_python.c b/c/call_python.c
new file mode 100644
--- /dev/null
+++ b/c/call_python.c
@@ -0,0 +1,6 @@
+
+
+static void _cffi_call_python(struct _cffi_callpy_s *callpy, char *args)
+{
+    abort();
+}
diff --git a/c/cffi1_module.c b/c/cffi1_module.c
--- a/c/cffi1_module.c
+++ b/c/cffi1_module.c
@@ -16,6 +16,7 @@
 #include "lib_obj.c"
 #include "cdlopen.c"
 #include "commontypes.c"
+#include "call_python.c"
 
 
 static int init_ffi_lib(PyObject *m)
@@ -149,7 +150,7 @@
     PyObject *m, *modules_dict;
     FFIObject *ffi;
     LibObject *lib;
-    Py_ssize_t version;
+    Py_ssize_t version, num_exports;
     char *module_name, *exports, *module_name_with_lib;
     void **raw;
     const struct _cffi_type_context_s *ctx;
@@ -172,7 +173,10 @@
     }
 
     /* initialize the exports array */
-    memcpy(exports, (char *)cffi_exports, sizeof(cffi_exports));
+    num_exports = 25;
+    if (ctx->flags & 1)    /* set to mean "uses _cffi_call_python" */
+        num_exports = 26;
+    memcpy(exports, (char *)cffi_exports, num_exports * sizeof(void *));
 
     /* make the module object */
     m = _my_Py_InitModule(module_name);
diff --git a/c/lib_obj.c b/c/lib_obj.c
--- a/c/lib_obj.c
+++ b/c/lib_obj.c
@@ -370,7 +370,7 @@
                             _CFFI_GETARG(g->type_op));
         if (ct == NULL)
             return NULL;
-        x = convert_to_object(g->address, ct);
+        x = convert_to_object((char *)&g->size_or_direct_fn, ct);
         Py_DECREF(ct);
         break;
 
diff --git a/cffi/recompiler.py b/cffi/recompiler.py
--- a/cffi/recompiler.py
+++ b/cffi/recompiler.py
@@ -118,6 +118,7 @@
 
 
 class Recompiler:
+    _num_callpy = 0
 
     def __init__(self, ffi, module_name, target_is_python=False):
         self.ffi = ffi
@@ -356,7 +357,10 @@
         else:
             prnt('  NULL,  /* no includes */')
         prnt('  %d,  /* num_types */' % (len(self.cffi_types),))
-        prnt('  0,  /* flags */')
+        flags = 0
+        if self._num_callpy:
+            flags |= 1     # set to mean "uses _cffi_call_python"
+        prnt('  %d,  /* flags */' % flags)
         prnt('};')
         prnt()
         #
@@ -1159,6 +1163,7 @@
             prnt('  return *(%s)p;' % (tp.result.get_c_name('*'),))
         prnt('}')
         prnt()
+        self._num_callpy += 1
 
     def _generate_cpy_call_python_ctx(self, tp, name):
         if self.target_is_python:
@@ -1169,7 +1174,7 @@
         type_index = self._typesdict[tp]
         type_op = CffiOp(OP_CALL_PYTHON, type_index)
         self._lsts["global"].append(
-            GlobalExpr(name, name, type_op, '&_cffi_callpy__%s' % name))
+            GlobalExpr(name, '&_cffi_callpy__%s' % name, type_op, name))
 
     # ----------
     # emitting the opcodes for individual types
diff --git a/testing/cffi1/test_recompiler.py b/testing/cffi1/test_recompiler.py
--- a/testing/cffi1/test_recompiler.py
+++ b/testing/cffi1/test_recompiler.py
@@ -1495,6 +1495,7 @@
     """)
     lib = verify(ffi, 'test_call_python_1', "")
     assert ffi.typeof(lib.bar) == ffi.typeof("int(*)(int, int)")
+    lib.bar(4, 5)
     XXX
 
 def test_call_python_2():
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to