Last active
November 28, 2016 15:58
-
-
Save wware/9ecd5fedf7d2dd335d4464584d8e03d9 to your computer and use it in GitHub Desktop.
Reminder of how to use SWIG to wrap C functions for use in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Do this: | |
make | |
gdb -x hook.x `which python` | |
More info: http://www.swig.org/Doc1.3/Python.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void wware_hook(void) | |
{ | |
return; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%module hook | |
%{ | |
void wware_hook(void); | |
%} | |
void wware_hook(void); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set breakpoint pending on | |
break wware_hook | |
run hook2.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hook | |
hook.wware_hook() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: _hook.so | |
wrapper.c: hook.i | |
swig -python -o wrapper.c hook.i | |
wrapper.o: wrapper.c | |
gcc -I/usr/include/python2.7 -fPIC -c wrapper.c | |
hook.o: hook.c | |
gcc -fPIC -c hook.c | |
_hook.so: hook.o wrapper.o | |
gcc -shared wrapper.o hook.o -lpython2.7 -o _hook.so | |
clean: | |
rm -f wrapper.c wrapper.o hook.o hook.so _hook.so hook.py hook.pyc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment