Visitar URL original
"Implicit conversion changes signedness" warning from unicodeobject.h · Issue #580 · oracle/graalpython · GitHub
Skip to content

"Implicit conversion changes signedness" warning from unicodeobject.h #580

Description

@skirpichev

The GraalVM declares PyUnicode_KIND as

enum PyUnicode_Kind {
/* Return values of the PyUnicode_KIND() function: */
    PyUnicode_1BYTE_KIND = 1,
    PyUnicode_2BYTE_KIND = 2,
    PyUnicode_4BYTE_KIND = 4
};

while Python C-API:

PyAPI_FUNC(int) PyUnicode_KIND(PyObject *op);

Activity

  1. msimacek commented on Dec 22, 2025

    @msimacek
    Contributor

    PyAPI_FUNC(int) PyUnicode_KIND(PyObject *op);

    This is the limited API definition. The normal one in CPython is:
    #define PyUnicode_KIND(op) _Py_RVALUE(_PyASCIIObject_CAST(op)->state.kind)
    The kind field is declared as an unsigned in a bitfield: unsigned int kind:3;

    Our definition is: #define PyUnicode_KIND(op) ((enum PyUnicode_Kind)GraalPyUnicode_KIND(_PyObject_CAST(op)))

    If we make it an int, it could cause warnings when you use PyUnicode_Kind or unsigned int as the variable type. I guess we could make it unsigned char which can be losslessly extended to both int and unsigned int. I'll need to experiment with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions