mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	gh-111506: Add _Py_OPAQUE_PYOBJECT to hide PyObject layout & related API (GH-136505)
Allow Py_LIMITED_API for (Py_GIL_DISABLED && _Py_OPAQUE_PYOBJECT)
API that's removed when _Py_OPAQUE_PYOBJECT is defined:
    - PyObject_HEAD
    - _PyObject_EXTRA_INIT
    - PyObject_HEAD_INIT
    - PyObject_VAR_HEAD
    - struct _object (i.e. PyObject) (opaque)
    - struct PyVarObject (opaque)
    - Py_SIZE
    - Py_SET_TYPE
    - Py_SET_SIZE
    - PyModuleDef_Base (opaque)
    - PyModuleDef_HEAD_INIT
    - PyModuleDef (opaque)
    - _Py_IsImmortal
    - _Py_IsStaticImmortal
Note that the `_Py_IsImmortal` removal (and a few other issues)
 means _Py_OPAQUE_PYOBJECT only works with limited
API 3.14+ now.
Co-authored-by: Victor Stinner <vstinner@python.org>
			
			
This commit is contained in:
		
							parent
							
								
									db47f4d844
								
							
						
					
					
						commit
						c7d24b81c3
					
				
					 8 changed files with 123 additions and 25 deletions
				
			
		|  | @ -36,6 +36,7 @@ PyAPI_FUNC(PyObject *) PyModuleDef_Init(PyModuleDef*); | |||
| PyAPI_DATA(PyTypeObject) PyModuleDef_Type; | ||||
| #endif | ||||
| 
 | ||||
| #ifndef _Py_OPAQUE_PYOBJECT | ||||
| typedef struct PyModuleDef_Base { | ||||
|   PyObject_HEAD | ||||
|   /* The function used to re-initialize the module.
 | ||||
|  | @ -63,6 +64,7 @@ typedef struct PyModuleDef_Base { | |||
|     0,        /* m_index */      \ | ||||
|     _Py_NULL, /* m_copy */       \ | ||||
|   } | ||||
| #endif  // _Py_OPAQUE_PYOBJECT
 | ||||
| 
 | ||||
| #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 | ||||
| /* New in 3.5 */ | ||||
|  | @ -104,6 +106,8 @@ struct PyModuleDef_Slot { | |||
| PyAPI_FUNC(int) PyUnstable_Module_SetGIL(PyObject *module, void *gil); | ||||
| #endif | ||||
| 
 | ||||
| 
 | ||||
| #ifndef _Py_OPAQUE_PYOBJECT | ||||
| struct PyModuleDef { | ||||
|   PyModuleDef_Base m_base; | ||||
|   const char* m_name; | ||||
|  | @ -115,6 +119,7 @@ struct PyModuleDef { | |||
|   inquiry m_clear; | ||||
|   freefunc m_free; | ||||
| }; | ||||
| #endif  // _Py_OPAQUE_PYOBJECT
 | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Petr Viktorin
						Petr Viktorin