8000 bpo-1635741: pyexpat error handling by koubaa · Pull Request #22489 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-1635741: pyexpat error handling #22489

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 8 commits into from
Nov 4, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
address comments
  • Loading branch information
koubaa committed Nov 2, 2020
commit f99b31c2ec36d1729d9f20184c1244233201b218
80 changes: 43 additions & 37 deletions Modules/pyexpat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1794,6 +1794,37 @@ add_model_module(PyObject *mod)
return 0;
}

static int add_features(PyObject *mod) {
#if XML_COMBINED_VERSION > 19505
PyObject *list = PyList_New(0);
if (list == NULL) {
return -1;
}

const XML_Feature *features = XML_GetFeatureList();
for (size_t i = 0; features[i].feature != XML_FEATURE_END; ++i) {
PyObject *item = Py_BuildValue("si", features[i].name,
features[i].value);
if (item == NULL) {
goto error;
}
int ok = PyList_Append(list, item);
Py_DECREF(item);
if (ok < 0) {
goto error;
}
}
if (PyModule_AddObject(mod, "features", list) < 0) {
goto error;
}

#endif
return 0;
error:
Py_DECREF(list);
return -1;
}

static int
pyexpat_exec(PyObject *mod)
{
Expand Down Expand Up @@ -1862,36 +1893,9 @@ pyexpat_exec(PyObject *mod)
return -1;
}

#if XML_COMBINED_VERSION > 19505
{
const XML_Feature *features = XML_GetFeatureList();
PyObject *list = PyList_New(0);
if (list == NULL) {
return -1;
}

int i = 0;
for (; features[i].feature != XML_FEATURE_END; ++i) {
PyObject *item = Py_BuildValue("si", features[i].name,
features[i].value);
if (item == NULL) {
Py_DECREF(list);
return -1;
}
int ok = PyList_Append(list, item);
Py_DECREF(item);
if (ok < 0) {
PyErr_Clear();
Py_DECREF(list);
return -1;
}
}
if (PyModule_AddObject(mod, "features", list) < 0) {
Py_DECREF(list);
return -1;
}
if (add_features(mod) < 0) {
return -1;
}
#endif

#define MYCONST(c) do { \
if (PyModule_AddIntConstant(mod, #c, c) < 0) { \
Expand Down Expand Up @@ -1949,24 +1953,26 @@ pyexpat_exec(PyObject *mod)
return 0;
}

static PyModuleDef_Slot pyexpat_slots[] = {
{Py_mod_exec, pyexpat_exec},
{0, NULL}
};

static struct PyModuleDef pyexpatmodule = {
PyModuleDef_HEAD_INIT,
.m_name = MODULE_NAME,
.m_doc = pyexpat_module_documentation,
.m_size = 0,
.m_size = -1,
.m_methods = pyexpat_methods,
.m_slots = pyexpat_slots
};

PyMODINIT_FUNC
PyInit_pyexpat(void)
{
return PyModuleDef_Init(&pyexpatmodule);
PyObject *mod = PyModule_Create(&pyexpatmodule);
if (mod == NULL)
return NULL;

if (pyexpat_exec(mod) < 0) {
Py_DECREF(mod);
return NULL;
}
return mod;
}

static void
Expand Down
0