mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	 5c7ed7550e
			
		
	
	
		5c7ed7550e
		
	
	
	
	
		
			
			The added parentheses around the PyIter_Next assignment suppress the following warning which gcc throws without: ``` warning: using the result of an assignment as a condition without parentheses [-Wparentheses] ``` The other change is a typo fix
		
			
				
	
	
		
			45 lines
		
	
	
	
		
			976 B
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			45 lines
		
	
	
	
		
			976 B
		
	
	
	
		
			C
		
	
	
	
	
	
| #define PY_SSIZE_T_CLEAN
 | |
| #include <Python.h>
 | |
| 
 | |
| typedef struct {
 | |
|     PyObject_HEAD
 | |
|     /* Type-specific fields go here. */
 | |
| } CustomObject;
 | |
| 
 | |
| static PyTypeObject CustomType = {
 | |
|     PyVarObject_HEAD_INIT(NULL, 0)
 | |
|     .tp_name = "custom.Custom",
 | |
|     .tp_doc = "Custom objects",
 | |
|     .tp_basicsize = sizeof(CustomObject),
 | |
|     .tp_itemsize = 0,
 | |
|     .tp_flags = Py_TPFLAGS_DEFAULT,
 | |
|     .tp_new = PyType_GenericNew,
 | |
| };
 | |
| 
 | |
| static PyModuleDef custommodule = {
 | |
|     PyModuleDef_HEAD_INIT,
 | |
|     .m_name = "custom",
 | |
|     .m_doc = "Example module that creates an extension type.",
 | |
|     .m_size = -1,
 | |
| };
 | |
| 
 | |
| PyMODINIT_FUNC
 | |
| PyInit_custom(void)
 | |
| {
 | |
|     PyObject *m;
 | |
|     if (PyType_Ready(&CustomType) < 0)
 | |
|         return NULL;
 | |
| 
 | |
|     m = PyModule_Create(&custommodule);
 | |
|     if (m == NULL)
 | |
|         return NULL;
 | |
| 
 | |
|     Py_INCREF(&CustomType);
 | |
|     if (PyModule_AddObject(m, "Custom", (PyObject *) &CustomType) < 0) {
 | |
|         Py_DECREF(&CustomType);
 | |
|         Py_DECREF(m);
 | |
|         return NULL;
 | |
|     }
 | |
| 
 | |
|     return m;
 | |
| }
 |