(More) Debugging of Statically Compiled Code

After having successfully implemented a first algorithm of mine in statically compiled julia i now struggle with debugging of a second one.

Since the error messages or reasons for crashes from statically compiled julia are more or less useless at the current stage of development, i would like to do most of the debugging before compiling the code, just with normal julia, so that i can be sure that the code is correct in principle.

With a lib made in StaticCompiler and called from Python, it is necessary to pass Numpy arrays in as separate pointer and size arguments and then use either MallocArray or my own Custom Type to get Array behaviour again on the Julia side.

Now to debug this reliably, i want the whole interface to stay the same. IE i still want to use the CustomMatrix or MallocArray type, even though I call it via the normal PyJulia Interface, where i could just supply the array in a transparent fashion.

To accomplish this, i need to create pointers and sizes in a way that is correctly understood by Julia as Ptr{T}. This is where i struggle. I first tried to simply call the original function with cTypes pointers from the python side, completely as in the compiled case. But this is understood as “PyObject” and gives an error. So on the second go, i try to provide a wrapper which extracts the array pointers.

I have tried the following, but i get messed up data (where indicated by the comments).
I know that the “debug wrapper” is guilty, because i have a version that works when statically compiled and called via ctypes. (Below i show only a minimal example)

This is the testwrapper which is supposed to dress the arrays up as “pointer and size” to mimick being called just as in the compiled version

function wrap1(indx::Vector{Int64})

Apparently i have a problem getting the pointer or correctly interpreting the data pointed to.

function test1(indsxp::Ptr{Int64},npos::Int64)
	indsx = CustomVector{Int64}(indsxp, npos)
       #prints a large number instead of "1"

To make it complete, i call it like that in python:

c = np.arange(10)+1

Okay, after some playing i can answer my own question:

The above solution works once you switch out “pointer_from_objref” with just “pointer”