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
Gwenaël Samain
cython
Commits
12f08145
Commit
12f08145
authored
Mar 07, 2009
by
Lisandro Dalcin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get rid of the few usages of strcmp(), now replaced with utility inline function __Pyx_StrEq()
parent
edcede5e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
11 deletions
+29
-11
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+26
-6
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+2
-4
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+1
-1
No files found.
Cython/Compiler/ModuleNode.py
View file @
12f08145
...
...
@@ -558,6 +558,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
putln
(
'static char %s[] = "%s";'
%
(
env
.
doc_cname
,
escape_byte_string
(
docstr
)))
env
.
use_utility_code
(
streq_utility_code
)
def
generate_extern_c_macro_definition
(
self
,
code
):
name
=
Naming
.
extern_c_macro
code
.
putln
(
"#ifdef __cplusplus"
)
...
...
@@ -1517,7 +1519,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
putln
(
"static int %s(PyObject *o, PyObject* py_name, char *name) {"
%
Naming
.
import_star_set
)
code
.
putln
(
"char** type_name = %s_type_names;"
%
Naming
.
import_star
)
code
.
putln
(
"while (*type_name) {"
)
code
.
putln
(
"if (
!strcmp
(name, *type_name)) {"
)
code
.
putln
(
"if (
__Pyx_StrEq
(name, *type_name)) {"
)
code
.
putln
(
'PyErr_Format(PyExc_TypeError, "Cannot overwrite C type %s", name);'
)
code
.
putln
(
'goto bad;'
)
code
.
putln
(
"}"
)
...
...
@@ -1527,7 +1529,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
putln
(
"if (0);"
)
# so the first one can be "else if"
for
name
,
entry
in
env
.
entries
.
items
():
if
entry
.
is_cglobal
and
entry
.
used
:
code
.
putln
(
'else if (
!strcmp
(name, "%s")) {'
%
name
)
code
.
putln
(
'else if (
__Pyx_StrEq
(name, "%s")) {'
%
name
)
if
entry
.
type
.
is_pyobject
:
if
entry
.
type
.
is_extension_type
or
entry
.
type
.
is_builtin_type
:
code
.
putln
(
"if (!(%s)) %s;"
%
(
...
...
@@ -2030,6 +2032,21 @@ proto = """\
#endif
"""
)
#------------------------------------------------------------------------------------
streq_utility_code
=
UtilityCode
(
proto
=
"""
static INLINE int __Pyx_StrEq(const char *, const char *); /*proto*/
"""
,
impl
=
"""
static INLINE int __Pyx_StrEq(const char *s1, const char *s2) {
while (*s1 != '
\
\
0' && *s1 == *s2) { s1++; s2++; }
return *s1 == *s2;
}
"""
)
#------------------------------------------------------------------------------------
import_module_utility_code
=
UtilityCode
(
proto
=
"""
static PyObject *__Pyx_ImportModule(const char *name); /*proto*/
...
...
@@ -2171,7 +2188,8 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void **f
#endif
PyObject *d = 0;
PyObject *cobj = 0;
char *desc;
const char *desc;
const char *s1, *s2;
d = PyObject_GetAttrString(module, api);
if (!d)
...
...
@@ -2183,13 +2201,15 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void **f
PyModule_GetName(module), funcname);
goto bad;
}
desc = (char *)PyCObject_GetDesc(cobj);
desc = (c
onst c
har *)PyCObject_GetDesc(cobj);
if (!desc)
goto bad;
if (strcmp(desc, sig) != 0) {
s1 = desc; s2 = sig;
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)",
PyModule_GetName(module), funcname, sig, desc);
PyModule_GetName(module), funcname, sig, desc);
goto bad;
}
*f = PyCObject_AsVoidPtr(cobj);
...
...
Cython/Compiler/Nodes.py
View file @
12f08145
...
...
@@ -5248,8 +5248,7 @@ static int __Pyx_ParseOptionalKeywords(
PyUnicode_Compare(**name, key) == 0) break;
#else
if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
strcmp(PyString_AS_STRING(**name),
PyString_AS_STRING(key)) == 0) break;
_PyString_Eq(**name, key)) break;
#endif
}
if (*name) {
...
...
@@ -5263,8 +5262,7 @@ static int __Pyx_ParseOptionalKeywords(
PyUnicode_Compare(**name, key) == 0) goto arg_passed_twice;
#else
if (PyString_GET_SIZE(**name) == PyString_GET_SIZE(key) &&
strcmp(PyString_AS_STRING(**name),
PyString_AS_STRING(key)) == 0) goto arg_passed_twice;
_PyString_Eq(**name, key)) goto arg_passed_twice;
#endif
}
if (kwds2) {
...
...
Cython/Compiler/Symtab.py
View file @
12f08145
...
...
@@ -1562,7 +1562,7 @@ impl = """
static PyObject* __Pyx_Method_ClassMethod(PyObject *method) {
/* It appears that PyMethodDescr_Type is not anywhere exposed in the Python/C API */
/* if (!PyObject_TypeCheck(method, &PyMethodDescr_Type)) { */
if (
strcmp(Py_TYPE(method)->tp_name, "method_descriptor") == 0
) { /* cdef classes */
if (
__Pyx_StrEq(Py_TYPE(method)->tp_name, "method_descriptor")
) { /* cdef classes */
PyMethodDescrObject *descr = (PyMethodDescrObject *)method;
return PyDescr_NewClassMethod(descr->d_type, descr->d_method);
}
...
...
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