|
Line
Link Here
|
| 0 |
-- python-pgsql-2.4.0.orig/pgresult.c |
0 |
++ python-pgsql-2.4.0/pgresult.c |
|
Lines 110-115
Link Here
|
| 110 |
|
110 |
|
| 111 |
/*--------------------------------------------------------------------------*/ |
111 |
/*--------------------------------------------------------------------------*/ |
| 112 |
|
112 |
|
|
|
113 |
#if (PY_VERSION_HEX < 0x02040000) |
| 114 |
|
| 115 |
/* code stolen from Python 2.4 */ |
| 116 |
|
| 117 |
#include <locale.h> |
| 118 |
|
| 119 |
#define ISSPACE(c) ((c) == ' ' || (c) == '\f' || (c) == '\n' || \ |
| 120 |
(c) == '\r' || (c) == '\t' || (c) == '\v') |
| 121 |
#define ISDIGIT(c) ((c) >= '0' && (c) <= '9') |
| 122 |
#define ISXDIGIT(c) (ISDIGIT(c) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F')) |
| 123 |
|
| 124 |
/** |
| 125 |
* PyOS_ascii_strtod: |
| 126 |
* @nptr: the string to convert to a numeric value. |
| 127 |
* @endptr: if non-%NULL, it returns the character after |
| 128 |
* the last character used in the conversion. |
| 129 |
* |
| 130 |
* Converts a string to a #gdouble value. |
| 131 |
* This function behaves like the standard strtod() function |
| 132 |
* does in the C locale. It does this without actually |
| 133 |
* changing the current locale, since that would not be |
| 134 |
* thread-safe. |
| 135 |
* |
| 136 |
* This function is typically used when reading configuration |
| 137 |
* files or other non-user input that should be locale independent. |
| 138 |
* To handle input from the user you should normally use the |
| 139 |
* locale-sensitive system strtod() function. |
| 140 |
* |
| 141 |
* If the correct value would cause overflow, plus or minus %HUGE_VAL |
| 142 |
* is returned (according to the sign of the value), and %ERANGE is |
| 143 |
* stored in %errno. If the correct value would cause underflow, |
| 144 |
* zero is returned and %ERANGE is stored in %errno. |
| 145 |
* |
| 146 |
* This function resets %errno before calling strtod() so that |
| 147 |
* you can reliably detect overflow and underflow. |
| 148 |
* |
| 149 |
* Return value: the #gdouble value. |
| 150 |
**/ |
| 151 |
double |
| 152 |
PyOS_ascii_strtod(const char *nptr, |
| 153 |
char **endptr) |
| 154 |
{ |
| 155 |
char *fail_pos; |
| 156 |
double val; |
| 157 |
struct lconv *locale_data; |
| 158 |
const char *decimal_point; |
| 159 |
int decimal_point_len; |
| 160 |
const char *p, *decimal_point_pos; |
| 161 |
const char *end = NULL; /* Silence gcc */ |
| 162 |
|
| 163 |
/* g_return_val_if_fail (nptr != NULL, 0); */ |
| 164 |
assert(nptr != NULL); |
| 165 |
|
| 166 |
fail_pos = NULL; |
| 167 |
|
| 168 |
locale_data = localeconv(); |
| 169 |
decimal_point = locale_data->decimal_point; |
| 170 |
decimal_point_len = strlen(decimal_point); |
| 171 |
|
| 172 |
assert(decimal_point_len != 0); |
| 173 |
|
| 174 |
decimal_point_pos = NULL; |
| 175 |
if (decimal_point[0] != '.' || |
| 176 |
decimal_point[1] != 0) |
| 177 |
{ |
| 178 |
p = nptr; |
| 179 |
/* Skip leading space */ |
| 180 |
while (ISSPACE(*p)) |
| 181 |
p++; |
| 182 |
|
| 183 |
/* Skip leading optional sign */ |
| 184 |
if (*p == '+' || *p == '-') |
| 185 |
p++; |
| 186 |
|
| 187 |
if (p[0] == '0' && |
| 188 |
(p[1] == 'x' || p[1] == 'X')) |
| 189 |
{ |
| 190 |
p += 2; |
| 191 |
/* HEX - find the (optional) decimal point */ |
| 192 |
|
| 193 |
while (ISXDIGIT(*p)) |
| 194 |
p++; |
| 195 |
|
| 196 |
if (*p == '.') |
| 197 |
{ |
| 198 |
decimal_point_pos = p++; |
| 199 |
|
| 200 |
while (ISXDIGIT(*p)) |
| 201 |
p++; |
| 202 |
|
| 203 |
if (*p == 'p' || *p == 'P') |
| 204 |
p++; |
| 205 |
if (*p == '+' || *p == '-') |
| 206 |
p++; |
| 207 |
while (ISDIGIT(*p)) |
| 208 |
p++; |
| 209 |
end = p; |
| 210 |
} |
| 211 |
} |
| 212 |
else |
| 213 |
{ |
| 214 |
while (ISDIGIT(*p)) |
| 215 |
p++; |
| 216 |
|
| 217 |
if (*p == '.') |
| 218 |
{ |
| 219 |
decimal_point_pos = p++; |
| 220 |
|
| 221 |
while (ISDIGIT(*p)) |
| 222 |
p++; |
| 223 |
|
| 224 |
if (*p == 'e' || *p == 'E') |
| 225 |
p++; |
| 226 |
if (*p == '+' || *p == '-') |
| 227 |
p++; |
| 228 |
while (ISDIGIT(*p)) |
| 229 |
p++; |
| 230 |
end = p; |
| 231 |
} |
| 232 |
} |
| 233 |
/* For the other cases, we need not convert the decimal point */ |
| 234 |
} |
| 235 |
|
| 236 |
/* Set errno to zero, so that we can distinguish zero results |
| 237 |
and underflows */ |
| 238 |
errno = 0; |
| 239 |
|
| 240 |
if (decimal_point_pos) |
| 241 |
{ |
| 242 |
char *copy, *c; |
| 243 |
|
| 244 |
/* We need to convert the '.' to the locale specific decimal point */ |
| 245 |
copy = malloc(end - nptr + 1 + decimal_point_len); |
| 246 |
|
| 247 |
c = copy; |
| 248 |
memcpy(c, nptr, decimal_point_pos - nptr); |
| 249 |
c += decimal_point_pos - nptr; |
| 250 |
memcpy(c, decimal_point, decimal_point_len); |
| 251 |
c += decimal_point_len; |
| 252 |
memcpy(c, decimal_point_pos + 1, end - (decimal_point_pos + 1)); |
| 253 |
c += end - (decimal_point_pos + 1); |
| 254 |
*c = 0; |
| 255 |
|
| 256 |
val = strtod(copy, &fail_pos); |
| 257 |
|
| 258 |
if (fail_pos) |
| 259 |
{ |
| 260 |
if (fail_pos > decimal_point_pos) |
| 261 |
fail_pos = (char *)nptr + (fail_pos - copy) - (decimal_point_len - 1); |
| 262 |
else |
| 263 |
fail_pos = (char *)nptr + (fail_pos - copy); |
| 264 |
} |
| 265 |
|
| 266 |
free(copy); |
| 267 |
|
| 268 |
} |
| 269 |
else |
| 270 |
val = strtod(nptr, &fail_pos); |
| 271 |
|
| 272 |
if (endptr) |
| 273 |
*endptr = fail_pos; |
| 274 |
|
| 275 |
return val; |
| 276 |
} |
| 277 |
|
| 278 |
#endif |
| 279 |
|
| 280 |
/*--------------------------------------------------------------------------*/ |
| 281 |
|
| 113 |
PyObject *PgResult_New(PGresult *res, PgConnection *conn, int type) |
282 |
PyObject *PgResult_New(PGresult *res, PgConnection *conn, int type) |
| 114 |
{ |
283 |
{ |
| 115 |
PgResult *self; |
284 |
PgResult *self; |
|
Lines 623-629
Link Here
|
| 623 |
/*FALLTHRU*/ |
792 |
/*FALLTHRU*/ |
| 624 |
|
793 |
|
| 625 |
case PG_FLOAT8: |
794 |
case PG_FLOAT8: |
| 626 |
valueObj = Py_BuildValue("d", strtod(value, NULL)); |
795 |
valueObj = Py_BuildValue("d", PyOS_ascii_strtod(value, NULL)); |
| 627 |
break; |
796 |
break; |
| 628 |
|
797 |
|
| 629 |
case PG_BYTEA: |
798 |
case PG_BYTEA: |