NiceLib icon indicating copy to clipboard operation
NiceLib copied to clipboard

Add 'arrin' and 'bufin' ArgHandlers, or similar

Open natezb opened this issue 5 years ago • 3 comments

This is for the case where the user passes in an array as input, and the C function requires a 'size' argument. This ArgHandler would automatically compute the array length and pass it in.

We could use the existing 'len' handler, or perhaps create a new one because the semantics are a bit different.

It's not clear that 'bufin' is necessary, since strings would normally be null-terminated. Might be good to have it just in case though.

natezb avatar Mar 02 '19 19:03 natezb

Is there an workaround ? Dealing exactly with that issue.

Tillsten avatar Jun 18 '20 08:06 Tillsten

It's been awhile since I've used NiceLib much, but I believe the typical workaround would be to hand-write a custom wrapper function. You could do this fully manually, or via "hybrid methods" (which unfortunately haven't been documented yet).

As an example use of hybrid methods, check out this Instrumental driver. The idea is that you decorate the hand-written method with a Sig---the auto-wrapped function is then available for use in the function body.

@Sig('in', 'in', 'inout')
def GETBOARDVAL(self, pcc_val):
    data = ffi.new('DWORD*')
    self._autofunc_GETBOARDVAL(pcc_val, ffi.cast('void*', data))
    return data[0]

Note the auto-wrapped function is available as self._autofunc_GETBOARDVAL within the function body. In your case you could do something like so:

@Sig('arr', 'in')
def myfunc(self, array):
    return self._autofunc_myfunc(array, len(array))  # Or however you find the size

natezb avatar Jun 25 '20 04:06 natezb

Thanks, thats quite helpful!

Tillsten avatar Jun 25 '20 13:06 Tillsten