static int basestruct_exec(PyObject *m) { PyObject *o; /* some members must be initialized at runtime, because they're not compile-time constants */ StructType_slots[1].pfunc = &PyDict_Type; StructType_slots[2].pfunc = PyDict_Type.tp_new; StructType_slots[3].pfunc = PyDict_Type.tp_dealloc; StructType_slots[4].pfunc = PyDict_Type.tp_hash; StructType_slots[5].pfunc = PyDict_Type.tp_traverse; StructType_slots[6].pfunc = PyDict_Type.tp_clear; StructType_slots[7].pfunc = PyDict_Type.tp_richcompare; #if PY_MAJOR_VERSION < 3 StructType_slots[8].pfunc = PyDict_Type.tp_compare; #endif o = PyType_FromSpec(&StructType_spec); if (o == NULL) goto fail; /* emulate more closely "real" heap types */ ((PyTypeObject *)o)->tp_name = "Struct"; PyModule_AddObject(m, "_Struct", o); return 0; fail: Py_XDECREF(m); return -1; }
PyTypeObject* init_preprocessor_type() { PreprocessorType = (PyTypeObject*)PyType_FromSpec(&PreprocessorTypeSpec); if (!PreprocessorType) return NULL; if (PyType_Ready((PyTypeObject*)PreprocessorType) < 0) return NULL; return PreprocessorType; }
static int execfunc(PyObject *m) { PyObject *temp = NULL; /* Due to cross platform compiler issues the slots must be filled * here. It's required for portability to Windows without requiring * C++. */ Str_Type_slots[0].pfunc = &PyUnicode_Type; /* Add a custom type */ temp = PyType_FromSpec(&Example_Type_spec); if (temp == NULL) goto fail; if (PyModule_AddObject(m, "Example", temp) != 0) goto fail; /* Add an exception type */ temp = PyErr_NewException("_testimportexec.error", NULL, NULL); if (temp == NULL) goto fail; if (PyModule_AddObject(m, "error", temp) != 0) goto fail; /* Add Str */ temp = PyType_FromSpec(&Str_Type_spec); if (temp == NULL) goto fail; if (PyModule_AddObject(m, "Str", temp) != 0) goto fail; if (PyModule_AddIntConstant(m, "int_const", 1969) != 0) goto fail; if (PyModule_AddStringConstant(m, "str_const", "something different") != 0) goto fail; return 0; fail: return -1; }
// Initialise the type and return true if there was no error. bool qpycore_pyqtSignal_init_type() { #if PY_VERSION_HEX >= 0x03040000 qpycore_pyqtSignal_TypeObject = (PyTypeObject *)PyType_FromSpec( &qpycore_pyqtSignal_Spec); return qpycore_pyqtSignal_TypeObject; #else if (PyType_Ready(&qpycore_pyqtSignal_Type) < 0) return false; qpycore_pyqtSignal_TypeObject = &qpycore_pyqtSignal_Type; return true; #endif }
/** * Create the sigrokdecode.Decoder type. * * @return The new type object. * * @private */ SRD_PRIV PyObject *srd_Decoder_type_new(void) { PyType_Spec spec; PyType_Slot slots[] = { { Py_tp_doc, "sigrok Decoder base class" }, { Py_tp_methods, Decoder_methods }, { Py_tp_new, (void *)&PyType_GenericNew }, { 0, NULL } }; spec.name = "sigrokdecode.Decoder"; spec.basicsize = sizeof(srd_Decoder); spec.itemsize = 0; spec.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; spec.slots = slots; return PyType_FromSpec(&spec); }
void init_recording() { MGLBytecode::init(); MGLRecorder_class = (PyTypeObject *)PyType_FromSpec(&MGLRecorder_spec); }