Author: cito
Date: Tue Nov 24 10:27:02 2015
New Revision: 619
Log:
Fixed a problem on NetBSD
It seems isdigit() and ispunct() expect unsigned chars instead of
ints on certain platforms, and silencing them by casting signed
chars to ints was counter productive, causing serious issues on
NetBSD and maybe other platforms. To avoid problems with the
implementation of isdigit() and ispunct() on different platforms
and with different locales, we totally avoid these functions now
and check the chars "manually" instead, which is an easy thing.
Modified:
trunk/module/TEST_PyGreSQL_classic_connection.py
trunk/module/pgmodule.c
Modified: trunk/module/TEST_PyGreSQL_classic_connection.py
==============================================================================
--- trunk/module/TEST_PyGreSQL_classic_connection.py Tue Nov 24 08:57:10
2015 (r618)
+++ trunk/module/TEST_PyGreSQL_classic_connection.py Tue Nov 24 10:27:02
2015 (r619)
@@ -1150,6 +1150,25 @@
pg.set_decimal_point(point)
self.assertIsInstance(r, str)
self.assertEqual(r, ',')
+ pg.set_decimal_point("'")
+ try:
+ r = pg.get_decimal_point()
+ finally:
+ pg.set_decimal_point(point)
+ self.assertIsInstance(r, str)
+ self.assertEqual(r, "'")
+ pg.set_decimal_point('')
+ try:
+ r = pg.get_decimal_point()
+ finally:
+ pg.set_decimal_point(point)
+ self.assertIsNone(r)
+ pg.set_decimal_point(None)
+ try:
+ r = pg.get_decimal_point()
+ finally:
+ pg.set_decimal_point(point)
+ self.assertIsNone(r)
def testSetDecimalPoint(self):
d = pg.Decimal
@@ -1198,6 +1217,14 @@
self.assertIsInstance(r, str)
self.assertIn(r, en_money)
r = query(select_money)
+ pg.set_decimal_point('')
+ try:
+ r = r.getresult()[0][0]
+ finally:
+ pg.set_decimal_point(point)
+ self.assertIsInstance(r, str)
+ self.assertIn(r, en_money)
+ r = query(select_money)
pg.set_decimal_point('.')
try:
r = r.getresult()[0][0]
@@ -1214,7 +1241,7 @@
self.assertIsInstance(r, d)
self.assertEqual(r, bad_money)
r = query(select_money)
- pg.set_decimal_point('!')
+ pg.set_decimal_point("'")
try:
r = r.getresult()[0][0]
finally:
@@ -1244,6 +1271,14 @@
self.assertIsInstance(r, str)
self.assertIn(r, de_money)
r = query(select_money)
+ pg.set_decimal_point('')
+ try:
+ r = r.getresult()[0][0]
+ finally:
+ pg.set_decimal_point(point)
+ self.assertIsInstance(r, str)
+ self.assertIn(r, de_money)
+ r = query(select_money)
pg.set_decimal_point(',')
try:
r = r.getresult()[0][0]
@@ -1259,7 +1294,7 @@
pg.set_decimal_point(point)
self.assertEqual(r, bad_money)
r = query(select_money)
- pg.set_decimal_point('!')
+ pg.set_decimal_point("'")
try:
r = r.getresult()[0][0]
finally:
Modified: trunk/module/pgmodule.c
==============================================================================
--- trunk/module/pgmodule.c Tue Nov 24 08:57:10 2015 (r618)
+++ trunk/module/pgmodule.c Tue Nov 24 10:27:02 2015 (r619)
@@ -3289,14 +3289,14 @@
*s && k <
sizeof(cashbuf) / sizeof(cashbuf[0]) - 1;
s++)
{
- if (isdigit((int)*s))
+ if (*s >= '0' && *s <=
'9')
cashbuf[k++] =
*s;
else if (*s ==
decimal_point)
cashbuf[k++] =
'.';
else if (*s == '(' ||
*s == '-')
cashbuf[k++] =
'-';
}
- cashbuf[k] = 0;
+ cashbuf[k] = '\0';
s = cashbuf;
/* FALLTHROUGH */ /* no break */
@@ -3442,14 +3442,14 @@
*s && k <
sizeof(cashbuf) / sizeof(cashbuf[0]) - 1;
s++)
{
- if (isdigit((int)*s))
+ if (*s >= '0' && *s <=
'9')
cashbuf[k++] =
*s;
else if (*s ==
decimal_point)
cashbuf[k++] =
'.';
else if (*s == '(' ||
*s == '-')
cashbuf[k++] =
'-';
}
- cashbuf[k] = 0;
+ cashbuf[k] = '\0';
s = cashbuf;
/* FALLTHROUGH */ /* no break */
@@ -3802,7 +3802,7 @@
if (PyArg_ParseTuple(args, "z", &s)) {
if (!s)
s = "\0";
- else if (*s && (*(s+1) || !ispunct((int)*s)))
+ else if (*s && (*(s+1) || !strchr(".,;: '*/_`|", *s)))
s = NULL;
}
@@ -3811,7 +3811,7 @@
Py_INCREF(Py_None); ret = Py_None;
} else {
PyErr_SetString(PyExc_TypeError,
- "set_decimal_point() takes a punctuation character");
+ "set_decimal_point() expects a decimal mark character");
}
return ret;
_______________________________________________
PyGreSQL mailing list
[email protected]
https://mail.vex.net/mailman/listinfo.cgi/pygresql