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")
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("}")
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;" % (
#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*/
#endif
PyObject *d = 0;
PyObject *cobj = 0;
- char *desc;
+ const char *desc;
+ const char *s1, *s2;
d = PyObject_GetAttrString(module, api);
if (!d)
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);
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) {
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) {
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);
}