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: [C API] Add tests on Py_FrozenMain()
Type: Stage: resolved
Components: C API Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: corona10, miss-islington, pablogsal, petr.viktorin, vstinner
Priority: normal Keywords: patch

Created on 2021-05-14 12:12 by vstinner, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 26126 merged vstinner, 2021-05-14 12:14
PR 26201 merged vstinner, 2021-05-17 22:33
PR 26203 merged vstinner, 2021-05-17 23:32
PR 26241 merged petr.viktorin, 2021-05-19 13:31
PR 26353 merged miss-islington, 2021-05-25 11:42
Messages (8)
msg393643 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-05-14 12:12
I would like to change Py_FrozenMain() using the new PyConfig C API, but I would prefer to first write tests of its current behavior. Currently, Py_FrozenMain() has no test.

Py_FrozenMain() is used by Tools/freeze/freeze.py. Old freeze.py issues:

* bpo-42613: freeze.py doesn't support sys.platlibdir different than lib nor multiarch
* bpo-40954: freeze.py aborts on macOS
* bpo-32217: freeze.py fails to work.
* bpo-27727: Update Tools/freeze to use .vcxproj files 
* bpo-27566: Tools/freeze/winmakemakefile.py clean target should use 'del' instead of 'rm' 
* bpo-26271: freeze.py makefile uses the wrong flags variables
* bpo-25504: undefined name 'modules' in Tools/freeze/checkextensions_win32.py 
* bpo-24871: freeze.py doesn't work on x86_64 Linux out of the box
* bpo-23405: Tools/freeze "make" gets missing file error with unix shared builds 
* bpo-21502: freeze.py not working properly with OS X framework builds
* bpo-16047: Tools/freeze no longer works in Python 3
* bpo-11824: freeze.py broken due to ABI flags
* bpo-7517: freeze.py not ported to python3
* bpo-6078: freeze.py doesn't work 
* bpo-1985: Bug/Patch: Problem with xml/__init__.py when using freeze.py 
* bpo-588452: $DEBUG_PYTHON -O freeze.py broken 

I never used freeze.py, but since we get bug reports, it seems like it's used by users :-)

Note: freeze.py has no test neither.


Py_FrozenMain() has been modified recently in bpo-44113:

commit 7565586724692e2ad164d770af9675f7a261fe3a
Author: Dong-hee Na <donghee.na@python.org>
Date:   Thu May 13 10:19:46 2021 +0900

    bpo-44113: Update fromzenmain not to use Py_SetProgramName (GH-26085)

See also: [capi-sig] Py_FrozenMain and the stable ABI
https://mail.python.org/archives/list/capi-sig@python.org/thread/5QLI3NUP3OSGLCCIBAQOTX4GEJQBWJ6F/

See also: [Python-Dev] What's the story on Py_FrozenMain?
https://mail.python.org/pipermail/python-dev/2013-November/130280.html
msg393836 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-05-17 21:58
commit eaede0ded72e67cee4a91c086847d54cb64ca74c
Author: Victor Stinner <vstinner@python.org>
Date:   Mon May 17 23:48:35 2021 +0200

    bpo-44131: Test Py_FrozenMain() (GH-26126)
    
    * Add test_frozenmain to test_embed
    * Add Programs/test_frozenmain.py
    * Add Programs/freeze_test_frozenmain.py
    * Add Programs/test_frozenmain.h
    * Add make regen-test-frozenmain
    * Add test_frozenmain command to Programs/_testembed
    * _testembed.c: add error(msg) function
msg393841 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-05-17 22:52
Compilation failed on s390x RHEL7 LTO + PGO 3.x buildbot:
https://buildbot.python.org/all/#/builders/244/builds/208

(...)
rm -f libpython3.11.a
ar rcs libpython3.11.a Modules/getbuildinfo.o (...) Python/frozen.o
lto1: error: libpython3.11.a: file too short
(null):0: confused by earlier errors, bailing out
lto-wrapper: gcc returned 1 exit status
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status

make[3]: *** [python] Error 1
make[3]: *** Waiting for unfinished jobs....

gcc -pthread   -flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none -g -fprofile-generate -Xlinker -export-dynamic -o python Programs/python.o libpython3.11.a -lcrypt -lpthread -ldl  -lutil -lm   -lm 
# Regenerate Programs/test_frozenmain.h
# from Programs/test_frozenmain.py
# using Programs/freeze_test_frozenmain.py
./python Programs/freeze_test_frozenmain.py Programs/test_frozenmain.h
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Programs/test_frozenmain.h written

