Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix check for bound methods on falsy objects. #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Yorwba
Copy link

@Yorwba Yorwba commented Apr 9, 2018

Minimal reproduction of the bug fixed by this PR:

class Falsy(object):
	def __bool__(self):
		return False
	__nonzero__ = __bool__
	def do_stuff(self):
		pass

Falsy().do_stuff()
ERROR:byterun.pyvm2:Caught exception during execution
Traceback (most recent call last):
  File "byterun/pyvm2.py", line 236, in dispatch
    why = bytecode_fn(*arguments)
  File "byterun/pyvm2.py", line 925, in byte_CALL_FUNCTION
    return self.call_function(arg, [], {})
  File "byterun/pyvm2.py", line 956, in call_function
    if not isinstance(posargs[0], func.im_class):
IndexError: list index out of range

Because instances of Falsy are falsy, if func.im_self treats them as nonexistent and does not add the self parameter to the argument list.

rocky added a commit to rocky/x-python that referenced this pull request May 2, 2020
rocky added a commit to rocky/x-python that referenced this pull request May 2, 2020
@rocky
Copy link

rocky commented May 2, 2020

@Yorwba @andychu - Thanks - I've applied this, including the test on the fork of this project (now called x-python)

I should note that the code given appears to be a problem in Python 2.x, not 3.x.

rocky added a commit to rocky/x-python that referenced this pull request May 2, 2020
Because instances of Falsy are falsy, `func.im_self` in
call_function() of xpython/pyvm2.ptreated them as nonexistent and
did not add the self parameter to the argument list.

The problem was exhibited on Python 2.7.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants