[Python-checkins] CVS: python/dist/src/Python bltinmodule.c,2.150,2.151 codecs.c,2.4,2.5
Guido van Rossum
python-dev@python.org
Wed, 5 Apr 2000 16:11:24 -0400 (EDT)
- Previous message: [Python-checkins] CVS: python/dist/src/Objects abstract.c,2.33,2.34 floatobject.c,2.55,2.56 intobject.c,2.39,2.40 longobject.c,1.54,1.55 unicodeobject.c,2.5,2.6
- Next message: [Python-checkins] CVS: python/dist/src/Include Python.h,2.14,2.15 intobject.h,2.16,2.17 longobject.h,2.12,2.13 unicodeobject.h,2.5,2.6
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /projects/cvsroot/python/dist/src/Python
In directory eric:/home/guido/hp/mal/py-patched/Python
Modified Files:
bltinmodule.c codecs.c
Log Message:
Marc-Andre's third try at this bulk patch seems to work (except that
his copy of test_contains.py seems to be broken -- the lines he
deleted were already absent). Checkin messages:
New Unicode support for int(), float(), complex() and long().
- new APIs PyInt_FromUnicode() and PyLong_FromUnicode()
- added support for Unicode to PyFloat_FromString()
- new encoding API PyUnicode_EncodeDecimal() which converts
Unicode to a decimal char* string (used in the above new
APIs)
- shortcuts for calls like int(<int object>) and float(<float obj>)
- tests for all of the above
Unicode compares and contains checks:
- comparing Unicode and non-string types now works; TypeErrors
are masked, all other errors such as ValueError during
Unicode coercion are passed through (note that PyUnicode_Compare
does not implement the masking -- PyObject_Compare does this)
- contains now works for non-string types too; TypeErrors are
masked and 0 returned; all other errors are passed through
Better testing support for the standard codecs.
Misc minor enhancements, such as an alias dbcs for the mbcs codec.
Changes:
- PyLong_FromString() now applies the same error checks as
does PyInt_FromString(): trailing garbage is reported
as error and not longer silently ignored. The only characters
which may be trailing the digits are 'L' and 'l' -- these
are still silently ignored.
- string.ato?() now directly interface to int(), long() and
float(). The error strings are now a little different, but
the type still remains the same. These functions are now
ready to get declared obsolete ;-)
- PyNumber_Int() now also does a check for embedded NULL chars
in the input string; PyNumber_Long() already did this (and
still does)
Followed by:
Looks like I've gone a step too far there... (and test_contains.py
seem to have a bug too).
I've changed back to reporting all errors in PyUnicode_Contains()
and added a few more test cases to test_contains.py (plus corrected
the join() NameError).
Index: bltinmodule.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Python/bltinmodule.c,v
retrieving revision 2.150
retrieving revision 2.151
diff -C2 -r2.150 -r2.151
*** bltinmodule.c 2000年03月10日 23:00:52 2.150
--- bltinmodule.c 2000年04月05日 20:11:21 2.151
***************
*** 450,454 ****
{
extern double strtod Py_PROTO((const char *, char **));
! char *s, *start, *end;
double x=0.0, y=0.0, z;
int got_re=0, got_im=0, done=0;
--- 450,455 ----
{
extern double strtod Py_PROTO((const char *, char **));
! const char *s, *start;
! char *end;
double x=0.0, y=0.0, z;
int got_re=0, got_im=0, done=0;
***************
*** 457,464 ****
int sign;
char buffer[256]; /* For errors */
! start = s = PyString_AS_STRING(v);
/* position on first nonblank */
while (*s && isspace(Py_CHARMASK(*s)))
s++;
--- 458,491 ----
int sign;
char buffer[256]; /* For errors */
+ int len;
! if (PyString_Check(v)) {
! s = PyString_AS_STRING(v);
! len = PyString_GET_SIZE(v);
! }
! else if (PyUnicode_Check(v)) {
! char s_buffer[256];
!
! if (PyUnicode_GET_SIZE(v) >= sizeof(s_buffer)) {
! PyErr_SetString(PyExc_ValueError,
! "complex() literal too large to convert");
! return NULL;
! }
! if (PyUnicode_EncodeDecimal(PyUnicode_AS_UNICODE(v),
! PyUnicode_GET_SIZE(v),
! s_buffer,
! NULL))
! return NULL;
! s = s_buffer;
! len = strlen(s);
! }
! else if (PyObject_AsCharBuffer(v, &s, &len)) {
! PyErr_SetString(PyExc_TypeError,
! "complex() needs a string first argument");
! return NULL;
! }
/* position on first nonblank */
+ start = s;
while (*s && isspace(Py_CHARMASK(*s)))
s++;
***************
*** 476,480 ****
case '0円':
! if (s-start != PyString_GET_SIZE(v)) {
PyErr_SetString(
PyExc_ValueError,
--- 503,507 ----
case '0円':
! if (s-start != len) {
PyErr_SetString(
PyExc_ValueError,
***************
*** 585,589 ****
if (!PyArg_ParseTuple(args, "O|O:complex", &r, &i))
return NULL;
! if (PyString_Check(r))
return complex_from_string(r);
if ((nbr = r->ob_type->tp_as_number) == NULL ||
--- 612,616 ----
if (!PyArg_ParseTuple(args, "O|O:complex", &r, &i))
return NULL;
! if (PyString_Check(r) || PyUnicode_Check(r))
return complex_from_string(r);
if ((nbr = r->ob_type->tp_as_number) == NULL ||
***************
*** 1290,1299 ****
if (base == -909)
return PyNumber_Int(v);
! else if (!PyString_Check(v)) {
PyErr_SetString(PyExc_TypeError,
"can't convert non-string with explicit base");
return NULL;
}
- return PyInt_FromString(PyString_AS_STRING(v), NULL, base);
}
--- 1317,1331 ----
if (base == -909)
return PyNumber_Int(v);
! else if (PyString_Check(v))
! return PyInt_FromString(PyString_AS_STRING(v), NULL, base);
! else if (PyUnicode_Check(v))
! return PyInt_FromUnicode(PyUnicode_AS_UNICODE(v),
! PyUnicode_GET_SIZE(v),
! base);
! else {
PyErr_SetString(PyExc_TypeError,
"can't convert non-string with explicit base");
return NULL;
}
}
***************
*** 1320,1329 ****
if (base == -909)
return PyNumber_Long(v);
! else if (!PyString_Check(v)) {
PyErr_SetString(PyExc_TypeError,
"can't convert non-string with explicit base");
return NULL;
}
- return PyLong_FromString(PyString_AS_STRING(v), NULL, base);
}
--- 1352,1366 ----
if (base == -909)
return PyNumber_Long(v);
! else if (PyString_Check(v))
! return PyLong_FromString(PyString_AS_STRING(v), NULL, base);
! else if (PyUnicode_Check(v))
! return PyLong_FromUnicode(PyUnicode_AS_UNICODE(v),
! PyUnicode_GET_SIZE(v),
! base);
! else {
PyErr_SetString(PyExc_TypeError,
"can't convert non-string with explicit base");
return NULL;
}
}
Index: codecs.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Python/codecs.c,v
retrieving revision 2.4
retrieving revision 2.5
diff -C2 -r2.4 -r2.5
*** codecs.c 2000年03月31日 17:25:23 2.4
--- codecs.c 2000年04月05日 20:11:21 2.5
***************
*** 85,90 ****
}
static
! PyObject *lowercasestring(const char *string)
{
register int i;
--- 85,93 ----
}
+ /* Convert a string to a normalized Python string: all characters are
+ converted to lower case, spaces are replaced with underscores. */
+
static
! PyObject *normalizestring(const char *string)
{
register int i;
***************
*** 97,102 ****
return NULL;
p = PyString_AS_STRING(v);
! for (i = 0; i < len; i++)
! p[i] = tolower(string[i]);
return v;
}
--- 100,111 ----
return NULL;
p = PyString_AS_STRING(v);
! for (i = 0; i < len; i++) {
! register char ch = string[i];
! if (ch == ' ')
! ch = '-';
! else
! ch = tolower(ch);
! p[i] = ch;
! }
return v;
}
***************
*** 133,138 ****
}
! /* Convert the encoding to a lower-cased Python string */
! v = lowercasestring(encoding);
if (v == NULL)
goto onError;
--- 142,149 ----
}
! /* Convert the encoding to a normalized Python string: all
! characters are converted to lower case, spaces and hypens are
! replaced with underscores. */
! v = normalizestring(encoding);
if (v == NULL)
goto onError;
- Previous message: [Python-checkins] CVS: python/dist/src/Objects abstract.c,2.33,2.34 floatobject.c,2.55,2.56 intobject.c,2.39,2.40 longobject.c,1.54,1.55 unicodeobject.c,2.5,2.6
- Next message: [Python-checkins] CVS: python/dist/src/Include Python.h,2.14,2.15 intobject.h,2.16,2.17 longobject.h,2.12,2.13 unicodeobject.h,2.5,2.6
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]