[pypy-dev] cannot use "id" in Rpython

Manuel Jacob me at manueljacob.de
Sun Jan 1 23:06:05 EST 2017


Hi Shubha,

I forgot to mention that the code line starting with "fptr_type = " is 
valid Python code, but not valid RPython code.  More details on this in 
the documentation [1].  You should be able to fix the error by moving 
the line to the module toplevel.

-Manuel

[1] http://rpython.readthedocs.io/en/latest/getting-started.html

On 2016-12-30 19:10, Shubha Ramani wrote:
> I don't know the signature of the function coming into execute_frame
> ahead of time. Therefore as you suggested Manuel,I am leaving the
> argument is an empty list []. This doesn't seem to work though. See
> the assertion error I'm getting below.All other examples of this
> technique I see being used are passing in specific argument types to
> define a succinctfunction signature, i.e. in
> test_warmstate.py: ENTER_JIT =
> lltype.Ptr(lltype.FuncType([lltype.Signed, lltype.Float,              
>                                                  lltype.Signed],
> lltype.Bool))  
> 
> The following causes an assertion error:
>  fun_name = _safe(pycode.co_name)                                    
>                     fptr_type = lltype.Ptr(lltype.FuncType([],
> lltype.Void))                                 fptr =
> llhelper(fptr_type, fun_name)     
> [translation] start debugger...>
> /opt/shubha_vtune_pypy/rpython/rtyper/lltypesystem/lltype.py(776)constPtr()->
> assert T.is_constant()
> 
> 
>     On Friday, December 30, 2016 8:59 AM, Shubha Ramani
> <shubharamani at yahoo.com> wrote:
> 
> 
>  This is very helpful. Thank you Manuel !
> I will try your suggestion.
> 
> Shubha
> 
>> On Dec 30, 2016, at 8:04 AM, Manuel Jacob <me at manueljacob.de> wrote:
>> 
>> 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 <rymg19 at 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 at 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 at 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 at python.org
>>>>> https://mail.python.org/mailman/listinfo/pypy-dev
>>> _______________________________________________
>>> pypy-dev mailing list
>>> pypy-dev at python.org
>>> https://mail.python.org/mailman/listinfo/pypy-dev


More information about the pypy-dev mailing list