To do: in-place API
Make in-place versions of all the API functions, like:
pyimport!(ans, "sys")
pyadd!(ans, x, y)
pygetattr!(ans, x, "foo")
These replace the pointer in ans::Py with the result of the computation, instead of allocating a new Py each time. This will allow writing super-fast non-allocating code where needed.
You'd use these by pre-allocating places to store the results with pynew, which can optionally by freed with pydel!.
The Python in-place operators would be like:
pyiadd!(ans, x) # like ans += x
These should generally return ans, to make chaining more convenient.
A function
pyhasnext!(ans, iterator)
would be useful to return true if there is a next item, and if so set ans to its value.
Even for complicated functions (such as pycall!) we can put all the temporary state we need into ans (e.g. by setting it to a tuple of all the things we need). We'd need to generalise the first argument ans to be anything with getptr and setptr! methods, and have a non-allocating PyTupleRef type which stores a pointer to a tuple and an index.
This issue has been marked as stale because it has been open for 30 days with no activity. If the issue is still relevant then please leave a comment, or else it will be closed in 7 days.
This issue has been closed because it has been stale for 7 days. If it is still relevant, please re-open it.