You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello!
I am in the process of writing a python profiler in Rust and I thought it would be a good starting point to
get my toes in pyo3
use case
the sys.setprofile/threading.setprofile function takes a callable that should accept Frame as first argument, the equivalent pyo3 type for frame is the PyFrame, the rust function I pass to setprofile is like so
unfortunately Bound does not implement PyFrameMethods for Bound<'py, PyFrame> and there is no such trait as PyFrameMethods to be implemented, so I can't access frame functions
(I am still in the process of understanding pyo3 so I might be wrong here)
I tried to use the ffi function directly; PyFrame_GetLineNumber for example, but it expect *mut PyFrameObject which is the underlying ffi object, and I don't have any way to get that ffi object since it is behind the Bound struct
implementation
create PyFrameMethods and implement it on Bound<'py, PyFrame>, since as_ptr cannot be used on PyFrame because as_ptr returns ffi::PyObject and we need PyFrameObject, a new function should be implemented on PyFrame to return the ffi type, and PyFrame struct member should be ffi:PyFrameObject instead of PyAny
I would be glad to take on this implementation
Do you need mentoring?
It would be helpful, yes
The text was updated successfully, but these errors were encountered:
Hello!
I am in the process of writing a python profiler in Rust and I thought it would be a good starting point to
get my toes in
pyo3
use case
the
sys.setprofile
/threading.setprofile
function takes a callable that should acceptFrame
as first argument, the equivalent pyo3 type for frame is thePyFrame
, the rust function I pass tosetprofile
is like soproblem
unfortunately
Bound
does not implementPyFrameMethods for Bound<'py, PyFrame>
and there is no such trait asPyFrameMethods
to be implemented, so I can't access frame functions(I am still in the process of understanding pyo3 so I might be wrong here)
I tried to use the
ffi
function directly;PyFrame_GetLineNumber
for example, but it expect*mut PyFrameObject
which is the underlying ffi object, and I don't have any way to get that ffi object since it is behind theBound
structimplementation
create
PyFrameMethods
and implement it onBound<'py, PyFrame>
, sinceas_ptr
cannot be used onPyFrame
becauseas_ptr
returnsffi::PyObject
and we needPyFrameObject
, a new function should be implemented onPyFrame
to return the ffi type, andPyFrame
struct member should beffi:PyFrameObject
instead ofPyAny
I would be glad to take on this implementation
It would be helpful, yes
The text was updated successfully, but these errors were encountered: