[Python-checkins] python/dist/src/Modules _localemodule.c, 2.45, 2.46 cPickle.c, 2.149, 2.150 stropmodule.c, 2.90, 2.91

loewis at users.sourceforge.net loewis at users.sourceforge.net
Tue Jun 8 14:52:56 EDT 2004


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26461/Modules

Modified Files:
	_localemodule.c cPickle.c stropmodule.c 
Log Message:
Patch #774665: Make Python LC_NUMERIC agnostic.


Index: _localemodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_localemodule.c,v
retrieving revision 2.45
retrieving revision 2.46
diff -C2 -d -r2.45 -r2.46
*** _localemodule.c	21 Mar 2004 19:34:30 -0000	2.45
--- _localemodule.c	8 Jun 2004 18:52:52 -0000	2.46
***************
*** 52,62 ****
  "(integer,string=None) -> string. Activates/queries locale processing.");
  
- /* to record the LC_NUMERIC settings */
- static PyObject* grouping = NULL;
- static PyObject* thousands_sep = NULL;
- static PyObject* decimal_point = NULL;
- /* if non-null, indicates that LC_NUMERIC is different from "C" */
- static char* saved_numeric = NULL;
- 
  /* the grouping is terminated by either 0 or CHAR_MAX */
  static PyObject*
--- 52,55 ----
***************
*** 168,172 ****
      char *locale = NULL, *result;
      PyObject *result_object;
-     struct lconv *lc;
  
      if (!PyArg_ParseTuple(args, "i|z:setlocale", &category, &locale))
--- 161,164 ----
***************
*** 184,210 ****
          if (!result_object)
              return NULL;
-         /* record changes to LC_NUMERIC */
-         if (category == LC_NUMERIC || category == LC_ALL) {
-             if (strcmp(locale, "C") == 0 || strcmp(locale, "POSIX") == 0) {
-                 /* user just asked for default numeric locale */
-                 if (saved_numeric)
-                     free(saved_numeric);
-                 saved_numeric = NULL;
-             } else {
-                 /* remember values */
-                 lc = localeconv();
-                 Py_XDECREF(grouping);
-                 grouping = copy_grouping(lc->grouping);
-                 Py_XDECREF(thousands_sep);
-                 thousands_sep = PyString_FromString(lc->thousands_sep);
-                 Py_XDECREF(decimal_point);
-                 decimal_point = PyString_FromString(lc->decimal_point);
-                 if (saved_numeric)
-                     free(saved_numeric);
-                 saved_numeric = strdup(locale);
-                 /* restore to "C" */
-                 setlocale(LC_NUMERIC, "C");
-             }
-         }
          /* record changes to LC_CTYPE */
          if (category == LC_CTYPE || category == LC_ALL)
--- 176,179 ----
***************
*** 214,220 ****
      } else {
          /* get locale */
-         /* restore LC_NUMERIC first, if appropriate */
-         if (saved_numeric)
-             setlocale(LC_NUMERIC, saved_numeric);
          result = setlocale(category, NULL);
          if (!result) {
--- 183,186 ----
***************
*** 223,229 ****
          }
          result_object = PyString_FromString(result);
-         /* restore back to "C" */
-         if (saved_numeric)
-             setlocale(LC_NUMERIC, "C");
      }
      return result_object;
--- 189,192 ----
***************
*** 263,280 ****
  
      /* Numeric information */
!     if (saved_numeric){
!         /* cannot use localeconv results */
!         PyDict_SetItemString(result, "decimal_point", decimal_point);
!         PyDict_SetItemString(result, "grouping", grouping);
!         PyDict_SetItemString(result, "thousands_sep", thousands_sep);
!     } else {
!         RESULT_STRING(decimal_point);
!         RESULT_STRING(thousands_sep);
!         x = copy_grouping(l->grouping);
!         if (!x)
!             goto failed;
!         PyDict_SetItemString(result, "grouping", x);
!         Py_XDECREF(x);
!     }
  
      /* Monetary information */
--- 226,236 ----
  
      /* Numeric information */
!     RESULT_STRING(decimal_point);
!     RESULT_STRING(thousands_sep);
!     x = copy_grouping(l->grouping);
!     if (!x)
!         goto failed;
!     PyDict_SetItemString(result, "grouping", x);
!     Py_XDECREF(x);
  
      /* Monetary information */
***************
*** 580,595 ****
         returns numeric values in the char* return value, which would
         crash PyString_FromString.  */
- #ifdef RADIXCHAR
-     if (saved_numeric) {
- 	if(item == RADIXCHAR) {
-             Py_INCREF(decimal_point);
-             return decimal_point;
-         }
-         if(item == THOUSEP) {
-             Py_INCREF(thousands_sep);
-             return thousands_sep;
-         }
-     }
- #endif
      for (i = 0; langinfo_constants[i].name; i++)
          if (langinfo_constants[i].value == item) {
--- 536,539 ----

Index: cPickle.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/cPickle.c,v
retrieving revision 2.149
retrieving revision 2.150
diff -C2 -d -r2.149 -r2.150
*** cPickle.c	26 Feb 2004 16:21:45 -0000	2.149
--- cPickle.c	8 Jun 2004 18:52:52 -0000	2.150
***************
*** 3320,3324 ****
  
  	errno = 0;
! 	d = strtod(s, &endptr);
  
  	if (errno || (endptr[0] != '\n') || (endptr[1] != '\0')) {
--- 3320,3324 ----
  
  	errno = 0;
! 	d = PyOS_ascii_strtod(s, &endptr);
  
  	if (errno || (endptr[0] != '\n') || (endptr[1] != '\0')) {

Index: stropmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/stropmodule.c,v
retrieving revision 2.90
retrieving revision 2.91
diff -C2 -d -r2.90 -r2.91
*** stropmodule.c	2 Aug 2002 02:27:13 -0000	2.90
--- stropmodule.c	8 Jun 2004 18:52:53 -0000	2.91
***************
*** 839,843 ****
  strop_atof(PyObject *self, PyObject *args)
  {
- 	extern double strtod(const char *, char **);
  	char *s, *end;
  	double x;
--- 839,842 ----
***************
*** 855,859 ****
  	errno = 0;
  	PyFPE_START_PROTECT("strop_atof", return 0)
! 	x = strtod(s, &end);
  	PyFPE_END_PROTECT(x)
  	while (*end && isspace(Py_CHARMASK(*end)))
--- 854,858 ----
  	errno = 0;
  	PyFPE_START_PROTECT("strop_atof", return 0)
! 	x = PyOS_ascii_strtod(s, &end);
  	PyFPE_END_PROTECT(x)
  	while (*end && isspace(Py_CHARMASK(*end)))




More information about the Python-checkins mailing list