8000 gh-90763: Modernise xx template module initialisation by erlend-aasland · Pull Request #93078 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-90763: Modernise xx template module initialisation #93078

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 3 commits into from
Jun 10, 2022
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
Address review: remove helper from xxlimited_35
  • Loading branch information
erlend-aasland committed May 23, 2022
commit 5ce42f783079f54891f4a564a98c9213b03cc462
42 changes: 24 additions & 18 deletions Modules/xxlimited_35.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,23 +236,11 @@ static PyMethodDef xx_methods[] = {
PyDoc_STRVAR(module_doc,
"This is a module for testing limited API from Python 3.5.");

static PyObject *
create_and_add_type(PyObject *module, const char *name, PyType_Spec *spec)
{
PyObject *type = PyType_FromSpec(spec);
if (type == NULL) {
return NULL;
}
if (PyModule_AddObject(module, name, type) < 0) {
Py_DECREF(type);
return NULL;
}
return type;
}

static int
xx_modexec(PyObject *m)
{
PyObject *o;

/* Due to cross platform compiler issues the slots must be filled
* here. It's required for portability to Windows without requiring
* C++. */
Expand All @@ -273,15 +261,33 @@ xx_modexec(PyObject *m)
return -1;
}

/* Add Xxo, Str, and Null types */
Xxo_Type = create_and_add_type(m, "Xxo", &Xxo_Type_spec);
/* Add Xxo */
Xxo_Type = PyType_FromSpec(&Xxo_Type_spec);
if (Xxo_Type == NULL) {
return -1;
}
if (create_and_add_type(m, "Str", &Str_Type_spec) == NULL) {
if (PyModule_AddObject(m, "Xxo", Xxo_Type) < 0) {
Py_DECREF(Xxo_Type);
return -1;
}

/* Add Str */
o = PyType_FromSpec(&Str_Type_spec);
if (o == NULL) {
return -1;
}
if (PyModule_AddObject(m, "Str", o) < 0) {
Py_DECREF(o);
return -1;
}

/* Add Null */
o = PyType_FromSpec(&Null_Type_spec);
if (o == NULL) {
return -1;
}
if (create_and_add_type(m, "Null", &Null_Type_spec) == NULL) {
if (PyModule_AddObject(m, "Null", o) < 0) {
Py_DECREF(o);
return -1;
}

Expand Down
0