From 6c1741df63b80c34900269c02d1fc3f2eb962501 Mon Sep 17 00:00:00 2001 From: chai2010 Date: Sun, 7 Jan 2018 02:38:46 +0800 Subject: [PATCH] =?UTF-8?q?ch2-07:=20=E4=BE=8B=E5=AD=90=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/ch2-07/hello-so/Makefile | 3 +++ examples/ch2-07/hello-so/hello.py | 9 +++++++++ 2 files changed, 12 insertions(+) create mode 100644 examples/ch2-07/hello-so/hello.py diff --git a/examples/ch2-07/hello-so/Makefile b/examples/ch2-07/hello-so/Makefile index 68d7737..f76a8b0 100644 --- a/examples/ch2-07/hello-so/Makefile +++ b/examples/ch2-07/hello-so/Makefile @@ -3,6 +3,9 @@ default: gcc -Wall _test_so.c ./say-hello.so ./a.out +run-py3: + python3 hello.py + clean: -rm *.so -rm *.out diff --git a/examples/ch2-07/hello-so/hello.py b/examples/ch2-07/hello-so/hello.py new file mode 100644 index 0000000..a5b01ec --- /dev/null +++ b/examples/ch2-07/hello-so/hello.py @@ -0,0 +1,9 @@ +from ctypes import * + +libso = CDLL("./say-hello.so") + +SayHello = libso.SayHello +SayHello.argtypes = [c_char_p] +SayHello.restype = None + +SayHello(c_char_p(b"hello"))