[Python-checkins] CVS: python/dist/src/Modules _testcapimodule.c,1.14,1.15

M.-A. Lemburg lemburg@users.sourceforge.net
Wed, 09 Jan 2002 08:21:30 -0800


Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv11966/Modules

Modified Files:
	_testcapimodule.c 
Log Message:
Fixed "u#" parser marker to pass through Unicode objects as-is without
going through the buffer interface API.

Added tests for this to the _testcapi module and updated docs.



Index: _testcapimodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_testcapimodule.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** _testcapimodule.c	2001/11/28 20:27:42	1.14
--- _testcapimodule.c	2002/01/09 16:21:27	1.15
***************
*** 308,311 ****
--- 308,358 ----
  #endif	/* ifdef HAVE_LONG_LONG */
  
+ #ifdef Py_USING_UNICODE
+ 
+ /* Test the u and u# codes for PyArg_ParseTuple. May leak memory in case
+    of an error.
+ */
+ static PyObject *
+ test_u_code(PyObject *self, PyObject *args)
+ {
+ 	PyObject *tuple, *obj;
+ 	Py_UNICODE *value;
+ 	int len;
+ 
+         if (!PyArg_ParseTuple(args, ":test_u_code"))
+                 return NULL;
+ 
+         tuple = PyTuple_New(1);
+         if (tuple == NULL)
+         	return NULL;
+ 
+         obj = PyUnicode_Decode("test", strlen("test"),
+ 			       "ascii", NULL);
+         if (obj == NULL)
+         	return NULL;
+ 
+         PyTuple_SET_ITEM(tuple, 0, obj);
+ 
+         value = 0;
+         if (PyArg_ParseTuple(tuple, "u:test_u_code", &value) < 0)
+         	return NULL;
+         if (value != PyUnicode_AS_UNICODE(obj))
+         	return raiseTestError("test_u_code",
+ 			"u code returned wrong value for u'test'");
+         value = 0;
+         if (PyArg_ParseTuple(tuple, "u#:test_u_code", &value, &len) < 0)
+         	return NULL;
+         if (value != PyUnicode_AS_UNICODE(obj) ||
+ 	    len != PyUnicode_GET_SIZE(obj))
+         	return raiseTestError("test_u_code",
+ 			"u# code returned wrong values for u'test'");
+ 	
+ 	Py_DECREF(tuple);
+ 	Py_INCREF(Py_None);
+ 	return Py_None;
+ }
+ 
+ #endif
+ 
  static PyObject *
  raise_exception(PyObject *self, PyObject *args)
***************
*** 343,346 ****
--- 390,396 ----
  	{"test_longlong_api",	test_longlong_api,	METH_VARARGS},
  	{"test_L_code",		test_L_code,		METH_VARARGS},
+ #endif
+ #ifdef Py_USING_UNICODE
+ 	{"test_u_code",		test_u_code,		METH_VARARGS},
  #endif
  	{NULL, NULL} /* sentinel */