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: Conflicts while using Py_LIMITED_API
Type: compile error Stage: resolved
Components: Build, C API, Windows Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: christian.heimes, erlendaasland, paul.moore, shreyanavigyan, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

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

Files
File name Uploaded Description Edit
main.c shreyanavigyan, 2021-05-07 07:59
Extension.h shreyanavigyan, 2021-05-07 07:59
Extension2.h shreyanavigyan, 2021-05-07 07:59
Messages (7)
msg393173 - (view) Author: Shreyan Avigyan (shreyanavigyan) * Date: 2021-05-07 07:43
I usually program in Python C API without defining Py_LIMITED_API. I thought about using the stable ABI today. To my surprise, there are lot of conflicts occurring if Py_LIMITED_API is defined. The whole list of errors are:-

1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\Extension.h(16,17): error C2037: left of 'tp_free' specifies undefined struct/union '_typeobject'
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\Extension.h(23,31): error C2037: left of 'tp_alloc' specifies undefined struct/union '_typeobject'
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\Extension.h(46,34): warning C4013: '_PyArg_ParseTupleAndKeywords_SizeT' undefined; assuming extern returning int
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\Extension.h(97,21): error C2079: 'ExampleType' uses undefined struct '_typeobject'
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\Extension.h(109,1): error C2078: too many initializers
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\Extension.h(99,3): error C2224: left of '.tp_name' must have struct/union type
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\Extension.h(100,3): error C2224: left of '.tp_doc' must have struct/union type
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\Extension.h(101,3): error C2224: left of '.tp_basicsize' must have struct/union type
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\Extension.h(102,3): error C2224: left of '.tp_itemsize' must have struct/union type
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\Extension.h(103,3): error C2224: left of '.tp_flags' must have struct/union type
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\Extension.h(104,3): error C2224: left of '.tp_new' must have struct/union type
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\Extension.h(105,3): error C2224: left of '.tp_init' must have struct/union type
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\Extension.h(106,3): error C2224: left of '.tp_dealloc' must have struct/union type
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\Extension.h(107,3): error C2224: left of '.tp_members' must have struct/union type
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\Extension.h(108,3): error C2224: left of '.tp_methods' must have struct/union type
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\Extension2.h(16,20): error C2037: left of 'tp_free' specifies undefined struct/union '_typeobject'
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\Extension2.h(23,33): error C2037: left of 'tp_alloc' specifies undefined struct/union '_typeobject'
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\Extension2.h(147,21): error C2079: 'CustomType' uses undefined struct '_typeobject'
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\Extension2.h(160,1): error C2078: too many initializers
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\Extension2.h(149,6): error C2224: left of '.tp_name' must have struct/union type
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\Extension2.h(150,6): error C2224: left of '.tp_doc' must have struct/union type
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\Extension2.h(151,6): error C2224: left of '.tp_basicsize' must have struct/union type
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\Extension2.h(152,6): error C2224: left of '.tp_itemsize' must have struct/union type
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\Extension2.h(153,6): error C2224: left of '.tp_flags' must have struct/union type
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\Extension2.h(154,6): error C2224: left of '.tp_new' must have struct/union type
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\Extension2.h(155,6): error C2224: left of '.tp_init' must have struct/union type
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\Extension2.h(156,6): error C2224: left of '.tp_dealloc' must have struct/union type
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\Extension2.h(157,6): error C2224: left of '.tp_members' must have struct/union type
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\Extension2.h(158,6): error C2224: left of '.tp_methods' must have struct/union type
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\Extension2.h(159,6): error C2224: left of '.tp_getset' must have struct/union type
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\main.c(18,32): warning C4133: 'function': incompatible types - from 'int *' to 'PyTypeObject *'
1>C:\Users\shrey\source\repos\PyTypeExtension\Extension\main.c(19,28): warning C4133: 'function': incompatible types - from 'int *' to 'PyTypeObject *'

This is pretty awkward because these errors only occur in stable ABI. Am I doing something wrong here or is there a bug out there?
msg393174 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2021-05-07 07:49
Looks like you are doing something wrong. For example you seem to use internal, private bits like "_typeobject" instead of public APIs like PyTypeObject.

These kind of questions are more appropriate for mailing list or https://discuss.python.org/ . Please also post links to your source code.
msg393175 - (view) Author: Shreyan Avigyan (shreyanavigyan) * Date: 2021-05-07 07:53
Thanks for the quick response but I'm using PyTypeObject only. But in stable ABI it uses the name _typeobject to represent it. And I have a lot of files in my module therefore it's difficult to attach them.
msg393176 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2021-05-07 07:56
Is your code on Github, Gitlab, or BitBucket? Otherwise please attach Extension.h. What's your platform and exact Python version?
msg393177 - (view) Author: Shreyan Avigyan (shreyanavigyan) * Date: 2021-05-07 07:59
I've two header files, one main.c file and it's on my local machine. My platform is Windows, Python is 3.9.5 32bit and IDE is Visual Studio 2019.
I'm attaching those files.
msg393181 - (view) Author: Shreyan Avigyan (shreyanavigyan) * Date: 2021-05-07 12:50
This is a Visual Studio solution. Will I attach the whole zip containing the projects and files and the the solution file?
msg393218 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-05-07 20:27
You need to create your type objects dynamically when using the Limited API. See PEP 384 for how to do so:
https://www.python.org/dev/peps/pep-0384/#type-objects

Quoting from the PEP:
"The structure of type objects is not available to applications; declaration of "static" type objects is not possible anymore (for applications using this ABI). Instead, type objects get created dynamically."
History
Date User Action Args
2022-04-11 14:59:45adminsetgithub: 88232
2021-05-07 20:27:21erlendaaslandsetstatus: open -> closed

nosy: + erlendaasland
messages: + msg393218

resolution: not a bug
stage: resolved
2021-05-07 12:50:54shreyanavigyansetmessages: + msg393181
2021-05-07 07:59:27shreyanavigyansetfiles: + Extension2.h
2021-05-07 07:59:15shreyanavigyansetfiles: + Extension.h
2021-05-07 07:59:03shreyanavigyansetfiles: + main.c

messages: + msg393177
2021-05-07 07:56:27christian.heimessetmessages: + msg393176
2021-05-07 07:53:15shreyanavigyansetmessages: + msg393175
2021-05-07 07:49:06christian.heimessetnosy: + christian.heimes
messages: + msg393174
2021-05-07 07:43:08shreyanavigyancreate