diff options
Diffstat (limited to 'Modules/_testcapimodule.c')
-rw-r--r-- | Modules/_testcapimodule.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 87f9d8b..ea0b1c7 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2087,7 +2087,7 @@ typedef struct { Py_ssize_t pyssizet_member; float float_member; double double_member; - char inplace_member[5]; + char inplace_member[6]; #ifdef HAVE_LONG_LONG PY_LONG_LONG longlong_member; unsigned PY_LONG_LONG ulonglong_member; @@ -2127,7 +2127,7 @@ test_structmembers_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) static char *keywords[] = { "T_BOOL", "T_BYTE", "T_UBYTE", "T_SHORT", "T_USHORT", "T_INT", "T_UINT", "T_LONG", "T_ULONG", "T_PYSSIZET", - "T_FLOAT", "T_DOUBLE", "T_INPLACE_STRING", + "T_FLOAT", "T_DOUBLE", "T_STRING_INPLACE", #ifdef HAVE_LONG_LONG "T_LONGLONG", "T_ULONGLONG", #endif @@ -2138,7 +2138,7 @@ test_structmembers_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) #endif ; test_structmembers *ob; - const char *s; + const char *s = NULL; Py_ssize_t string_len = 0; ob = PyObject_New(test_structmembers, type); if (ob == NULL) @@ -2166,12 +2166,17 @@ test_structmembers_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) Py_DECREF(ob); return NULL; } - if (string_len > 5) { - Py_DECREF(ob); - PyErr_SetString(PyExc_ValueError, "string too long"); - return NULL; + if (s != NULL) { + if (string_len > 5) { + Py_DECREF(ob); + PyErr_SetString(PyExc_ValueError, "string too long"); + return NULL; + } + strcpy(ob->structmembers.inplace_member, s); + } + else { + strcpy(ob->structmembers.inplace_member, ""); } - strcpy(ob->structmembers.inplace_member, s); return (PyObject *)ob; } @@ -2250,7 +2255,9 @@ PyInit__testcapi(void) Py_TYPE(&test_structmembersType)=&PyType_Type; Py_INCREF(&test_structmembersType); - PyModule_AddObject(m, "test_structmembersType", (PyObject *)&test_structmembersType); + /* don't use a name starting with "test", since we don't want + test_capi to automatically call this */ + PyModule_AddObject(m, "_test_structmembersType", (PyObject *)&test_structmembersType); PyModule_AddObject(m, "CHAR_MAX", PyLong_FromLong(CHAR_MAX)); PyModule_AddObject(m, "CHAR_MIN", PyLong_FromLong(CHAR_MIN)); |