Commit f9326e16 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Our list format is the same as CPython's

well, except that two fields were swapped, and there is an
extra struct wrapper in there.  But with some small changes
we can now let capi code use the list macros for faster list
manipulation.
parent 81b321dc
...@@ -20,8 +20,6 @@ returned item's reference count. ...@@ -20,8 +20,6 @@ returned item's reference count.
extern "C" { extern "C" {
#endif #endif
// Pyston change: comment this out since this is not the format we're using
#if 0
typedef struct { typedef struct {
PyObject_VAR_HEAD PyObject_VAR_HEAD
/* Vector of pointers to list elements. list[0] is ob_item[0], etc. */ /* Vector of pointers to list elements. list[0] is ob_item[0], etc. */
...@@ -40,9 +38,6 @@ typedef struct { ...@@ -40,9 +38,6 @@ typedef struct {
*/ */
Py_ssize_t allocated; Py_ssize_t allocated;
} PyListObject; } PyListObject;
#endif
struct _PyListObject;
typedef struct _PyListObject PyListObject;
// Pyston change: this is no longer a static object // Pyston change: this is no longer a static object
PyAPI_DATA(PyTypeObject*) list_cls; PyAPI_DATA(PyTypeObject*) list_cls;
...@@ -69,13 +64,9 @@ PyAPI_FUNC(PyObject *) _PyList_Extend(PyListObject *, PyObject *) PYSTON_NOEXCEP ...@@ -69,13 +64,9 @@ PyAPI_FUNC(PyObject *) _PyList_Extend(PyListObject *, PyObject *) PYSTON_NOEXCEP
PyAPI_FUNC(PyObject **) PyList_Items(PyObject *) PYSTON_NOEXCEPT; PyAPI_FUNC(PyObject **) PyList_Items(PyObject *) PYSTON_NOEXCEPT;
/* Macro, trading safety for speed */ /* Macro, trading safety for speed */
// Pyston changes: these aren't direct macros any more [they potentially could be though] #define PyList_GET_ITEM(op, i) (((PyListObject *)(op))->ob_item[i])
#define PyList_GET_ITEM(op, i) PyList_GetItem((PyObject*)(op), (i)) #define PyList_SET_ITEM(op, i, v) (((PyListObject *)(op))->ob_item[i] = (v))
#define PyList_SET_ITEM(op, i, v) PyList_SetItem((PyObject*)(op), (i), (v)) #define PyList_GET_SIZE(op) Py_SIZE(op)
#define PyList_GET_SIZE(op) PyList_Size((PyObject*)(op))
//#define PyList_GET_ITEM(op, i) (((PyListObject *)(op))->ob_item[i])
//#define PyList_SET_ITEM(op, i, v) (((PyListObject *)(op))->ob_item[i] = (v))
//#define PyList_GET_SIZE(op) Py_SIZE(op)
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -257,12 +257,22 @@ extern "C" Box* listSetitemInt(BoxedList* self, BoxedInt* slice, Box* v) { ...@@ -257,12 +257,22 @@ extern "C" Box* listSetitemInt(BoxedList* self, BoxedInt* slice, Box* v) {
} }
extern "C" int PyList_SetItem(PyObject* op, Py_ssize_t i, PyObject* newitem) noexcept { extern "C" int PyList_SetItem(PyObject* op, Py_ssize_t i, PyObject* newitem) noexcept {
assert(isSubclass(op->cls, list_cls)); PyObject* olditem;
try { PyObject** p;
listSetitemUnboxed(static_cast<BoxedList*>(op), i, newitem); if (!PyList_Check(op)) {
} catch (ExcInfo e) { Py_XDECREF(newitem);
abort(); PyErr_BadInternalCall();
return -1;
}
if (i < 0 || i >= Py_SIZE(op)) {
Py_XDECREF(newitem);
PyErr_SetString(PyExc_IndexError, "list assignment index out of range");
return -1;
} }
p = ((PyListObject*)op)->ob_item + i;
olditem = *p;
*p = newitem;
Py_XDECREF(olditem);
return 0; return 0;
} }
......
...@@ -602,6 +602,12 @@ public: ...@@ -602,6 +602,12 @@ public:
DEFAULT_CLASS_SIMPLE(list_cls); DEFAULT_CLASS_SIMPLE(list_cls);
}; };
static_assert(sizeof(BoxedList) <= sizeof(PyListObject), "");
static_assert(sizeof(BoxedList) >= sizeof(PyListObject), "");
static_assert(offsetof(BoxedList, size) == offsetof(PyListObject, ob_size), "");
static_assert(offsetof(BoxedList, elts) == offsetof(PyListObject, ob_item), "");
static_assert(offsetof(GCdArray, elts) == 0, "");
static_assert(offsetof(BoxedList, capacity) == offsetof(PyListObject, allocated), "");
class BoxedTuple : public BoxVar { class BoxedTuple : public BoxVar {
public: public:
......
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