'RCore' object has no attribute '_r_core_free'
Ret2c7 opened this issue · 7 comments
Environment
r2pipe language is python
radare2 5.8.9 31576 @ linux-x86-64
birth: git.5.8.8-1011-g72e00141b3 2024-01-11__11:05:41
commit: 72e00141b32082394592a624ed8567fdb1051b3c
options: gpl -O? cs:5 cl:2 make
Linux x86_64
1.8.4
Description
When I use the r2diaphora plug-in, the following error appears
File "/home/c7/.local/lib/python3.10/site-packages/r2pipe/open_base.py", line 252, in cmd
res = self._cmd(cmd, **kwargs)
File "/home/c7/.local/lib/python3.10/site-packages/r2pipe/open_base.py", line 202, in _cmd_native
self.native.cmd_str("o " + self.uri)
File "/home/c7/.local/lib/python3.10/site-packages/r2pipe/native.py", line 130, in cmd_str
return self._r_core_cmd_str(self._o, cmd)
AttributeError: 'RCore' object has no attribute '_r_core_cmd_str'
Exception ignored in: <function RCore.__del__ at 0x7f5b75b88ee0>
Traceback (most recent call last):
File "/home/c7/.local/lib/python3.10/site-packages/r2pipe/native.py", line 128, in __del__
AttributeError: 'RCore' object has no attribute '_r_core_free'
I found that r2lib() in RCORE returned None, which should not be expected. Further follow-up in r2lib() found that the returned lib_name is libr_core.so, and then the following exception will trigger that the file cannot be found. I don’t know if It is the issue of absolute paths and relative paths that causes this problem
Can you hardcode the full path to libr_core? And override what find_library returns and see what happens?
I've tried hardcoding lib_name, the value is /usr/local/lib/libr_core.so
But now a new error appeared
File "/home/c7/.local/lib/python3.10/site-packages/r2pipe/open_base.py", line 252, in cmd
res = self._cmd(cmd, **kwargs)
File "/home/c7/.local/lib/python3.10/site-packages/r2pipe/open_base.py", line 202, in _cmd_native
self.native.cmd_str("o " + self.uri)
File "/home/c7/.local/lib/python3.10/site-packages/r2pipe/native.py", line 130, in cmd_str
return self._r_core_cmd_str(self._o, cmd)
TypeError: 'tuple' object is not callable
Exception ignored in: <function RCore.__del__ at 0x7f043f994ee0>
Traceback (most recent call last):
File "/home/c7/.local/lib/python3.10/site-packages/r2pipe/native.py", line 128, in __del__
TypeError: 'tuple' object is not callable
What do you mean?
register() returns a tuple,and received through the following code
self._r_core_cmd_str = register("r_core_cmd_str", "c_void_p, c_char_p", "c_char_p")
self._r_core_free = register("r_core_free", "c_void_p", "c_void_p")
Called through the following code
def __del__(self):
self._r_core_free(self._o)
def cmd_str(self, cmd):
return self._r_core_cmd_str(self._o, cmd)
The error message mentions 'tuple' object is not callable
So I changed it to
def __del__(self):
self._r_core_free[0](self._o)
def cmd_str(self, cmd):
return self._r_core_cmd_str[1](self._o, cmd)
I don’t know if this modification is in line with expectations
ok thats weird, the code works perfectly fine on macOS, but fails on Linux. The good part is that i can reproduce, but your fix breaks macos 🤪 let me do some checks and maybe add tests in the CI and push a proper fix.
Thanks for reporting!
Fixed in https://pypi.org/project/r2pipe/1.8.6/
thanks! your patch was actually good, i dont get why mac's python permits to call tupples, its weird