This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Erroneous code objects created with PyCode_New
Type: Stage:
Components: None Versions:
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: nnorwitz Nosy List: nnorwitz, timmcl
Priority: normal Keywords:

Created on 2003-12-09 03:15 by timmcl, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg19336 - (view) Author: Tim McLennan (timmcl) Date: 2003-12-09 03:15
If you copy a code object by calling say new.code with
just the members of an existing code object with
free/cell variables - such as the following nested example:

def null():
    return None

def wrapfunc(func):
    def _inner(*args):
       return func(*args)
    return _inner

wrapped = wrapfunc(null)

code_object = wrapped.func_code

new_code_object = new.code(<  code_object  >)


then the new_code_object will not have had its
free/cell vars removed and will thus not disassemble
correctly.  Furthermore 
if you create a function out of it, then calling the
function will raise - 
SystemError:
R:Python23srcPython-2.3.2Objectscellobject.c:
22: bad argument to internal function

Looking at the code in PyCode_New I can't see why this
should happen.

(Bug noticed on Python 2.3.2 on windows)
msg19337 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2005-10-02 06:59
Logged In: YES 
user_id=33168

I don't think this is still a bug any longer. 
new.function() seems to require closure be passed in if the
function has cell variables.

When I disassemble new_code_object, I get the same as the
original.
msg19338 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2005-12-19 03:45
Logged In: YES 
user_id=33168

Assuming this is fixed.
History
Date User Action Args
2022-04-11 14:56:01adminsetgithub: 39683
2003-12-09 03:15:01timmclcreate