diff options
Diffstat (limited to 'psycopg')
| -rw-r--r-- | psycopg/config.h | 13 | ||||
| -rw-r--r-- | psycopg/cursor_type.c | 20 |
2 files changed, 31 insertions, 2 deletions
diff --git a/psycopg/config.h b/psycopg/config.h index e21e819..a250109 100644 --- a/psycopg/config.h +++ b/psycopg/config.h @@ -52,6 +52,17 @@ static void Dprintf(const char *fmt, ...) {} #if defined(_WIN32) || defined(__BEOS__) #ifdef _WIN32 + +/* A Python extension should be linked to only one C runtime: the same one as + * the Python interpreter itself. Straightforwardly using the strdup function + * causes MinGW to implicitly link to the msvcrt.dll, which is not appropriate + * for any Python version later than 2.3. + * Microsoft C runtimes for Windows 98 and later make a _strdup function + * available, which replaces the "normal" strdup. If we replace all psycopg + * calls to strdup with calls to _strdup, MinGW no longer implicitly links to + * the obsolete C runtime. */ +#define strdup _strdup + #include <winsock2.h> #define pthread_mutex_t HANDLE #define pthread_condvar_t HANDLE @@ -102,7 +113,7 @@ static struct tm *localtime_r(time_t *t, struct tm *tm) #define inline #endif -#if defined(__FreeBSD__) || defined(_WIN32) || defined(__sun__) +#if defined(__FreeBSD__) || (defined(_WIN32) && !defined(__GNUC__)) || defined(__sun__) /* what's this, we have no round function either? */ static double round(double num) { diff --git a/psycopg/cursor_type.c b/psycopg/cursor_type.c index 26c53c6..55924d5 100644 --- a/psycopg/cursor_type.c +++ b/psycopg/cursor_type.c @@ -79,7 +79,7 @@ _mogrify(PyObject *var, PyObject *fmt, connectionObject *conn, PyObject **new) PyObject *key, *value, *n, *item; char *d, *c; Py_ssize_t index = 0; - int force = 0; + int force = 0, kind = 0; /* from now on we'll use n and replace its value in *new only at the end, just before returning. we also init *new to NULL to exit with an error @@ -88,6 +88,15 @@ _mogrify(PyObject *var, PyObject *fmt, connectionObject *conn, PyObject **new) c = PyString_AsString(fmt); while(*c) { + /* check if some crazy guy mixed formats */ + if (kind == 2) { + Py_XDECREF(n); + psyco_set_error(ProgrammingError, (PyObject*)conn, + "argument formats can't be mixed", NULL, NULL); + return -1; + } + kind = 1; + /* handle plain percent symbol in format string */ if (c[0] == '%' && c[1] == '%') { c+=2; force = 1; @@ -182,6 +191,15 @@ _mogrify(PyObject *var, PyObject *fmt, connectionObject *conn, PyObject **new) because we don't need to check the old/new dictionary for keys */ + /* check if some crazy guy mixed formats */ + if (kind == 1) { + Py_XDECREF(n); + psyco_set_error(ProgrammingError, (PyObject*)conn, + "argument formats can't be mixed", NULL, NULL); + return -1; + } + kind = 2; + value = PySequence_GetItem(var, index); /* value has refcnt inc'ed by 1 here */ |
