[Python-checkins] r79664 - in python/branches/release26-maint: Lib/test/test_structmembers.py Modules/_testcapimodule.c

mark.dickinson python-checkins at python.org
Sat Apr 3 12:46:46 CEST 2010


Author: mark.dickinson
Date: Sat Apr  3 12:46:46 2010
New Revision: 79664

Log:
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.
........


Modified:
   python/branches/release26-maint/   (props changed)
   python/branches/release26-maint/Lib/test/test_structmembers.py
   python/branches/release26-maint/Modules/_testcapimodule.c

Modified: python/branches/release26-maint/Lib/test/test_structmembers.py
==============================================================================
--- python/branches/release26-maint/Lib/test/test_structmembers.py	(original)
+++ python/branches/release26-maint/Lib/test/test_structmembers.py	Sat Apr  3 12:46:46 2010
@@ -1,4 +1,4 @@
-from _testcapi import test_structmembersType, \
+from _testcapi import _test_structmembersType, \
     CHAR_MAX, CHAR_MIN, UCHAR_MAX, \
     SHRT_MAX, SHRT_MIN, USHRT_MAX, \
     INT_MAX, INT_MIN, UINT_MAX, \
@@ -8,7 +8,7 @@
 import warnings, exceptions, unittest, sys
 from test import test_support
 
-ts=test_structmembersType(False, 1, 2, 3, 4, 5, 6, 7, 8,
+ts=_test_structmembersType(False, 1, 2, 3, 4, 5, 6, 7, 8,
                           9.99999, 10.1010101010, "hi")
 
 class ReadWriteTests(unittest.TestCase):

Modified: python/branches/release26-maint/Modules/_testcapimodule.c
==============================================================================
--- python/branches/release26-maint/Modules/_testcapimodule.c	(original)
+++ python/branches/release26-maint/Modules/_testcapimodule.c	Sat Apr  3 12:46:46 2010
@@ -969,7 +969,7 @@
 	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;
@@ -1008,7 +1008,7 @@
 	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
@@ -1019,7 +1019,7 @@
 #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)
@@ -1032,7 +1032,7 @@
 					 &ob->structmembers.short_member,
 					 &ob->structmembers.ushort_member,
 					 &ob->structmembers.int_member,
-					 &ob->structmembers.uint_member, 
+					 &ob->structmembers.uint_member,
 					 &ob->structmembers.long_member,
 					 &ob->structmembers.ulong_member,
 					 &ob->structmembers.float_member,
@@ -1046,12 +1046,17 @@
 		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;
 }
 
@@ -1116,7 +1121,9 @@
 
 	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", PyInt_FromLong(CHAR_MAX));
 	PyModule_AddObject(m, "CHAR_MIN", PyInt_FromLong(CHAR_MIN));


More information about the Python-checkins mailing list