diff options
| author | stderr64 <stderr64@null.net> | 2025-10-28 18:11:09 +0200 |
|---|---|---|
| committer | stderr64 <stderr64@null.net> | 2025-10-28 18:11:09 +0200 |
| commit | 557bf9c01fd78848167c1db8327aed259c5b3690 (patch) | |
| tree | e58d1d10861e2586353f3a14193609134314d34f /python_cdll_multithread/cdll.py | |
| parent | 56346d0b8041caa99ce1ac57becff11e78fd561e (diff) | |
| download | experiments-557bf9c01fd78848167c1db8327aed259c5b3690.tar.gz experiments-557bf9c01fd78848167c1db8327aed259c5b3690.tar.zst | |
Added some stuff
Diffstat (limited to 'python_cdll_multithread/cdll.py')
| -rwxr-xr-x | python_cdll_multithread/cdll.py | 49 |
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 ); |
