[Python-checkins] CVS: python/dist/src/Python bltinmodule.c,2.226,2.227 compile.c,2.217,2.218 getargs.c,2.61,2.62 marshal.c,1.64,1.65 modsupport.c,2.57,2.58 pythonrun.c,2.146,2.147 sysmodule.c,2.91,2.92

Martin v. L?wis loewis@users.sourceforge.net
Fri, 17 Aug 2001 11:39:27 -0700


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

Modified Files:
	bltinmodule.c compile.c getargs.c marshal.c modsupport.c 
	pythonrun.c sysmodule.c 
Log Message:
Patch #445762: Support --disable-unicode
- Do not compile unicodeobject, unicodectype, and unicodedata if Unicode is disabled
- check for Py_USING_UNICODE in all places that use Unicode functions
- disables unicode literals, and the builtin functions
- add the types.StringTypes list
- remove Unicode literals from most tests.


Index: bltinmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/bltinmodule.c,v
retrieving revision 2.226
retrieving revision 2.227
diff -C2 -d -r2.226 -r2.227
*** bltinmodule.c	2001/08/16 13:15:00	2.226
--- bltinmodule.c	2001/08/17 18:39:25	2.227
***************
*** 277,280 ****
--- 277,281 ----
  
  
+ #ifdef Py_USING_UNICODE
  static PyObject *
  builtin_unichr(PyObject *self, PyObject *args)
***************
*** 325,328 ****
--- 326,330 ----
  \n\
  Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff.";
+ #endif
  
  
***************
*** 631,634 ****
--- 633,637 ----
  	if (!PyArg_ParseTuple(args, "OO|O:getattr", &v, &name, &dflt))
  		return NULL;
+ #ifdef Py_USING_UNICODE
  	if (PyUnicode_Check(name)) {
  		name = _PyUnicode_AsDefaultEncodedString(name, NULL);
***************
*** 636,639 ****
--- 639,643 ----
  			return NULL;
  	}
+ #endif
  
  	if (!PyString_Check(name)) {
***************
*** 683,686 ****
--- 687,691 ----
  	if (!PyArg_ParseTuple(args, "OO:hasattr", &v, &name))
  		return NULL;
+ #ifdef Py_USING_UNICODE
  	if (PyUnicode_Check(name)) {
  		name = _PyUnicode_AsDefaultEncodedString(name, NULL);
***************
*** 688,691 ****
--- 693,697 ----
  			return NULL;
  	}
+ #endif
  
  	if (!PyString_Check(name)) {
***************
*** 1253,1256 ****
--- 1259,1263 ----
  			return PyInt_FromLong(ord);
  		}
+ #ifdef Py_USING_UNICODE
  	} else if (PyUnicode_Check(obj)) {
  		size = PyUnicode_GET_SIZE(obj);
***************
*** 1259,1262 ****
--- 1266,1270 ----
  			return PyInt_FromLong(ord);
  		}
+ #endif
  	} else {
  		PyErr_Format(PyExc_TypeError,
***************
*** 1844,1848 ****
--- 1852,1858 ----
   	{"setattr",	builtin_setattr,    METH_VARARGS, setattr_doc},
   	{"slice",       builtin_slice,      METH_VARARGS, slice_doc},
+ #ifdef Py_USING_UNICODE
   	{"unichr",	builtin_unichr,     METH_VARARGS, unichr_doc},
+ #endif
   	{"vars",	builtin_vars,       METH_VARARGS, vars_doc},
   	{"xrange",	builtin_xrange,     METH_VARARGS, xrange_doc},
***************
*** 1906,1912 ****
--- 1916,1924 ----
  	if (PyDict_SetItemString(dict, "type", (PyObject *) &PyType_Type) < 0)
  		return NULL;
+ #ifdef Py_USING_UNICODE
  	if (PyDict_SetItemString(dict, "unicode",
  				 (PyObject *) &PyUnicode_Type) < 0)
  		return NULL;
+ #endif
  	debug = PyInt_FromLong(Py_OptimizeFlag == 0);
  	if (PyDict_SetItemString(dict, "__debug__", debug) < 0) {

Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.217
retrieving revision 2.218
diff -C2 -d -r2.217 -r2.218
*** compile.c	2001/08/14 20:01:59	2.217
--- compile.c	2001/08/17 18:39:25	2.218
***************
*** 521,526 ****
  static PyCodeObject *jcompile(node *, char *, struct compiling *,
  			      PyCompilerFlags *);
! static PyObject *parsestrplus(node *);
! static PyObject *parsestr(char *);
  static node *get_rawdocstring(node *);
  
--- 521,526 ----
  static PyCodeObject *jcompile(node *, char *, struct compiling *,
  			      PyCompilerFlags *);
! static PyObject *parsestrplus(struct compiling*, node *);
! static PyObject *parsestr(struct compiling *, char *);
  static node *get_rawdocstring(node *);
  
***************
*** 1112,1116 ****
  
  static PyObject *
! parsestr(char *s)
  {
  	PyObject *v;
--- 1112,1116 ----
  
  static PyObject *
! parsestr(struct compiling *com, char *s)
  {
  	PyObject *v;
***************
*** 1123,1131 ****
--- 1123,1139 ----
  	int quote = first;
  	int rawmode = 0;
+ #ifdef Py_USING_UNICODE
  	int unicode = 0;
+ #endif
  	if (isalpha(quote) || quote == '_') {
  		if (quote == 'u' || quote == 'U') {
+ #ifdef Py_USING_UNICODE
  			quote = *++s;
  			unicode = 1;
+ #else
+ 			com_error(com, PyExc_SyntaxError,
+ 				  "Unicode literals not supported in this Python");
+ 			return NULL;
+ #endif
  		}
  		if (quote == 'r' || quote == 'R') {
***************
*** 1156,1159 ****
--- 1164,1168 ----
  		}
  	}
+ #ifdef Py_USING_UNICODE
  	if (unicode || Py_UnicodeFlag) {
  		if (rawmode)
***************
*** 1164,1167 ****
--- 1173,1177 ----
  				s, len, NULL);
  	}
+ #endif
  	if (rawmode || strchr(s, '\\') == NULL)
  		return PyString_FromStringAndSize(s, len);
***************
*** 1239,1252 ****
  
  static PyObject *
! parsestrplus(node *n)
  {
  	PyObject *v;
  	int i;
  	REQ(CHILD(n, 0), STRING);
! 	if ((v = parsestr(STR(CHILD(n, 0)))) != NULL) {
  		/* String literal concatenation */
  		for (i = 1; i < NCH(n); i++) {
  		    PyObject *s;
! 		    s = parsestr(STR(CHILD(n, i)));
  		    if (s == NULL)
  			goto onError;
--- 1249,1262 ----
  
  static PyObject *
! parsestrplus(struct compiling* c, node *n)
  {
  	PyObject *v;
  	int i;
  	REQ(CHILD(n, 0), STRING);
! 	if ((v = parsestr(c, STR(CHILD(n, 0)))) != NULL) {
  		/* String literal concatenation */
  		for (i = 1; i < NCH(n); i++) {
  		    PyObject *s;
! 		    s = parsestr(c, STR(CHILD(n, i)));
  		    if (s == NULL)
  			goto onError;
***************
*** 1256,1259 ****
--- 1266,1270 ----
  			    goto onError;
  		    }
+ #ifdef Py_USING_UNICODE
  		    else {
  			PyObject *temp;
***************
*** 1265,1268 ****
--- 1276,1280 ----
  			v = temp;
  		    }
+ #endif
  		}
  	}
***************
*** 1446,1450 ****
  		break;
  	case STRING:
! 		v = parsestrplus(n);
  		if (v == NULL) {
  			c->c_errors++;
--- 1458,1462 ----
  		break;
  	case STRING:
! 		v = parsestrplus(c, n);
  		if (v == NULL) {
  			c->c_errors++;
***************
*** 2937,2941 ****
  
  	case STRING:
! 		v = parsestr(STR(n));
  		if (v == NULL) {
  			PyErr_Clear();
--- 2949,2953 ----
  
  	case STRING:
! 		v = parsestr(c, STR(n));
  		if (v == NULL) {
  			PyErr_Clear();
***************
*** 3331,3335 ****
  
  static PyObject *
! get_docstring(node *n)
  {
  	/* Don't generate doc-strings if run with -OO */
--- 3343,3347 ----
  
  static PyObject *
! get_docstring(struct compiling *c, node *n)
  {
  	/* Don't generate doc-strings if run with -OO */
***************
*** 3339,3343 ****
  	if (n == NULL)
  		return NULL;
! 	return parsestrplus(n);
  }
  
--- 3351,3355 ----
  	if (n == NULL)
  		return NULL;
! 	return parsestrplus(c, n);
  }
  
***************
*** 3795,3799 ****
  	PyObject *doc;
  	REQ(n, file_input); /* (NEWLINE | stmt)* ENDMARKER */
! 	doc = get_docstring(n);
  	if (doc != NULL) {
  		int i = com_addconst(c, doc);
--- 3807,3811 ----
  	PyObject *doc;
  	REQ(n, file_input); /* (NEWLINE | stmt)* ENDMARKER */
! 	doc = get_docstring(c, n);
  	if (doc != NULL) {
  		int i = com_addconst(c, doc);
***************
*** 3820,3824 ****
  	REQ(n, funcdef); /* funcdef: 'def' NAME parameters ':' suite */
  	c->c_name = STR(CHILD(n, 1));
! 	doc = get_docstring(CHILD(n, 4));
  	if (doc != NULL) {
  		(void) com_addconst(c, doc);
--- 3832,3836 ----
  	REQ(n, funcdef); /* funcdef: 'def' NAME parameters ':' suite */
  	c->c_name = STR(CHILD(n, 1));
! 	doc = get_docstring(c, CHILD(n, 4));
  	if (doc != NULL) {
  		(void) com_addconst(c, doc);
***************
*** 3870,3874 ****
  	c->c_private = c->c_name;
  	ch = CHILD(n, NCH(n)-1); /* The suite */
! 	doc = get_docstring(ch);
  	if (doc != NULL) {
  		int i = com_addconst(c, doc);
--- 3882,3886 ----
  	c->c_private = c->c_name;
  	ch = CHILD(n, NCH(n)-1); /* The suite */
! 	doc = get_docstring(c, ch);
  	if (doc != NULL) {
  		int i = com_addconst(c, doc);

Index: getargs.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/getargs.c,v
retrieving revision 2.61
retrieving revision 2.62
diff -C2 -d -r2.61 -r2.62
*** getargs.c	2001/07/30 22:34:24	2.61
--- getargs.c	2001/08/17 18:39:25	2.62
***************
*** 567,570 ****
--- 567,571 ----
  				*q = PyString_GET_SIZE(arg);
  			}
+ #ifdef Py_USING_UNICODE
  			else if (PyUnicode_Check(arg)) {
  				arg = UNICODE_DEFAULT_ENCODING(arg);
***************
*** 575,578 ****
--- 576,580 ----
  				*q = PyString_GET_SIZE(arg);
  			}
+ #endif
  			else { /* any buffer-like object */
  				char *buf;
***************
*** 588,591 ****
--- 590,594 ----
  			if (PyString_Check(arg))
  				*p = PyString_AS_STRING(arg);
+ #ifdef Py_USING_UNICODE
  			else if (PyUnicode_Check(arg)) {
  				arg = UNICODE_DEFAULT_ENCODING(arg);
***************
*** 595,598 ****
--- 598,602 ----
  				*p = PyString_AS_STRING(arg);
  			}
+ #endif
  			else
  				return converterr("string", arg, msgbuf);
***************
*** 617,620 ****
--- 621,625 ----
  				*q = PyString_GET_SIZE(arg);
  			}
+ #ifdef Py_USING_UNICODE
  			else if (PyUnicode_Check(arg)) {
  				arg = UNICODE_DEFAULT_ENCODING(arg);
***************
*** 625,628 ****
--- 630,634 ----
  				*q = PyString_GET_SIZE(arg);
  			}
+ #endif
  			else { /* any buffer-like object */
  				char *buf;
***************
*** 641,644 ****
--- 647,651 ----
  			else if (PyString_Check(arg))
  				*p = PyString_AsString(arg);
+ #ifdef Py_USING_UNICODE
  			else if (PyUnicode_Check(arg)) {
  				arg = UNICODE_DEFAULT_ENCODING(arg);
***************
*** 648,651 ****
--- 655,659 ----
  				*p = PyString_AS_STRING(arg);
  			}
+ #endif
  			else
  				return converterr("string or None", 
***************
*** 671,681 ****
  		char **buffer;
  		const char *encoding;
! 		PyObject *u, *s;
  		int size, recode_strings;
  
  		/* Get 'e' parameter: the encoding name */
  		encoding = (const char *)va_arg(*p_va, const char *);
  		if (encoding == NULL)
  			encoding = PyUnicode_GetDefaultEncoding();
  			
  		/* Get output buffer parameter:
--- 679,691 ----
  		char **buffer;
  		const char *encoding;
! 		PyObject *s;
  		int size, recode_strings;
  
  		/* Get 'e' parameter: the encoding name */
  		encoding = (const char *)va_arg(*p_va, const char *);
+ #ifdef Py_USING_UNICODE
  		if (encoding == NULL)
  			encoding = PyUnicode_GetDefaultEncoding();
+ #endif
  			
  		/* Get output buffer parameter:
***************
*** 703,706 ****
--- 713,719 ----
  		}
  		else {
+ #ifdef Py_USING_UNICODE
+ 		    	PyObject *u;
+ 
  			/* Convert object to Unicode */
  			u = PyUnicode_FromObject(arg);
***************
*** 724,727 ****
--- 737,743 ----
  					arg, msgbuf);
  			}
+ #else
+ 			return converterr("string<e>", arg, msgbuf);
+ #endif
  		}
  		size = PyString_GET_SIZE(s);
***************
*** 809,812 ****
--- 825,829 ----
  	}
  
+ #ifdef Py_USING_UNICODE
  	case 'u': {/* raw unicode buffer (Py_UNICODE *) */
  		if (*format == '#') { /* any buffer-like object */
***************
*** 830,833 ****
--- 847,851 ----
  		break;
  	}
+ #endif
  
  	case 'S': { /* string object */
***************
*** 840,843 ****
--- 858,862 ----
  	}
  	
+ #ifdef Py_USING_UNICODE
  	case 'U': { /* Unicode object */
  		PyObject **p = va_arg(*p_va, PyObject **);
***************
*** 848,851 ****
--- 867,871 ----
  		break;
  	}
+ #endif
  	
  	case 'O': { /* object */

Index: marshal.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/marshal.c,v
retrieving revision 1.64
retrieving revision 1.65
diff -C2 -d -r1.64 -r1.65
*** marshal.c	2001/06/18 22:08:13	1.64
--- marshal.c	2001/08/17 18:39:25	1.65
***************
*** 188,191 ****
--- 188,192 ----
  		w_string(PyString_AS_STRING(v), n, p);
  	}
+ #ifdef Py_USING_UNICODE
  	else if (PyUnicode_Check(v)) {
  	        PyObject *utf8;
***************
*** 202,205 ****
--- 203,207 ----
  		Py_DECREF(utf8);
  	}
+ #endif
  	else if (PyTuple_Check(v)) {
  		w_byte(TYPE_TUPLE, p);
***************
*** 473,476 ****
--- 475,479 ----
  		return v;
  
+ #ifdef Py_USING_UNICODE
  	case TYPE_UNICODE:
  	    {
***************
*** 495,498 ****
--- 498,502 ----
  		return v;
  	    }
+ #endif
  
  	case TYPE_TUPLE:

Index: modsupport.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/modsupport.c,v
retrieving revision 2.57
retrieving revision 2.58
diff -C2 -d -r2.57 -r2.58
*** modsupport.c	2001/08/04 03:11:25	2.57
--- modsupport.c	2001/08/17 18:39:25	2.58
***************
*** 200,203 ****
--- 200,204 ----
  }
  
+ #ifdef Py_USING_UNICODE
  static int
  _ustrlen(Py_UNICODE *u)
***************
*** 208,211 ****
--- 209,213 ----
  	return i;
  }
+ #endif
  
  static PyObject *
***************
*** 270,273 ****
--- 272,276 ----
  			return PyLong_FromLongLong((LONG_LONG)va_arg(*p_va, LONG_LONG));
  #endif
+ #ifdef Py_USING_UNICODE
  		case 'u':
  		{
***************
*** 292,295 ****
--- 295,299 ----
  			return v;
  		}
+ #endif
  		case 'f':
  		case 'd':

Index: pythonrun.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/pythonrun.c,v
retrieving revision 2.146
retrieving revision 2.147
diff -C2 -d -r2.146 -r2.147
*** pythonrun.c	2001/08/16 08:24:00	2.146
--- pythonrun.c	2001/08/17 18:39:25	2.147
***************
*** 126,131 ****
--- 126,133 ----
  	_PyCodecRegistry_Init();
  
+ #ifdef Py_USING_UNICODE
  	/* Init Unicode implementation; relies on the codec registry */
  	_PyUnicode_Init();
+ #endif
  
  	bimod = _PyBuiltin_Init();
***************
*** 207,212 ****
--- 209,216 ----
  	PyOS_FiniInterrupts();
  
+ #ifdef Py_USING_UNICODE
  	/* Cleanup Unicode implementation */
  	_PyUnicode_Fini();
+ #endif
  
  	/* Cleanup Codec registry */

Index: sysmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/sysmodule.c,v
retrieving revision 2.91
retrieving revision 2.92
diff -C2 -d -r2.91 -r2.92
*** sysmodule.c	2001/08/16 13:15:00	2.91
--- sysmodule.c	2001/08/17 18:39:25	2.92
***************
*** 177,180 ****
--- 177,182 ----
  implementation.";
  
+ #ifdef Py_USING_UNICODE
+ 
  static PyObject *
  sys_setdefaultencoding(PyObject *self, PyObject *args)
***************
*** 194,197 ****
--- 196,201 ----
  Set the current default string encoding used by the Unicode implementation.";
  
+ #endif
+ 
  /*
   * Cached interned string objects used for calling the profile and
***************
*** 531,536 ****
--- 535,542 ----
  	{"excepthook",	sys_excepthook, METH_VARARGS, excepthook_doc},
  	{"exit",	sys_exit, METH_OLDARGS, exit_doc},
+ #ifdef Py_USING_UNICODE
  	{"getdefaultencoding", (PyCFunction)sys_getdefaultencoding, METH_NOARGS,
  	 getdefaultencoding_doc}, 
+ #endif
  #ifdef HAVE_DLOPEN
  	{"getdlopenflags", (PyCFunction)sys_getdlopenflags, METH_NOARGS, 
***************
*** 554,559 ****
--- 560,567 ----
  	{"mdebug",	sys_mdebug, METH_VARARGS},
  #endif
+ #ifdef Py_USING_UNICODE
  	{"setdefaultencoding", sys_setdefaultencoding, METH_VARARGS,
  	 setdefaultencoding_doc}, 
+ #endif
  	{"setcheckinterval",	sys_setcheckinterval, METH_VARARGS,
  	 setcheckinterval_doc}, 
***************
*** 783,789 ****
--- 791,799 ----
  			     v = PyInt_FromLong(PyInt_GetMax()));
  	Py_XDECREF(v);
+ #ifdef Py_USING_UNICODE
  	PyDict_SetItemString(sysdict, "maxunicode",
  			     v = PyInt_FromLong(PyUnicode_GetMax()));
  	Py_XDECREF(v);
+ #endif
  	PyDict_SetItemString(sysdict, "builtin_module_names",
  		   v = list_builtin_module_names());