Author: Armin Rigo <[email protected]>
Branch: cffi-1.0
Changeset: r1898:f12a2d9ca1f8
Date: 2015-04-30 17:52 +0200
http://bitbucket.org/cffi/cffi/changeset/f12a2d9ca1f8/
Log: Prepare for the PyPy version: we want to make a similar C extension
module, but one which happens to use none of the Py* API and defines
a different entry point.
diff --git a/_cffi1/_cffi_include.h b/_cffi1/_cffi_include.h
--- a/_cffi1/_cffi_include.h
+++ b/_cffi1/_cffi_include.h
@@ -46,6 +46,11 @@
# endif
#endif
+
+/********** CPython-specific section **********/
+#ifndef PYPY_VERSION
+
+
#if PY_MAJOR_VERSION < 3
# undef PyCapsule_CheckExact
# undef PyCapsule_GetPointer
@@ -68,15 +73,6 @@
#define _cffi_to_c_double PyFloat_AsDouble
#define _cffi_to_c_float PyFloat_AsDouble
-#define _cffi_from_c_int_const(x) \
- (((x) > 0) ? \
- ((unsigned long long)(x) <= (unsigned long long)LONG_MAX) ? \
- PyInt_FromLong((long)(x)) : \
- PyLong_FromUnsignedLongLong((unsigned long long)(x)) : \
- ((long long)(x) >= (long long)LONG_MIN) ? \
- PyInt_FromLong((long)(x)) : \
- PyLong_FromLongLong((long long)(x)))
-
#define _cffi_from_c_int(x, type) \
(((type)-1) > 0 ? /* unsigned */ \
(sizeof(type) < sizeof(long) ? \
@@ -122,7 +118,7 @@
#define _cffi_to_c_pointer \
((char *(*)(PyObject *, CTypeDescrObject *))_cffi_exports[11])
#define _cffi_get_struct_layout \
- ((PyObject *(*)(Py_ssize_t[]))_cffi_exports[12])
+ not used any more
#define _cffi_restore_errno \
((void(*)(void))_cffi_exports[13])
#define _cffi_save_errno \
@@ -160,28 +156,6 @@
assert((((uintptr_t)_cffi_types[index]) & 1) == 0), \
(CTypeDescrObject *)_cffi_types[index])
-#define _cffi_array_len(array) (sizeof(array) / sizeof((array)[0]))
-
-#define _cffi_prim_int(size, sign) \
- ((size) == sizeof(int) ? ((sign) ? _CFFI_PRIM_INT : _CFFI_PRIM_UINT) :
\
- (size) == sizeof(long)? ((sign) ? _CFFI_PRIM_LONG : _CFFI_PRIM_ULONG) :
\
- (size) == 1 ? ((sign) ? _CFFI_PRIM_INT8 : _CFFI_PRIM_UINT8) :
\
- (size) == 2 ? ((sign) ? _CFFI_PRIM_INT16 : _CFFI_PRIM_UINT16) :
\
- (size) == 4 ? ((sign) ? _CFFI_PRIM_INT32 : _CFFI_PRIM_UINT32) :
\
- (size) == 8 ? ((sign) ? _CFFI_PRIM_INT64 : _CFFI_PRIM_UINT64) :
\
- 0)
-
-#define _cffi_check_int(got, got_nonpos, expected) \
- ((got_nonpos) == (expected <= 0) && \
- (got) == (unsigned long long)expected)
-
-#ifdef __GNUC__
-# define _CFFI_UNUSED_FN __attribute__((unused))
-#else
-# define _CFFI_UNUSED_FN /* nothing */
-#endif
-
-
static int _cffi_init(void)
{
PyObject *module, *c_api_object = NULL;
@@ -215,3 +189,29 @@
Py_XDECREF(c_api_object);
return -1;
}
+
+
+#endif
+/********** end CPython-specific section **********/
+
+
+#define _cffi_array_len(array) (sizeof(array) / sizeof((array)[0]))
+
+#define _cffi_prim_int(size, sign) \
+ ((size) == sizeof(int) ? ((sign) ? _CFFI_PRIM_INT : _CFFI_PRIM_UINT) :
\
+ (size) == sizeof(long)? ((sign) ? _CFFI_PRIM_LONG : _CFFI_PRIM_ULONG) :
\
+ (size) == 1 ? ((sign) ? _CFFI_PRIM_INT8 : _CFFI_PRIM_UINT8) :
\
+ (size) == 2 ? ((sign) ? _CFFI_PRIM_INT16 : _CFFI_PRIM_UINT16) :
\
+ (size) == 4 ? ((sign) ? _CFFI_PRIM_INT32 : _CFFI_PRIM_UINT32) :
\
+ (size) == 8 ? ((sign) ? _CFFI_PRIM_INT64 : _CFFI_PRIM_UINT64) :
\
+ 0)
+
+#define _cffi_check_int(got, got_nonpos, expected) \
+ ((got_nonpos) == (expected <= 0) && \
+ (got) == (unsigned long long)expected)
+
+#ifdef __GNUC__
+# define _CFFI_UNUSED_FN __attribute__((unused))
+#else
+# define _CFFI_UNUSED_FN /* nothing */
+#endif
diff --git a/_cffi1/manual.c b/_cffi1/manual.c
--- a/_cffi1/manual.c
+++ b/_cffi1/manual.c
@@ -32,6 +32,7 @@
_CFFI_OP(_CFFI_OP_STRUCT_UNION, 0),
};
+#ifndef PYPY_VERSION
static PyObject *
_cffi_f_foo42(PyObject *self, PyObject *args)
{
@@ -68,7 +69,14 @@
return _cffi_from_c_int(result, int);
}
+#else
+static int _cffi_f_foo42(int x0, int *x1)
+{
+ return foo42(x0, x1);
+}
+#endif
+#ifndef PYPY_VERSION
static PyObject *
_cffi_f_foo64(PyObject *self, PyObject *arg0)
{
@@ -87,6 +95,12 @@
return _cffi_from_c_int(result, int);
}
+#else
+static int _cffi_f_foo64(int x0)
+{
+ return foo64(x0);
+}
+#endif
static int _cffi_const_AA(unsigned long long *output)
{
@@ -134,6 +148,7 @@
0,
};
+#ifndef PYPY_VERSION
PyMODINIT_FUNC
initmanual(void)
{
@@ -142,3 +157,10 @@
_cffi_init_module("manual", &_cffi_type_context);
}
+#else
+PyMODINIT_FUNC
+_cffi_pypyinit_manual(const struct _cffi_type_context_s **p)
+{
+ *p = &_cffi_type_context;
+}
+#endif
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit