8000 bpo-34784: Posixmodule: Heap StructSequence by eduardo-elizondo · Pull Request #9665 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-34784: Posixmodule: Heap StructSequence #9665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Nov 13, 2018
Prev Previous commit
Next Next commit
Final cleanups
  • Loading branch information
eduardo-elizondo committed Nov 6, 2018
commit 80c03b3bb85b841fd0f1075d671c605323773382
15 changes: 10 additions & 5 deletions Objects/structseq.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,11 @@ count_members(PyStructSequence_Desc *desc, Py_ssize_t *n_unnamed_members) {
Py_ssize_t i;

*n_unnamed_members = 0;
for (i = 0; desc->fields[i].name != NULL; ++i)
if (desc->fields[i].name == PyStructSequence_UnnamedField)
for (i = 0; desc->fields[i].name != NULL; ++i) {
if (desc->fields[i].name == PyStructSequence_UnnamedField) {
(*n_unnamed_members)++;
}
}
return i;
}

Expand All @@ -306,8 +308,9 @@ initialize_structseq_dict(PyStructSequence_Desc *desc, PyObject* dict,
#define SET_DICT_FROM_SIZE(key, value) \
do { \
v = PyLong_FromSsize_t(value); \
if (v == NULL) \
if (v == NULL) { \
return -1; \
} \
if (PyDict_SetItemString(dict, key, v) < 0) { \
Py_DECREF(v); \
return -1; \
Expand Down Expand Up @@ -447,12 +450,14 @@ PyStructSequence_NewType(PyStructSequence_Desc *desc)
type = (PyTypeObject *)PyType_FromSpecWithBases(&spec, bases);
Py_DECREF(bases);
PyMem_FREE(members);
if (type == NULL)
if (type == NULL) {
return NULL;
}

if (initialize_structseq_dict(
desc, type->tp_dict, n_members, n_unnamed_members) < 0)
desc, type->tp_dict, n_members, n_unnamed_members) < 0) {
return NULL;
}

return type;
}
Expand Down
0