summaryrefslogtreecommitdiff
path: root/python_cdll_multithread/cdll.py
diff options
context:
space:
mode:
Diffstat (limited to 'python_cdll_multithread/cdll.py')
-rwxr-xr-xpython_cdll_multithread/cdll.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/python_cdll_multithread/cdll.py b/python_cdll_multithread/cdll.py
new file mode 100755
index 0000000..eb76d35
--- /dev/null
+++ b/python_cdll_multithread/cdll.py
@@ -0,0 +1,49 @@
+#!/usr/bin/python3 -u
+import sys;
+import time;
+from ctypes import *;
+
+testlib = CDLL( "./libpcdlltest.so" );
+
+print( testlib );
+
+testlib.testfunc.restype = c_void_p;
+testlib.testfunc2.restype = c_void_p;
+testlib.testfunc3.restype = c_char_p;
+testlib.cleanup_buffer.restype = c_void_p;
+
+print( "Executing first test function (simple message from C code)" );
+
+testlib.testfunc();
+
+print( "Executing test function 2 (pass python value to it)" );
+
+pvar = create_string_buffer( bytes("test message", "utf8") );
+testlib.testfunc2( pvar );
+del pvar;
+
+print( "Executing test function 3 (return value from C code)" );
+
+test_value = testlib.testfunc3().decode("utf8");
+print( f"Returned value: {test_value}" );
+del test_value;
+
+print( "Executing buffer cleanup functiion" );
+
+testlib.cleanup_buffer();
+
+print( "Starting C thread" );
+
+testlib.threadstarter();
+
+print( "Printing garbage from python code" );
+
+for pcount in range(0, 40):
+ print( f"Count is now in python {pcount}" );
+ time.sleep( 1 );
+
+print( "All tests done" );
+
+del testlib;
+
+sys.exit( 0 );