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

Jeremy Hylton jhylton@users.sourceforge.net
Wed, 26 Sep 2001 13:01:15 -0700


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

Modified Files:
	_testcapimodule.c 
Log Message:
Add tests for new PyErr_NormalizeException() behavior

Add raise_exception() to the _testcapi module.  It isn't a test, but
the C API exists only to support test_exceptions.  raise_exception()
takes two arguments -- an exception class and an integer specifying
how many arguments it should be called with.

test_exceptions uses BadException() to test the interpreter's behavior
when there is a problem instantiating the exception.  test_capi1()
calls it with too many arguments.  test_capi2() causes an exception to
be raised in the Python code of the constructor.


Index: _testcapimodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_testcapimodule.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** _testcapimodule.c	2001/07/26 13:41:05	1.10
--- _testcapimodule.c	2001/09/26 20:01:13	1.11
***************
*** 258,263 ****
--- 258,289 ----
  #endif	/* ifdef HAVE_LONG_LONG */
  
+ static PyObject *
+ raise_exception(PyObject *self, PyObject *args)
+ {
+ 	PyObject *exc;
+ 	PyObject *exc_args, *v;
+ 	int num_args, i;
+ 
+ 	if (!PyArg_ParseTuple(args, "Oi:raise_exception",
+ 			      &exc, &num_args))
+ 		return NULL;
+ 
+ 	exc_args = PyTuple_New(num_args);
+ 	if (exc_args == NULL)
+ 		return NULL;
+ 	for (i = 0; i < num_args; ++i) {
+ 		v = PyInt_FromLong(i);
+ 		if (v == NULL) {
+ 			Py_DECREF(exc_args);
+ 			return NULL;
+ 		}
+ 		PyTuple_SET_ITEM(exc_args, i, v);
+ 	}
+ 	PyErr_SetObject(exc, exc_args);
+ 	return NULL;
+ }
  
  static PyMethodDef TestMethods[] = {
+ 	{"raise_exception",	raise_exception,	METH_VARARGS},
  	{"test_config",		test_config,		METH_VARARGS},
  	{"test_list_api",	test_list_api,		METH_VARARGS},