| 
									
										
										
										
											2019-04-13 10:46:21 +09:00
										 |  |  | #define PY_SSIZE_T_CLEAN
 | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  | #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); | 
					
						
							| 
									
										
										
										
											2019-09-12 05:11:20 -07:00
										 |  |  |     if (PyModule_AddObject(m, "Custom", (PyObject *) &CustomType) < 0) { | 
					
						
							|  |  |  |         Py_DECREF(&CustomType); | 
					
						
							| 
									
										
										
										
											2019-12-24 23:25:56 -05:00
										 |  |  |         Py_DECREF(m); | 
					
						
							| 
									
										
										
										
											2019-09-12 05:11:20 -07:00
										 |  |  |         return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-07 18:14:03 +02:00
										 |  |  |     return m; | 
					
						
							|  |  |  | } |