[libgda] Use value returned from setlocale()



commit 311c64ccd8f53e0176dce5266efe4281ae8abef3
Author: Vivien Malerba <malerba gnome-db org>
Date:   Sun Nov 15 16:18:04 2009 +0100

    Use value returned from setlocale()
    
    instead of the global extern variable gda_numeric_locale.
    This also fix some crashes on Windows where the
    gda_numeric_locale variable should be prefixed with
    __declspec(dllimport)

 libgda/gda-init.c                           |   16 +++++++++++++++-
 providers/mysql/gda-mysql-recordset.c       |   15 ++++++++-------
 providers/postgres/gda-postgres-recordset.c |   12 ++++++------
 3 files changed, 29 insertions(+), 14 deletions(-)
---
diff --git a/libgda/gda-init.c b/libgda/gda-init.c
index 9a7e0d5..4f72c68 100644
--- a/libgda/gda-init.c
+++ b/libgda/gda-init.c
@@ -29,7 +29,21 @@
 #include <sql-parser/gda-sql-parser.h>
 #include <libgda/gda-types.h>
 
-/* global variables */
+/*
+ * global variables
+ *
+ * REM: to use them from another Windows DLL, they have to be declared like:
+ *     __declspec(dllimport) extern gchar *gda_numeric_locale;
+ *
+ * Better yet is to define the IMPORT macro as:
+ * 
+ *     #ifdef G_OS_WIN32
+ *       #define IMPORT __declspec(dllimport)
+ *     #else
+ *       #define IMPORT
+ *     #endif
+ *     IMPORT extern gchar *gda_numeric_locale;
+ */
 xmlDtdPtr       gda_array_dtd = NULL;
 xmlDtdPtr       gda_paramlist_dtd = NULL;
 xmlDtdPtr       gda_server_op_dtd = NULL;
diff --git a/providers/mysql/gda-mysql-recordset.c b/providers/mysql/gda-mysql-recordset.c
index cf33651..5be82dc 100644
--- a/providers/mysql/gda-mysql-recordset.c
+++ b/providers/mysql/gda-mysql-recordset.c
@@ -35,8 +35,6 @@
 #include <locale.h>
 #endif
 
-extern gchar *gda_numeric_locale;
-
 #define _GDA_PSTMT(x) ((GdaPStmt*)(x))
 
 enum
@@ -736,10 +734,11 @@ new_row_from_mysql_stmt (GdaMysqlRecordset *imodel, gint rownum, GError **error)
 
 			break;
 		case MYSQL_TYPE_FLOAT:
-		case MYSQL_TYPE_DOUBLE:
+		case MYSQL_TYPE_DOUBLE: {
+			char *current_locale;
 			g_memmove (&doublevalue, mysql_bind_result[i].buffer, sizeof(double));
 			
-			setlocale (LC_NUMERIC, "C");
+			current_locale = setlocale (LC_NUMERIC, "C");
 			if (type == G_TYPE_FLOAT)
 				g_value_set_float (value, (float) doublevalue);
 			else if (type == G_TYPE_DOUBLE)
@@ -751,9 +750,10 @@ new_row_from_mysql_stmt (GdaMysqlRecordset *imodel, gint rownum, GError **error)
 					     _("Type %s not mapped for value %f"),
 					     g_type_name (type), doublevalue);
 			}
-			setlocale (LC_NUMERIC, gda_numeric_locale);
+			setlocale (LC_NUMERIC, current_locale);
 			
 			break;
+		}
 		case MYSQL_TYPE_STRING:
 		case MYSQL_TYPE_VAR_STRING:
 		case MYSQL_TYPE_BLOB:
@@ -788,9 +788,10 @@ new_row_from_mysql_stmt (GdaMysqlRecordset *imodel, gint rownum, GError **error)
 			}
 			else if (type == G_TYPE_DOUBLE) {
 				if (length > 0) {
-					setlocale (LC_NUMERIC, "C");
+					char *current_locale;
+					current_locale = setlocale (LC_NUMERIC, "C");
 					g_value_set_double (value, atof (strvalue));
-					setlocale (LC_NUMERIC, gda_numeric_locale);
+					setlocale (LC_NUMERIC, current_locale);
 				}
 				else {
 					/* error: wrong column type */
diff --git a/providers/postgres/gda-postgres-recordset.c b/providers/postgres/gda-postgres-recordset.c
index fd61028..088ebb9 100644
--- a/providers/postgres/gda-postgres-recordset.c
+++ b/providers/postgres/gda-postgres-recordset.c
@@ -34,8 +34,6 @@
 #include <locale.h>
 #endif
 
-extern gchar *gda_numeric_locale;
-
 #define _GDA_PSTMT(x) ((GdaPStmt*)(x))
 
 static void gda_postgres_recordset_class_init (GdaPostgresRecordsetClass *klass);
@@ -640,14 +638,16 @@ set_value (GdaConnection *cnc, GdaRow *row, GValue *value, GType type, const gch
 	else if (type == GDA_TYPE_SHORT)
 		gda_value_set_short (value, atoi (thevalue));
 	else if (type == G_TYPE_FLOAT) {
-		setlocale (LC_NUMERIC, "C");
+		char *current_locale;
+		current_locale = setlocale (LC_NUMERIC, "C");
 		g_value_set_float (value, atof (thevalue));
-		setlocale (LC_NUMERIC, gda_numeric_locale);
+		setlocale (LC_NUMERIC, current_locale);
 	}
 	else if (type == G_TYPE_DOUBLE) {
-		setlocale (LC_NUMERIC, "C");
+		char *current_locale;
+		current_locale = setlocale (LC_NUMERIC, "C");
 		g_value_set_double (value, atof (thevalue));
-		setlocale (LC_NUMERIC, gda_numeric_locale);
+		setlocale (LC_NUMERIC, current_locale);
 	}
 	else if (type == GDA_TYPE_NUMERIC) {
 		GdaNumeric numeric;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]