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

bpo-42431: Fix outdated bytes comments #23458

Merged
merged 4 commits into from
Dec 3, 2020

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Nov 22, 2020

Also move definitions of internal macros F_LJUST etc to private header.

https://bugs.python.org/issue42431

Also move definitions of internal macros F_LJUST etc to private header.
@@ -2,6 +2,9 @@
# error "this header file must not be included directly"
#endif

/* Caching the hash (ob_shash) saves recalculation of a bytes' hash value.
This significantly speeds up dict lookups. */
Copy link
Member

Choose a reason for hiding this comment

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

Maybe move this comment before ob_shash definition, in the structure.

Copy link
Member Author

Choose a reason for hiding this comment

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

Or just remove it as trivial? We do not have similar note for other cached hashes, and initially this comment was about strings.

#define Py_INTERNAL_FORMAT_H
#ifdef __cplusplus
extern "C" {
#endif
Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with adding pycore_format.h.

But maybe we could rename pycore_bytes_methods.h to pycore_bytes.h or pycore_bytesobject.h and put everything in a single header file. It's up to you.

It seems like unicode doesn't use these constants, so maybe be more explicit in the file name and rename it to "pycore_bytesformat.h" or "pycore_bytes_format.h"?

Copy link
Member Author

Choose a reason for hiding this comment

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

These constants are used both by bytes and unicode formatters. This is the reason why they are declared in the header file.

pycore_bytes_methods.h contains declarations for bytes_methods.c which contains common code and docstrings for bytes and bytearray.

* F_SIGN '+'
* F_BLANK ' '
* F_ALT '#'
* F_ZERO '0'
Copy link
Member

Choose a reason for hiding this comment

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

Would you mind to give an example of function which uses these constants?

Copy link
Member Author

Choose a reason for hiding this comment

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

They are used in a number of internal functions. Their names do not matter because they are static.

@@ -5,6 +5,7 @@
#include "Python.h"
#include "pycore_abstract.h" // _PyIndex_Check()
#include "pycore_bytes_methods.h" // _Py_bytes_startswith()
#include "pycore_format.h" // F_LJUST etc
Copy link
Member

Choose a reason for hiding this comment

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

Remark: I have a personal preference to only give the name of a single symbol which is "imported" (included). I do that to check sometimes if the include is still needed. One symbol is enough (not "etc.") ;-)

@serhiy-storchaka serhiy-storchaka requested a review from a team as a code owner November 23, 2020 09:43
@serhiy-storchaka serhiy-storchaka merged commit 2ad9382 into python:master Dec 3, 2020
@serhiy-storchaka serhiy-storchaka deleted the bytes-comments branch December 3, 2020 10:46
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 13, 2021
Also move definitions of internal macros F_LJUST etc to private header.
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.

4 participants