[pypy-commit] creflect default: in-progress
arigo
noreply at buildbot.pypy.org
Sat Nov 29 22:32:48 CET 2014
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r125:10955dc30513
Date: 2014-11-29 22:12 +0100
http://bitbucket.org/cffi/creflect/changeset/10955dc30513/
Log: in-progress
diff --git a/zeffir/test/basic.crx b/zeffir/test/basic.crx
new file mode 100644
--- /dev/null
+++ b/zeffir/test/basic.crx
@@ -0,0 +1,9 @@
+#define forty_two 42
+
+
+
+// CREFLECT: start
+
+static const int forty_two;
+
+// CREFLECT: end
diff --git a/zeffir/test/test_basic.py b/zeffir/test/test_basic.py
new file mode 100644
--- /dev/null
+++ b/zeffir/test/test_basic.py
@@ -0,0 +1,34 @@
+import os, sys
+from udir import udir, include_dir
+
+def setup_module(mod):
+ zeffir_dir = os.path.join(os.path.dirname(__file__), '..')
+ zeffir_lib_path = str(udir.join('zeffir.so'))
+ err = os.system("cd '%s' && "
+ "gcc -g -I'%s' -Wall -Werror -fPIC -shared zeffir.c -o '%s'" %
+ (zeffir_dir, include_dir, zeffir_lib_path))
+ assert not err
+ #
+ sys.path.insert(0, str(udir))
+ global zeffir
+ import zeffir
+ #
+ basic_c_path = str(udir.join('basic.c'))
+ basic_lib_path = str(udir.join('libbasic.so'))
+ err = os.system("cd '%s'/test && "
+ "PYTHONPATH=../.. ../../bin/creflect basic.crx '%s' && "
+ "gcc -g -I../../creflect -fPIC -shared '%s' -o '%s'" %
+ (zeffir_dir, basic_c_path, basic_c_path, basic_lib_path))
+ assert not err
+ #
+ global ffi, lib
+ ffi, lib = zeffir.open('basic', relative_to=zeffir_lib_path)
+
+
+def test_ffi_type():
+ assert type(ffi).__module__ == 'zeffir'
+ assert type(ffi).__name__ == 'FFI'
+
+def test_forty_two():
+ assert lib.forty_two == 42
+ assert type(lib.forty_two) is int
diff --git a/zeffir/test/udir.py b/zeffir/test/udir.py
new file mode 100644
--- /dev/null
+++ b/zeffir/test/udir.py
@@ -0,0 +1,5 @@
+import py
+import sysconfig
+
+udir = py.path.local.make_numbered_dir(prefix = 'zeffir-')
+include_dir = sysconfig.get_config_var('INCLUDEPY')
diff --git a/zeffir/zeffir.c b/zeffir/zeffir.c
--- a/zeffir/zeffir.c
+++ b/zeffir/zeffir.c
@@ -6,10 +6,48 @@
/************************************************************/
typedef struct {
- Py_OBJECT_HEAD
- PyObject *libname;
+ PyObject_HEAD
+ char *libname;
} PyFFIObject;
+static void ffi_dealloc(PyFFIObject *ffi)
+{
+ free(ffi->libname);
+ PyObject_Del(ffi);
+}
+
+static PyTypeObject FFI_Type = {
+ PyVarObject_HEAD_INIT(NULL, 0)
+ "zeffir.FFI",
+ sizeof(PyFFIObject),
+ 0,
+ (destructor)ffi_dealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ PyObject_GenericGetAttr, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ 0, /* tp_methods */
+ 0, /* tp_members */
+};
+
/************************************************************/
static PyObject *b_open(PyObject *self, PyObject *args, PyObject *kwds)
@@ -24,8 +62,11 @@
PyFFIObject *ffi = PyObject_New(PyFFIObject, &FFI_Type);
if (ffi == NULL)
return NULL;
+ ffi->libname = strdup(libname);
- return Py_BuildValue("OO", ffi, Py_None);
+ PyObject *result = Py_BuildValue("OO", ffi, Py_None);
+ Py_DECREF(ffi);
+ return result;
}
@@ -41,4 +82,6 @@
m = Py_InitModule("zeffir", ZeffirMethods);
(void)m;
+
+ PyType_Ready(&FFI_Type);
}
More information about the pypy-commit
mailing list