Skip to content

Commit 42dcff4

Browse files
authored
Merge pull request #3 from icfaust/master
Update to Python3.10
2 parents e5a3bf2 + ace60c3 commit 42dcff4

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Declaration of variables
22
CC = gcc
3-
CC_FLAGS = -shared -fPIC -I/usr/include/python2.7 \
3+
CC_FLAGS = -shared -fPIC -I/usr/include/python3.10 \
44
-Wall -Wextra -Wno-unused-parameter -O2 -g
55

66
# File names
@@ -15,7 +15,7 @@ all: $(OBJECTS)
1515
$(CC) $(CC_FLAGS) $< -o $@
1616

1717
run: $(OBJECTS)
18-
python -c "import fib; print fib.fib(5)"
18+
python -c "import fib; print(fib.fib(5))"
1919
python -c "import hello; hello.greet('Foobar')"
2020

2121
# To remove generated files

Readme.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
Python/C API quick start
22
=========================
33

4-
A quick example of Python 2.7 modules implemented in C using the Python/C API.
4+
A quick example of Python 3.10 modules implemented in C using the Python/C API.
55

66
```
77
make all
88
python -c "import hello; hello.greet('World')"
9-
python -c "import fib; print fib.fib(5)"
9+
python -c "import fib; print(fib.fib(5))"
1010
make clean
1111
```
1212

fibmodule.c

+15-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,21 @@ static PyMethodDef FibMethods[] = {
3131
{NULL, NULL, 0, NULL} /* Sentinel */
3232
};
3333

34+
/* Create PyModuleDef structure */
35+
static struct PyModuleDef fibStruct = {
36+
PyModuleDef_HEAD_INIT,
37+
"fib",
38+
"",
39+
-1,
40+
FibMethods,
41+
NULL,
42+
NULL,
43+
NULL,
44+
NULL
45+
};
46+
3447
/* Module initialization */
35-
PyMODINIT_FUNC
36-
initfib(void)
48+
PyObject *PyInit_fib(void)
3749
{
38-
(void) Py_InitModule("fib", FibMethods);
50+
return PyModule_Create(&fibStruct);
3951
}

hellomodule.c

+16-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,22 @@ static PyMethodDef HelloMethods[] = {
2323
{NULL, NULL, 0, NULL} /* Sentinel */
2424
};
2525

26+
/* Create PyModuleDef stucture */
27+
static struct PyModuleDef helloStruct = {
28+
PyModuleDef_HEAD_INIT,
29+
"hello",
30+
"",
31+
-1,
32+
HelloMethods,
33+
NULL,
34+
NULL,
35+
NULL,
36+
NULL
37+
};
38+
39+
2640
/* Module initialization */
27-
PyMODINIT_FUNC
28-
inithello(void)
41+
PyObject *PyInit_hello(void)
2942
{
30-
(void) Py_InitModule("hello", HelloMethods);
43+
return PyModule_Create(&helloStruct);
3144
}

0 commit comments

Comments
 (0)