How to debug crashing C++ library loaded in python project

I am attempting to figure out why calling a function in a dynamically loaded lib crashes python. I’m doing the following, I have a C++ function in a dynamic library file, which is loaded in python using ctypes. I then call the function from python: lib = cdll.LoadLibrary(libPath) # Note: using c_char_p instead of POINTER(c_char)… Read More How to debug crashing C++ library loaded in python project

Mallocing and Freeing in C, but passing the pointer through Python via ctypes

I would like to put a malloc a function in C. I would then like to call this function from Python 3.10 via ctypes.DLL. I then would like to free it. However, I get a segmentation fault. Here’s my very simple C code: #include <stdlib.h> struct QueueItem { void *value; struct QueueItem *next; }; struct… Read More Mallocing and Freeing in C, but passing the pointer through Python via ctypes

I can't get output numbers with ctypes cuda

cuda1.cu #include <iostream> using namespace std ; # define DELLEXPORT extern "C" __declspec(dllexport) __global__ void kernel(long* answer = 0){ *answer = threadIdx.x + (blockIdx.x * blockDim.x); } DELLEXPORT void resoult(long* h_answer){ long* d_answer = 0; cudaMalloc(&d_answer, sizeof(long)); kernel<<<10,1000>>>(d_answer); cudaMemcpy(&h_answer, d_answer, sizeof(long), cudaMemcpyDeviceToHost); cudaFree(d_answer); } main.py import ctypes import numpy as np add_lib = ctypes.CDLL(".\\a.dll") resoult=… Read More I can't get output numbers with ctypes cuda

How to convert a binary data into c_ubyte_Array_64 in python

How to convert ` b’\x00\x00\x00\x00\x00\x00\x00\x01′ c_ubyte_Array_64 in python. I could find any resources only so any help would really appreciated. I have to send this message which should be of type c_ubyte_Array_64 import ctypes messages = { "RESET": b’\x00\x00\x00\x00\x00\x00\x00\x01′, } ba = bytearray(messages[‘RESET’]) I tried it in the above manner but it gives me this… Read More How to convert a binary data into c_ubyte_Array_64 in python