Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 096ad87

Browse files
author
Anselm Kruis
committed
Stackless issue #144: Replace copied code in pricklepit.c dictview_new
Replace copied code by a limited API function. This fixes the assertion error caused by commit 2eea952.
1 parent 4c622b1 commit 096ad87

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

Stackless/pickling/prickelpit.c

+15-20
Original file line numberDiff line numberDiff line change
@@ -1475,39 +1475,34 @@ static int init_methodtype(void)
14751475
14761476
******************************************************/
14771477

1478-
/*
1479-
* unfortunately we have to copy here.
1480-
* XXX automate checking such situations.
1481-
*/
1482-
1483-
1484-
typedef struct {
1485-
PyObject_HEAD
1486-
PyDictObject *dv_dict;
1487-
} dictviewobject;
14881478

14891479
static PyTypeObject wrap_PyDictKeys_Type;
14901480

1491-
PyObject *
1481+
static PyObject *
14921482
dictview_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
14931483
{
1494-
dictviewobject *inst;
1484+
PyObject *inst;
14951485
PyObject *dict;
1496-
if (PyTuple_Size(args) != 1)
1486+
Py_ssize_t size = PyTuple_Size(args);
1487+
1488+
if (size == -1) {
14971489
return NULL;
1490+
}
1491+
if (size != 1) {
1492+
PyErr_SetString(PyExc_ValueError, "args must contain exactly one argument");
1493+
return NULL;
1494+
}
14981495
dict = PyTuple_GetItem(args, 0);
1499-
inst = PyObject_GC_New(dictviewobject, type->tp_base);
1500-
if (inst == NULL)
1496+
if (dict == NULL)
15011497
return NULL;
1502-
Py_INCREF(dict);
1503-
inst->dv_dict = (PyDictObject *)dict;
1498+
inst = _PyDictView_New(dict, type->tp_base);
15041499
if (inst != NULL)
15051500
Py_TYPE(inst) = type;
15061501
return (PyObject *)inst;
15071502
}
15081503

15091504
static PyObject *
1510-
dictkeysview_reduce(dictviewobject *di)
1505+
dictkeysview_reduce(_PyDictViewObject *di)
15111506
{
15121507
PyObject *tup;
15131508

@@ -1522,7 +1517,7 @@ dictkeysview_reduce(dictviewobject *di)
15221517
static PyTypeObject wrap_PyDictValues_Type;
15231518

15241519
static PyObject *
1525-
dictvaluesview_reduce(dictviewobject *di)
1520+
dictvaluesview_reduce(_PyDictViewObject *di)
15261521
{
15271522
PyObject *tup;
15281523

@@ -1537,7 +1532,7 @@ dictvaluesview_reduce(dictviewobject *di)
15371532
static PyTypeObject wrap_PyDictItems_Type;
15381533

15391534
static PyObject *
1540-
dictitemsview_reduce(dictviewobject *di)
1535+
dictitemsview_reduce(_PyDictViewObject *di)
15411536
{
15421537
PyObject *tup;
15431538

0 commit comments

Comments
 (0)