Skip to content
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);
Comment thread
erlend-aasland marked this conversation as resolved.
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