Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 82294 Details for
Bug 126413
[dev-python/pypgsql] Parsing of float values is not locale agnostic
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Debian's provided patch
float_parse_fix.patch (text/plain), 4.46 KB, created by
Mikael Cluseau
on 2006-03-16 05:11:46 UTC
(
hide
)
Description:
Debian's provided patch
Filename:
MIME Type:
Creator:
Mikael Cluseau
Created:
2006-03-16 05:11:46 UTC
Size:
4.46 KB
patch
obsolete
>--- python-pgsql-2.4.0.orig/pgresult.c >+++ python-pgsql-2.4.0/pgresult.c >@@ -110,6 +110,175 @@ > > /*--------------------------------------------------------------------------*/ > >+#if (PY_VERSION_HEX < 0x02040000) >+ >+/* code stolen from Python 2.4 */ >+ >+#include <locale.h> >+ >+#define ISSPACE(c) ((c) == ' ' || (c) == '\f' || (c) == '\n' || \ >+ (c) == '\r' || (c) == '\t' || (c) == '\v') >+#define ISDIGIT(c) ((c) >= '0' && (c) <= '9') >+#define ISXDIGIT(c) (ISDIGIT(c) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F')) >+ >+/** >+ * PyOS_ascii_strtod: >+ * @nptr: the string to convert to a numeric value. >+ * @endptr: if non-%NULL, it returns the character after >+ * the last character used in the conversion. >+ * >+ * Converts a string to a #gdouble value. >+ * This function behaves like the standard strtod() function >+ * does in the C locale. It does this without actually >+ * changing the current locale, since that would not be >+ * thread-safe. >+ * >+ * This function is typically used when reading configuration >+ * files or other non-user input that should be locale independent. >+ * To handle input from the user you should normally use the >+ * locale-sensitive system strtod() function. >+ * >+ * If the correct value would cause overflow, plus or minus %HUGE_VAL >+ * is returned (according to the sign of the value), and %ERANGE is >+ * stored in %errno. If the correct value would cause underflow, >+ * zero is returned and %ERANGE is stored in %errno. >+ * >+ * This function resets %errno before calling strtod() so that >+ * you can reliably detect overflow and underflow. >+ * >+ * Return value: the #gdouble value. >+ **/ >+double >+PyOS_ascii_strtod(const char *nptr, >+ char **endptr) >+{ >+ char *fail_pos; >+ double val; >+ struct lconv *locale_data; >+ const char *decimal_point; >+ int decimal_point_len; >+ const char *p, *decimal_point_pos; >+ const char *end = NULL; /* Silence gcc */ >+ >+/* g_return_val_if_fail (nptr != NULL, 0); */ >+ assert(nptr != NULL); >+ >+ fail_pos = NULL; >+ >+ locale_data = localeconv(); >+ decimal_point = locale_data->decimal_point; >+ decimal_point_len = strlen(decimal_point); >+ >+ assert(decimal_point_len != 0); >+ >+ decimal_point_pos = NULL; >+ if (decimal_point[0] != '.' || >+ decimal_point[1] != 0) >+ { >+ p = nptr; >+ /* Skip leading space */ >+ while (ISSPACE(*p)) >+ p++; >+ >+ /* Skip leading optional sign */ >+ if (*p == '+' || *p == '-') >+ p++; >+ >+ if (p[0] == '0' && >+ (p[1] == 'x' || p[1] == 'X')) >+ { >+ p += 2; >+ /* HEX - find the (optional) decimal point */ >+ >+ while (ISXDIGIT(*p)) >+ p++; >+ >+ if (*p == '.') >+ { >+ decimal_point_pos = p++; >+ >+ while (ISXDIGIT(*p)) >+ p++; >+ >+ if (*p == 'p' || *p == 'P') >+ p++; >+ if (*p == '+' || *p == '-') >+ p++; >+ while (ISDIGIT(*p)) >+ p++; >+ end = p; >+ } >+ } >+ else >+ { >+ while (ISDIGIT(*p)) >+ p++; >+ >+ if (*p == '.') >+ { >+ decimal_point_pos = p++; >+ >+ while (ISDIGIT(*p)) >+ p++; >+ >+ if (*p == 'e' || *p == 'E') >+ p++; >+ if (*p == '+' || *p == '-') >+ p++; >+ while (ISDIGIT(*p)) >+ p++; >+ end = p; >+ } >+ } >+ /* For the other cases, we need not convert the decimal point */ >+ } >+ >+ /* Set errno to zero, so that we can distinguish zero results >+ and underflows */ >+ errno = 0; >+ >+ if (decimal_point_pos) >+ { >+ char *copy, *c; >+ >+ /* We need to convert the '.' to the locale specific decimal point */ >+ copy = malloc(end - nptr + 1 + decimal_point_len); >+ >+ c = copy; >+ memcpy(c, nptr, decimal_point_pos - nptr); >+ c += decimal_point_pos - nptr; >+ memcpy(c, decimal_point, decimal_point_len); >+ c += decimal_point_len; >+ memcpy(c, decimal_point_pos + 1, end - (decimal_point_pos + 1)); >+ c += end - (decimal_point_pos + 1); >+ *c = 0; >+ >+ val = strtod(copy, &fail_pos); >+ >+ if (fail_pos) >+ { >+ if (fail_pos > decimal_point_pos) >+ fail_pos = (char *)nptr + (fail_pos - copy) - (decimal_point_len - 1); >+ else >+ fail_pos = (char *)nptr + (fail_pos - copy); >+ } >+ >+ free(copy); >+ >+ } >+ else >+ val = strtod(nptr, &fail_pos); >+ >+ if (endptr) >+ *endptr = fail_pos; >+ >+ return val; >+} >+ >+#endif >+ >+/*--------------------------------------------------------------------------*/ >+ > PyObject *PgResult_New(PGresult *res, PgConnection *conn, int type) > { > PgResult *self; >@@ -623,7 +792,7 @@ > /*FALLTHRU*/ > > case PG_FLOAT8: >- valueObj = Py_BuildValue("d", strtod(value, NULL)); >+ valueObj = Py_BuildValue("d", PyOS_ascii_strtod(value, NULL)); > break; > > case PG_BYTEA:
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 126413
: 82294 |
82295