Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Python3.10 #3

Merged
merged 7 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Declaration of variables
CC = gcc
CC_FLAGS = -shared -fPIC -I/usr/include/python2.7 \
CC_FLAGS = -shared -fPIC -I/usr/include/python3.10 \
-Wall -Wextra -Wno-unused-parameter -O2 -g

# File names
Expand All @@ -15,7 +15,7 @@ all: $(OBJECTS)
$(CC) $(CC_FLAGS) $< -o $@

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

# To remove generated files
Expand Down
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Python/C API quick start
=========================

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

```
make all
python -c "import hello; hello.greet('World')"
python -c "import fib; print fib.fib(5)"
python -c "import fib; print(fib.fib(5))"
make clean
```

Expand Down
18 changes: 15 additions & 3 deletions fibmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,21 @@ static PyMethodDef FibMethods[] = {
{NULL, NULL, 0, NULL} /* Sentinel */
};

/* Create PyModuleDef structure */
static struct PyModuleDef fibStruct = {
PyModuleDef_HEAD_INIT,
"fib",
"",
-1,
FibMethods,
NULL,
NULL,
NULL,
NULL
};

/* Module initialization */
PyMODINIT_FUNC
initfib(void)
PyObject *PyInit_fib(void)
{
(void) Py_InitModule("fib", FibMethods);
return PyModule_Create(&fibStruct);
}
19 changes: 16 additions & 3 deletions hellomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,22 @@ static PyMethodDef HelloMethods[] = {
{NULL, NULL, 0, NULL} /* Sentinel */
};

/* Create PyModuleDef stucture */
static struct PyModuleDef helloStruct = {
PyModuleDef_HEAD_INIT,
"hello",
"",
-1,
HelloMethods,
NULL,
NULL,
NULL,
NULL
};


/* Module initialization */
PyMODINIT_FUNC
inithello(void)
PyObject *PyInit_hello(void)
{
(void) Py_InitModule("hello", HelloMethods);
return PyModule_Create(&helloStruct);
}