Skip to content

Commit e119367

Browse files
committed
Add top-level modules
1 parent cd29989 commit e119367

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

tests/packages/importlib_editable/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ find_package(
66
COMPONENTS Interpreter Development.Module
77
REQUIRED)
88

9+
python_add_library(emod MODULE emod.c WITH_SOABI)
10+
install(TARGETS emod DESTINATION .)
11+
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/pmod.py" DESTINATION .)
12+
913
add_subdirectory(pkg)
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#define PY_SSIZE_T_CLEAN
2+
#include <Python.h>
3+
4+
float square(float x) { return x * x; }
5+
6+
static PyObject *square_wrapper(PyObject *self, PyObject *args) {
7+
float input, result;
8+
if (!PyArg_ParseTuple(args, "f", &input)) {
9+
return NULL;
10+
}
11+
result = square(input);
12+
return PyFloat_FromDouble(result);
13+
}
14+
15+
static PyMethodDef emod_methods[] = {
16+
{"square", square_wrapper, METH_VARARGS, "Square function"},
17+
{NULL, NULL, 0, NULL}};
18+
19+
static struct PyModuleDef emod_module = {PyModuleDef_HEAD_INIT, "emod",
20+
NULL, -1, emod_methods};
21+
22+
/* name here must match extension name, with PyInit_ prefix */
23+
PyMODINIT_FUNC PyInit_emod(void) {
24+
return PyModule_Create(&emod_module);
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def square(x):
2+
return x * x

0 commit comments

Comments
 (0)