diff -r cabe1a04a4d0 Cython/Compiler/ModuleNode.py --- a/Cython/Compiler/ModuleNode.py Fri Mar 06 18:57:07 2009 -0200 +++ b/Cython/Compiler/ModuleNode.py Fri Mar 06 19:09:29 2009 -0200 @@ -558,6 +558,8 @@ code.putln('static char %s[] = "%s";' % ( env.doc_cname, escape_byte_string(docstr))) + env.use_utility_code(strcmp_utility_code) + def generate_extern_c_macro_definition(self, code): name = Naming.extern_c_macro code.putln("#ifdef __cplusplus") @@ -1517,7 +1519,7 @@ 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_StrCmp(name, *type_name) == 0) {") code.putln('PyErr_Format(PyExc_TypeError, "Cannot overwrite C type %s", name);') code.putln('goto bad;') code.putln("}") @@ -1527,7 +1529,7 @@ 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_StrCmp(name, "%s") == 0) {' % 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,24 @@ #endif """) +#------------------------------------------------------------------------------------ + +strcmp_utility_code = UtilityCode( +proto = """ +static INLINE int __Pyx_StrCmp(const char *, const char *); /*proto*/ +""", +impl = """ +static INLINE int __Pyx_StrCmp(const char *s1, const char *s2) { + unsigned char uc1, uc2; + while (*s1 != '\\0' && *s1 == *s2) { s1++; s2++; } + uc1 = *(unsigned char *)s1; + uc2 = *(unsigned char *)s2; + return ((uc1 < uc2) ? -1 : (uc1 > uc2)); +} +""") + +#------------------------------------------------------------------------------------ + import_module_utility_code = UtilityCode( proto = """ static PyObject *__Pyx_ImportModule(const char *name); /*proto*/ @@ -2171,7 +2191,8 @@ #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 +2204,15 @@ PyModule_GetName(module), funcname); goto bad; } - desc = (char *)PyCObject_GetDesc(cobj); + desc = (const char *)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); diff -r cabe1a04a4d0 Cython/Compiler/Nodes.py --- a/Cython/Compiler/Nodes.py Fri Mar 06 18:57:07 2009 -0200 +++ b/Cython/Compiler/Nodes.py Fri Mar 06 19:09:29 2009 -0200 @@ -2478,7 +2478,7 @@ code.putln("%s = PyObject_GetAttr(%s, %s); %s" % (self.func_node.result(), self_arg, self.py_func.interned_attr_cname, err)) code.put_gotref(self.func_node.py_result()) # It appears that this type is not anywhere exposed in the Python/C API - is_builtin_function_or_method = '(strcmp(Py_TYPE(%s)->tp_name, "builtin_function_or_method") == 0)' % self.func_node.result() + is_builtin_function_or_method = '(__Pyx_StrCmp(Py_TYPE(%s)->tp_name, "builtin_function_or_method") == 0)' % self.func_node.result() is_overridden = '(PyCFunction_GET_FUNCTION(%s) != (void *)&%s)' % (self.func_node.result(), self.py_func.entry.func_cname) code.putln('if (!%s || %s) {' % (is_builtin_function_or_method, is_overridden)) self.body.generate_execution_code(code) @@ -5249,8 +5249,7 @@ 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) { @@ -5264,8 +5263,7 @@ 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) { diff -r cabe1a04a4d0 Cython/Compiler/Symtab.py --- a/Cython/Compiler/Symtab.py Fri Mar 06 18:57:07 2009 -0200 +++ b/Cython/Compiler/Symtab.py Fri Mar 06 19:09:29 2009 -0200 @@ -1562,7 +1562,7 @@ 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_StrCmp(Py_TYPE(method)->tp_name, "method_descriptor") == 0) { /* cdef classes */ PyMethodDescrObject *descr = (PyMethodDescrObject *)method; return PyDescr_NewClassMethod(descr->d_type, descr->d_method); }