Merge branch 'cython' into 'master'

Cython enhancements

See merge request ita1024/waf!2196
This commit is contained in:
ita1024 2018-12-29 10:11:19 +00:00
commit e68dc88857
7 changed files with 4556 additions and 1713 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,5 @@
/* Generated by Cython 0.29 */
#ifndef __PYX_HAVE__cy_cxxtest
#define __PYX_HAVE__cy_cxxtest
@ -12,10 +14,17 @@
#endif
#endif
__PYX_EXTERN_C DL_IMPORT(void) cy_hello(void);
#ifndef DL_IMPORT
#define DL_IMPORT(_T) _T
#endif
__PYX_EXTERN_C void cy_hello(void);
#endif /* !__PYX_HAVE_API__cy_cxxtest */
/* WARNING: the interface of the module init function changed in CPython 3.5. */
/* It now returns a PyModuleDef instance instead of a PyModule instance. */
#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC initcy_cxxtest(void);
#else

View File

@ -1,31 +1,18 @@
/* Generated by Cython 0.29 */
#ifndef __PYX_HAVE_API__cy_cxxtest
#define __PYX_HAVE_API__cy_cxxtest
#include "Python.h"
#include "cy_cxxtest.h"
static void (*__pyx_f_10cy_cxxtest_cy_hello)(void) = 0;
#define cy_hello __pyx_f_10cy_cxxtest_cy_hello
#ifndef __PYX_HAVE_RT_ImportModule
#define __PYX_HAVE_RT_ImportModule
static PyObject *__Pyx_ImportModule(const char *name) {
PyObject *py_name = 0;
PyObject *py_module = 0;
#if PY_MAJOR_VERSION < 3
py_name = PyString_FromString(name);
#else
py_name = PyUnicode_FromString(name);
#endif
if (!py_name)
goto bad;
py_module = PyImport_Import(py_name);
Py_DECREF(py_name);
return py_module;
bad:
Py_XDECREF(py_name);
return 0;
}
static void (*__pyx_api_f_10cy_cxxtest_cy_hello)(void) = 0;
#define cy_hello __pyx_api_f_10cy_cxxtest_cy_hello
#if !defined(__Pyx_PyIdentifier_FromString)
#if PY_MAJOR_VERSION < 3
#define __Pyx_PyIdentifier_FromString(s) PyString_FromString(s)
#else
#define __Pyx_PyIdentifier_FromString(s) PyUnicode_FromString(s)
#endif
#endif
#ifndef __PYX_HAVE_RT_ImportFunction
@ -37,21 +24,20 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**
void (*fp)(void);
void *p;
} tmp;
d = PyObject_GetAttrString(module, (char *)"__pyx_capi__");
if (!d)
goto bad;
cobj = PyDict_GetItemString(d, funcname);
if (!cobj) {
PyErr_Format(PyExc_ImportError,
"%s does not export expected C function %s",
"%.200s does not export expected C function %.200s",
PyModule_GetName(module), funcname);
goto bad;
}
#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
#if PY_VERSION_HEX >= 0x02070000
if (!PyCapsule_IsValid(cobj, sig)) {
PyErr_Format(PyExc_TypeError,
"C function %s.%s has wrong signature (expected %s, got %s)",
"C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
PyModule_GetName(module), funcname, sig, PyCapsule_GetName(cobj));
goto bad;
}
@ -65,7 +51,7 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**
while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; }
if (*s1 != *s2) {
PyErr_Format(PyExc_TypeError,
"C function %s.%s has wrong signature (expected %s, got %s)",
"C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
PyModule_GetName(module), funcname, sig, desc);
goto bad;
}
@ -82,11 +68,12 @@ bad:
}
#endif
static int import_cy_cxxtest(void) {
PyObject *module = 0;
module = __Pyx_ImportModule("cy_cxxtest");
module = PyImport_ImportModule("cy_cxxtest");
if (!module) goto bad;
if (__Pyx_ImportFunction(module, "cy_hello", (void (**)(void))&__pyx_f_10cy_cxxtest_cy_hello, "void (void)") < 0) goto bad;
if (__Pyx_ImportFunction(module, "cy_hello", (void (**)(void))&__pyx_api_f_10cy_cxxtest_cy_hello, "void (void)") < 0) goto bad;
Py_DECREF(module); module = 0;
return 0;
bad:

View File

@ -1,4 +1,7 @@
from cpython.version cimport PY_VERSION
cimport cy_ctest
#cimport commented_import
def pyhello():
cy_ctest.hello()
print("Compiled with python version %s" % PY_VERSION)

View File

@ -1,8 +1,9 @@
from cpython.version cimport PY_VERSION
cimport cy_cxxtest
def pyhello():
cy_cxxtest.hello()
print("Compiled with python version %s" % PY_VERSION)
cdef public api void cy_hello():
print("hello cython-world!")

View File

@ -8,8 +8,9 @@ from waflib.TaskGen import extension
cy_api_pat = re.compile(r'\s*?cdef\s*?(public|api)\w*')
re_cyt = re.compile(r"""
(?:from\s+(\w+)\s+)? # optionally match "from foo" and capture foo
c?import\s(\w+|[*]) # require "import bar" and capture bar
^\s* # must begin with some whitespace characters
(?:from\s+(\w+)(?:\.\w+)*\s+)? # optionally match "from foo(.baz)" and capture foo
c?import\s(\w+|[*]) # require "import bar" and capture bar
""", re.M | re.VERBOSE)
@extension('.pyx')
@ -85,12 +86,12 @@ class cython(Task.Task):
node = self.inputs[0]
txt = node.read()
mods = []
mods = set()
for m in re_cyt.finditer(txt):
if m.group(1): # matches "from foo import bar"
mods.append(m.group(1))
mods.add(m.group(1))
else:
mods.append(m.group(2))
mods.add(m.group(2))
Logs.debug('cython: mods %r', mods)
incs = getattr(self.generator, 'cython_includes', [])
@ -99,7 +100,7 @@ class cython(Task.Task):
found = []
missing = []
for x in mods:
for x in sorted(mods):
for y in incs:
k = y.find_resource(x + '.pxd')
if k: