| 1 |
#include "parts.h" |
| 2 |
#include "util.h" |
| 3 |
|
| 4 |
// Test PyImport_ImportModuleAttr() |
| 5 |
static PyObject * |
| 6 |
pyimport_importmoduleattr(PyObject *self, PyObject *args) |
| 7 |
{ |
| 8 |
PyObject *mod_name, *attr_name; |
| 9 |
if (!PyArg_ParseTuple(args, "OO", &mod_name, &attr_name)) { |
| 10 |
return NULL; |
| 11 |
} |
| 12 |
NULLABLE(mod_name); |
| 13 |
NULLABLE(attr_name); |
| 14 |
|
| 15 |
return PyImport_ImportModuleAttr(mod_name, attr_name); |
| 16 |
} |
| 17 |
|
| 18 |
|
| 19 |
// Test PyImport_ImportModuleAttrString() |
| 20 |
static PyObject * |
| 21 |
pyimport_importmoduleattrstring(PyObject *self, PyObject *args) |
| 22 |
{ |
| 23 |
const char *mod_name, *attr_name; |
| 24 |
Py_ssize_t len; |
| 25 |
if (!PyArg_ParseTuple(args, "z#z#", &mod_name, &len, &attr_name, &len)) { |
| 26 |
return NULL; |
| 27 |
} |
| 28 |
|
| 29 |
return PyImport_ImportModuleAttrString(mod_name, attr_name); |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
static PyMethodDef test_methods[] = { |
| 34 |
{"PyImport_ImportModuleAttr", pyimport_importmoduleattr, METH_VARARGS}, |
| 35 |
{"PyImport_ImportModuleAttrString", pyimport_importmoduleattrstring, METH_VARARGS}, |
| 36 |
{NULL}, |
| 37 |
}; |
| 38 |
|
| 39 |
int |
| 40 |
_PyTestCapi_Init_Import(PyObject *m) |
| 41 |
{ |
| 42 |
return PyModule_AddFunctions(m, test_methods); |
| 43 |
} |
| 44 |
|