[Skencil-commits] r515 - in skencil/branches/skencil-0.6: . Sketch/Modules

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Sun Jan 29 18:40:46 CET 2006


Author: bh
Date: 2006-01-29 18:40:45 +0100 (Sun, 29 Jan 2006)
New Revision: 515

Modified:
   skencil/branches/skencil-0.6/ChangeLog
   skencil/branches/skencil-0.6/Sketch/Modules/curveobject.c
   skencil/branches/skencil-0.6/Sketch/Modules/pstokenize.c
   skencil/branches/skencil-0.6/Sketch/Modules/skreadmodule.c
Log:
Merge -r 512:513 from trunk:

* Sketch/Modules/curveobject.c (curve_parse_string_append),
Sketch/Modules/skreadmodule.c (sklex),
Sketch/Modules/pstokenize.c (read_name_or_number): Set LC_NUMERIC
locale to "C" to make sure the C format for floats is recognized
instead of any locale specific format.


Modified: skencil/branches/skencil-0.6/ChangeLog
===================================================================
--- skencil/branches/skencil-0.6/ChangeLog	2006-01-29 17:18:21 UTC (rev 514)
+++ skencil/branches/skencil-0.6/ChangeLog	2006-01-29 17:40:45 UTC (rev 515)
@@ -1,3 +1,11 @@
 2006-01-29  Bernhard Herzog  <bh at intevation.de>
 
+	* Sketch/Modules/curveobject.c (curve_parse_string_append),
+	Sketch/Modules/skreadmodule.c (sklex),
+	Sketch/Modules/pstokenize.c (read_name_or_number): Set LC_NUMERIC
+	locale to "C" to make sure the C format for floats is recognized
+	instead of any locale specific format.
+
+2006-01-29  Bernhard Herzog  <bh at intevation.de>
+
 	* ChangeLog: Started ChangeLog for Skencil 0.6

Modified: skencil/branches/skencil-0.6/Sketch/Modules/curveobject.c
===================================================================
--- skencil/branches/skencil-0.6/Sketch/Modules/curveobject.c	2006-01-29 17:18:21 UTC (rev 514)
+++ skencil/branches/skencil-0.6/Sketch/Modules/curveobject.c	2006-01-29 17:40:45 UTC (rev 515)
@@ -1,5 +1,5 @@
 /* Sketch - A Python-based interactive drawing program
- * Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003 by Bernhard Herzog
+ * Copyright (C) 1997 -- 2006 by Bernhard Herzog
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -19,6 +19,8 @@
 /* a poly bezier object */
 
 #include <math.h>
+#include <string.h>
+#include <locale.h>
 
 #include <Python.h>
 #include <structmember.h>
@@ -1449,6 +1451,10 @@
 curve_parse_string_append(SKCurveObject * self, const char * string)
 {
     CurveSegment segment;
+    char * old_locale;
+
+    old_locale = strdup(setlocale(LC_NUMERIC, NULL));
+    setlocale(LC_NUMERIC, "C");
     
     if (string[1] == 'c')
     {
@@ -1460,7 +1466,7 @@
 		   &x1, &y1, &x2, &y2, &x, &y, &cont) != 7)
 	{
 	    PyErr_SetString(PyExc_ValueError, "cannot parse string");
-	    return 0;
+	    goto fail;
 	}
 
 	segment.cont = cont;
@@ -1469,7 +1475,7 @@
 	segment.x2 = x2;	segment.y2 = y2;
 	
 	if (!SKCurve_AppendSegment(self, &segment))
-	    return 0;
+	    goto fail;
     }
     else if (string[1] == 's')
     {
@@ -1480,23 +1486,28 @@
 	if (sscanf(string, "bs%*[ (]%lf,%lf,%d", &x, &y, &cont) != 3)
 	{
 	    PyErr_SetString(PyExc_ValueError, "cannot parse string");
-	    return 0;
+	    goto fail;
 	}
 
 	segment.cont = cont;
 	segment.x = x;		segment.y = y;
 
 	if (!SKCurve_AppendSegment(self, &segment))
-	    return 0;
+	    goto fail;
     }
     else
     {
 	PyErr_SetString(PyExc_ValueError,
 			"string must begin with 'bc' or 'bs'");
-	return 0;
+	goto fail;
     }
 
     return 1;
+
+fail:
+    setlocale(LC_NUMERIC, old_locale);
+    free(old_locale);
+    return 0;
 }
 
 static PyObject *

Modified: skencil/branches/skencil-0.6/Sketch/Modules/pstokenize.c
===================================================================
--- skencil/branches/skencil-0.6/Sketch/Modules/pstokenize.c	2006-01-29 17:18:21 UTC (rev 514)
+++ skencil/branches/skencil-0.6/Sketch/Modules/pstokenize.c	2006-01-29 17:40:45 UTC (rev 515)
@@ -1,5 +1,5 @@
 /* Sketch - A Python-based interactive drawing program
- * Copyright (C) 1998, 1999, 2000, 2001 by Bernhard Herzog
+ * Copyright (C) 1998, 1999, 2000, 2001, 2003, 2006 by Bernhard Herzog
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -20,6 +20,7 @@
  * Functions to tokenize PostScript-files.
  */
 
+#include <locale.h>
 #include <Python.h>
 #include <structmember.h>
 #include <filterobj.h>
@@ -461,7 +462,17 @@
 	    p += 1;
 	if (char_types[(int)*p] & FLOATCHAR)
 	{
-	    double result = strtod(start, &numend);
+	    char * old_locale;
+	    double result;
+
+	    /* Change LC_NUMERIC locale to "C" around the strtod
+	     * call so that it parses the number correctly. */
+	    old_locale = strdup(setlocale(LC_NUMERIC, NULL));
+	    setlocale(LC_NUMERIC, "C");
+	    result = strtod(start, &numend);
+	    setlocale(LC_NUMERIC, old_locale);
+	    free(old_locale);
+
 	    if (numend == buf)
 	    {
 		Py_DECREF(value);

Modified: skencil/branches/skencil-0.6/Sketch/Modules/skreadmodule.c
===================================================================
--- skencil/branches/skencil-0.6/Sketch/Modules/skreadmodule.c	2006-01-29 17:18:21 UTC (rev 514)
+++ skencil/branches/skencil-0.6/Sketch/Modules/skreadmodule.c	2006-01-29 17:40:45 UTC (rev 515)
@@ -1,5 +1,5 @@
 /* Sketch - A Python-based interactive drawing program
- * Copyright (C) 1998, 1999, 2001 by Bernhard Herzog
+ * Copyright (C) 1998, 1999, 2000, 2001, 2006 by Bernhard Herzog
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -27,6 +27,8 @@
  */
 
 #include <ctype.h>
+#include <locale.h>
+#include <string.h>
 #include <Python.h>
 
 typedef struct {
@@ -208,7 +210,19 @@
 		p += 1;
 	    if (*p == '.' || *p == 'e' || *p == 'E')
 	    {
-		double result = strtod(buffer->buffer - 1, &(buffer->buffer));
+		char * old_locale;
+		double result;
+
+		/* Change LC_NUMERIC locale to "C" around the strtod
+		 * call so that it parses the number correctly. */
+		old_locale = strdup(setlocale(LC_NUMERIC, NULL));
+		setlocale(LC_NUMERIC, "C");
+
+		result = strtod(buffer->buffer - 1, &(buffer->buffer));
+
+		setlocale(LC_NUMERIC, old_locale);
+		free(old_locale);
+
 		*lval = PyFloat_FromDouble(result);
 		return FLOAT;
 	    }



More information about the Skencil-commits mailing list