make[4]: Leaving directory `/home/dje/cpython-buildarea/3.x.edelsohn-rhel-z.lto-pgo/build'
make[3]: Leaving directory `/home/dje/cpython-buildarea/3.x.edelsohn-rhel-z.lto-pgo/build'
make[2]: *** [build_all_generate_profile] Error 2
make[2]: Leaving directory `/home/dje/cpython-buildarea/3.x.edelsohn-rhel-z.lto-pgo/build'
make[1]: *** [profile-gen-stamp] Error 2
make[1]: Leaving directory `/home/dje/cpython-buildarea/3.x.edelsohn-rhel-z.lto-pgo/build'
make: *** [profile-run-stamp] Error 2
program finished with exit code 2
elapsedTime=62.919052
msg393859 - (view) Author: Petr Viktorin (petr.viktorin) * (Python committer) Date: 2021-05-18 09:04
The tests are now skipped on Windows. It might be better to use a feature check: hasattr(ctypes.pythonapi, 'Py_FrozenMain')


IMO, Py_FrozenMain is quite specific: it's OK if it's exported, but also OK if it's missing. (Unless you're compiling a special build with frozen modules, which won't work at all without Py_FrozenMain.)
msg393893 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-05-18 17:42
> The tests are now skipped on Windows. It might be better to use a feature check: hasattr(ctypes.pythonapi, 'Py_FrozenMain')

On Unix, _testembed gets the symbol since it's used. Currently, hasattr(ctypes.pythonapi, 'Py_FrozenMain') returns false if Python is built without --enable-shared, even if _testembed is able to get Py_FrozenMain().

I hope that bpo-44133 will be solved soon.
msg394334 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-05-25 11:59
New changeset 68b9c20a98887bf0a92698f8df9f28b9440970dc by Miss Islington (bot) in branch '3.10':
bpo-43795: Remove Py_FrozenMain from the Limited API & Stable ABI  (GH-26241) (GH-26353)
https://github.com/python/cpython/commit/68b9c20a98887bf0a92698f8df9f28b9440970dc
msg394376 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-05-25 16:37
commit eaede0ded72e67cee4a91c086847d54cb64ca74c
Author: Victor Stinner <vstinner@python.org>
Date:   Mon May 17 23:48:35 2021 +0200

    bpo-44131: Test Py_FrozenMain() (GH-26126)
    
    * Add test_frozenmain to test_embed
    * Add Programs/test_frozenmain.py
    * Add Programs/freeze_test_frozenmain.py
    * Add Programs/test_frozenmain.h
    * Add make regen-test-frozenmain
    * Add test_frozenmain command to Programs/_testembed
    * _testembed.c: add error(msg) function

commit 58a993957abec7e47acb20376d2753051fa75452
Author: Victor Stinner <vstinner@python.org>
Date:   Thu May 20 12:08:05 2021 +0200

    bpo-44131: Py_FrozenMain() uses PyConfig_SetBytesArgv() (GH-26201)
    
    Moreover, Py_FrozenMain() relies on Py_InitializeFromConfig() to
    handle the PYTHONUNBUFFERED environment variable and configure C
    stdio streams like stdout (make the stream unbuffered).
msg394483 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-05-26 22:38
I marked bpo-36940 as a duplicate of this issue.
History
Date User Action Args
2022-04-11 14:59:45adminsetgithub: 88297
2021-05-26 22:38:25vstinnersetmessages: + msg394483
2021-05-26 22:38:11vstinnerlinkissue36940 superseder
2021-05-25 16:37:12vstinnersetmessages: + msg394376
2021-05-25 12:52:42pablogsalsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-05-25 11:59:26pablogsalsetnosy: + pablogsal
messages: + msg394334
2021-05-25 11:42:11miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request24945
2021-05-19 13:31:12petr.viktorinsetpull_requests: + pull_request24858
2021-05-18 17:42:22vstinnersetmessages: + msg393893
2021-05-18 09:04:55petr.viktorinsetmessages: + msg393859
2021-05-17 23:32:58vstinnersetpull_requests: + pull_request24820
2021-05-17 22:52:03vstinnersetmessages: + msg393841
2021-05-17 22:33:44vstinnersetpull_requests: + pull_request24818
2021-05-17 21:58:42vstinnersetmessages: + msg393836
2021-05-14 12:14:46vstinnersetkeywords: + patch
stage: patch review
pull_requests: + pull_request24766
2021-05-14 12:12:49vstinnercreate