Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
5bafe5c3
Commit
5bafe5c3
authored
Oct 18, 2007
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix C API namespace pollution
parent
06ed8931
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
6 deletions
+27
-6
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+25
-6
Cython/Compiler/Naming.py
Cython/Compiler/Naming.py
+2
-0
No files found.
Cython/Compiler/ModuleNode.py
View file @
5bafe5c3
...
...
@@ -1732,18 +1732,31 @@ function_export_utility_code = [
static int __Pyx_ExportFunction(char *n, void *f, char *s); /*proto*/
"""
,
r"""
static int __Pyx_ExportFunction(char *n, void *f, char *s) {
PyObject *d = 0;
PyObject *p = 0;
d = PyObject_GetAttrString(%(MODULE)s, "%(API)s");
if (!d) {
PyErr_Clear();
d = PyDict_New();
if (!d)
goto bad;
Py_INCREF(d);
if (PyModule_AddObject(%(MODULE)s, "%(API)s", d) < 0)
goto bad;
}
p = PyCObject_FromVoidPtrAndDesc(f, s, 0);
if (!p)
goto bad;
if (Py
Module_AddObject(%(MODULE)s
, n, p) < 0)
if (Py
Dict_SetItemString(d
, n, p) < 0)
goto bad;
Py_DECREF(d);
return 0;
bad:
Py_XDECREF(p);
Py_XDECREF(d);
return -1;
}
"""
%
{
'MODULE'
:
Naming
.
module_cname
}]
"""
%
{
'MODULE'
:
Naming
.
module_cname
,
'API'
:
Naming
.
api_name
}]
#------------------------------------------------------------------------------------
...
...
@@ -1752,13 +1765,17 @@ function_import_utility_code = [
static int __Pyx_ImportFunction(PyObject *module, char *funcname, void **f, char *sig); /*proto*/
"""
,
"""
static int __Pyx_ImportFunction(PyObject *module, char *funcname, void **f, char *sig) {
PyObject *d = 0;
PyObject *cobj = 0;
char *desc;
cobj = PyObject_GetAttrString(module, funcname);
d = PyObject_GetAttrString(module, "%(API)s");
if (!d)
goto bad;
cobj = PyDict_GetItemString(d, funcname);
if (!cobj) {
PyErr_Format(PyExc_ImportError,
"%
s does not export expected C function
%s",
"%
%s does not export expected C function %
%s",
PyModule_GetName(module), funcname);
goto bad;
}
...
...
@@ -1767,15 +1784,17 @@ static int __Pyx_ImportFunction(PyObject *module, char *funcname, void **f, char
goto bad;
if (strcmp(desc, sig) != 0) {
PyErr_Format(PyExc_TypeError,
"C function %
s.%s has wrong signature (expected %s, got
%s)",
"C function %
%s.%%s has wrong signature (expected %%s, got %
%s)",
PyModule_GetName(module), funcname, sig, desc);
goto bad;
}
*f = PyCObject_AsVoidPtr(cobj);
Py_DECREF(cobj);
Py_DECREF(d);
return 0;
bad:
Py_XDECREF(cobj);
Py_XDECREF(d);
return -1;
}
"""
]
"""
%
dict
(
API
=
Naming
.
api_name
)
]
Cython/Compiler/Naming.py
View file @
5bafe5c3
...
...
@@ -67,6 +67,8 @@ exc_lineno_name = pyrex_prefix + "exc_lineno"
exc_vars
=
(
exc_type_name
,
exc_value_name
,
exc_tb_name
)
api_name
=
pyrex_prefix
+
"capi__"
h_guard_prefix
=
"__PYX_HAVE__"
api_guard_prefix
=
"__PYX_HAVE_API__"
api_func_guard
=
"__PYX_HAVE_API_FUNC_"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment