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

gh-106078: Suppress the warning caused by multi-phase initialization of decimal #107524

Merged
merged 6 commits into from
Oct 6, 2023

Conversation

CharlieZhao95
Copy link
Contributor

@CharlieZhao95 CharlieZhao95 commented Aug 1, 2023

>>> python -m test test_decimal
Running Release|x64 interpreter...
0:00:00 Run tests sequentially
0:00:00 [1/1] test_decimal
...: warning: mpd_setminalloc: ignoring request to set MPD_MINALLOC a second time

This warnning is caused by the multi-phase initialization of decimal module. When decimal module is repeatedly imported, decimal_exec will be executed multiple times and this warning will be raised.

See #107287 (comment) for details.

@CharlieZhao95
Copy link
Contributor Author

Maybe we can skip news for this PR.

@CharlieZhao95
Copy link
Contributor Author

CharlieZhao95 commented Aug 1, 2023

It looks like the global variable check is failing, the tool cannot ignore static variables inside functions. Adding
__attribute__((constructor)) might be a more elegant option.

Forget this. Unfortunately, there is no equivalent for __attribute__((constructor)) on Windows.

@CharlieZhao95 CharlieZhao95 marked this pull request as ready for review August 1, 2023 08:38
@rhettinger rhettinger removed their request for review August 3, 2023 14:51
Modules/_decimal/_decimal.c Outdated Show resolved Hide resolved
Copy link
Member

@Eclips4 Eclips4 left a comment

Choose a reason for hiding this comment

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

I've tested it locally, and it works. Multiple imports of decimal doesn't make any warnings anymore.
LGTM.

@AlexWaygood
Copy link
Member

AlexWaygood commented Oct 3, 2023

The warning that's being suppressed here was recently brought up again in #110266

@erlend-aasland
Copy link
Contributor

See also the discussion about a global init/exit API for extension modules.

@AlexWaygood AlexWaygood merged commit de10522 into python:main Oct 6, 2023
21 checks passed
@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot s390x RHEL7 LTO + PGO 3.x has failed when building commit de10522.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/244/builds/5628) and take a look at the build logs.
  4. Check if the failure is related to this commit (de10522) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/244/builds/5628

Summary of the results of the build (if available):

==

Click to see traceback logs
Note: checking out 'de1052245f67d5c5a5dbb4f39449f7687f58fd78'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD is now at de10522... gh-106078: Suppress the warning caused by multi-phase initialization of `decimal` (#107524)
Switched to and reset branch 'main'

find: ‘build’: No such file or directory
find: ‘build’: No such file or directory
find: ‘build’: No such file or directory
find: ‘build’: No such file or directory
make[2]: [clean-retain-profile] Error 1 (ignored)
Python/instrumentation.c: In function ‘allocate_instrumentation_data’:
Python/instrumentation.c:1497:9: warning: missing braces around initializer [-Wmissing-braces]
         code->_co_monitoring->local_monitors = (_Py_LocalMonitors){ 0 };
         ^
Python/instrumentation.c:1497:9: warning: (near initialization for ‘(anonymous).tools’) [-Wmissing-braces]
Python/instrumentation.c:1498:9: warning: missing braces around initializer [-Wmissing-braces]
         code->_co_monitoring->active_monitors = (_Py_LocalMonitors){ 0 };
         ^
Python/instrumentation.c:1498:9: warning: (near initialization for ‘(anonymous).tools’) [-Wmissing-braces]
Objects/bytes_methods.c: In function ‘find_internal’:
Objects/bytes_methods.c:526:31: warning: ‘subobj’ may be used uninitialized in this function [-Wmaybe-uninitialized]
         if (PyObject_GetBuffer(subobj, &subbuf, PyBUF_SIMPLE) != 0)
                               ^
Objects/bytes_methods.c: In function ‘_Py_bytes_find’:
Objects/bytes_methods.c:526:31: warning: ‘subobj’ may be used uninitialized in this function [-Wmaybe-uninitialized]
Objects/bytes_methods.c:513:15: note: ‘subobj’ was declared here
     PyObject *subobj;
               ^
Objects/bytes_methods.c: In function ‘_Py_bytes_rfind’:
Objects/bytes_methods.c:526:31: warning: ‘subobj’ may be used uninitialized in this function [-Wmaybe-uninitialized]
         if (PyObject_GetBuffer(subobj, &subbuf, PyBUF_SIMPLE) != 0)
                               ^
Objects/bytes_methods.c:513:15: note: ‘subobj’ was declared here
     PyObject *subobj;
               ^
Objects/bytes_methods.c: In function ‘_Py_bytes_count’:
Objects/bytes_methods.c:675:31: warning: ‘sub_obj’ may be used uninitialized in this function [-Wmaybe-uninitialized]
         if (PyObject_GetBuffer(sub_obj, &vsub, PyBUF_SIMPLE) != 0)
                               ^
Python/instrumentation.c: In function ‘allocate_instrumentation_data’:
Python/instrumentation.c:1497:9: warning: missing braces around initializer [-Wmissing-braces]
         code->_co_monitoring->local_monitors = (_Py_LocalMonitors){ 0 };
         ^
Python/instrumentation.c:1497:9: warning: (near initialization for ‘(anonymous).tools’) [-Wmissing-braces]
Python/instrumentation.c:1498:9: warning: missing braces around initializer [-Wmissing-braces]
         code->_co_monitoring->active_monitors = (_Py_LocalMonitors){ 0 };
         ^
Python/instrumentation.c:1498:9: warning: (near initialization for ‘(anonymous).tools’) [-Wmissing-braces]
Python/pytime.c: In function ‘pytime_mul’:
Python/pytime.c:1388:1: note: correcting inconsistent profile data
 }
 ^
./Modules/_io/clinic/fileio.c.h: In function ‘_io_FileIO_close’:
./Modules/_io/fileio.c:175:32: warning: ‘exc’ may be used uninitialized in this function [-Wmaybe-uninitialized]
         _PyErr_ChainExceptions1(exc);
                                ^
./Modules/_io/fileio.c:160:15: note: ‘exc’ was declared here
     PyObject *exc;
               ^
./Modules/_io/clinic/textio.c.h: In function ‘_io_TextIOWrapper_seek’:
./Modules/_io/textio.c:2601:45: warning: ‘MEM[(char * {ref-all})&cookie + 20B]’ may be used uninitialized in this function [-Wmaybe-uninitialized]
         decoded = PyObject_CallMethodObjArgs(self->decoder, &_Py_ID(decode),
                                             ^
./Modules/_io/textio.c:2452:17: note: ‘MEM[(char * {ref-all})&cookie + 20B]’ was declared here
     cookie_type cookie;
                 ^
./Modules/_io/textio.c:2610:54: warning: ‘MEM[(char * {ref-all})&cookie + 16B]’ may be used uninitialized in this function [-Wmaybe-uninitialized]
         if (PyUnicode_GetLength(self->decoded_chars) < cookie.chars_to_skip) {
                                                      ^
./Modules/_io/textio.c:2452:17: note: ‘MEM[(char * {ref-all})&cookie + 16B]’ was declared here
     cookie_type cookie;
                 ^
./Modules/_io/textio.c:2420:40: warning: ‘MEM[(char * {ref-all})&cookie + 8B]’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     return _textiowrapper_encoder_reset(
                                        ^
./Modules/_io/textio.c:2452:17: note: ‘MEM[(char * {ref-all})&cookie + 8B]’ was declared here
     cookie_type cookie;
                 ^
./Modules/_io/textio.c:2420:40: warning: ‘MEM[(char * {ref-all})&cookie]’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     return _textiowrapper_encoder_reset(
                                        ^
./Modules/_io/textio.c:2452:17: note: ‘MEM[(char * {ref-all})&cookie]’ was declared here
     cookie_type cookie;
                 ^

make: *** [buildbottest] Error 5

Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
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