Skip to content

Throwing exceptions across modules causes namespace issues #290

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

Closed
pfalcon opened this issue Feb 14, 2014 · 5 comments
Closed

Throwing exceptions across modules causes namespace issues #290

pfalcon opened this issue Feb 14, 2014 · 5 comments
Labels

Comments

@pfalcon
Copy link
Contributor

pfalcon commented Feb 14, 2014

Testcase:

$ cat submod.py 
def foo():
    raise OSError

$ cat testcase2.py 
import submod

def func1():
    return

def func2():
    try:
        submod.foo()
    except OSError:
        pass
    func1()

func2()

$ micropython testcase2.py 
Traceback (most recent call last):
  File "testcase2.py", line 14, in <module>
  File "testcase2.py", line 11, in func2
NameError: name 'func1' is not defined
@pfalcon
Copy link
Contributor Author

pfalcon commented Feb 14, 2014

That's because objfun.c:

    rt_globals_set(self->globals);
    mp_obj_t result = mp_execute_byte_code(self->bytecode, args, n_args, self->def_args + self->n_def_args - use_def_args, use_def_arg...
    rt_globals_set(old_globals);

If exception occurs in func body execution, nothing restores old globals. And apparently it makes no sense to add unwind-protect to fun_bc_call(), because mp_execute_byte_code() soon will do another nlr_push. So, apparently mp_execute_byte_code() should be passed a namespace and should take care of saving/restoring current one.

@pfalcon
Copy link
Contributor Author

pfalcon commented Feb 14, 2014

No working on this further so far, assuming @dpgeorge will have better idea where/how to implement this.

@pfalcon
Copy link
Contributor Author

pfalcon commented Feb 14, 2014

Also, consider generator impl at the same time - objgenerator doesn't have any calls to rt_globals_set() at all.

pfalcon added a commit that referenced this issue Feb 15, 2014
…odule.

Issue #290. This currently fails, to draw attention to the issue.
pfalcon referenced this issue in pfalcon/pycopy Feb 15, 2014
@pfalcon
Copy link
Contributor Author

pfalcon commented Feb 15, 2014

Ok, so I'm eager to get my piece working ;-). I pushed a testcase for this to testsuite (so it's broken now), and submitted #292 as proposed fix.

@pfalcon pfalcon added the bug label Feb 15, 2014
dpgeorge added a commit that referenced this issue Feb 15, 2014
Addresses issue #290, and hopefully sets up things to allow generators
throwing exceptions, etc.
@pfalcon
Copy link
Contributor Author

pfalcon commented Feb 16, 2014

This was fixed.

@pfalcon pfalcon closed this as completed Feb 16, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant