Commit 631bd896 authored by Marius Wachtler's avatar Marius Wachtler

add the _bisect module

+ fix a leak in PyList_Insert
parent 48ec63a6
......@@ -20,6 +20,7 @@ add_custom_target(copy_stdlib ALL DEPENDS ${STDLIB_TARGETS})
# compile specified files in from_cpython/Modules
file(GLOB_RECURSE STDMODULE_SRCS Modules
_bisectmodule.c
_codecsmodule.c
_collectionsmodule.c
_csv.c
......
......@@ -698,12 +698,7 @@ extern "C" Box* listDelitem(BoxedList* self, Box* slice) {
return rtn;
}
extern "C" Box* listInsert(BoxedList* self, Box* idx, Box* v) {
if (idx->cls != int_cls) {
raiseExcHelper(TypeError, "an integer is required");
}
int64_t n = static_cast<BoxedInt*>(idx)->n;
extern "C" void listInsertInternal(BoxedList* self, int64_t n, Box* v) {
if (n < 0)
n = self->size + n;
......@@ -721,6 +716,15 @@ extern "C" Box* listInsert(BoxedList* self, Box* idx, Box* v) {
Py_INCREF(v);
self->elts->elts[n] = v;
}
}
extern "C" Box* listInsert(BoxedList* self, Box* idx, Box* v) {
if (idx->cls != int_cls) {
raiseExcHelper(TypeError, "an integer is required");
}
int64_t n = static_cast<BoxedInt*>(idx)->n;
listInsertInternal(self, n, v);
Py_RETURN_NONE;
}
......@@ -735,7 +739,7 @@ extern "C" int PyList_Insert(PyObject* op, Py_ssize_t where, PyObject* newitem)
PyErr_BadInternalCall();
return -1;
}
listInsert((BoxedList*)op, boxInt(where), newitem);
listInsertInternal((BoxedList*)op, where, newitem);
return 0;
} catch (ExcInfo e) {
setCAPIException(e);
......
......@@ -51,6 +51,7 @@
#include "runtime/super.h"
#include "runtime/util.h"
extern "C" void init_bisect();
extern "C" void initerrno();
extern "C" void init_sha();
extern "C" void init_sha256();
......@@ -4085,6 +4086,7 @@ extern "C" {
struct _inittab _PyImport_Inittab[] = { { "array", initarray },
{ "_ast", init_ast },
{ "binascii", initbinascii },
{ "_bisect", init_bisect },
{ "_codecs", init_codecs },
{ "_collections", init_collections },
{ "cStringIO", initcStringIO },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment