Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
natezb opened this issue Mar 2, 2019 · 3 comments
Open

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

natezb opened this issue Mar 2, 2019 · 3 comments

Comments

@natezb
Copy link
Collaborator

natezb commented Mar 2, 2019

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.

@Tillsten
Copy link
Contributor

Is there an workaround ? Dealing exactly with that issue.

@natezb
Copy link
Collaborator Author

natezb commented Jun 25, 2020

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

@Tillsten
Copy link
Contributor

Thanks, thats quite helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants