GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — [C API] Avoid "const PyObject*" type · Issue #91768 · python/cpython Closed Labels type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error DescriptionWhen I converted The problem is that passing Example explaining the issue: static inline int value(int *p) { return *p; } #define value(p) value((int*)(p)) int main() { int x = 1; const int *p = &x; return value(p); } Output: $ gcc x.c -Wcast-qual -o x && ./x; echo $? x.c: In function 'main': x.c:2:24: warning: cast discards 'const' qualifier from pointer target type [-Wcast-qual] 2 | #define value(p) value((int*)(p)) | ^ x.c:8:12: note: in expansion of macro 'value' 8 | return value(p); | ^~~~~ 1 In practice, the problem was that building a C extension (which includes static inline int Py_IS_TYPE(const PyObject *ob, const PyTypeObject *type) { return Py_TYPE(ob) == type; } #define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST_CONST(ob), type) See the issue #88544 for the compiler error. I removed the Py_TYPE() call in Py_IS_TYPE() to work around the issue: static inline int Py_IS_TYPE(const PyObject *ob, const PyTypeObject *type) { // bpo-44378: Don't use Py_TYPE() since Py_TYPE() requires a non-const // object. return ob->ob_type == type; } #define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST_CONST(ob), type) But this problem strikes back when I try to convert unicodeobject.h macros to static inline functions for PEP 670 which removes the cast to To avoid these problems, I propose to avoid Activity
MetadataMetadataAssigneesLabelstype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error ProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |