The id of an object is not necessarily related in any way to the address of an object in Python.

In RPython, you can convert a function to a low-level function pointer with llhelper() from rpython.rtyper.annlowlevel. You can call it like this:

fptr_type = lltype.Ptr(lltype.FuncType([], lltype.Void))
fptr = llhelper(fptr_type, func)

Depending on what you want to do with the function address exactly, you might need to cast the function pointer to a RPython "Address" with cast_ptr_to_adr() from rpython.rtyper.lltypesystem.llmemory.

On 2016-12-30 14:42, Shubha Ramani via pypy-dev wrote:
It's not a bad idea for me. I'm hooking up to a tool made by intel
called "vtune" which requires the function name, function size and
function address from the original python script code. I got the first
two from Python reflection (the way VmProf does it) but I need the
third (original script function  address). Is __repr__ supported in
Rpython ? The string returned by __repr__ contains the Python address
at least in Python. If id() doesn't work but __repr__ does then I can
use it in the overloaded execute_frame and that should be fine.

Shubha

On Dec 29, 2016, at 4:29 PM, Ryan Gonzalez <rym...@gmail.com> wrote:

What exactly are you trying to do. Using id to get the address of a function is usually a bad idea...

--
Ryan (ライアン)
Yoko Shimomura > ryo (supercell/EGOIST) > Hiroyuki Sawano >> everyone else
http://kirbyfan64.github.io/

On Dec 29, 2016 1:19 PM, "Shubha Ramani via pypy-dev" <pypy-dev@python.org> wrote:

What can I use then ? I need the address of the function ?

[translation:ERROR] Exception: cannot use id() in RPython; see objectmodel.compute_xxx()
Processing block:
 block@19 is a <class 'rpython.flowspace.flowcontext.SpamBlock'>
 in (pypy.module._vtune.interp_vtune:28)_get_full_name
 containing the following operations:
       buf_0 = simple_call((type RStringIO))
       v943 = getattr(buf_0, ('write'))
       v944 = getattr(pycode_0, ('co_code'))
       v945 = simple_call(v943, v944)
       v946 = getattr(buf_0, ('getsize'))
       size_code_0 = simple_call(v946)
       v947 = getattr(pycode_0, ('co_name'))
       id_func_0 = id(v947)
       v948 = getattr(pycode_0, ('co_name'))
       v949 = simple_call((function _safe), v948)
       v950 = getattr(pycode_0, ('co_firstlineno'))
       v951 = getattr(pycode_0, ('co_filename'))
       v952 = simple_call((function _safe), v951)
       v953 = newtuple(v949, v950, v952, size_code_0, id_func_0)
       v954 = mod(('vtune:%s:%d:%s:%d:%d'), v953)
 --end--
[translation] start debugger...
> /opt/shubha_vtune_pypy/rpython/annotator/unaryop.py(188)id()
-> raise Exception("cannot use id() in RPython; "
(Pdb+)


_______________________________________________
pypy-dev mailing list
pypy-dev@python.org
https://mail.python.org/mailman/listinfo/pypy-dev


_______________________________________________
pypy-dev mailing list
pypy-dev@python.org
https://mail.python.org/mailman/listinfo/pypy-dev
_______________________________________________
pypy-dev mailing list
pypy-dev@python.org
https://mail.python.org/mailman/listinfo/pypy-dev

Reply via email to