[Python-checkins] python/dist/src/Python bltinmodule.c,2.275,2.276 ceval.c,2.348,2.349 compile.c,2.273,2.274

M.-A. Lemburg mal@lemburg.com
Mon, 10 Feb 2003 09:57:15 +0100


jvr@users.sourceforge.net wrote:
> Update of /cvsroot/python/python/dist/src/Python
> In directory sc8-pr-cvs1:/tmp/cvs-serv19147/Python
> 
> Modified Files:
> 	bltinmodule.c ceval.c compile.c 
> Log Message:
> patch #683515: "Add unicode support to compile(), eval() and exec"
> Incorporated nnorwitz's comment re. Py__USING_UNICODE.
> 
> 
> Index: bltinmodule.c
> ===================================================================
> RCS file: /cvsroot/python/python/dist/src/Python/bltinmodule.c,v
> retrieving revision 2.275
> retrieving revision 2.276
> diff -C2 -d -r2.275 -r2.276
> *** bltinmodule.c	4 Feb 2003 20:24:43 -0000	2.275
> --- bltinmodule.c	10 Feb 2003 08:21:07 -0000	2.276
> ***************
> *** 341,349 ****
>   	int supplied_flags = 0;
>   	PyCompilerFlags cf;
>   
> ! 	if (!PyArg_ParseTuple(args, "sss|ii:compile", &str, &filename,
>   			      &startstr, &supplied_flags, &dont_inherit))
>   		return NULL;
>   
>   	if (strcmp(startstr, "exec") == 0)
>   		start = Py_file_input;
> --- 341,370 ----
>   	int supplied_flags = 0;
>   	PyCompilerFlags cf;
> + 	PyObject *result, *cmd, *tmp = NULL;
>   
> ! 	if (!PyArg_ParseTuple(args, "Oss|ii:compile", &cmd, &filename,
>   			      &startstr, &supplied_flags, &dont_inherit))
>   		return NULL;
>   
> + 	cf.cf_flags = supplied_flags;
> + 
> + #ifdef Py_USING_UNICODE
> + 	if (PyUnicode_Check(cmd)) {
> + 		tmp = PyUnicode_AsUTF8String(cmd);
> + 		if (tmp == NULL)
> + 			return NULL;
> + 		cmd = tmp;
> + 		cf.cf_flags |= PyCF_SOURCE_IS_UTF8;
> + 	}
> + #endif
> + 	if (!PyString_Check(cmd)) {
> + 		PyErr_SetString(PyExc_TypeError,
> + 				"compile() arg 1 must be a string");
> + 		return NULL;
> + 	}
> + 
> + 	if (PyString_AsStringAndSize(cmd, &str, NULL))
> + 		return NULL;
> + 

This will break code: the "s" parser marker allows passing in
any buffer compatible object. You'll have to use
PyObject_AsReadBuffer() here to be backward compatible.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Software directly from the Source  (#1, Feb 09 2003)
 >>> Python/Zope Products & Consulting ...         http://www.egenix.com/
 >>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________
Python UK 2003, Oxford:                                     51 days left
EuroPython 2003, Charleroi, Belgium:                       135 days left