[pypy-commit] cffi cffi-1.0: Add RTLD_xxx flags to the CompiledFFI type
arigo
noreply at buildbot.pypy.org
Sat May 16 22:10:42 CEST 2015
Author: Armin Rigo <arigo at tunes.org>
Branch: cffi-1.0
Changeset: r2017:81cf3d528d2c
Date: 2015-05-16 21:04 +0200
http://bitbucket.org/cffi/cffi/changeset/81cf3d528d2c/
Log: Add RTLD_xxx flags to the CompiledFFI type
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -5946,6 +5946,28 @@
convert_array_from_object,
};
+static struct { const char *name; int value; } all_dlopen_flags[] = {
+ { "RTLD_LAZY", RTLD_LAZY },
+ { "RTLD_NOW", RTLD_NOW },
+ { "RTLD_GLOBAL", RTLD_GLOBAL },
+#ifdef RTLD_LOCAL
+ { "RTLD_LOCAL", RTLD_LOCAL },
+#else
+ { "RTLD_LOCAL", 0 },
+#endif
+#ifdef RTLD_NODELETE
+ { "RTLD_NODELETE", RTLD_NODELETE },
+#endif
+#ifdef RTLD_NOLOAD
+ { "RTLD_NOLOAD", RTLD_NOLOAD },
+#endif
+#ifdef RTLD_DEEPBIND
+ { "RTLD_DEEPBIND", RTLD_DEEPBIND },
+#endif
+ { NULL, 0 }
+};
+
+
/************************************************************/
#include "cffi1_module.c"
@@ -5973,6 +5995,7 @@
#endif
{
PyObject *m, *v;
+ int i;
v = PySys_GetObject("version");
if (v == NULL || !PyText_Check(v) ||
@@ -6048,27 +6071,16 @@
PyModule_AddIntConstant(m, "_WIN", 32) < 0 || /* win32 */
# endif
#endif
-
- PyModule_AddIntConstant(m, "RTLD_LAZY", RTLD_LAZY) < 0 ||
- PyModule_AddIntConstant(m, "RTLD_NOW", RTLD_NOW) < 0 ||
- PyModule_AddIntConstant(m, "RTLD_GLOBAL", RTLD_GLOBAL) < 0 ||
-#ifdef RTLD_LOCAL
- PyModule_AddIntConstant(m, "RTLD_LOCAL", RTLD_LOCAL) < 0 ||
-#else
- PyModule_AddIntConstant(m, "RTLD_LOCAL", 0) < 0 ||
-#endif
-#ifdef RTLD_NODELETE
- PyModule_AddIntConstant(m, "RTLD_NODELETE", RTLD_NODELETE) < 0 ||
-#endif
-#ifdef RTLD_NOLOAD
- PyModule_AddIntConstant(m, "RTLD_NOLOAD", RTLD_NOLOAD) < 0 ||
-#endif
-#ifdef RTLD_DEEPBIND
- PyModule_AddIntConstant(m, "RTLD_DEEPBIND", RTLD_DEEPBIND) < 0 ||
-#endif
0)
INITERROR;
+ for (i = 0; all_dlopen_flags[i].name != NULL; i++) {
+ if (PyModule_AddIntConstant(m,
+ all_dlopen_flags[i].name,
+ all_dlopen_flags[i].value) < 0)
+ INITERROR;
+ }
+
init_errno();
if (init_ffi_lib(m) < 0)
diff --git a/c/cffi1_module.c b/c/cffi1_module.c
--- a/c/cffi1_module.c
+++ b/c/cffi1_module.c
@@ -18,6 +18,7 @@
static int init_ffi_lib(PyObject *m)
{
PyObject *x;
+ int i;
if (PyType_Ready(&FFI_Type) < 0)
return -1;
@@ -38,6 +39,15 @@
(PyObject *)&CData_Type) < 0)
return -1;
+ for (i = 0; all_dlopen_flags[i].name != NULL; i++) {
+ x = PyInt_FromLong(all_dlopen_flags[i].value);
+ if (x == NULL || PyDict_SetItemString(FFI_Type.tp_dict,
+ all_dlopen_flags[i].name,
+ x) < 0)
+ return -1;
+ Py_DECREF(x);
+ }
+
x = (PyObject *)&FFI_Type;
Py_INCREF(x);
if (PyModule_AddObject(m, "FFI", x) < 0)
diff --git a/testing/cffi1/test_re_python.py b/testing/cffi1/test_re_python.py
--- a/testing/cffi1/test_re_python.py
+++ b/testing/cffi1/test_re_python.py
@@ -131,3 +131,9 @@
assert p[0] == 1239
p[0] -= 1
assert lib.globalvar42 == 1238
+
+def test_rtld_constants():
+ from re_python_pysrc import ffi
+ ffi.RTLD_NOW # check that we have the attributes
+ ffi.RTLD_LAZY
+ ffi.RTLD_GLOBAL
More information about the pypy-commit
mailing list