Skip to content

Instantly share code, notes, and snippets.

@yinyin
Created July 8, 2010 21:45
Show Gist options
  • Save yinyin/468692 to your computer and use it in GitHub Desktop.
Save yinyin/468692 to your computer and use it in GitHub Desktop.
#include <Python.h>
typedef struct {
PyObject_HEAD
/* Type-specific fields go here. */
} pytrymod_TryobjObject;
static PyTypeObject pymodtry_TryobjType = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
"pytrymod.Tryobj", /*tp_name*/
sizeof(pytrymod_TryobjObject), /*tp_basicsize*/
0, /*tp_itemsize*/
0, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT, /*tp_flags*/
"Tryobj objects", /* tp_doc */
};
static PyMethodDef tryobj_methods[] = {
{NULL} /* Sentinel */
};
#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
#define PyMODINIT_FUNC void
#endif
PyMODINIT_FUNC inittryobj(void)
{
PyObject* m;
pymodtry_TryobjType.tp_new = PyType_GenericNew;
if (PyType_Ready(&pymodtry_TryobjType) < 0)
return;
m = Py_InitModule3("pytrymod", tryobj_methods, "Example module that creates an extension type.");
Py_INCREF(&pymodtry_TryobjType);
PyModule_AddObject(m, "Tryobj", (PyObject *)&pymodtry_TryobjType);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment