Skip to content

Uses deprecated Py_UNICODE API and fails to build with GCC 14 #4

@glaubitz

Description

@glaubitz

Trying to build metamagic.json with GCC 14 as the default C/C++ compiler fails with:

[   13s] gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -O2 -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -g -DOPENSSL_LOAD_CONF -fwrapv -fno-semantic-interposition -O2 -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -g -IVendor/ -O2 -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -g -IVendor/ -O2 -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -flto=auto -g -fPIC -I/usr/include/python3.12 -c metamagic/json/_encoder/_encoder.c -o build/temp.linux-x86_64-cpython-312/metamagic/json/_encoder/_encoder.o -O3
[   13s] metamagic/json/_encoder/_encoder.c:53:31: warning: missing braces around initializer [-Wmissing-braces]
[   13s]    53 | PyTypeObject PyEncoder_Type = {
[   13s]       |                               ^
[   13s] In file included from /usr/include/python3.12/Python.h:44,
[   13s]                  from metamagic/json/_encoder/_encoder_buffer.h:11,
[   13s]                  from metamagic/json/_encoder/_encoder.c:8:
[   13s] /usr/include/python3.12/object.h:142:9: error: initialization of ‘long int’ from ‘void *’ makes integer from pointer without a cast [-Wint-conversion]
[   13s]   142 |         (type)                   \
[   13s]       |         ^
[   13s] metamagic/json/_encoder/_encoder.c:54:5: note: in expansion of macro ‘PyObject_HEAD_INIT’
[   13s]    54 |     PyObject_HEAD_INIT(NULL)
[   13s]       |     ^~~~~~~~~~~~~~~~~~
[   13s] /usr/include/python3.12/object.h:142:9: note: (near initialization for ‘PyEncoder_Type.ob_base.ob_size’)
[   13s]   142 |         (type)                   \
[   13s]       |         ^
[   13s] metamagic/json/_encoder/_encoder.c:54:5: note: in expansion of macro ‘PyObject_HEAD_INIT’
[   13s]    54 |     PyObject_HEAD_INIT(NULL)
[   13s]       |     ^~~~~~~~~~~~~~~~~~
[   13s] metamagic/json/_encoder/_encoder.c:53:31: warning: missing braces around initializer [-Wmissing-braces]
[   13s]    53 | PyTypeObject PyEncoder_Type = {
[   13s]       |                               ^
[   13s] metamagic/json/_encoder/_encoder.c:53:31: warning: missing braces around initializer [-Wmissing-braces]
[   13s] metamagic/json/_encoder/_encoder.c: In function ‘encode_string’:
[   13s] metamagic/json/_encoder/_encoder.c:873:21: error: implicit declaration of function ‘PyUnicode_GET_SIZE’; did you mean ‘PyDict_GET_SIZE’? [-Wimplicit-function-declaration]
[   13s]   873 |     input_size    = PyUnicode_GET_SIZE(pystr);
[   13s]       |                     ^~~~~~~~~~~~~~~~~~
[   13s]       |                     PyDict_GET_SIZE
[   13s] metamagic/json/_encoder/_encoder.c:874:21: error: implicit declaration of function ‘PyUnicode_AS_UNICODE’; did you mean ‘PyUnicode_AsUCS4’? [-Wimplicit-function-declaration]
[   13s]   874 |     input_unicode = PyUnicode_AS_UNICODE(pystr);
[   13s]       |                     ^~~~~~~~~~~~~~~~~~~~
[   13s]       |                     PyUnicode_AsUCS4
[   13s] metamagic/json/_encoder/_encoder.c:874:19: error: assignment to ‘Py_UNICODE *’ {aka ‘int *’} from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
[   13s]   874 |     input_unicode = PyUnicode_AS_UNICODE(pystr);
[   13s]       |                   ^
[   13s] metamagic/json/_encoder/_encoder.c: In function ‘encode_json’:
[   13s] metamagic/json/_encoder/_encoder.c:903:19: error: assignment to ‘Py_UNICODE *’ {aka ‘int *’} from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
[   13s]   903 |     input_unicode = PyUnicode_AS_UNICODE(pystr);
[   13s]       |                   ^
[   13s] In file included from metamagic/json/_encoder/_encoder.c:12:
[   13s] metamagic/json/_encoder/_encoder.h: At top level:
[   13s] metamagic/json/_encoder/_encoder.h:25:22: warning: ‘PyType_BaseEncoder’ defined but not used [-Wunused-variable]
[   13s]    25 | static PyTypeObject* PyType_BaseEncoder;
[   13s]       |                      ^~~~~~~~~~~~~~~~~~
[   13s] error: command '/usr/bin/gcc' failed with exit code 1

Since Py_UNICODE is a deprecated API (see: https://peps.python.org/pep-0624/), its use should be replaced to fix this bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions