Skip to content

Commit

Permalink
Merge pull request #43 from mfenniak/error-handling-bugfix
Browse files Browse the repository at this point in the history
Don't crash in SQL_ASCII DBs in PyString_AsString
  • Loading branch information
mfenniak authored May 11, 2024
2 parents 0408cfe + d48819e commit ea5b3f0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
done so far:
- drop support for Python 3 versions prior to 3.9
- drop support for Postgres versions prior to 12
- fix bug in error handling on SQL_ASCII databases (https://github.com/pgsql-io/multicorn2/pull/43)

to do:
- confirm support for Python 3.11 & 3.12
Expand All @@ -11,7 +12,7 @@ to do:
- drop support for Postgres versions prior to 10
- drop support for Python 2
- support for Python 3.6++
- add support for PG13
- add support for PG13
- experimental support for PG14

1.4.0:
Expand Down
8 changes: 5 additions & 3 deletions src/python.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ void appendBinaryStringInfoQuote(StringInfo buffer,

static void begin_remote_xact(CacheEntry * entry);

static char* ascii_encoding_name = "ascii";

/*
* Get a (python) encoding name for an attribute.
*/
Expand All @@ -108,7 +110,7 @@ getPythonEncodingName()

if (strcmp(encoding_name, "SQL_ASCII") == 0)
{
encoding_name = "ascii";
encoding_name = ascii_encoding_name;
}
return encoding_name;
}
Expand Down Expand Up @@ -169,7 +171,7 @@ char *
PyString_AsString(PyObject *unicode)
{
char *rv;
PyObject *o = PyUnicode_AsEncodedString(unicode, GetDatabaseEncodingName(), NULL);
PyObject *o = PyUnicode_AsEncodedString(unicode, getPythonEncodingName(), NULL);
errorCheck();
rv = pstrdup(PyBytes_AsString(o));
Py_XDECREF(o);
Expand All @@ -185,7 +187,7 @@ PyString_AsStringAndSize(PyObject *obj, char **buffer, Py_ssize_t *length)

if (PyUnicode_Check(obj))
{
o = PyUnicode_AsEncodedString(obj, GetDatabaseEncodingName(), NULL);
o = PyUnicode_AsEncodedString(obj, getPythonEncodingName(), NULL);
errorCheck();
rv = PyBytes_AsStringAndSize(o, &tempbuffer, length);
*buffer = pstrdup(tempbuffer);
Expand Down

0 comments on commit ea5b3f0

Please sign in to comment.