[pypy-commit] cffi cffi-1.0: Rename "_cffi_backend.so" to "_cffi1_backend.so" to avoid confusion with

arigo noreply at buildbot.pypy.org
Tue Apr 14 15:54:34 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: cffi-1.0
Changeset: r1700:5694f0b6aee0
Date: 2015-04-14 15:54 +0200
http://bitbucket.org/cffi/cffi/changeset/5694f0b6aee0/

Log:	Rename "_cffi_backend.so" to "_cffi1_backend.so" to avoid confusion
	with old versions of cffi.

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -5272,12 +5272,6 @@
     return NULL;
 }
 
-static PyObject *b__get_types(PyObject *self, PyObject *noarg)
-{
-    return PyTuple_Pack(2, (PyObject *)&CData_Type,
-                           (PyObject *)&CTypeDescr_Type);
-}
-
 /************************************************************/
 
 static char _testfunc0(char a, char b)
@@ -5582,7 +5576,6 @@
 #ifdef MS_WIN32
     {"getwinerror", b_getwinerror, METH_VARARGS},
 #endif
-    {"_get_types", b__get_types, METH_NOARGS},
     {"_testfunc", b__testfunc, METH_VARARGS},
     {"_testbuff", b__testbuff, METH_VARARGS},
     {NULL,     NULL}    /* Sentinel */
@@ -5738,7 +5731,7 @@
 #if PY_MAJOR_VERSION >= 3
 static struct PyModuleDef FFIBackendModuleDef = {
   PyModuleDef_HEAD_INIT,
-  "_cffi_backend",
+  "_cffi1_backend",
   NULL,
   -1,
   FFIBackendMethods,
@@ -5752,7 +5745,7 @@
 #define INITERROR return
 
 PyMODINIT_FUNC
-init_cffi_backend(void)
+init_cffi1_backend(void)
 #endif
 {
     PyObject *m, *v;
@@ -5769,7 +5762,7 @@
 #if PY_MAJOR_VERSION >= 3
     m = PyModule_Create(&FFIBackendModuleDef);
 #else
-    m = Py_InitModule("_cffi_backend", FFIBackendMethods);
+    m = Py_InitModule("_cffi1_backend", FFIBackendMethods);
 #endif
 
     if (m == NULL)
@@ -5848,6 +5841,9 @@
 
     init_errno();
 
+    if (init_ffi_lib(m) < 0)
+        INITERROR;
+
 #if PY_MAJOR_VERSION >= 3
     if (init_file_emulator() < 0)
         INITERROR;
diff --git a/new/_cffi_include.h b/new/_cffi_include.h
--- a/new/_cffi_include.h
+++ b/new/_cffi_include.h
@@ -161,7 +161,7 @@
     PyObject *module, *c_api_object = NULL;
     void *src;
 
-    module = PyImport_ImportModule("_cffi_backend");
+    module = PyImport_ImportModule("_cffi1_backend");
     if (module == NULL)
         goto failure;
 
@@ -175,7 +175,7 @@
     src = PyCapsule_GetPointer(c_api_object, "cffi");
     if ((uintptr_t)(((void **)src)[0]) < _CFFI_NUM_EXPORTS) {
         PyErr_SetString(PyExc_ImportError,
-                        "the _cffi_backend module is an outdated version");
+                        "the _cffi1_backend module is an outdated version");
         goto failure;
     }
     memcpy(_cffi_exports, src, _CFFI_NUM_EXPORTS * sizeof(void *));
diff --git a/new/cffi1_module.c b/new/cffi1_module.c
--- a/new/cffi1_module.c
+++ b/new/cffi1_module.c
@@ -13,12 +13,8 @@
 //#include "lib_obj.c"
 
 
-static int init_ffi_lib(void)
+static int init_ffi_lib(PyObject *m)
 {
-    static int ffi_lib_ok = 0;
-    if (ffi_lib_ok)
-        return 0;
-
     if (!PyType_Ready(&FFI_Type) < 0)
         return -1;
     if (!PyType_Ready(&Lib_Type) < 0)
@@ -30,16 +26,16 @@
     if (PyDict_SetItemString(FFI_Type.tp_dict, "error", FFIError) < 0)
         return -1;
 
-    ffi_lib_ok = 1;
+    Py_INCREF(&FFI_Type);
+    if (PyModule_AddObject(m, "FFI", (PyObject *)&FFI_Type) < 0)
+        return -1;
+
     return 0;
 }
 
 static int _cffi_init_module(char *module_name,
                              const struct _cffi_type_context_s *ctx)
 {
-    if (init_ffi_lib() < 0)
-        return -1;
-
     PyObject *m = Py_InitModule(module_name, NULL);
     if (m == NULL)
         return -1;
diff --git a/new/ffi_obj.c b/new/ffi_obj.c
--- a/new/ffi_obj.c
+++ b/new/ffi_obj.c
@@ -65,9 +65,13 @@
 static PyObject *ffiobj_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
     /* user-facing initialization code, for explicit FFI() calls */
-    /* XXX LATER */
-    PyErr_SetString(PyExc_NotImplementedError, "FFI()");
-    return NULL;
+    static const struct _cffi_type_context_s empty_ctx = { 0 };
+
+    char *keywords[] = {NULL};
+    if (!PyArg_ParseTupleAndKeywords(args, kwds, ":FFI", keywords))
+        return NULL;
+
+    return (PyObject *)ffi_internal_new(&empty_ctx);
 }
 
 #define ACCEPT_STRING   1
diff --git a/new/test_realize_c_type.py b/new/test_realize_c_type.py
--- a/new/test_realize_c_type.py
+++ b/new/test_realize_c_type.py
@@ -1,15 +1,16 @@
-import os
 
-def setup_module():
-    err = os.system("python setup.py build_ext -i")
-    if err != 0:
-        raise Exception(err)
-    global realize_c_type
-    import realize_c_type
 
+def check(input, expected_output=None):
+    import _cffi1_backend
+    ffi = _cffi1_backend.FFI()
+    ct = ffi.typeof(input)
+    assert isinstance(ct, ffi.CType)
+    assert ct.cname == (expected_output or input)
 
 def test_void():
-    assert realize_c_type.test("void") == "VOID"
+    check("void", "void")
+    check("  void  ", "void")
 
 def test_int_star():
-    assert realize_c_type.test("int *") == ("pointer", "INT")
+    check("int")
+    check("int *")
diff --git a/setup_base.py b/setup_base.py
--- a/setup_base.py
+++ b/setup_base.py
@@ -9,9 +9,7 @@
     from distutils.core import setup
     from distutils.extension import Extension
     standard = '__pypy__' not in sys.modules
-    setup(packages=['cffi'],
-          requires=['pycparser'],
-          ext_modules=[Extension(name = '_cffi_backend',
+    setup(ext_modules=[Extension(name = '_cffi1_backend',
                                  include_dirs=include_dirs,
                                  sources=sources,
                                  libraries=libraries,


More information about the pypy-commit mailing list