summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2010-04-03 10:59:11 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2010-04-03 10:59:11 (GMT)
commitf53b1e2f770b640ae9b167dd3b18f5f94a96c284 (patch)
tree693e2f7a73d38f2dec3441797fa8a926275fdbf0 /Modules
parent8e16b7e46f4857a9236964a4deb0ace408691560 (diff)
downloadcpython-f53b1e2f770b640ae9b167dd3b18f5f94a96c284.zip
cpython-f53b1e2f770b640ae9b167dd3b18f5f94a96c284.tar.gz
cpython-f53b1e2f770b640ae9b167dd3b18f5f94a96c284.tar.bz2
Merged revisions 79665 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r79665 | mark.dickinson | 2010-04-03 11:49:56 +0100 (Sat, 03 Apr 2010) | 20 lines Merged revisions 79661 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r79661 | mark.dickinson | 2010-04-03 11:27:05 +0100 (Sat, 03 Apr 2010) | 14 lines Fix a couple of issues with the test_structmembersType class in _testcapimodule - rename to _test_structmembersType to avoid the class being automatically called by test_capi - allow space for trailing NUL in inplace_member field of all_structmembers - use T_STRING_INPLACE instead of T_INPLACE_STRING as keyword argument to _test_structmembersType initializer - don't attempt to initialize inplace_member field if T_STRING_INPLACE argument wasn't supplied. ........ ................
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_testcapimodule.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 0def230..54e596a 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -1672,7 +1672,7 @@ typedef struct {
unsigned long ulong_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;
@@ -1711,7 +1711,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_FLOAT", "T_DOUBLE", "T_INPLACE_STRING",
+ "T_FLOAT", "T_DOUBLE", "T_STRING_INPLACE",
#ifdef HAVE_LONG_LONG
"T_LONGLONG", "T_ULONGLONG",
#endif
@@ -1722,7 +1722,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)
@@ -1749,12 +1749,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;
}
@@ -1833,7 +1838,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));