From 557bf9c01fd78848167c1db8327aed259c5b3690 Mon Sep 17 00:00:00 2001 From: stderr64 Date: Tue, 28 Oct 2025 18:11:09 +0200 Subject: Added some stuff --- python_cdll_multithread/libpcdlltest.c | 54 ++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 python_cdll_multithread/libpcdlltest.c (limited to 'python_cdll_multithread/libpcdlltest.c') diff --git a/python_cdll_multithread/libpcdlltest.c b/python_cdll_multithread/libpcdlltest.c new file mode 100644 index 0000000..6bc10ea --- /dev/null +++ b/python_cdll_multithread/libpcdlltest.c @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +char *t3_buffer = NULL; + +__attribute__((visibility("default"))) extern void *testfunc(){ + fputs( "Yes, it worked, testfunc executed\n", stdout ); + return NULL; +} + +__attribute__((visibility("default"))) extern void *testfunc2( char *testvalue ){ + fprintf( stdout, "Value passed from python: %s\n", (const char*)testvalue ); + return NULL; +} + +__attribute__((visibility("default"))) extern char *testfunc3(){ + t3_buffer = (char*)calloc( strlen("test") + 1, sizeof(char) ); + assert( t3_buffer != NULL ); + snprintf( t3_buffer, (strlen("test") * sizeof(char)) + 1, "test" ); + return t3_buffer; +} + +__attribute__((visibility("default"))) extern void *cleanup_buffer(){ + if ( t3_buffer == NULL ) + return NULL; + free( t3_buffer ); + t3_buffer = NULL; + fputs( "Buffer freed\n", stdout ); + return NULL; +} + +__attribute__((visibility("hidden"))) extern void *thread_func( void *uptr ){ + uint32_t loop_counter = 0; + for ( ; loop_counter < 30; loop_counter++ ){ + fprintf( stdout, "Loop counter is now %i\n", loop_counter ); + sleep( 1 ); + } + return NULL; +} + +__attribute__((visibility("default"))) extern void *threadstarter(){ + pthread_t tid = 0; + if ( pthread_create(&tid, NULL, &thread_func, NULL) == -1 ) + return NULL; + return NULL; +} -- cgit v1.2.3-94-g38b9