Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Kirill Smelkov
cpython
Commits
7ffcf848
Commit
7ffcf848
authored
Jun 02, 2019
by
Pablo Galindo
Committed by
GitHub
Jun 02, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-37126: Allow structseq objects to be tracked by the GC (GH-13729)
parent
13ed0799
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
2 deletions
+20
-2
Misc/NEWS.d/next/Core and Builtins/2019-06-01-20-03-13.bpo-37126.tP6lL4.rst
...ore and Builtins/2019-06-01-20-03-13.bpo-37126.tP6lL4.rst
+2
-0
Objects/structseq.c
Objects/structseq.c
+18
-2
No files found.
Misc/NEWS.d/next/Core and Builtins/2019-06-01-20-03-13.bpo-37126.tP6lL4.rst
0 → 100644
View file @
7ffcf848
All structseq objects are now tracked by the garbage collector. Patch by
Pablo Galindo.
Objects/structseq.c
View file @
7ffcf848
...
...
@@ -3,6 +3,7 @@
#include "Python.h"
#include "pycore_tupleobject.h"
#include "pycore_object.h"
#include "structmember.h"
static
const
char
visible_length_key
[]
=
"n_sequence_fields"
;
...
...
@@ -59,6 +60,18 @@ PyStructSequence_GetItem(PyObject* op, Py_ssize_t i)
return
PyStructSequence_GET_ITEM
(
op
,
i
);
}
static
int
structseq_traverse
(
PyStructSequence
*
obj
,
visitproc
visit
,
void
*
arg
)
{
Py_ssize_t
i
,
size
;
size
=
REAL_SIZE
(
obj
);
for
(
i
=
0
;
i
<
size
;
++
i
)
{
Py_VISIT
(
obj
->
ob_item
[
i
]);
}
return
0
;
}
static
void
structseq_dealloc
(
PyStructSequence
*
obj
)
{
...
...
@@ -166,6 +179,7 @@ structseq_new_impl(PyTypeObject *type, PyObject *arg, PyObject *dict)
}
Py_DECREF
(
arg
);
_PyObject_GC_TRACK
(
res
);
return
(
PyObject
*
)
res
;
}
...
...
@@ -388,6 +402,7 @@ PyStructSequence_InitType2(PyTypeObject *type, PyStructSequence_Desc *desc)
type
->
tp_methods
=
structseq_methods
;
type
->
tp_new
=
structseq_new
;
type
->
tp_flags
=
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_HAVE_GC
;
type
->
tp_traverse
=
(
traverseproc
)
structseq_traverse
;
n_members
=
count_members
(
desc
,
&
n_unnamed_members
);
members
=
PyMem_NEW
(
PyMemberDef
,
n_members
-
n_unnamed_members
+
1
);
...
...
@@ -426,7 +441,7 @@ PyStructSequence_NewType(PyStructSequence_Desc *desc)
PyMemberDef
*
members
;
PyObject
*
bases
;
PyTypeObject
*
type
;
PyType_Slot
slots
[
7
];
PyType_Slot
slots
[
8
];
PyType_Spec
spec
;
Py_ssize_t
n_members
,
n_unnamed_members
;
...
...
@@ -446,7 +461,8 @@ PyStructSequence_NewType(PyStructSequence_Desc *desc)
slots
[
3
]
=
(
PyType_Slot
){
Py_tp_methods
,
structseq_methods
};
slots
[
4
]
=
(
PyType_Slot
){
Py_tp_new
,
structseq_new
};
slots
[
5
]
=
(
PyType_Slot
){
Py_tp_members
,
members
};
slots
[
6
]
=
(
PyType_Slot
){
0
,
0
};
slots
[
6
]
=
(
PyType_Slot
){
Py_tp_traverse
,
(
traverseproc
)
structseq_traverse
};
slots
[
7
]
=
(
PyType_Slot
){
0
,
0
};
/* Initialize Spec */
/* The name in this PyType_Spec is statically allocated so it is */
...
...
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