summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_ctypes/_ctypes.c42
-rw-r--r--Modules/_ctypes/callproc.c8
-rw-r--r--Modules/_ctypes/cfield.c20
-rw-r--r--Modules/_decimal/_decimal.c10
-rw-r--r--Modules/_elementtree.c19
-rw-r--r--Modules/_functoolsmodule.c39
-rw-r--r--Modules/_sqlite/connection.c4
-rw-r--r--Modules/_sqlite/module.h2
-rw-r--r--Modules/arraymodule.c2
-rw-r--r--Modules/expat/xmlrole.c4
-rw-r--r--Modules/expat/xmltok.c4
-rw-r--r--Modules/readline.c132
12 files changed, 187 insertions, 99 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index 2e01323..a7a8105 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -1124,7 +1124,7 @@ CharArray_get_raw(CDataObject *self)
static PyObject *
CharArray_get_value(CDataObject *self)
{
- int i;
+ Py_ssize_t i;
char *ptr = self->b_ptr;
for (i = 0; i < self->b_size; ++i)
if (*ptr++ == '\0')
@@ -1180,9 +1180,9 @@ static PyGetSetDef CharArray_getsets[] = {
static PyObject *
WCharArray_get_value(CDataObject *self)
{
- unsigned int i;
+ Py_ssize_t i;
wchar_t *ptr = (wchar_t *)self->b_ptr;
- for (i = 0; i < self->b_size/sizeof(wchar_t); ++i)
+ for (i = 0; i < self->b_size/(Py_ssize_t)sizeof(wchar_t); ++i)
if (*ptr++ == (wchar_t)0)
break;
return PyUnicode_FromWideChar((wchar_t *)self->b_ptr, i);
@@ -1211,7 +1211,7 @@ WCharArray_set_value(CDataObject *self, PyObject *value)
wstr = PyUnicode_AsUnicodeAndSize(value, &len);
if (wstr == NULL)
return -1;
- if ((unsigned)len > self->b_size/sizeof(wchar_t)) {
+ if ((size_t)len > self->b_size/sizeof(wchar_t)) {
PyErr_SetString(PyExc_ValueError,
"string too long");
result = -1;
@@ -1252,8 +1252,10 @@ add_methods(PyTypeObject *type, PyMethodDef *meth)
descr = PyDescr_NewMethod(type, meth);
if (descr == NULL)
return -1;
- if (PyDict_SetItemString(dict,meth->ml_name, descr) < 0)
+ if (PyDict_SetItemString(dict, meth->ml_name, descr) < 0) {
+ Py_DECREF(descr);
return -1;
+ }
Py_DECREF(descr);
}
return 0;
@@ -1268,8 +1270,10 @@ add_members(PyTypeObject *type, PyMemberDef *memb)
descr = PyDescr_NewMember(type, memb);
if (descr == NULL)
return -1;
- if (PyDict_SetItemString(dict, memb->name, descr) < 0)
+ if (PyDict_SetItemString(dict, memb->name, descr) < 0) {
+ Py_DECREF(descr);
return -1;
+ }
Py_DECREF(descr);
}
return 0;
@@ -1285,8 +1289,10 @@ add_getset(PyTypeObject *type, PyGetSetDef *gsp)
descr = PyDescr_NewGetSet(type, gsp);
if (descr == NULL)
return -1;
- if (PyDict_SetItemString(dict, gsp->name, descr) < 0)
+ if (PyDict_SetItemString(dict, gsp->name, descr) < 0) {
+ Py_DECREF(descr);
return -1;
+ }
Py_DECREF(descr);
}
return 0;
@@ -1778,6 +1784,7 @@ static PyObject *CreateSwappedType(PyTypeObject *type, PyObject *args, PyObject
newname = PyUnicode_Concat(name, suffix);
if (newname == NULL) {
+ Py_DECREF(swapped_args);
return NULL;
}
@@ -1797,8 +1804,10 @@ static PyObject *CreateSwappedType(PyTypeObject *type, PyObject *args, PyObject
stgdict = (StgDictObject *)PyObject_CallObject(
(PyObject *)&PyCStgDict_Type, NULL);
- if (!stgdict) /* XXX leaks result! */
+ if (!stgdict) {
+ Py_DECREF(result);
return NULL;
+ }
stgdict->ffi_type_pointer = *fmt->pffi_type;
stgdict->align = fmt->pffi_type->alignment;
@@ -1978,8 +1987,10 @@ PyCSimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
PyObject *meth;
int x;
meth = PyDescr_NewClassMethod(result, ml);
- if (!meth)
+ if (!meth) {
+ Py_DECREF(result);
return NULL;
+ }
x = PyDict_SetItemString(result->tp_dict,
ml->ml_name,
meth);
@@ -2159,8 +2170,10 @@ converters_from_argtypes(PyObject *ob)
nArgs = PyTuple_GET_SIZE(ob);
converters = PyTuple_New(nArgs);
- if (!converters)
+ if (!converters) {
+ Py_DECREF(ob);
return NULL;
+ }
/* I have to check if this is correct. Using c_char, which has a size
of 1, will be assumed to be pushed as only one byte!
@@ -4052,14 +4065,9 @@ _init_pos_args(PyObject *self, PyTypeObject *type,
}
val = PyTuple_GET_ITEM(args, i + index);
if (kwds && PyDict_GetItem(kwds, name)) {
- char *field = PyBytes_AsString(name);
- if (field == NULL) {
- PyErr_Clear();
- field = "???";
- }
PyErr_Format(PyExc_TypeError,
- "duplicate values for field '%s'",
- field);
+ "duplicate values for field %R",
+ name);
Py_DECREF(pair);
Py_DECREF(name);
return -1;
diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c
index 03a911f..30e3a96 100644
--- a/Modules/_ctypes/callproc.c
+++ b/Modules/_ctypes/callproc.c
@@ -157,8 +157,10 @@ _ctypes_get_errobj(int **pspace)
return NULL;
memset(space, 0, sizeof(int) * 2);
errobj = PyCapsule_New(space, CTYPES_CAPSULE_NAME_PYMEM, pymem_destructor);
- if (errobj == NULL)
+ if (errobj == NULL) {
+ PyMem_Free(space);
return NULL;
+ }
if (-1 == PyDict_SetItem(dict, error_object_name,
errobj)) {
Py_DECREF(errobj);
@@ -1681,6 +1683,10 @@ POINTER(PyObject *self, PyObject *cls)
if (result == NULL)
return result;
key = PyLong_FromVoidPtr(result);
+ if (key == NULL) {
+ Py_DECREF(result);
+ return NULL;
+ }
} else if (PyType_Check(cls)) {
typ = (PyTypeObject *)cls;
buf = PyMem_Malloc(strlen(typ->tp_name) + 3 + 1);
diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c
index 8cb6d66..d666be5 100644
--- a/Modules/_ctypes/cfield.c
+++ b/Modules/_ctypes/cfield.c
@@ -1246,8 +1246,7 @@ U_set(void *ptr, PyObject *value, Py_ssize_t length)
"unicode string expected instead of %s instance",
value->ob_type->tp_name);
return NULL;
- } else
- Py_INCREF(value);
+ }
wstr = PyUnicode_AsUnicodeAndSize(value, &size);
if (wstr == NULL)
@@ -1256,7 +1255,6 @@ U_set(void *ptr, PyObject *value, Py_ssize_t length)
PyErr_Format(PyExc_ValueError,
"string too long (%zd, maximum length %zd)",
size, length);
- Py_DECREF(value);
return NULL;
} else if (size < length-1)
/* copy terminating NUL character if there is space */
@@ -1266,6 +1264,7 @@ U_set(void *ptr, PyObject *value, Py_ssize_t length)
return NULL;
}
+ Py_INCREF(value);
return value;
}
@@ -1292,9 +1291,7 @@ s_set(void *ptr, PyObject *value, Py_ssize_t length)
char *data;
Py_ssize_t size;
- if(PyBytes_Check(value)) {
- Py_INCREF(value);
- } else {
+ if(!PyBytes_Check(value)) {
PyErr_Format(PyExc_TypeError,
"expected bytes, %s found",
value->ob_type->tp_name);
@@ -1302,11 +1299,9 @@ s_set(void *ptr, PyObject *value, Py_ssize_t length)
}
data = PyBytes_AS_STRING(value);
- if (!data)
- return NULL;
size = strlen(data); /* XXX Why not Py_SIZE(value)? */
if (size < length) {
- /* This will copy the leading NUL character
+ /* This will copy the terminating NUL character
* if there is space for it.
*/
++size;
@@ -1314,13 +1309,11 @@ s_set(void *ptr, PyObject *value, Py_ssize_t length)
PyErr_Format(PyExc_ValueError,
"bytes too long (%zd, maximum length %zd)",
size, length);
- Py_DECREF(value);
return NULL;
}
/* Also copy the terminating NUL character if there is space */
memcpy((char *)ptr, data, size);
- Py_DECREF(value);
_RET(value);
}
@@ -1428,9 +1421,7 @@ BSTR_set(void *ptr, PyObject *value, Py_ssize_t size)
/* convert value into a PyUnicodeObject or NULL */
if (Py_None == value) {
value = NULL;
- } else if (PyUnicode_Check(value)) {
- Py_INCREF(value); /* for the descref below */
- } else {
+ } else if (!PyUnicode_Check(value)) {
PyErr_Format(PyExc_TypeError,
"unicode string expected instead of %s instance",
value->ob_type->tp_name);
@@ -1449,7 +1440,6 @@ BSTR_set(void *ptr, PyObject *value, Py_ssize_t size)
return NULL;
}
bstr = SysAllocStringLen(wvalue, (unsigned)wsize);
- Py_DECREF(value);
} else
bstr = NULL;
diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c
index 112b44f..22053b4 100644
--- a/Modules/_decimal/_decimal.c
+++ b/Modules/_decimal/_decimal.c
@@ -2630,12 +2630,18 @@ PyDecType_FromSequenceExact(PyTypeObject *type, PyObject *v,
/* class method */
static PyObject *
-dec_from_float(PyObject *dec, PyObject *pyfloat)
+dec_from_float(PyObject *type, PyObject *pyfloat)
{
PyObject *context;
+ PyObject *result;
CURRENT_CONTEXT(context);
- return PyDecType_FromFloatExact((PyTypeObject *)dec, pyfloat, context);
+ result = PyDecType_FromFloatExact(&PyDec_Type, pyfloat, context);
+ if (type != (PyObject *)&PyDec_Type && result != NULL) {
+ Py_SETREF(result, PyObject_CallFunctionObjArgs(type, result, NULL));
+ }
+
+ return result;
}
/* create_decimal_from_float */
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index 0f1d6a1..85ffca2 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -1582,10 +1582,23 @@ _elementtree_Element_remove_impl(ElementObject *self, PyObject *subelement)
static PyObject*
element_repr(ElementObject* self)
{
- if (self->tag)
- return PyUnicode_FromFormat("<Element %R at %p>", self->tag, self);
- else
+ int status;
+
+ if (self->tag == NULL)
return PyUnicode_FromFormat("<Element at %p>", self);
+
+ status = Py_ReprEnter((PyObject *)self);
+ if (status == 0) {
+ PyObject *res;
+ res = PyUnicode_FromFormat("<Element %R at %p>", self->tag, self);
+ Py_ReprLeave((PyObject *)self);
+ return res;
+ }
+ if (status > 0)
+ PyErr_Format(PyExc_RuntimeError,
+ "reentrant call inside %s.__repr__",
+ Py_TYPE(self)->tp_name);
+ return NULL;
}
/*[clinic input]
diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c
index 1aa4571..d785c49 100644
--- a/Modules/_functoolsmodule.c
+++ b/Modules/_functoolsmodule.c
@@ -203,40 +203,45 @@ static PyGetSetDef partial_getsetlist[] = {
static PyObject *
partial_repr(partialobject *pto)
{
- PyObject *result;
+ PyObject *result = NULL;
PyObject *arglist;
- PyObject *tmp;
Py_ssize_t i, n;
PyObject *key, *value;
+ int status;
- arglist = PyUnicode_FromString("");
- if (arglist == NULL) {
- return NULL;
+ status = Py_ReprEnter((PyObject *)pto);
+ if (status != 0) {
+ if (status < 0)
+ return NULL;
+ return PyUnicode_FromFormat("%s(...)", Py_TYPE(pto)->tp_name);
}
+
+ arglist = PyUnicode_FromString("");
+ if (arglist == NULL)
+ goto done;
/* Pack positional arguments */
assert (PyTuple_Check(pto->args));
n = PyTuple_GET_SIZE(pto->args);
for (i = 0; i < n; i++) {
- tmp = PyUnicode_FromFormat("%U, %R", arglist,
- PyTuple_GET_ITEM(pto->args, i));
- Py_DECREF(arglist);
- if (tmp == NULL)
- return NULL;
- arglist = tmp;
+ Py_SETREF(arglist, PyUnicode_FromFormat("%U, %R", arglist,
+ PyTuple_GET_ITEM(pto->args, i)));
+ if (arglist == NULL)
+ goto done;
}
/* Pack keyword arguments */
assert (PyDict_Check(pto->kw));
for (i = 0; PyDict_Next(pto->kw, &i, &key, &value);) {
- tmp = PyUnicode_FromFormat("%U, %U=%R", arglist,
- key, value);
- Py_DECREF(arglist);
- if (tmp == NULL)
- return NULL;
- arglist = tmp;
+ Py_SETREF(arglist, PyUnicode_FromFormat("%U, %U=%R", arglist,
+ key, value));
+ if (arglist == NULL)
+ goto done;
}
result = PyUnicode_FromFormat("%s(%R%U)", Py_TYPE(pto)->tp_name,
pto->fn, arglist);
Py_DECREF(arglist);
+
+ done:
+ Py_ReprLeave((PyObject *)pto);
return result;
}
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index 7570624..6aa4764 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -164,6 +164,10 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject
#ifdef WITH_THREAD
self->thread_ident = PyThread_get_thread_ident();
#endif
+ if (!check_same_thread && sqlite3_libversion_number() < 3003001) {
+ PyErr_SetString(pysqlite_NotSupportedError, "shared connections not available");
+ return -1;
+ }
self->check_same_thread = check_same_thread;
self->function_pinboard = PyDict_New();
diff --git a/Modules/_sqlite/module.h b/Modules/_sqlite/module.h
index b51724b..0fb5a55 100644
--- a/Modules/_sqlite/module.h
+++ b/Modules/_sqlite/module.h
@@ -42,7 +42,7 @@ extern PyObject* pysqlite_NotSupportedError;
extern PyObject* time_time;
extern PyObject* time_sleep;
-/* A dictionary, mapping colum types (INTEGER, VARCHAR, etc.) to converter
+/* A dictionary, mapping column types (INTEGER, VARCHAR, etc.) to converter
* functions, that convert the SQL value to the appropriate Python value.
* The key is uppercase.
*/
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index f73c599..2803177 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -1268,7 +1268,7 @@ array_array_buffer_info_impl(arrayobject *self)
}
PyTuple_SET_ITEM(retval, 0, v);
- v = PyLong_FromLong((long)(Py_SIZE(self)));
+ v = PyLong_FromSsize_t(Py_SIZE(self));
if (v == NULL) {
Py_DECREF(retval);
return NULL;
diff --git a/Modules/expat/xmlrole.c b/Modules/expat/xmlrole.c
index 9a8f85d..44772e2 100644
--- a/Modules/expat/xmlrole.c
+++ b/Modules/expat/xmlrole.c
@@ -2,6 +2,8 @@
See the file COPYING for copying permission.
*/
+#include <stddef.h>
+
#ifdef COMPILED_FROM_DSP
#include "winconfig.h"
#elif defined(MACOS_CLASSIC)
@@ -16,8 +18,6 @@
#endif
#endif /* ndef COMPILED_FROM_DSP */
-#include <stddef.h>
-
#include "expat_external.h"
#include "internal.h"
#include "xmlrole.h"
diff --git a/Modules/expat/xmltok.c b/Modules/expat/xmltok.c
index 205c07e..bf09dfc 100644
--- a/Modules/expat/xmltok.c
+++ b/Modules/expat/xmltok.c
@@ -2,6 +2,8 @@
See the file COPYING for copying permission.
*/
+#include <stddef.h>
+
#ifdef COMPILED_FROM_DSP
#include "winconfig.h"
#elif defined(MACOS_CLASSIC)
@@ -16,8 +18,6 @@
#endif
#endif /* ndef COMPILED_FROM_DSP */
-#include <stddef.h>
-
#include "expat_external.h"
#include "internal.h"
#include "xmltok.h"
diff --git a/Modules/readline.c b/Modules/readline.c
index 8c00dec..91f7cca 100644
--- a/Modules/readline.c
+++ b/Modules/readline.c
@@ -128,20 +128,40 @@ static PyModuleDef readlinemodule;
#define readlinestate_global ((readlinestate *)PyModule_GetState(PyState_FindModule(&readlinemodule)))
+/* Convert to/from multibyte C strings */
+
+static PyObject *
+encode(PyObject *b)
+{
+ return PyUnicode_EncodeLocale(b, "surrogateescape");
+}
+
+static PyObject *
+decode(const char *s)
+{
+ return PyUnicode_DecodeLocale(s, "surrogateescape");
+}
+
+
/* Exported function to send one line to readline's init file parser */
static PyObject *
-parse_and_bind(PyObject *self, PyObject *args)
+parse_and_bind(PyObject *self, PyObject *string)
{
- char *s, *copy;
- if (!PyArg_ParseTuple(args, "s:parse_and_bind", &s))
+ char *copy;
+ PyObject *encoded = encode(string);
+ if (encoded == NULL) {
return NULL;
+ }
/* Make a copy -- rl_parse_and_bind() modifies its argument */
/* Bernard Herzog */
- copy = PyMem_Malloc(1 + strlen(s));
- if (copy == NULL)
+ copy = PyMem_Malloc(1 + PyBytes_GET_SIZE(encoded));
+ if (copy == NULL) {
+ Py_DECREF(encoded);
return PyErr_NoMemory();
- strcpy(copy, s);
+ }
+ strcpy(copy, PyBytes_AS_STRING(encoded));
+ Py_DECREF(encoded);
rl_parse_and_bind(copy);
PyMem_Free(copy); /* Free the copy */
Py_RETURN_NONE;
@@ -441,17 +461,18 @@ get the ending index of the completion scope");
/* Set the tab-completion word-delimiters that readline uses */
static PyObject *
-set_completer_delims(PyObject *self, PyObject *args)
+set_completer_delims(PyObject *self, PyObject *string)
{
char *break_chars;
-
- if (!PyArg_ParseTuple(args, "s:set_completer_delims", &break_chars)) {
+ PyObject *encoded = encode(string);
+ if (encoded == NULL) {
return NULL;
}
/* Keep a reference to the allocated memory in the module state in case
some other module modifies rl_completer_word_break_characters
(see issue #17289). */
- break_chars = strdup(break_chars);
+ break_chars = strdup(PyBytes_AS_STRING(encoded));
+ Py_DECREF(encoded);
if (break_chars) {
free(completer_word_break_characters);
completer_word_break_characters = break_chars;
@@ -531,10 +552,11 @@ static PyObject *
py_replace_history(PyObject *self, PyObject *args)
{
int entry_number;
- char *line;
+ PyObject *line;
+ PyObject *encoded;
HIST_ENTRY *old_entry;
- if (!PyArg_ParseTuple(args, "is:replace_history_item", &entry_number,
+ if (!PyArg_ParseTuple(args, "iU:replace_history_item", &entry_number,
&line)) {
return NULL;
}
@@ -543,7 +565,12 @@ py_replace_history(PyObject *self, PyObject *args)
"History index cannot be negative");
return NULL;
}
- old_entry = replace_history_entry(entry_number, line, (void *)NULL);
+ encoded = encode(line);
+ if (encoded == NULL) {
+ return NULL;
+ }
+ old_entry = replace_history_entry(entry_number, PyBytes_AS_STRING(encoded), (void *)NULL);
+ Py_DECREF(encoded);
if (!old_entry) {
PyErr_Format(PyExc_ValueError,
"No history item at position %d",
@@ -562,14 +589,14 @@ replaces history item given by its position with contents of line");
/* Add a line to the history buffer */
static PyObject *
-py_add_history(PyObject *self, PyObject *args)
+py_add_history(PyObject *self, PyObject *string)
{
- char *line;
-
- if(!PyArg_ParseTuple(args, "s:add_history", &line)) {
+ PyObject *encoded = encode(string);
+ if (encoded == NULL) {
return NULL;
}
- add_history(line);
+ add_history(PyBytes_AS_STRING(encoded));
+ Py_DECREF(encoded);
Py_RETURN_NONE;
}
@@ -583,7 +610,7 @@ add an item to the history buffer");
static PyObject *
get_completer_delims(PyObject *self, PyObject *noarg)
{
- return PyUnicode_FromString(rl_completer_word_break_characters);
+ return decode(rl_completer_word_break_characters);
}
PyDoc_STRVAR(doc_get_completer_delims,
@@ -673,7 +700,7 @@ get_history_item(PyObject *self, PyObject *args)
}
#endif /* __APPLE__ */
if ((hist_ent = history_get(idx)))
- return PyUnicode_FromString(hist_ent->line);
+ return decode(hist_ent->line);
else {
Py_RETURN_NONE;
}
@@ -702,7 +729,7 @@ return the current (not the maximum) length of history.");
static PyObject *
get_line_buffer(PyObject *self, PyObject *noarg)
{
- return PyUnicode_FromString(rl_line_buffer);
+ return decode(rl_line_buffer);
}
PyDoc_STRVAR(doc_get_line_buffer,
@@ -730,12 +757,14 @@ Clear the current readline history.");
/* Exported function to insert text into the line buffer */
static PyObject *
-insert_text(PyObject *self, PyObject *args)
+insert_text(PyObject *self, PyObject *string)
{
- char *s;
- if (!PyArg_ParseTuple(args, "s:insert_text", &s))
+ PyObject *encoded = encode(string);
+ if (encoded == NULL) {
return NULL;
- rl_insert_text(s);
+ }
+ rl_insert_text(PyBytes_AS_STRING(encoded));
+ Py_DECREF(encoded);
Py_RETURN_NONE;
}
@@ -763,9 +792,9 @@ contents of the line buffer.");
static struct PyMethodDef readline_methods[] =
{
- {"parse_and_bind", parse_and_bind, METH_VARARGS, doc_parse_and_bind},
+ {"parse_and_bind", parse_and_bind, METH_O, doc_parse_and_bind},
{"get_line_buffer", get_line_buffer, METH_NOARGS, doc_get_line_buffer},
- {"insert_text", insert_text, METH_VARARGS, doc_insert_text},
+ {"insert_text", insert_text, METH_O, doc_insert_text},
{"redisplay", redisplay, METH_NOARGS, doc_redisplay},
{"read_init_file", read_init_file, METH_VARARGS, doc_read_init_file},
{"read_history_file", read_history_file,
@@ -792,8 +821,8 @@ static struct PyMethodDef readline_methods[] =
{"get_endidx", get_endidx, METH_NOARGS, doc_get_endidx},
{"set_completer_delims", set_completer_delims,
- METH_VARARGS, doc_set_completer_delims},
- {"add_history", py_add_history, METH_VARARGS, doc_add_history},
+ METH_O, doc_set_completer_delims},
+ {"add_history", py_add_history, METH_O, doc_add_history},
{"remove_history_item", py_remove_history, METH_VARARGS, doc_remove_history},
{"replace_history_item", py_replace_history, METH_VARARGS, doc_replace_history},
{"get_completer_delims", get_completer_delims,
@@ -890,7 +919,7 @@ on_completion_display_matches_hook(char **matches,
int num_matches, int max_length)
{
int i;
- PyObject *m=NULL, *s=NULL, *r=NULL;
+ PyObject *sub, *m=NULL, *s=NULL, *r=NULL;
#ifdef WITH_THREAD
PyGILState_STATE gilstate = PyGILState_Ensure();
#endif
@@ -898,16 +927,17 @@ on_completion_display_matches_hook(char **matches,
if (m == NULL)
goto error;
for (i = 0; i < num_matches; i++) {
- s = PyUnicode_FromString(matches[i+1]);
+ s = decode(matches[i+1]);
if (s == NULL)
goto error;
if (PyList_SetItem(m, i, s) == -1)
goto error;
}
+ sub = decode(matches[0]);
r = PyObject_CallFunction(readlinestate_global->completion_display_matches_hook,
- "sOi", matches[0], m, max_length);
+ "NNi", sub, m, max_length);
- Py_DECREF(m); m=NULL;
+ m=NULL;
if (r == NULL ||
(r != Py_None && PyLong_AsLong(r) == -1 && PyErr_Occurred())) {
@@ -955,22 +985,24 @@ on_completion(const char *text, int state)
{
char *result = NULL;
if (readlinestate_global->completer != NULL) {
- PyObject *r;
+ PyObject *r = NULL, *t;
#ifdef WITH_THREAD
PyGILState_STATE gilstate = PyGILState_Ensure();
#endif
rl_attempted_completion_over = 1;
- r = PyObject_CallFunction(readlinestate_global->completer, "si", text, state);
+ t = decode(text);
+ r = PyObject_CallFunction(readlinestate_global->completer, "Ni", t, state);
if (r == NULL)
goto error;
if (r == Py_None) {
result = NULL;
}
else {
- char *s = _PyUnicode_AsString(r);
- if (s == NULL)
+ PyObject *encoded = encode(r);
+ if (encoded == NULL)
goto error;
- result = strdup(s);
+ result = strdup(PyBytes_AS_STRING(encoded));
+ Py_DECREF(encoded);
}
Py_DECREF(r);
goto done;
@@ -994,6 +1026,9 @@ static char **
flex_complete(const char *text, int start, int end)
{
char **result;
+ char saved;
+ size_t start_size, end_size;
+ wchar_t *s;
#ifdef WITH_THREAD
PyGILState_STATE gilstate = PyGILState_Ensure();
#endif
@@ -1003,6 +1038,27 @@ flex_complete(const char *text, int start, int end)
#ifdef HAVE_RL_COMPLETION_SUPPRESS_APPEND
rl_completion_suppress_append = 0;
#endif
+
+ saved = rl_line_buffer[start];
+ rl_line_buffer[start] = 0;
+ s = Py_DecodeLocale(rl_line_buffer, &start_size);
+ rl_line_buffer[start] = saved;
+ if (s == NULL) {
+ goto done;
+ }
+ PyMem_RawFree(s);
+ saved = rl_line_buffer[end];
+ rl_line_buffer[end] = 0;
+ s = Py_DecodeLocale(rl_line_buffer + start, &end_size);
+ rl_line_buffer[end] = saved;
+ if (s == NULL) {
+ goto done;
+ }
+ PyMem_RawFree(s);
+ start = (int)start_size;
+ end = start + (int)end_size;
+
+done:
Py_XDECREF(readlinestate_global->begidx);
Py_XDECREF(readlinestate_global->endidx);
readlinestate_global->begidx = PyLong_FromLong((long) start);