Repository navigation
Seg fault on a method call #436
Copy link
Copy link
Closed
Milestone
Description
Issue type
Bug
How did you install PythonMonkey?
Source
OS platform and distribution
Ubuntu 22.04.4 LTS x86_64
Python version (python --version)
3.10
PythonMonkey version (pip show pythonmonkey)
0.9.0
Bug Description
In Python, when a method is called, the first parameter is the instance of the object
Anyways, if I defined a function without any arguments, and call the method in Python it seg faults
Standalone code to reproduce the issue
import pythonmonkey as pm; print(pm.__version__)
class What:
def some_method(): # should be `def some_method(the_obj_self):`...
return 3
obj = What()
pm.eval('x => x.some_method()')(obj)Relevant log output or backtrace
0.9.0
Segmentation fault (core dumped)Additional info if applicable
Here is the output with asan
0.9.0
AddressSanitizer:DEADLYSIGNAL
=================================================================
==1523849==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000010 (pc 0x5bcd24ea0e3a bp 0x77d954799600 sp 0x7fff7db59020 T0)
==1523849==The signal is caused by a READ memory access.
==1523849==Hint: address points to the zero page.
#0 0x5bcd24ea0e3a in PyObject_Call (/usr/bin/python3.10+0x169e3a)
#1 0x77d95a3abd8d in callPyFunc(JSContext*, unsigned int, JS::Value*) /home/will/git/pythonmonkey/src/jsTypeFactory.cc:436
#2 0x77d959107912 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) (/home/will/git/pythonmonkey/python/pythonmonkey/libmozjs-129a1.so+0x1707912)
#3 0x77d959111d26 in js::Interpret(JSContext*, js::RunState&) (/home/will/git/pythonmonkey/python/pythonmonkey/libmozjs-129a1.so+0x1711d26)
#4 0x77d95910750e in js::RunScript(JSContext*, js::RunState&) (/home/will/git/pythonmonkey/python/pythonmonkey/libmozjs-129a1.so+0x170750e)
#5 0x77d959107b95 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) (/home/will/git/pythonmonkey/python/pythonmonkey/libmozjs-129a1.so+0x1707b95)
#6 0x77d959108115 in js::Call(JSContext*, JS::Handle<JS::Value>, JS::Handle<JS::Value>, js::AnyInvokeArgs const&, JS::MutableHandle<JS::Value>, js::CallReason) (/home/will/git/pythonmonkey/python/pythonmonkey/libmozjs-129a1.so+0x1708115)
#7 0x77d9591b955a in JS_CallFunctionValue(JSContext*, JS::Handle<JSObject*>, JS::Handle<JS::Value>, JS::HandleValueArray const&, JS::MutableHandle<JS::Value>) (/home/will/git/pythonmonkey/python/pythonmonkey/libmozjs-129a1.so+0x17b955a)
#8 0x77d95a3358c7 in JSFunctionProxyMethodDefinitions::JSFunctionProxy_call(_object*, _object*, _object*) /home/will/git/pythonmonkey/src/JSFunctionProxy.cc:57
#9 0x5bcd24e8852a in _PyObject_MakeTpCall (/usr/bin/python3.10+0x15152a)
#10 0x5bcd24e80b1b in _PyEval_EvalFrameDefault (/usr/bin/python3.10+0x149b1b)
#11 0x5bcd24e77095 (/usr/bin/python3.10+0x140095)
#12 0x5bcd24f6cf65 in PyEval_EvalCode (/usr/bin/python3.10+0x235f65)
#13 0x5bcd24f97e97 (/usr/bin/python3.10+0x260e97)
#14 0x5bcd24f9179a (/usr/bin/python3.10+0x25a79a)
#15 0x5bcd24f97be4 (/usr/bin/python3.10+0x260be4)
#16 0x5bcd24f970c7 in _PyRun_SimpleFileObject (/usr/bin/python3.10+0x2600c7)
#17 0x5bcd24f96d12 in _PyRun_AnyFileObject (/usr/bin/python3.10+0x25fd12)
#18 0x5bcd24f8970d in Py_RunMain (/usr/bin/python3.10+0x25270d)
#19 0x5bcd24f5fdfc in Py_BytesMain (/usr/bin/python3.10+0x228dfc)
#20 0x77d95e029d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
#21 0x77d95e029e3f in __libc_start_main_impl ../csu/libc-start.c:392
#22 0x5bcd24f5fcf4 in _start (/usr/bin/python3.10+0x228cf4)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/usr/bin/python3.10+0x169e3a) in PyObject_Call
==1523849==ABORTINGWhat branch of PythonMonkey were you developing on? (If applicable)
main
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
- StatusShow more project fieldsDone
Activity
wiwichips commentedon Sep 11, 2024
Possibly related to #435 ?
[-]Seg fault on a method defined without object reference parameter[/-][+]Seg fault on a method call[/+]wiwichips commentedon Sep 11, 2024
Nevermind, I still get seg faults when I do have
selfin the method - so my earlier theory can be ignored...?OUTPUT:
, but also sometimes the output shows up as:
philippedistributive commentedon Sep 11, 2024
@wiwichips yeah you need a suppr.txt like this one to properly run the sanitizer:
leak:_PyObject_Malloc
leak:_PyObject_Realloc
leak:__interceptor_malloc
leak:__interceptor_realloc
leak:JobQueue::JobQueue
leak:DictType::getPyObject
leak:ListType::getPyObject
leak:JSFunctionProxyMethodDefinitions::JSFunctionProxy_new
leak:BufferType::toJsTypedArray
leak:JSMethodProxyMethodDefinitions::JSMethodProxy_new
leak:eval
philippedistributive commentedon Sep 11, 2024
@wiwichips cannot repro with the self in there. Can you still repro?
philippedistributive commentedon Sep 11, 2024
It seems like adding the self argument solves the issue indeed, and with the following, we get
Python 3.12.3 (main, Jul 31 2024, 17:43:48) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
class What:
... def some_method(): # should be
def some_method(the_obj_self):...... return 3
...
obj = What()
obj.some_method()
Traceback (most recent call last):
File "", line 1, in
TypeError: What.some_method() takes 0 positional arguments but 1 was given
which is the same as we should get here, so instead of crash now we get:
Traceback (most recent call last):
File "/home/philippe/Sources/PythonMonkey/buggy3.py", line 9, in
pm.eval('x => x.some_method()')(obj)
pythonmonkey.SpiderMonkeyError: Error in file evaluate, on line 1, column 8:
Error: Python TypeError: What.some_method() takes 0 positional arguments but 1 was given
JS Stack Trace:
@evaluate:1:8