Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
e6d24149
Commit
e6d24149
authored
Apr 12, 2016
by
Kevin Modzelewski
Committed by
Kevin Modzelewski
Apr 13, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add refcounting to slots_test.c
parent
58b4dd04
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
10 deletions
+36
-10
test/test_extension/slots_test.c
test/test_extension/slots_test.c
+36
-8
test/tests/capi_slots.py
test/tests/capi_slots.py
+0
-1
test/tests/type_flags.py
test/tests/type_flags.py
+0
-1
No files found.
test/test_extension/slots_test.c
View file @
e6d24149
...
...
@@ -179,13 +179,18 @@ slots_testeriter_init(PyObject *self, PyObject *args, PyObject *kwds)
return
0
;
}
void
iter_dealloc
(
slots_tester_iterobj
*
obj
)
{
Py_XDECREF
(
obj
->
obj
);
Py_TYPE
(
obj
)
->
tp_free
(
obj
);
}
static
PyTypeObject
slots_tester_seqiter
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"slots_test.slots_tester_seqiter"
,
/* tp_name */
sizeof
(
slots_tester_iterobj
),
/* tp_basicsize */
0
,
/* tp_itemsize */
/* methods */
0
,
/* tp_dealloc */
(
destructor
)
iter_dealloc
,
/* tp_dealloc */
0
,
/* tp_print */
0
,
/* tp_getattr */
0
,
/* tp_setattr */
...
...
@@ -295,13 +300,18 @@ static PyMappingMethods slots_tester_map_asmapping = {
(
objobjargproc
)
slots_tester_map_ass_sub
,
/*mp_ass_subscript*/
};
void
map_dealloc
(
slots_tester_object
*
obj
)
{
Py_XDECREF
(
obj
->
dict
);
Py_TYPE
(
obj
)
->
tp_free
(
obj
);
}
static
PyTypeObject
slots_tester_map
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"slots_test.slots_tester_map"
,
/* tp_name */
sizeof
(
slots_tester_object
),
/* tp_basicsize */
0
,
/* tp_itemsize */
/* methods */
0
,
/* tp_dealloc */
(
destructor
)
map_dealloc
,
/* tp_dealloc */
0
,
/* tp_print */
0
,
/* tp_getattr */
0
,
/* tp_setattr */
...
...
@@ -346,6 +356,11 @@ static PyObject* N(slots_tester_object* lhs) { \
Py_INCREF(R); \
return (PyObject*)R; \
}
#define CREATE_UN_NOINCREF(N, R) \
static PyObject* N(slots_tester_object* lhs) { \
printf(PYSTON_STRINGIFY(N) ", %d\n", lhs->n); \
return (PyObject*)R; \
}
#define CREATE_BIN(N) \
static PyObject* N(slots_tester_object* lhs, PyObject* rhs) { \
...
...
@@ -385,9 +400,9 @@ CREATE_BIN(s_or);
CREATE_UN
(
s_int
,
Py_True
);
CREATE_UN
(
s_long
,
Py_True
);
CREATE_UN
(
s_float
,
PyFloat_FromDouble
(
1
.
0
));
CREATE_UN
(
s_oct
,
PyString_FromString
(
"oct"
));
CREATE_UN
(
s_hex
,
PyString_FromString
(
"hex"
));
CREATE_UN
_NOINCREF
(
s_float
,
PyFloat_FromDouble
(
1
.
0
));
CREATE_UN
_NOINCREF
(
s_oct
,
PyString_FromString
(
"oct"
));
CREATE_UN
_NOINCREF
(
s_hex
,
PyString_FromString
(
"hex"
));
#undef CREATE_BIN
...
...
@@ -652,7 +667,9 @@ call_funcs(PyObject* _module, PyObject* args) {
}
if
(
cls
->
tp_new
)
{
PyObject
*
rtn
=
cls
->
tp_new
(
cls
,
PyTuple_New
(
0
),
PyDict_New
());
PyObject
*
args
=
PyTuple_New
(
0
);
PyObject
*
rtn
=
cls
->
tp_new
(
cls
,
args
,
NULL
);
Py_DECREF
(
args
);
if
(
!
rtn
)
{
printf
(
"tp_new_exists but returned an error!
\n
"
);
PyErr_Print
();
...
...
@@ -707,7 +724,9 @@ call_funcs(PyObject* _module, PyObject* args) {
PyMappingMethods
*
map
=
cls
->
tp_as_mapping
;
if
(
map
->
mp_subscript
)
{
PyObject
*
rtn
=
map
->
mp_subscript
(
obj
,
PyInt_FromLong
(
1
));
PyObject
*
arg
=
PyInt_FromLong
(
1
);
PyObject
*
rtn
=
map
->
mp_subscript
(
obj
,
arg
);
Py_DECREF
(
arg
);
printf
(
"mp_subscript exists and returned
\n
"
);
Py_DECREF
(
rtn
);
}
else
{
...
...
@@ -870,13 +889,22 @@ initslots_test(void)
return
;
// Not sure if the result of PyInt_FromLong needs to be decref'd
PyDict_SetItemString
(
slots_tester_seq
.
tp_dict
,
"set_through_tpdict"
,
PyInt_FromLong
(
123
));
PyObject
*
num
=
PyInt_FromLong
(
123
);
PyDict_SetItemString
(
slots_tester_seq
.
tp_dict
,
"set_through_tpdict"
,
num
);
Py_DECREF
(
num
);
Py_INCREF
(
&
slots_tester_seq
);
PyModule_AddObject
(
m
,
"SlotsTesterSeq"
,
(
PyObject
*
)
&
slots_tester_seq
);
Py_INCREF
(
&
slots_tester_map
);
PyModule_AddObject
(
m
,
"SlotsTesterMap"
,
(
PyObject
*
)
&
slots_tester_map
);
Py_INCREF
(
&
slots_tester_num
);
PyModule_AddObject
(
m
,
"SlotsTesterNum"
,
(
PyObject
*
)
&
slots_tester_num
);
Py_INCREF
(
&
slots_tester_sub
);
PyModule_AddObject
(
m
,
"SlotsTesterSub"
,
(
PyObject
*
)
&
slots_tester_sub
);
Py_INCREF
(
&
slots_tester_nonsubclassable
);
PyModule_AddObject
(
m
,
"SlotsTesterNonsubclassable"
,
(
PyObject
*
)
&
slots_tester_nonsubclassable
);
Py_INCREF
(
&
slots_tester_nullreturngetattr
);
PyModule_AddObject
(
m
,
"SlotsTesterNullReturnGetAttr"
,
(
PyObject
*
)
&
slots_tester_nullreturngetattr
);
Py_INCREF
(
&
slots_tester_descrget
);
PyModule_AddObject
(
m
,
"SlotsTesterDescrGet"
,
(
PyObject
*
)
&
slots_tester_descrget
);
}
test/tests/capi_slots.py
View file @
e6d24149
# expected: reffail
import
slots_test
for
i
in
xrange
(
3
):
...
...
test/tests/type_flags.py
View file @
e6d24149
# expected: reffail
import
slots_test
HEAPTYPE
=
1
<<
9
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment