|
@@ -2,7 +2,7 @@
|
|
|
#include <Python.h>
|
|
|
#include "structmember.h"
|
|
|
|
|
|
-#define CFFI_VERSION "1.16.0"
|
|
|
+#define CFFI_VERSION "1.17.0"
|
|
|
|
|
|
#ifdef MS_WIN32
|
|
|
#include <windows.h>
|
|
@@ -53,11 +53,15 @@
|
|
|
# if _MSC_VER < 1800 /* MSVC < 2013 */
|
|
|
typedef unsigned char _Bool;
|
|
|
# endif
|
|
|
+# define _cffi_float_complex_t _Fcomplex /* include <complex.h> for it */
|
|
|
+# define _cffi_double_complex_t _Dcomplex /* include <complex.h> for it */
|
|
|
#else
|
|
|
# include <stdint.h>
|
|
|
# if (defined (__SVR4) && defined (__sun)) || defined(_AIX) || defined(__hpux)
|
|
|
# include <alloca.h>
|
|
|
# endif
|
|
|
+# define _cffi_float_complex_t float _Complex
|
|
|
+# define _cffi_double_complex_t double _Complex
|
|
|
#endif
|
|
|
|
|
|
/* Convert from closure pointer to function pointer. */
|
|
@@ -112,6 +116,15 @@
|
|
|
# define CFFI_CHECK_FFI_PREP_CIF_VAR __builtin_available(macos 10.15, ios 13, watchos 6, tvos 13, *)
|
|
|
# define CFFI_CHECK_FFI_PREP_CIF_VAR_MAYBE 1
|
|
|
|
|
|
+#elif defined(__EMSCRIPTEN__)
|
|
|
+
|
|
|
+# define CFFI_CHECK_FFI_CLOSURE_ALLOC 1
|
|
|
+# define CFFI_CHECK_FFI_CLOSURE_ALLOC_MAYBE 1
|
|
|
+# define CFFI_CHECK_FFI_PREP_CLOSURE_LOC 1
|
|
|
+# define CFFI_CHECK_FFI_PREP_CLOSURE_LOC_MAYBE 1
|
|
|
+# define CFFI_CHECK_FFI_PREP_CIF_VAR 1
|
|
|
+# define CFFI_CHECK_FFI_PREP_CIF_VAR_MAYBE 1
|
|
|
+
|
|
|
#else
|
|
|
|
|
|
# define CFFI_CHECK_FFI_CLOSURE_ALLOC 0
|
|
@@ -134,8 +147,8 @@
|
|
|
# define PyText_Check PyUnicode_Check
|
|
|
# define PyTextAny_Check PyUnicode_Check
|
|
|
# define PyText_FromFormat PyUnicode_FromFormat
|
|
|
-# define PyText_AsUTF8 _PyUnicode_AsString /* PyUnicode_AsUTF8 in Py3.3 */
|
|
|
-# define PyText_AS_UTF8 _PyUnicode_AsString
|
|
|
+# define PyText_AsUTF8 PyUnicode_AsUTF8
|
|
|
+# define PyText_AS_UTF8 PyUnicode_AsUTF8
|
|
|
# if PY_VERSION_HEX >= 0x03030000
|
|
|
# define PyText_GetSize PyUnicode_GetLength
|
|
|
# else
|
|
@@ -1612,6 +1625,8 @@ convert_struct_from_object(char *data, CTypeDescrObject *ct, PyObject *init,
|
|
|
return _convert_error(init, ct, expected);
|
|
|
}
|
|
|
|
|
|
+static PyObject* try_extract_directfnptr(PyObject *x); /* forward */
|
|
|
+
|
|
|
#ifdef __GNUC__
|
|
|
# if __GNUC__ >= 4
|
|
|
/* Don't go inlining this huge function. Needed because occasionally
|
|
@@ -1639,9 +1654,18 @@ convert_from_object(char *data, CTypeDescrObject *ct, PyObject *init)
|
|
|
CTypeDescrObject *ctinit;
|
|
|
|
|
|
if (!CData_Check(init)) {
|
|
|
- expected = "cdata pointer";
|
|
|
- goto cannot_convert;
|
|
|
+ PyObject *func_cdata = try_extract_directfnptr(init);
|
|
|
+ if (func_cdata != NULL && CData_Check(func_cdata)) {
|
|
|
+ init = func_cdata;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if (PyErr_Occurred())
|
|
|
+ return -1;
|
|
|
+ expected = "cdata pointer";
|
|
|
+ goto cannot_convert;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
ctinit = ((CDataObject *)init)->c_type;
|
|
|
if (!(ctinit->ct_flags & (CT_POINTER|CT_FUNCTIONPTR))) {
|
|
|
if (ctinit->ct_flags & CT_ARRAY)
|
|
@@ -2445,7 +2469,11 @@ static Py_hash_t cdata_hash(PyObject *v)
|
|
|
}
|
|
|
Py_DECREF(vv);
|
|
|
}
|
|
|
+#if PY_VERSION_HEX < 0x030D0000
|
|
|
return _Py_HashPointer(((CDataObject *)v)->c_data);
|
|
|
+#else
|
|
|
+ return Py_HashPointer(((CDataObject *)v)->c_data);
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
static Py_ssize_t
|
|
@@ -4080,10 +4108,20 @@ static CDataObject *cast_to_integer_or_char(CTypeDescrObject *ct, PyObject *ob)
|
|
|
value = res;
|
|
|
}
|
|
|
else {
|
|
|
+ if (PyCFunction_Check(ob)) {
|
|
|
+ PyObject *func_cdata = try_extract_directfnptr(ob);
|
|
|
+ if (func_cdata != NULL && CData_Check(func_cdata)) {
|
|
|
+ value = (Py_intptr_t)((CDataObject *)func_cdata)->c_data;
|
|
|
+ goto got_value;
|
|
|
+ }
|
|
|
+ if (PyErr_Occurred())
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
value = _my_PyLong_AsUnsignedLongLong(ob, 0);
|
|
|
if (value == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())
|
|
|
return NULL;
|
|
|
}
|
|
|
+ got_value:
|
|
|
if (ct->ct_flags & CT_IS_BOOL)
|
|
|
value = !!value;
|
|
|
cd = _new_casted_primitive(ct);
|
|
@@ -4140,6 +4178,15 @@ static PyObject *do_cast(CTypeDescrObject *ct, PyObject *ob)
|
|
|
return new_simple_cdata(cdsrc->c_data, ct);
|
|
|
}
|
|
|
}
|
|
|
+ if (PyCFunction_Check(ob)) {
|
|
|
+ PyObject *func_cdata = try_extract_directfnptr(ob);
|
|
|
+ if (func_cdata != NULL && CData_Check(func_cdata)) {
|
|
|
+ char *ptr = ((CDataObject *)func_cdata)->c_data;
|
|
|
+ return new_simple_cdata(ptr, ct);
|
|
|
+ }
|
|
|
+ if (PyErr_Occurred())
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
if ((ct->ct_flags & CT_POINTER) &&
|
|
|
(ct->ct_itemdescr->ct_flags & CT_IS_FILE) &&
|
|
|
PyFile_Check(ob)) {
|
|
@@ -4522,7 +4569,7 @@ static void *b_do_dlopen(PyObject *args, const char **p_printable_filename,
|
|
|
if (sz1 < 0)
|
|
|
return NULL;
|
|
|
w1[sz1] = 0;
|
|
|
- handle = dlopenW(w1);
|
|
|
+ handle = dlopenWinW(w1, flags);
|
|
|
goto got_handle;
|
|
|
}
|
|
|
PyErr_Clear();
|
|
@@ -6117,7 +6164,11 @@ static void _my_PyErr_WriteUnraisable(PyObject *t, PyObject *v, PyObject *tb,
|
|
|
|
|
|
PyErr_Restore(t, v, tb);
|
|
|
if (s != NULL) {
|
|
|
+#if PY_VERSION_HEX >= 0x030D0000
|
|
|
+ PyErr_FormatUnraisable("Exception ignored %S", s);
|
|
|
+#else
|
|
|
_PyErr_WriteUnraisableMsg(PyText_AS_UTF8(s), NULL);
|
|
|
+#endif
|
|
|
Py_DECREF(s);
|
|
|
}
|
|
|
else
|