Skip to content

bpo-36333: Clarify fileutils.h documentation #12406

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

Merged
merged 1 commit into from
Mar 18, 2019
Merged

bpo-36333: Clarify fileutils.h documentation #12406

merged 1 commit into from
Mar 18, 2019

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Mar 18, 2019

The last parameter of _Py_wreadlink(), _Py_wrealpath() and
_Py_wgetcwd() is a length, not a size: number of characters including
the trailing NUL character.

Enhance also documentation of error conditions.

https://bugs.python.org/issue36333

The last parameter of _Py_wreadlink(), _Py_wrealpath() and
_Py_wgetcwd() is a length, not a size: number of characters including
the trailing NUL character.

Enhance also documentation of error conditions.
Copy link
Member

@matrixise matrixise left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vstinner vstinner merged commit 1be0d11 into python:master Mar 18, 2019
@vstinner vstinner deleted the fileutils_doc branch March 18, 2019 16:47
@serhiy-storchaka
Copy link
Member

To me, length is the number of characters not including the trailing NUL character, and size is the number of characters including the trailing NUL character.

This change looks confusing to me.

@vstinner
Copy link
Member Author

To me, length is the number of characters not including the trailing NUL character, and size is the number of characters including the trailing NUL character.

Oh. I tried but I failed to find a clear "definition" of "length" vs "size". Usually for me, on a wchar_t* string, size means the number of bytes: wcslen(str)*sizeof(wchar_t), whereas length means the number of characters excluding trainling NUL: wcslen(str).

In fact, I don't know any exact term for "length including trailing NUL". That's why I added doc to be more explicit about that.

Since this PR, I also modified getpath.c to handle differently buffer length/size. I added functions which take Py_ARRAY_LENGTH(buffer) to decide if an operation will overflow a string or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants