-
-
Save parsa/8c99c2faf64fb80447ef39fe98cd584e to your computer and use it in GitHub Desktop.
Revisions
-
tonyseek revised this gist
Dec 6, 2013 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,5 @@ #include <iostream> class User { std::string name; -
tonyseek renamed this gist
Dec 6, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
tonyseek revised this gist
Dec 6, 2013 . 1 changed file with 21 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ Run with Python:: pip-2.7 install cffi PYTHON=python2.7 sh go.sh Run with PyPy:: pip-pypy install cffi PYTHON=pypy sh go.sh Run with Py3K:: pip-3.3 install cffi PYTHON=python3.3 sh go.sh The expected output:: => now run the native one hello, world => now run the pypy bound one hello, cffi -
tonyseek created this gist
Dec 6, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ #!/usr/bin/env sh set -e [ -z "$PYTHON" ] && PYTHON="python" g++ -o ./hello ./libhello.cpp echo "=> now run the native one" ./hello g++ -o ./libhello.so ./libhello.cpp -fPIC -shared echo "=> now run the $PYTHON bound one" python hello.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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ import cffi ffi = cffi.FFI() ffi.cdef("void cffi_hello(char *name);") C = ffi.dlopen("./libhello.so") def hello(name): C.cffi_hello(name) if __name__ == "__main__": hello("cffi") 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ #include <iostream> class User; class User { std::string name; public: User(char *name):name(name) {} User(std::string &name):name(name) {} std::string greet() { return "hello, " + name; } }; void hello(char *name) { User user(name); std::cout << user.greet() << std::endl; } int main() { hello((char *) "world"); return 0; } extern "C" { extern void cffi_hello(char *name) { return hello(name); } }