diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2012-03-05 02:48:11 +0000 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2012-03-05 02:48:11 +0000 |
commit | b8c75d9de0874481ebbe6bd39ba16399ef7b3995 (patch) | |
tree | 4b1e7ee931329dace42df4a46ab6d98a21969f6f /psycopg/utils.c | |
parent | 37aa62ca52149360331e54740a2f70567343710e (diff) | |
parent | 2c309dfdb46cce51ff17688c97b391e39f2a392e (diff) | |
download | psycopg2-b8c75d9de0874481ebbe6bd39ba16399ef7b3995.tar.gz |
Merge branch 'gcc-python-plugin' into devel
Diffstat (limited to 'psycopg/utils.c')
-rw-r--r-- | psycopg/utils.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/psycopg/utils.c b/psycopg/utils.c index 2e81c11..57586c5 100644 --- a/psycopg/utils.c +++ b/psycopg/utils.c @@ -113,20 +113,19 @@ psycopg_escape_identifier_easy(const char *from, Py_ssize_t len) * Allocate a new buffer on the Python heap containing the new string. * 'len' is optional: if 0 the length is calculated. * - * Return NULL and set an exception in case of error. + * Store the return in 'to' and return 0 in case of success, else return -1 + * and raise an exception. */ -char * -psycopg_strdup(const char *from, Py_ssize_t len) +RAISES_NEG int +psycopg_strdup(char **to, const char *from, Py_ssize_t len) { - char *rv; - if (!len) { len = strlen(from); } - if (!(rv = PyMem_Malloc(len + 1))) { + if (!(*to = PyMem_Malloc(len + 1))) { PyErr_NoMemory(); - return NULL; + return -1; } - strcpy(rv, from); - return rv; + strcpy(*to, from); + return 0; } /* Ensure a Python object is a bytes string. @@ -139,7 +138,7 @@ psycopg_strdup(const char *from, Py_ssize_t len) * * It is safe to call the function on NULL. */ -PyObject * +STEALS(1) PyObject * psycopg_ensure_bytes(PyObject *obj) { PyObject *rv = NULL; @@ -169,7 +168,7 @@ psycopg_ensure_bytes(PyObject *obj) * The function is ref neutral: steals a ref from obj and adds one to the * return value. It is safe to call it on NULL. */ -PyObject * +STEALS(1) PyObject * psycopg_ensure_text(PyObject *obj) { #if PY_MAJOR_VERSION < 3 |