Skip to content

Commit

Permalink
Clean up technique for building simpleext with different name
Browse files Browse the repository at this point in the history
  • Loading branch information
adang1345 committed Jul 31, 2023
1 parent 4d3f523 commit 7a57e24
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 58 deletions.
5 changes: 3 additions & 2 deletions tests/simpleext/build/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
python_requires='==3.10.*',
zip_safe=False,
ext_modules=[Extension(
f'simpleext{n}', [f'simpleext{n}.c'],
f'simpleext{n}', [f'simpleext.c'],
include_dirs=['simpledll'],
libraries=['simpledll'],
library_dirs=library_dirs
library_dirs=library_dirs,
define_macros=[('SIMPLEEXT_INIT', f'PyInit_simpleext{n}'), ('SIMPLEEXT_MODNAME', f'"simpleext{n}"')],
)]
)
11 changes: 9 additions & 2 deletions tests/simpleext/build/simpleext.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
#include <Python.h>
#include "simpledll.h"

#ifndef SIMPLEEXT_INIT
#define SIMPLEEXT_INIT PyInit_simpleext
#endif
#ifndef SIMPLEEXT_MODNAME
#define SIMPLEEXT_MODNAME "simpleext"
#endif

static PyObject *simpleext_helloworld(PyObject *self, PyObject *args)
{
helloworld();
Expand All @@ -15,13 +22,13 @@ static PyMethodDef SimpleExtMethods[] = {

static struct PyModuleDef simpleextmodule = {
PyModuleDef_HEAD_INIT,
"simpleext",
SIMPLEEXT_MODNAME,
NULL,
-1,
SimpleExtMethods
};

PyMODINIT_FUNC PyInit_simpleext(void)
PyMODINIT_FUNC SIMPLEEXT_INIT(void)
{
return PyModule_Create(&simpleextmodule);
}
27 changes: 0 additions & 27 deletions tests/simpleext/build/simpleext0.c

This file was deleted.

27 changes: 0 additions & 27 deletions tests/simpleext/build/simpleext1.c

This file was deleted.

0 comments on commit 7a57e24

Please sign in to comment.