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}) ...@@ -20,6 +20,7 @@ add_custom_target(copy_stdlib ALL DEPENDS ${STDLIB_TARGETS})
# compile specified files in from_cpython/Modules # compile specified files in from_cpython/Modules
file(GLOB_RECURSE STDMODULE_SRCS Modules file(GLOB_RECURSE STDMODULE_SRCS Modules
_bisectmodule.c
_codecsmodule.c _codecsmodule.c
_collectionsmodule.c _collectionsmodule.c
_csv.c _csv.c
......
...@@ -698,12 +698,7 @@ extern "C" Box* listDelitem(BoxedList* self, Box* slice) { ...@@ -698,12 +698,7 @@ extern "C" Box* listDelitem(BoxedList* self, Box* slice) {
return rtn; return rtn;
} }
extern "C" Box* listInsert(BoxedList* self, Box* idx, Box* v) { extern "C" void listInsertInternal(BoxedList* self, int64_t n, Box* v) {
if (idx->cls != int_cls) {
raiseExcHelper(TypeError, "an integer is required");
}
int64_t n = static_cast<BoxedInt*>(idx)->n;
if (n < 0) if (n < 0)
n = self->size + n; n = self->size + n;
...@@ -721,6 +716,15 @@ extern "C" Box* listInsert(BoxedList* self, Box* idx, Box* v) { ...@@ -721,6 +716,15 @@ extern "C" Box* listInsert(BoxedList* self, Box* idx, Box* v) {
Py_INCREF(v); Py_INCREF(v);
self->elts->elts[n] = 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; Py_RETURN_NONE;
} }
...@@ -735,7 +739,7 @@ extern "C" int PyList_Insert(PyObject* op, Py_ssize_t where, PyObject* newitem) ...@@ -735,7 +739,7 @@ extern "C" int PyList_Insert(PyObject* op, Py_ssize_t where, PyObject* newitem)
PyErr_BadInternalCall(); PyErr_BadInternalCall();
return -1; return -1;
} }
listInsert((BoxedList*)op, boxInt(where), newitem); listInsertInternal((BoxedList*)op, where, newitem);
return 0; return 0;
} catch (ExcInfo e) { } catch (ExcInfo e) {
setCAPIException(e); setCAPIException(e);
......
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
#include "runtime/super.h" #include "runtime/super.h"
#include "runtime/util.h" #include "runtime/util.h"
extern "C" void init_bisect();
extern "C" void initerrno(); extern "C" void initerrno();
extern "C" void init_sha(); extern "C" void init_sha();
extern "C" void init_sha256(); extern "C" void init_sha256();
...@@ -4085,6 +4086,7 @@ extern "C" { ...@@ -4085,6 +4086,7 @@ extern "C" {
struct _inittab _PyImport_Inittab[] = { { "array", initarray }, struct _inittab _PyImport_Inittab[] = { { "array", initarray },
{ "_ast", init_ast }, { "_ast", init_ast },
{ "binascii", initbinascii }, { "binascii", initbinascii },
{ "_bisect", init_bisect },
{ "_codecs", init_codecs }, { "_codecs", init_codecs },
{ "_collections", init_collections }, { "_collections", init_collections },
{ "cStringIO", initcStringIO }, { "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