From c5bc1a3b9aed38012b4d030e3e2bc760e35a74ed Mon Sep 17 00:00:00 2001 From: Federico Di Gregorio Date: Thu, 3 Nov 2005 16:03:06 +0000 Subject: [PATCH] Small changes to interval parsing. --- ChangeLog | 11 ++++++++--- psycopg/typecast.c | 9 +++++++++ psycopg/typecast_datetime.c | 10 +++++----- setup.cfg | 4 ++-- setup.py | 2 +- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index f99137f5..d34d261b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,14 @@ -2005-11-03 Federico Di Gregorio +2005-11-04 Federico Di Gregorio - * Applied patch from Daniele Varazzo to enablÃeDecimal on Python + * psycopg/typecast_datetime.c: now typecast_PYINTERVAL_cast limit the + scan to 'len' characters in the string (should fix #65.) + +2005-11-03 Federico Di Gregorio + + * Applied patch from Daniele Varazzo to enable Decimal on Python 2.3 when the module is available (run-time check, nice.) -2005-10-26 Federico Di Gregorio +2005-10-26 Federico Di Gregorio * setup.cfg: added include_dirs line for SUSE 9.3. diff --git a/psycopg/typecast.c b/psycopg/typecast.c index 7ab8bc57..e627e97a 100644 --- a/psycopg/typecast.c +++ b/psycopg/typecast.c @@ -38,6 +38,15 @@ skip_until_space(char *s) return s; } +static char * +skip_until_space2(char *s, int *len) +{ + while (*len > 0 && *s && *s != ' ') { + s++; (*len)--; + } + return s; +} + /** include casting objects **/ #include "psycopg/typecast_basic.c" diff --git a/psycopg/typecast_datetime.c b/psycopg/typecast_datetime.c index 40c80f3f..7f963d9b 100644 --- a/psycopg/typecast_datetime.c +++ b/psycopg/typecast_datetime.c @@ -89,7 +89,7 @@ typecast_PYDATETIME_cast(char *str, int len, PyObject *curs) } else { - Dprintf("typecast_PYDATETIME_cast: s = %s", str); + Dprintf("typecast_PYDATETIME_cast: s = %s", str); n = sscanf(str, "%d-%d-%d %d:%d:%lf%c%d:%d", &y, &m, &d, &hh, &mm, &ss, &tzs, &tzh, &tzm); Dprintf("typecast_PYDATETIME_cast: date parsed, %d components", n); @@ -172,7 +172,7 @@ typecast_PYINTERVAL_cast(char *str, int len, PyObject *curs) Dprintf("typecast_PYINTERVAL_cast: s = %s", str); - while (*str) { + while (len-- > 0 && *str) { switch (*str) { case '-': @@ -190,7 +190,7 @@ typecast_PYINTERVAL_cast(char *str, int len, PyObject *curs) case 'y': if (part == 0) { years = (long)(v*sign); - str = skip_until_space(str); + str = skip_until_space2(str, &len); v = 0.0; sign = 1.0; part = 1; } break; @@ -198,7 +198,7 @@ typecast_PYINTERVAL_cast(char *str, int len, PyObject *curs) case 'm': if (part <= 1) { months = (long)(v*sign); - str = skip_until_space(str); + str = skip_until_space2(str, &len); v = 0.0; sign = 1.0; part = 2; } break; @@ -206,7 +206,7 @@ typecast_PYINTERVAL_cast(char *str, int len, PyObject *curs) case 'd': if (part <= 2) { days = (long)(v*sign); - str = skip_until_space(str); + str = skip_until_space2(str, &len); v = 0.0; sign = 1.0; part = 3; } break; diff --git a/setup.cfg b/setup.cfg index 0bb03d1f..4759da1b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -7,8 +7,8 @@ define=PSYCOPG_EXTENSIONS,PSYCOPG_DISPLAY_SIZE,HAVE_PQFREEMEM,HAVE_PQPROTOCOL3 use_pydatetime=1 # Set to 1 if you want to enable "Decimal" type on python 2.3. -# If the "decimal" module is found in the PYTHONPATH it will be used, -# else fall back on the float type. +# If the "decimal" module is found in the PYTHONPATH it will be used, else +# fall back on the float type. use_decimal=0 # "include_dirs" is the preferred method for locating postgresql headers, diff --git a/setup.py b/setup.py index 3ded6e42..95b489ce 100644 --- a/setup.py +++ b/setup.py @@ -55,7 +55,7 @@ from distutils.command.build_ext import build_ext from distutils.sysconfig import get_python_inc from distutils.ccompiler import get_default_compiler -PSYCOPG_VERSION = '2.0b5' +PSYCOPG_VERSION = '2.0b6' version_flags = [] # to work around older distutil limitations