[Python-checkins] CVS: python/dist/src/Python bltinmodule.c,2.179,2.180

M.-A. Lemburg python-dev@python.org
Tue, 19 Sep 2000 13:59:39 -0700


Update of /cvsroot/python/python/dist/src/Python
In directory slayer.i.sourceforge.net:/tmp/cvs-serv15921/Python

Modified Files:
	bltinmodule.c 
Log Message:
This patch adds a new Python C API called PyString_AsStringAndSize()
which implements the automatic conversion from Unicode to a string
object using the default encoding.

The new API is then put to use to have eval() and exec accept
Unicode objects as code parameter. This closes bugs #110924
and #113890.

As side-effect, the traditional C APIs PyString_Size() and
PyString_AsString() will also accept Unicode objects as
parameters.

Index: bltinmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/bltinmodule.c,v
retrieving revision 2.179
retrieving revision 2.180
diff -C2 -r2.179 -r2.180
*** bltinmodule.c	2000/09/18 16:22:27	2.179
--- bltinmodule.c	2000/09/19 20:59:36	2.180
***************
*** 749,763 ****
  	if (PyCode_Check(cmd))
  		return PyEval_EvalCode((PyCodeObject *) cmd, globals, locals);
! 	if (!PyString_Check(cmd)) {
  		PyErr_SetString(PyExc_TypeError,
  			   "eval() argument 1 must be string or code object");
  		return NULL;
  	}
! 	str = PyString_AsString(cmd);
! 	if (strlen(str) != (size_t)PyString_Size(cmd)) {
! 		PyErr_SetString(PyExc_ValueError,
! 			   "embedded '\\0' in string arg");
  		return NULL;
- 	}
  	while (*str == ' ' || *str == '\t')
  		str++;
--- 749,760 ----
  	if (PyCode_Check(cmd))
  		return PyEval_EvalCode((PyCodeObject *) cmd, globals, locals);
! 	if (!PyString_Check(cmd) &&
! 	    !PyUnicode_Check(cmd)) {
  		PyErr_SetString(PyExc_TypeError,
  			   "eval() argument 1 must be string or code object");
  		return NULL;
  	}
! 	if (PyString_AsStringAndSize(cmd, &str, NULL))
  		return NULL;
  	while (*str == ' ' || *str == '\t')
  		str++;