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

$DEBUG_PYTHON -O freeze.py broken #36948

Closed
mwhudson opened this issue Jul 30, 2002 · 6 comments
Closed

$DEBUG_PYTHON -O freeze.py broken #36948

mwhudson opened this issue Jul 30, 2002 · 6 comments
Assignees

Comments

@mwhudson
Copy link

BPO 588452
Nosy @mwhudson, @gvanrossum, @theller
Files
  • marshal.c.diff: Patch for Python/marshal.c
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/theller'
    closed_at = <Date 2002-07-30.18:40:35.000>
    created_at = <Date 2002-07-30.09:13:48.000>
    labels = []
    title = '$DEBUG_PYTHON -O freeze.py broken'
    updated_at = <Date 2002-07-30.18:40:35.000>
    user = 'https://github.com/mwhudson'

    bugs.python.org fields:

    activity = <Date 2002-07-30.18:40:35.000>
    actor = 'gvanrossum'
    assignee = 'theller'
    closed = True
    closed_date = None
    closer = None
    components = ['None']
    creation = <Date 2002-07-30.09:13:48.000>
    creator = 'mwh'
    dependencies = []
    files = ['561']
    hgrepos = []
    issue_num = 588452
    keywords = []
    message_count = 6.0
    messages = ['11747', '11748', '11749', '11750', '11751', '11752']
    nosy_count = 3.0
    nosy_names = ['mwh', 'gvanrossum', 'theller']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue588452'
    versions = []

    @mwhudson
    Copy link
    Author

    I have no idea how long this bug has existed for. I
    could well be a long time. I noticed it while trying
    to kill off SET_LINENO.

    To reproduce, build a debug python, cd to Tools/freeze/
    and run

    $ /path/to/python -O freeze.py hello.py

    I get a wodge ot modulefinder (I presume) output, and then:

    freezing BaseHTTPServer ...
    freezing FixTk ...
    freezing SocketServer ...
    freezing StringIO ...
    freezing Tkconstants ...
    freezing Tkinter ...
    python: ../Python/marshal.c:66: w_more: Assertion
    `(int)(char)(c) == (c)' failed.
    Aborted (core dumped)

    This is on x86; on my PPC laptop where I discovered
    this, it gets quite a bit further before dying. So
    maybe some endianness fun.

    The assert that fails is in a Py_SAFEDOWNCAST macro.

    I have *no* idea where to start with this one;
    assigning to Thomas because I have a vague recollection
    he knows something about how freeze works <evil cackle>
    -- feel free to reassign!

    @theller
    Copy link

    theller commented Jul 30, 2002

    Logged In: YES
    user_id=11105

    Fails for me too (Win2k, python debug build). But it is a
    marshal issue!
    Here's a script to reproduce it when running with a debug
    build:
    import marshal; marshal.dumps([128] * 1000)
    (anything between 128 and 255 will trigger the error, and the
    list must be large enough.

    The debugger shows that w_long is called with x = 128, and
    than w_more() is called with c = 128, and the
    Py_SAFEDOWNCAST macro fails, maybe because char is
    signed on this platform.

    @theller
    Copy link

    theller commented Jul 30, 2002

    Logged In: YES
    user_id=11105

    As I can see, the proper fix is to replace

    static void
    w_long(long x, WFILE *p)
    {
        w_byte((int)( x      & 0xff), p);
        w_byte((int)((x>> 8) & 0xff), p);
        w_byte((int)((x>>16) & 0xff), p);
       w_byte((int)((x>>24) & 0xff), p);
    }

    with

    static void
    w_long(long x, WFILE *p)
    {
        w_byte((char)( x      & 0xff), p);
        w_byte((char)((x>> 8) & 0xff), p);
        w_byte((char)((x>>16) & 0xff), p);
        w_byte((char)((x>>24) & 0xff), p);
    }

    and similar for the w_short() function.
    Even safer would be to use the Py_SAFE_DOWNCAST
    macro also in the w_byte macro.
    Attached a patch for marshal.c.

    @mwhudson
    Copy link
    Author

    Logged In: YES
    user_id=6656

    That fixes both my initial problem and your test case. Nice
    work!

    Check it in and add a test case?

    It would be nice to have w_byte as an inline function with
    sensible declaration...

    @theller
    Copy link

    theller commented Jul 30, 2002

    Logged In: YES
    user_id=11105

    Check in and added test case:

    committed * Up-To-Date 1.3 Lib/test/test_marshal.py
    committed * Up-To-Date 1.73 Python/marshal.c

    @gvanrossum
    Copy link
    Member

    Logged In: YES
    user_id=6380

    Nice work guys!

    (Now I wonder where Py_SAFE_DOWNCAST comes from. :-)

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
    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

    No branches or pull requests

    3 participants