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

Incorrect division in [wave.py] #51930

Closed
alfps mannequin opened this issue Jan 12, 2010 · 6 comments
Closed

Incorrect division in [wave.py] #51930

alfps mannequin opened this issue Jan 12, 2010 · 6 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@alfps
Copy link
Mannequin

alfps mannequin commented Jan 12, 2010

BPO 7681
Nosy @benjaminp, @briancurtin
Files
  • error.py
  • issue7681.diff: patch against release31-maint, r77454
  • 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 = None
    closed_at = <Date 2010-01-13.03:50:27.961>
    created_at = <Date 2010-01-12.12:01:21.872>
    labels = ['type-bug', 'library']
    title = 'Incorrect division in [wave.py]'
    updated_at = <Date 2010-01-13.03:50:27.953>
    user = 'https://bugs.python.org/alfps'

    bugs.python.org fields:

    activity = <Date 2010-01-13.03:50:27.953>
    actor = 'benjamin.peterson'
    assignee = 'none'
    closed = True
    closed_date = <Date 2010-01-13.03:50:27.961>
    closer = 'benjamin.peterson'
    components = ['Library (Lib)']
    creation = <Date 2010-01-12.12:01:21.872>
    creator = 'alfps'
    dependencies = []
    files = ['15835', '15846']
    hgrepos = []
    issue_num = 7681
    keywords = ['patch', 'needs review']
    message_count = 6.0
    messages = ['97629', '97630', '97633', '97668', '97673', '97683']
    nosy_count = 3.0
    nosy_names = ['benjamin.peterson', 'brian.curtin', 'alfps']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'patch review'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue7681'
    versions = ['Python 3.1']

    @alfps
    Copy link
    Mannequin Author

    alfps mannequin commented Jan 12, 2010

    CPython 3.1.1 in Windows XP.

    Traceback (most recent call last):
      File "C:\Documents and Settings\Alf\sound\error.py", line 6, in <module>
        writer.setframerate( framerate )
    NameError: name 'framerate' is not defined
    Exception wave.Error: Error('sampling rate not specified',) in <bound method Wave_write.__del__ of <wave.Wave_write obje
    ct at 0x00FE87F0>> ignored

    TO FIX:

    "/" needs to be changed to "//" in lines and 243 464 of [wave.py]

    @alfps alfps mannequin added type-crash A hard crash of the interpreter, possibly with a core dump stdlib Python modules in the Lib dir labels Jan 12, 2010
    @alfps
    Copy link
    Mannequin Author

    alfps mannequin commented Jan 12, 2010

    Sorry, here's correct error message:

    Traceback (most recent call last):
      File "C:\Documents and Settings\Alf\sound\error.py", line 8, in <module>
        writer.writeframes( b"\0"*2*4 )
      File "C:\Program Files\cpython\python31\lib\wave.py", line 432, in writeframes
        self.writeframesraw(data)
      File "C:\Program Files\cpython\python31\lib\wave.py", line 416, in writeframesraw
        self._ensure_header_written(len(data))
      File "C:\Program Files\cpython\python31\lib\wave.py", line 459, in _ensure_header_written
        self._write_header(datasize)
      File "C:\Program Files\cpython\python31\lib\wave.py", line 472, in _write_header
        self._sampwidth * 8, 'data'))
    struct.error: required argument is not an integer
    Exception struct.error: 'required argument is not an integer' in <bound method Wave_write.__del__ of <wave.Wave_write ob
    ject at 0x00FE87F0>> ignored

    @briancurtin
    Copy link
    Member

    In your example, the "n_frames" name does not exist, which is causing the problem. In your first comment, "framerate" also did not exist.

    I don't know what a proper frame rate value is, but I just put 10 in there and it worked fine. Can you confirm?

    @briancurtin briancurtin removed the type-crash A hard crash of the interpreter, possibly with a core dump label Jan 12, 2010
    @alfps
    Copy link
    Mannequin Author

    alfps mannequin commented Jan 12, 2010

    No, sorry, the bugs in [wave.py] have nothing to do with a name IN A COMMENT in the trivial code to exercise the bugs.

    To reproduce the crash, just run the supplied code with Python 3.1.1 in Windows XP.

    The cause of the crash is, as I pointed out, use of Python 2.x "/" division instead of Python 3.x "//" division. The author of [wave.py] had fixed that in some places. But he/she forgot two places.

    Cheers & hth.,

    • Alf

    @briancurtin
    Copy link
    Member

    There is no crash, but I see what you are saying now.
    Patch to correct the two divisions and a test similar to your example.

    @briancurtin briancurtin changed the title Incorrect division in [wave.py] causing crash Incorrect division in [wave.py] Jan 13, 2010
    @briancurtin briancurtin added the type-bug An unexpected behavior, bug, or error label Jan 13, 2010
    @benjaminp
    Copy link
    Contributor

    Thanks for the patch! Applied in r77459.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants