C API: copying a PyStatus emits -Wdeprecated-declarations in C++ with clang since gh-158080
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 56/100
Direção de pesquisa
Start with the PyStatus definition in Include/cpython/initconfig.h and the Py_COMP_DIAG* macros in Include/pyport.h. Reproduce the warning by compiling the documented Doc/c-api/init_config.rst usage pattern as C++ with clang++ -Werror, then check whether suppressing the diagnostic around the structure definition removes the copy warnings while real uses of deprecated members still warn. Done means the C++ example compiles cleanly and deprecated API uses remain diagnosed; a C++ regression test in Lib/test/test_cppext is suggested.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Bug description:
Since gh-158080 (GH-158085), PyStatus.exitcode is declared with Py_DEPRECATED(3.16) in Include/cpython/initconfig.h. Because the C API passes and returns PyStatus by value (PyStatus_Exception(), PyStatus_IsError(), Py_InitializeFromConfig(), ...), C++ code that uses the API in the documented way makes clang generate the implicit copy constructor / move assignment operator of PyStatus. These use the deprecated member, so clang emits -Wdeprecated-declarations even though the code never touches exitcode. With -Werror, the build fails.
The usage pattern of the Doc/c-api/init_config.rst examples (ex: init_python()), compiled as C++, is enough to reproduce:
#include <Python.h>
int main(int argc, char** argv) {
PyStatus status;
PyConfig config;
PyConfig_InitPythonConfig(&config);
status = PyConfig_SetBytesString(&config, &config.program_name, argv[0]);
if (PyStatus_Exception(status)) {
goto exception;
}
status = Py_InitializeFromConfig(&config);
if (PyStatus_Exception(status)) {
goto exception;
}
PyConfig_Clear(&config);
return Py_RunMain();
exception:
PyConfig_Clear(&config);
Py_ExitStatusException(status);
}
$ clang++ -std=c++17 -Wall -Werror -I<cpython>/Include -I<build> -c embed.cpp
Include/cpython/initconfig.h:10:9: error: 'exitcode' is deprecated [-Werror,-Wdeprecated-declarations]
embed.cpp:7:12: note: in implicit move assignment operator for 'PyStatus' first required here
Include/cpython/initconfig.h:10:9: error: 'exitcode' is deprecated [-Werror,-Wdeprecated-declarations]
Include/cpython/initconfig.h:10:9: error: 'exitcode' is deprecated [-Werror,-Wdeprecated-declarations]
embed.cpp:8:28: note: in implicit copy constructor for 'PyStatus' first required here
- Reproduced with 3.16.0a1, with Ubuntu clang 21.1.8 (Linux aarch64) and Apple clang 21.0.0 (macOS arm64); the
PyStatusdefinition is unchanged on currentmain. - g++ 15, and clang compiling the same file as C, emit no warning.
- The diagnostic is reported at the definition of the structure in
initconfig.h, so users cannot silence it locally with a pragma around their own calls; they have to wrap the#include <Python.h>itself.
Possible fix
Suppress the warning around the definition of the structure, with the existing _Py_COMP_DIAG_* macros of pyport.h:
/* --- PyStatus ----------------------------------------------- */
+_Py_COMP_DIAG_PUSH
+_Py_COMP_DIAG_IGNORE_DEPR_DECLS
typedef struct {
enum {
_PyStatus_TYPE_OK=0,
_PyStatus_TYPE_ERROR=1,
_PyStatus_TYPE_EXIT=2 // deprecated
} _type;
const char *func;
const char *err_msg;
Py_DEPRECATED(3.16) int exitcode;
} PyStatus;
+_Py_COMP_DIAG_POP
With this change the example above compiles cleanly with clang++ -Werror, while real uses (status.exitcode, PyStatus_Exit(), PyStatus_IsExit()) still emit the deprecation warning. (Alternatively, only the functions could be marked deprecated and the member documented as deprecated.)
A C++ test in Lib/test/test_cppext that copies a PyStatus would catch regressions of this kind.
CPython versions tested on:
3.16, CPython main branch
Operating systems tested on:
Linux, macOS
- Linguagem predominante
- Python
- Estrelas
- 77.7k
- Forks
- 38.3k
- Merge médio
- 14h 29min
- PRs com merge (30d)
- 699
Preparar o ambiente
Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de python/cpython
-
topic-socket type-bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
python/cpython#160561 · 7 comentários ·
Mantenedores costumam responder em até 1 dia
-
tests topic-profiling type-bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
python/cpython#160334 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
extension-modules type-bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
Mantenedores costumam responder em até 1 dia
-
Remove unused FVS_* macrosAbertainterpreter-core type-feature
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 78/100
python/cpython#160109 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
extension-modules type-bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
python/cpython#160001 · 3 comentários ·
Mantenedores costumam responder em até 1 dia
Todas as issues de python/cpython
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
NVIDIA/flare-local-inference#90 ·
Mantenedores costumam responder em até 1 dia
-
area/streaming comp/gateway P2 platform/telegram type/bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
NousResearch/hermes-agent#144897 ·
Mantenedores costumam responder em até 1 dia
-
request-theme
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 66/100
LizardByte/ThemerrDB#9575 ·
Mantenedores costumam responder em até 1 dia
-
Author Page: noshin-nawalAbertaauthor-page correction
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
acl-org/acl-anthology#10599 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
zilliztech/memsearch#818 ·
Mantenedores costumam responder em até 1 dia