--
---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/cython-users/3608eb74-ef9d-42a7-a4bc-51135afcd589n%40googlegroups.com.
--
---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/cython-users/141CDE42-F38F-419B-A2A4-6CE6923DDE5A%40gmail.com.
To view this discussion visit https://groups.google.com/d/msgid/cython-users/CABa1M20qHmJibUiukR6FAZzVy8Bjd5kT0ncuWCA_%2BLCtwe_KgQ%40mail.gmail.com.
You could write this relatively easily using Cython's pyx file mode.
It'd just be a case of doing something like:
```
from cpython.object cimport PyObject
from cpython.mem cimport PyMem_Malloc
cdef extern from "Python.h":
PyObject *PyTuple_New(Py_ssize_t size)
# ... other definitions
def myfoo():
py_ssize_t n = 10
cdef PyObject** stack =
<PyObject**>PyMem_Malloc(sizeof(PyObject*)*n)
if stack == NULL:
raise MemoryError()
try:
stack[0] = PyTuple_New(10)
# other code presumably goes here
return <object>stack[0]
finally:
PyMem_Free(stack)
```
You'll have to manually do some of the definitions yourself because Cython's own wrappings defined the return type as `object` which means it'll try to handle the reference counting - this doesn't seem to be what you want.
I doubt that pure-Python mode is complete enough to support all is. It doesn't seem hugely useful to try to use pure-Python because there's no chance that it can usefully run in Python. So I'd stick to the "traditional" Cython syntax for this kind of code.
David
To view this discussion visit https://groups.google.com/d/msgid/cython-users/B6B774E5-F36E-42B9-A39E-48EAEE9E7090%40gmail.com.
To view this discussion visit https://groups.google.com/d/msgid/cython-users/3fe00570-6e62-4615-9ef7-83ebe8dd7a84%40d-woods.co.uk.
To view this discussion visit https://groups.google.com/d/msgid/cython-users/095FDF36-6129-452F-BCC4-B59D59B1F80A%40gmail.com.