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: misleading comment on PyBytes_FromStringAndSize
Type: Stage:
Components: Documentation Versions: Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, eli.bendersky, python-dev, vstinner
Priority: low Keywords: easy, patch

Created on 2011-03-22 14:41 by eli.bendersky, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue11634.1.patch eli.bendersky, 2011-03-23 04:34
Messages (9)
msg131750 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2011-03-22 14:41
The comment string above the implementation of _PyBytes_FromStringAndSize in Objects/bytesobject.c starts with:

  /*
  For both PyBytes_FromString() and PyBytes_FromStringAndSize(), the
  parameter `size' denotes number of characters to allocate, not 
  counting   any null terminating character.

This is misleading since PyBytes_FromString() has no 'size' parameter. 

The problem also exists for PyString in Python 2.x
msg131751 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-03-22 14:43
Could you write a patch to fix this comment?
msg131765 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2011-03-22 18:52
Sure, I just wanted confirmation from another dev that it's indeed an error and I'm not missing anything. 

I suppose the fix is just replace "for both PyBytes_FromString() and PyBytes_FromStringAndSize()" with just "for PyBytes_FromStringAndSize()".

I'll commit the change to all relevant branches.
msg131777 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-03-22 20:22
PyObject *
PyBytes_FromString(const char *str)
{
    register size_t size;
    ...
    size = strlen(str);
    ...
}

PyBytes_FromString() does compute the input string size using strlen().
msg131847 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2011-03-23 03:48
Yes it does, but the comment says something about "parameter 'size'" which is clearly absent from the function signature of PyBytes_FromString.
msg131853 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2011-03-23 04:31
I propose the attached patch (for the latest default branch). It simply removes the first paragraph of that comment, since it's misleading and redundant. The *last* paragraph explains the same thing just in a clear and correct way (except that it also has a small typo the patch fixes :-)
msg132029 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-03-24 20:51
New changeset a729dfdbd24b by Eli Bendersky in branch 'default':
Issue #11634: Remove misleading paragraph from a comment
http://hg.python.org/cpython/rev/a729dfdbd24b
msg132030 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-03-24 20:56
New changeset 44749e501982 by Eli Bendersky in branch '2.7':
Issue #11634: Remove misleading paragraph from a comment
http://hg.python.org/cpython/rev/44749e501982
msg132031 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2011-03-24 20:57
Patch reviewed by Nick Coghlan and committed
History
Date User Action Args
2022-04-11 14:57:15adminsetgithub: 55843
2011-03-24 20:57:53eli.benderskysetstatus: open -> closed
resolution: fixed
messages: + msg132031

versions: + Python 2.7, - Python 3.2
2011-03-24 20:56:49python-devsetmessages: + msg132030
2011-03-24 20:51:24python-devsetnosy: + python-dev
messages: + msg132029
2011-03-23 04:34:02eli.benderskysetfiles: + issue11634.1.patch
nosy: vstinner, eli.bendersky, docs@python
keywords: + patch
2011-03-23 04:31:52eli.benderskysetnosy: vstinner, eli.bendersky, docs@python
messages: + msg131853
2011-03-23 03:48:57eli.benderskysetnosy: vstinner, eli.bendersky, docs@python
messages: + msg131847
2011-03-22 20:22:18vstinnersetnosy: vstinner, eli.bendersky, docs@python
messages: + msg131777
2011-03-22 18:52:05eli.benderskysetnosy: vstinner, eli.bendersky, docs@python
messages: + msg131765
2011-03-22 14:43:18vstinnersetnosy: + vstinner
messages: + msg131751
2011-03-22 14:41:22eli.benderskycreate