s = PyUnicode_FromString("\n"); if (s == NULL) goto Done; result = PyUnicode_Join(s, pieces); Py_DECREF(s); Done: Py_XDECREF(pieces); return result; } static PyObject * path_iter(PyObject *seq); /* forward declaration */ PyTypeObject PycairoPath_Type = { PyVarObject_HEAD_INIT((PyTypeObject *)0x7FFFFFFF, 0) //PyObject_HEAD_INIT(NULL) //0, /* ob_size */ "cairo.Path", /* tp_name */ sizeof(PycairoPath), /* tp_basicsize */ 0, /* tp_itemsize */ (destructor)path_dealloc, /* 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 */
ImpulseResponse_dealloc(ImpulseResponseP* self) { if(self->impulseResponse) delete reinterpret_cast<std::shared_ptr<aud::ImpulseResponse>*>(self->impulseResponse); Py_TYPE(self)->tp_free((PyObject *)self); } static PyMethodDef ImpulseResponse_methods[] = { { nullptr } /* Sentinel */ }; PyDoc_STRVAR(M_aud_ImpulseResponse_doc, "An ImpulseResponse object represents a filter with which to convolve a sound."); PyTypeObject ImpulseResponseType = { PyVarObject_HEAD_INIT(nullptr, 0) "aud.ImpulseResponse", /* tp_name */ sizeof(ImpulseResponseP), /* tp_basicsize */ 0, /* tp_itemsize */ (destructor)ImpulseResponse_dealloc, /* tp_dealloc */ 0, /* tp_print */ 0, /* tp_getattr */ 0, /* tp_setattr */ 0, /* tp_reserved */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ 0, /* tp_hash */ 0, /* tp_call */ 0, /* tp_str */
{"getOptions", (PyCFunction) getOptions, METH_VARARGS}, {"getOption", (PyCFunction) getOption, METH_VARARGS}, {"setOption", (PyCFunction) setOption, METH_VARARGS}, {"setAutoOption", (PyCFunction) setAutoOption, METH_VARARGS}, {"startScan", (PyCFunction) startScan, METH_VARARGS}, {"cancelScan", (PyCFunction) cancelScan, METH_VARARGS}, {"readScan", (PyCFunction) readScan, METH_VARARGS}, {"closeScan", (PyCFunction) closeScan, METH_VARARGS}, {NULL, NULL} }; static PyTypeObject ScanDevice_type = { PyVarObject_HEAD_INIT( &PyType_Type, 0 ) /* ob_size */ "_ScanDevice", /* tp_name */ sizeof(_ScanDevice ), /* tp_basicsize */ 0, /* tp_itemsize */ ( destructor ) deAlloc, /* 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 */
namespace Python { // -------------------- Draw Service -------------------- const char* DrawServiceBinder::msName = "DrawService"; // ------------------------------------------ PyTypeObject DrawServiceBinder::msType = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "opde.services.DrawService", // char *tp_name; */ sizeof(DrawServiceBinder::Object), // int tp_basicsize; */ 0, // int tp_itemsize; /* not used much */ DrawServiceBinder::dealloc, // destructor tp_dealloc; */ 0, // printfunc tp_print; */ 0, // getattrfunc tp_getattr; /* __getattr__ */ 0, // setattrfunc tp_setattr; /* __setattr__ */ 0, // cmpfunc tp_compare; /* __cmp__ */ repr, // reprfunc tp_repr; /* __repr__ */ 0, // PyNumberMethods *tp_as_number; */ 0, // PySequenceMethods *tp_as_sequence; */ 0, // PyMappingMethods *tp_as_mapping; */ 0, // hashfunc tp_hash; /* __hash__ */ 0, // ternaryfunc tp_call; /* __call__ */ 0, // reprfunc tp_str; /* __str__ */ PyObject_GenericGetAttr, // getattrofunc tp_getattro; */ 0, // setattrofunc tp_setattro; */ 0, // PyBufferProcs *tp_as_buffer; */ 0, // long tp_flags; */ 0, // char *tp_doc; */ 0, // traverseproc tp_traverse; */ 0, // inquiry tp_clear; */ 0, // richcmpfunc tp_richcompare; */ 0, // long tp_weaklistoffset; */ 0, // getiterfunc tp_iter; */ 0, // iternextfunc tp_iternext; */ msMethods, // struct PyMethodDef *tp_methods; */ 0, // struct memberlist *tp_members; */ 0, // struct getsetlist *tp_getset; */ }; // ------------------------------------------ PyMethodDef DrawServiceBinder::msMethods[] = { {"createSheet", createSheet, METH_VARARGS}, {"destroySheet", destroySheet, METH_VARARGS}, {"getSheet", getSheet, METH_VARARGS}, {"setActiveSheet", setActiveSheet, METH_VARARGS}, {"createDrawSource", createDrawSource, METH_VARARGS}, {"createRenderedImage", createRenderedImage, METH_VARARGS}, {"createRenderedLabel", createRenderedLabel, METH_VARARGS}, {"destroyDrawOperation", destroyDrawOperation, METH_VARARGS}, {"createAtlas", createAtlas, METH_VARARGS}, {"destroyAtlas", destroyAtlas, METH_VARARGS}, {"loadFont", loadFont, METH_VARARGS}, {"setFontPalette", setFontPalette, METH_VARARGS}, {NULL, NULL}, }; // ------------------------------------------ PyObject* DrawServiceBinder::createSheet(PyObject* self, PyObject* args) { __PYTHON_EXCEPTION_GUARD_BEGIN_; DrawServicePtr o; if (!python_cast<DrawServicePtr>(self, &msType, &o)) __PY_CONVERR_RET; // argument - the name of the sheet to create, string const char* sname; if (PyArg_ParseTuple(args, "s", &sname)) { const DrawSheetPtr& i = o->createSheet(sname); PyObject *o = DrawSheetBinder::create(i); return o; } else { // Invalid parameters PyErr_SetString(PyExc_TypeError, "Expected a string argument!"); return NULL; } __PYTHON_EXCEPTION_GUARD_END_; } // ------------------------------------------ PyObject* DrawServiceBinder::destroySheet(PyObject* self, PyObject* args) { __PYTHON_EXCEPTION_GUARD_BEGIN_; PyObject *result = NULL; DrawServicePtr o; if (!python_cast<DrawServicePtr>(self, &msType, &o)) __PY_CONVERR_RET; PyObject *sheet; if (PyArg_ParseTuple(args, "O", &sheet)) { // cast to drawsheet and destroy DrawSheetPtr ds; if (!DrawSheetBinder::extract(sheet, ds)) __PY_CONVERR_RET; o->destroySheet(ds); } result = Py_None; Py_INCREF(result); return result; __PYTHON_EXCEPTION_GUARD_END_; } // ------------------------------------------ PyObject* DrawServiceBinder::getSheet(PyObject* self, PyObject* args) { __PYTHON_EXCEPTION_GUARD_BEGIN_; PyObject *result = NULL; DrawServicePtr o; if (!python_cast<DrawServicePtr>(self, &msType, &o)) __PY_CONVERR_RET; // argument - the name of the sheet to create, string const char* sname; if (PyArg_ParseTuple(args, "s", &sname)) { const DrawSheetPtr& i = o->getSheet(sname); PyObject *o = DrawSheetBinder::create(i); result = o; Py_INCREF(result); return result; } else { // Invalid parameters PyErr_SetString(PyExc_TypeError, "Expected a string argument!"); return NULL; } __PYTHON_EXCEPTION_GUARD_END_; } // ------------------------------------------ PyObject* DrawServiceBinder::setActiveSheet(PyObject* self, PyObject* args) { __PYTHON_EXCEPTION_GUARD_BEGIN_; DrawServicePtr o; if (!python_cast<DrawServicePtr>(self, &msType, &o)) __PY_CONVERR_RET; PyObject *sheet; if (PyArg_ParseTuple(args, "O", &sheet)) { DrawSheetPtr ds; if (!DrawSheetBinder::extract(sheet, ds)) __PY_CONVERR_RET; o->setActiveSheet(ds); __PY_NONE_RET; }else { // Invalid parameters PyErr_SetString(PyExc_TypeError, "Expected a DrawSheet as an argument!"); return NULL; } __PYTHON_EXCEPTION_GUARD_END_; } // ------------------------------------------ PyObject* DrawServiceBinder::createDrawSource(PyObject* self, PyObject* args) { __PYTHON_EXCEPTION_GUARD_BEGIN_; DrawServicePtr o; if (!python_cast<DrawServicePtr>(self, &msType, &o)) __PY_CONVERR_RET; // argument - the name of the sheet to create, string const char *name, *group; if (PyArg_ParseTuple(args, "ss", &name, &group)) { DrawSourcePtr i = o->createDrawSource(name, group); PyObject *o = DrawSourceBinder::create(i); return o; } else { // Invalid parameters PyErr_SetString(PyExc_TypeError, "Expected two string arguments!"); return NULL; } __PYTHON_EXCEPTION_GUARD_END_; } // ------------------------------------------ PyObject* DrawServiceBinder::createRenderedImage(PyObject* self, PyObject* args) { __PYTHON_EXCEPTION_GUARD_BEGIN_; PyObject *result = NULL; DrawServicePtr o; if (!python_cast<DrawServicePtr>(self, &msType, &o)) __PY_CONVERR_RET; PyObject *ds; if (PyArg_ParseTuple(args, "O", &ds)) { DrawSourcePtr cds; if (!DrawSourceBinder::extract(ds, cds)) __PY_CONVERR_RET; RenderedImage* ri = o->createRenderedImage(cds); return RenderedImageBinder::create(ri); } return result; __PYTHON_EXCEPTION_GUARD_END_; } // ------------------------------------------ PyObject* DrawServiceBinder::createRenderedLabel(PyObject* self, PyObject* args) { __PYTHON_EXCEPTION_GUARD_BEGIN_; PyObject *result = NULL; DrawServicePtr o; if (!python_cast<DrawServicePtr>(self, &msType, &o)) __PY_CONVERR_RET; PyObject *ds; if (PyArg_ParseTuple(args, "O", &ds)) { FontDrawSourcePtr cds; if (!FontDrawSourceBinder::extract(ds, cds)) __PY_CONVERR_RET; RenderedLabel* ri = o->createRenderedLabel(cds); return RenderedLabelBinder::create(ri); } return result; __PYTHON_EXCEPTION_GUARD_END_; } // ------------------------------------------ PyObject* DrawServiceBinder::destroyDrawOperation(PyObject* self, PyObject* args) { __PYTHON_EXCEPTION_GUARD_BEGIN_; DrawServicePtr o; if (!python_cast<DrawServicePtr>(self, &msType, &o)) __PY_CONVERR_RET; PyObject *dop; if (!PyArg_ParseTuple(args, "O", &dop)) __PY_BADPARM_RET(1); DrawOperation* dopc; if (!DrawOperationBinder::extract(dop, dopc)) __PY_CONVERR_RET; o->destroyDrawOperation(dopc); __PY_NONE_RET; __PYTHON_EXCEPTION_GUARD_END_; } // ------------------------------------------ PyObject* DrawServiceBinder::createAtlas(PyObject* self, PyObject* args) { __PYTHON_EXCEPTION_GUARD_BEGIN_; DrawServicePtr o; if (!python_cast<DrawServicePtr>(self, &msType, &o)) __PY_CONVERR_RET; TextureAtlasPtr a = o->createAtlas(); return TextureAtlasBinder::create(a); __PYTHON_EXCEPTION_GUARD_END_; } // ------------------------------------------ PyObject* DrawServiceBinder::destroyAtlas(PyObject* self, PyObject* args) { __PYTHON_EXCEPTION_GUARD_BEGIN_; DrawServicePtr o; if (!python_cast<DrawServicePtr>(self, &msType, &o)) __PY_CONVERR_RET; PyObject *atp; if (!PyArg_ParseTuple(args, "O", &atp)) __PY_BADPARM_RET(1); TextureAtlasPtr atl; if (!TextureAtlasBinder::extract(atp, atl)) __PY_CONVERR_RET; o->destroyAtlas(atl); __PY_NONE_RET; __PYTHON_EXCEPTION_GUARD_END_; } // ------------------------------------------ PyObject* DrawServiceBinder::loadFont(PyObject* self, PyObject* args) { __PYTHON_EXCEPTION_GUARD_BEGIN_; DrawServicePtr o; if (!python_cast<DrawServicePtr>(self, &msType, &o)) __PY_CONVERR_RET; // name, group PyObject* patlas = NULL; char *name, *group; if (!PyArg_ParseTuple(args, "Oss", &patlas, &name, &group)) __PY_BADPARMS_RET; TextureAtlasPtr atlas; if (!TextureAtlasBinder::extract(patlas, atlas)) __PY_BADPARM_RET("atlas"); FontDrawSourcePtr fds = o->loadFont(atlas, name, group); return FontDrawSourceBinder::create(fds); __PYTHON_EXCEPTION_GUARD_END_; } // ------------------------------------------ PyObject* DrawServiceBinder::setFontPalette(PyObject* self, PyObject* args) { __PYTHON_EXCEPTION_GUARD_BEGIN_; DrawServicePtr o; if (!python_cast<DrawServicePtr>(self, &msType, &o)) __PY_CONVERR_RET; int ptype; char *fname; char *group; if (!PyArg_ParseTuple(args, "iss", &ptype, &fname, &group)) __PY_BADPARMS_RET; Ogre::ManualFonFileLoader::PaletteType pt; // validate the ptype switch (ptype) { case (int)ManualFonFileLoader::ePT_Default : pt = ManualFonFileLoader::ePT_Default; break; case (int)ManualFonFileLoader::ePT_DefaultBook : pt = ManualFonFileLoader::ePT_DefaultBook; break; case (int)ManualFonFileLoader::ePT_PCX : pt = ManualFonFileLoader::ePT_PCX; break; case (int)ManualFonFileLoader::ePT_External : pt = ManualFonFileLoader::ePT_External; break; default: __PY_BADPARM_RET("paltype"); } // okay! call o->setFontPalette(pt, fname, group); __PY_NONE_RET; __PYTHON_EXCEPTION_GUARD_END_; } // ------------------------------------------ PyObject* DrawServiceBinder::repr(PyObject *self) { #ifdef IS_PY3K return PyBytes_FromFormat("<DrawService at %p>", self); #else return PyString_FromFormat("<DrawService at %p>", self); #endif } // ------------------------------------------ PyObject* DrawServiceBinder::create() { Object* object = construct(&msType); if (object != NULL) { object->mInstance = GET_SERVICE(DrawService); } return (PyObject *)object; } // ------------------------------------------ void DrawServiceBinder::init(PyObject* module) { publishType(module, &msType, msName); PyModule_AddIntConstant(module, "PT_DEFAULT", ManualFonFileLoader::ePT_Default); PyModule_AddIntConstant(module, "PT_DEFAULTBOOK", ManualFonFileLoader::ePT_DefaultBook); PyModule_AddIntConstant(module, "PT_PCX", ManualFonFileLoader::ePT_PCX); PyModule_AddIntConstant(module, "PT_EXTERNAL", ManualFonFileLoader::ePT_External); } // -------------------- Draw Operation -------------------- const char* DrawOperationBinder::msName = "DrawOperation"; // ------------------------------------------ PyTypeObject DrawOperationBinder::msType = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "opde.services.DrawOperation", // char *tp_name; */ sizeof(DrawOperationBinder::Object), // int tp_basicsize; */ 0, // int tp_itemsize; /* not used much */ DrawOperationBinder::dealloc, // destructor tp_dealloc; */ 0, // printfunc tp_print; */ 0, // getattrfunc tp_getattr; /* __getattr__ */ 0, // setattrfunc tp_setattr; /* __setattr__ */ 0, // cmpfunc tp_compare; /* __cmp__ */ repr, // reprfunc tp_repr; /* __repr__ */ 0, // PyNumberMethods *tp_as_number; */ 0, // PySequenceMethods *tp_as_sequence; */ 0, // PyMappingMethods *tp_as_mapping; */ 0, // hashfunc tp_hash; /* __hash__ */ 0, // ternaryfunc tp_call; /* __call__ */ 0, // reprfunc tp_str; /* __str__ */ PyObject_GenericGetAttr, // getattrofunc tp_getattro; */ PyObject_GenericSetAttr, // setattrofunc tp_setattro; */ 0, // PyBufferProcs *tp_as_buffer; */ // for inheritance searches to work we need this #ifdef IS_PY3K #warning Check for correctness 1, // long tp_flags; */ #else Py_TPFLAGS_HAVE_CLASS, // long tp_flags; */ #endif 0, // char *tp_doc; */ 0, // traverseproc tp_traverse; */ 0, // inquiry tp_clear; */ 0, // richcmpfunc tp_richcompare; */ 0, // long tp_weaklistoffset; */ 0, // getiterfunc tp_iter; */ 0, // iternextfunc tp_iternext; */ msMethods, // struct PyMethodDef *tp_methods; */ 0, // struct memberlist /* *tp_members; */ msGetSet // struct getsetlist /* *tp_getset; */ }; // ------------------------------------------ PyMethodDef DrawOperationBinder::msMethods[] = { {"setPosition", setPosition, METH_VARARGS}, {"setZOrder", setZOrder, METH_VARARGS}, {"setClipRect", setClipRect, METH_VARARGS}, {NULL, NULL} }; const char* position = "position"; const char* zOrder = "zorder"; const char* clippingRect = "cliprect"; const char* positionDoc = "On-Screen Position"; const char* zOrderDoc = "Z Order"; const char* clippingRectDoc = "Clipping rectangle"; // ------------------------------------------ PyGetSetDef DrawOperationBinder::msGetSet[] = { {const_cast<char *>(position), getPPosition, setPPosition, const_cast<char*>(positionDoc), NULL}, {const_cast<char *>(zOrder), getPZOrder, setPZOrder, const_cast<char*>(zOrderDoc), NULL}, {const_cast<char *>(clippingRect), getPClipRect, setPClipRect, const_cast<char*>(clippingRectDoc), NULL}, {NULL} }; // ------------------------------------------ CastInfo<DrawOperation*> DrawOperationBinder::msCastInfo[] = { {&RenderedImageBinder::msType, &defaultPythonUpcaster<DrawOperation*, RenderedImage*>}, {&RenderedLabelBinder::msType, &defaultPythonUpcaster<DrawOperation*, RenderedLabel*>}, {NULL} }; // ------------------------------------------ PyObject* DrawOperationBinder::setPosition(PyObject* self, PyObject* args) { // args: either (x,y) or ((x,y)). The setPPosition expects (x,y) so we have to unwrap the tuple if encountered PyObject *tup; // We can't use PyArg_ParseTuple as it terminates on parameter inconsistencies. // instead, we look at the tuple in more detail and decide if (!PyTuple_Check(args)) __PY_BADPARMS_RET; int len = PyTuple_Size(args); if (len == 2) { // use the args direcly, the called func. checks if (setPPosition(self, args, NULL) == 0) { __PY_NONE_RET; } else { // otherwise return null to indicate a problem return NULL; } } else if (len == 1) { // extract the tuple PyObject *tup = PyTuple_GetItem(args, 0); if (!PyTuple_Check(tup)) __PY_BADPARMS_RET; if (setPPosition(self, tup, NULL) == 0) { __PY_NONE_RET; } else { // otherwise return null to indicate a problem return NULL; } } else { // Not the right type, no sir! __PY_BADPARMS_RET; } if (PyArg_ParseTuple(args, "O", &tup)) { // tuple in tuple } else { if (setPPosition(self, args, NULL) == 0) { __PY_NONE_RET; } else { // otherwise return null to indicate a problem return NULL; } } } // ------------------------------------------ PyObject* DrawOperationBinder::setZOrder(PyObject* self, PyObject* args) { if (setPZOrder(self, args, NULL) == 0) { // if succeeded __PY_NONE_RET; } else { // otherwise return null to indicate a problem return NULL; } } // ------------------------------------------ PyObject* DrawOperationBinder::setClipRect(PyObject* self, PyObject* args) { int len = PyTuple_Size(args); if (len != 1) __PY_BADPARMS_RET; PyObject *tup = PyTuple_GetItem(args, 0); if (!PyTuple_Check(tup)) __PY_BADPARMS_RET; if (setPClipRect(self, tup, NULL) == 0) { // if succeeded __PY_NONE_RET; } else { // otherwise return null to indicate a problem return NULL; } } // ------------------------------------------ int DrawOperationBinder::setPPosition(PyObject *self, PyObject *value, void *closure) { __PYTHON_EXCEPTION_GUARD_BEGIN_; DrawOperation* o = NULL; assert(self != NULL); if (!python_cast<DrawOperation*>(self, &msType, &o, msCastInfo)) __PY_CONVERR_RET_VAL(-1); assert(o != NULL); if (value == NULL) { PyErr_SetString(PyExc_TypeError, "Cannot delete the attribute"); return -1; } // okay, we can proceed with the setting now PixelCoord pc; if (TypeInfo<PixelCoord>::fromPyObject(value, pc)) { o->setPosition(pc); return 0; } else { // Invalid parameters PyErr_SetString(PyExc_TypeError, "Expected a two integer tuple!"); return -1; } __PYTHON_EXCEPTION_GUARD_END_RVAL(-1); } // ------------------------------------------ int DrawOperationBinder::setPZOrder(PyObject *self, PyObject *value, void *closure) { __PYTHON_EXCEPTION_GUARD_BEGIN_; DrawOperation* o = NULL; if (!python_cast<DrawOperation*>(self, &msType, &o, msCastInfo)) __PY_CONVERR_RET_VAL(-1); if (value == NULL) { PyErr_SetString(PyExc_TypeError, "Cannot delete the attribute"); return -1; } int z; if (PyArg_ParseTuple(value, "i", &z)) { o->setZOrder(z); return 0; } else { // Invalid parameters PyErr_SetString(PyExc_TypeError, "Expected an integer argument!"); return -1; } __PYTHON_EXCEPTION_GUARD_END_RVAL(-1); } // ------------------------------------------ int DrawOperationBinder::setPClipRect(PyObject *self, PyObject *value, void *closure) { __PYTHON_EXCEPTION_GUARD_BEGIN_; DrawOperation* o = NULL; if (!python_cast<DrawOperation*>(self, &msType, &o, msCastInfo)) __PY_CONVERR_RET_VAL(-1); if (value == NULL) { PyErr_SetString(PyExc_TypeError, "Cannot delete the attribute"); return -1; } ClipRect rect; if (!TypeInfo<ClipRect>::fromPyObject(value, rect)) { PyErr_SetString(PyExc_TypeError, "Expected a 4 integer tuple(left,right,top,bottom)!"); return -1; }; o->setClipRect(rect); return 0; __PYTHON_EXCEPTION_GUARD_END_RVAL(-1); } // ------------------------------------------ PyObject* DrawOperationBinder::getPPosition(PyObject *self, void *closure) { __PYTHON_EXCEPTION_GUARD_BEGIN_; DrawOperation* o = NULL; if (!python_cast<DrawOperation*>(self, &msType, &o, msCastInfo)) __PY_CONVERR_RET; return TypeInfo<PixelCoord>::toPyObject(o->getPosition()); __PYTHON_EXCEPTION_GUARD_END_; } // ------------------------------------------ PyObject* DrawOperationBinder::getPZOrder(PyObject *self, void *closure) { __PYTHON_EXCEPTION_GUARD_BEGIN_; DrawOperation* o = NULL; if (!python_cast<DrawOperation*>(self, &msType, &o, msCastInfo)) __PY_CONVERR_RET; return TypeInfo<int>::toPyObject(o->getZOrder()); __PYTHON_EXCEPTION_GUARD_END_; } // ------------------------------------------ PyObject* DrawOperationBinder::getPClipRect(PyObject *self, void *closure) { __PYTHON_EXCEPTION_GUARD_BEGIN_; DrawOperation* o = NULL; if (!python_cast<DrawOperation*>(self, &msType, &o, msCastInfo)) __PY_CONVERR_RET; return TypeInfo<ClipRect>::toPyObject(o->getClipRect()); __PYTHON_EXCEPTION_GUARD_END_; } // ------------------------------------------ PyObject* DrawOperationBinder::repr(PyObject *self) { #ifdef IS_PY3K return PyBytes_FromFormat("<DrawOperation at %p>", self); #else return PyString_FromFormat("<DrawOperation at %p>", self); #endif } // ------------------------------------------ bool DrawOperationBinder::extract(PyObject *object, DrawOperation*& op) { return python_cast<DrawOperation*>(object, &msType, &op, msCastInfo); } // ------------------------------------------ PyObject* DrawOperationBinder::create(DrawOperation *sh) { Object* object = construct(&msType); if (object != NULL) { object->mInstance = sh; } return (PyObject *)object; } // ------------------------------------------ void DrawOperationBinder::init(PyObject* module) { publishType(module, &msType, msName); } } // namespace Python
// ------------------------------------------ void LinkServiceBinder::init(PyObject *module) { publishType(module, &msType, msName); LinkBinder::init(module); LinkQueryResultBinder::init(module); RelationBinder::init(module); } // -------------------- Link -------------------- const char *LinkBinder::msName = "Link"; // ------------------------------------------ PyTypeObject LinkBinder::msType = { PyVarObject_HEAD_INIT(&PyType_Type, 0) msName, // char *tp_name; */ sizeof(LinkBinder::Base), // int tp_basicsize; */ 0, // int tp_itemsize; /* not used much */ LinkBinder::dealloc, // destructor tp_dealloc; */ 0, // printfunc tp_print; */ LinkBinder::getattr, // getattrfunc tp_getattr; /* __getattr__ */ }; // ------------------------------------------ PyObject *LinkBinder::getattr(PyObject *self, char *name) { Link *o; if (!python_cast<Link*>(self, &msType, &o)) __PY_CONVERR_RET; if (!o)
static int __Pyx_Generator_set_qualname(__pyx_GeneratorObject *self, PyObject *value) { PyObject *tmp; #if PY_MAJOR_VERSION >= 3 if (unlikely(value == NULL || !PyUnicode_Check(value))) { #else if (unlikely(value == NULL || !PyString_Check(value))) { #endif PyErr_SetString(PyExc_TypeError, "__qualname__ must be set to a string object"); return -1; } tmp = self->gi_qualname; Py_INCREF(value); self->gi_qualname = value; Py_XDECREF(tmp); return 0; } static PyGetSetDef __pyx_Generator_getsets[] = { {(char *) "__name__", (getter)__Pyx_Generator_get_name, (setter)__Pyx_Generator_set_name, (char*) PyDoc_STR("name of the generator"), 0}, {(char *) "__qualname__", (getter)__Pyx_Generator_get_qualname, (setter)__Pyx_Generator_set_qualname, (char*) PyDoc_STR("qualified name of the generator"), 0}, {0, 0, 0, 0, 0} }; static PyMemberDef __pyx_Generator_memberlist[] = { {(char *) "gi_running", T_BOOL, offsetof(__pyx_GeneratorObject, is_running), READONLY, NULL}, {0, 0, 0, 0, 0} }; static PyMethodDef __pyx_Generator_methods[] = { {"send", (PyCFunction) __Pyx_Generator_Send, METH_O, 0}, {"throw", (PyCFunction) __Pyx_Generator_Throw, METH_VARARGS, 0}, {"close", (PyCFunction) __Pyx_Generator_Close, METH_NOARGS, 0}, {0, 0, 0, 0} }; static PyTypeObject __pyx_GeneratorType_type = { PyVarObject_HEAD_INIT(0, 0) "generator", /*tp_name*/ sizeof(__pyx_GeneratorObject), /*tp_basicsize*/ 0, /*tp_itemsize*/ (destructor) __Pyx_Generator_dealloc,/*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 0, /*tp_compare*/ #else 0, /*reserved*/ #endif 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 | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE, /*tp_flags*/ 0, /*tp_doc*/ (traverseproc) __Pyx_Generator_traverse, /*tp_traverse*/ 0, /*tp_clear*/ 0, /*tp_richcompare*/ offsetof(__pyx_GeneratorObject, gi_weakreflist), /*tp_weaklistoffset*/ 0, /*tp_iter*/ (iternextfunc) __Pyx_Generator_Next, /*tp_iternext*/ __pyx_Generator_methods, /*tp_methods*/ __pyx_Generator_memberlist, /*tp_members*/ __pyx_Generator_getsets, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ 0, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ 0, /*tp_mro*/ 0, /*tp_cache*/ 0, /*tp_subclasses*/ 0, /*tp_weaklist*/ #if PY_VERSION_HEX >= 0x030400a1 0, /*tp_del*/ #else __Pyx_Generator_del, /*tp_del*/ #endif 0, /*tp_version_tag*/ #if PY_VERSION_HEX >= 0x030400a1 __Pyx_Generator_del, /*tp_finalize*/ #endif }; static __pyx_GeneratorObject *__Pyx_Generator_New(__pyx_generator_body_t body, PyObject *closure, PyObject *name, PyObject *qualname) { __pyx_GeneratorObject *gen = PyObject_GC_New(__pyx_GeneratorObject, &__pyx_GeneratorType_type); if (gen == NULL) return NULL; gen->body = body; gen->closure = closure; Py_XINCREF(closure); gen->is_running = 0; gen->resume_label = 0; gen->classobj = NULL; gen->yieldfrom = NULL; gen->exc_type = NULL; gen->exc_value = NULL; gen->exc_traceback = NULL; gen->gi_weakreflist = NULL; Py_XINCREF(qualname); gen->gi_qualname = qualname; Py_XINCREF(name); gen->gi_name = name; PyObject_GC_Track(gen); return gen; }
namespace boost { namespace python { namespace objects { struct life_support { PyObject_HEAD PyObject* patient; }; extern "C" { static void life_support_dealloc(PyObject* self) { Py_XDECREF(((life_support*)self)->patient); self->ob_type->tp_free(self); } static PyObject * life_support_call(PyObject *self, PyObject *arg, PyObject * /*kw*/) { // Let the patient die now Py_XDECREF(((life_support*)self)->patient); ((life_support*)self)->patient = 0; // Let the weak reference die. This probably kills us. Py_XDECREF(PyTuple_GET_ITEM(arg, 0)); return ::boost::python::detail::none(); } } PyTypeObject life_support_type = { PyVarObject_HEAD_INIT(NULL, 0)//(&PyType_Type) const_cast<char*>("Boost.Python.life_support"), sizeof(life_support), 0, life_support_dealloc, /* tp_dealloc */ 0, /* tp_print */ 0, /* tp_getattr */ 0, /* tp_setattr */ 0, /* tp_compare */ 0, //(reprfunc)func_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ 0, /* tp_hash */ life_support_call, /* tp_call */ 0, /* tp_str */ 0, // PyObject_GenericGetAttr, /* tp_getattro */ 0, // PyObject_GenericSetAttr, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT /* | Py_TPFLAGS_HAVE_GC */,/* tp_flags */ 0, /* tp_doc */ 0, // (traverseproc)func_traverse, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, //offsetof(PyLife_SupportObject, func_weakreflist), /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ 0, /* tp_methods */ 0, // func_memberlist, /* tp_members */ 0, //func_getsetlist, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, //offsetof(PyLife_SupportObject, func_dict), /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ 0, /* tp_free */ 0, /* tp_is_gc */ 0, /* tp_bases */ 0, /* tp_mro */ 0, /* tp_cache */ 0, /* tp_subclasses */ 0, /* tp_weaklist */ #if PYTHON_API_VERSION >= 1012 0 /* tp_del */ #endif }; PyObject* make_nurse_and_patient(PyObject* nurse, PyObject* patient) { if (nurse == Py_None || nurse == patient) return nurse; if (Py_TYPE(&life_support_type) == 0) { Py_TYPE(&life_support_type) = &PyType_Type; PyType_Ready(&life_support_type); } life_support* system = PyObject_New(life_support, &life_support_type); if (!system) return 0; system->patient = 0; // We're going to leak this reference, but don't worry; the // life_support system decrements it when the nurse dies. PyObject* weakref = PyWeakref_NewRef(nurse, (PyObject*)system); // weakref has either taken ownership, or we have to release it // anyway Py_DECREF(system); if (!weakref) return 0; system->patient = patient; Py_XINCREF(patient); // hang on to the patient until death return weakref; } }}} // namespace boost::python::objects
{"get_missing_byte_count", (PyCFunction)DataTransferRequest_get_missing_byte_count, METH_NOARGS, "Return count of bytes that couldn't be transferred. Note that this produces undefined behaviour if called on an object that's currently queued."}, {NULL} /* Sentinel */ }; static PyGetSetDef DataTransferRequest_getsetters[] = { {"opaque", (getter)DataTransferRequest_getopaque, (setter)DataTransferRequest_setopaque, "Opaque value", NULL}, {"errno", (getter)DataTransferRequest_get_errno, (setter)DataTransferRequest_set_errno, "Errno of last I/O attempt. Undefined behaviour will result if accessed while this DTR is queued.", NULL}, {NULL} /* Sentinel */ }; static PyTypeObject DataTransferRequestType = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "_blockfd.DataTransferRequest", /* tp_name */ sizeof(DataTransferRequest), /* tp_basicsize */ 0, /* tp_itemsize */ (destructor)DataTransferRequest_dealloc,/* 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 */
free(num_str); return py_obj; } static PyMethodDef Reader_methods[] = { { "get", Reader_get, METH_VARARGS, "Get record for IP address" }, { "metadata", Reader_metadata, METH_NOARGS, "Returns metadata object for database" }, { "close", Reader_close, METH_NOARGS, "Closes database"}, { NULL, NULL, 0, NULL } }; static PyTypeObject Reader_Type = { PyVarObject_HEAD_INIT(NULL, 0) .tp_basicsize = sizeof(Reader_obj), .tp_dealloc = Reader_dealloc, .tp_doc = "Reader object", .tp_flags = Py_TPFLAGS_DEFAULT, .tp_methods = Reader_methods, .tp_name = "Reader", .tp_init = Reader_init, }; static PyMethodDef Metadata_methods[] = { { NULL, NULL, 0, NULL } }; /* *INDENT-OFF* */ static PyMemberDef Metadata_members[] = { { "binary_format_major_version", T_OBJECT, offsetof(
} static PyObject * spamlist_state_get(spamlistobject *self) { return PyLong_FromLong(self->state); } static PyGetSetDef spamlist_getsets[] = { {"state", (getter)spamlist_state_get, NULL, PyDoc_STR("an int variable for demonstration purposes")}, {0} }; static PyTypeObject spamlist_type = { PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) "xxsubtype.spamlist", sizeof(spamlistobject), 0, 0, /* tp_dealloc */ 0, /* tp_print */ 0, /* tp_getattr */ 0, /* tp_setattr */ 0, /* tp_reserved */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ 0, /* tp_hash */ 0, /* tp_call */ 0, /* tp_str */
static PyMethodDef bpy_lib_methods[] = { {"__enter__", (PyCFunction)bpy_lib_enter, METH_NOARGS}, {"__exit__", (PyCFunction)bpy_lib_exit, METH_VARARGS}, {"__dir__", (PyCFunction)bpy_lib_dir, METH_NOARGS}, {NULL} /* sentinel */ }; static void bpy_lib_dealloc(BPy_Library *self) { Py_XDECREF(self->dict); Py_TYPE(self)->tp_free(self); } static PyTypeObject bpy_lib_Type = { PyVarObject_HEAD_INIT(NULL, 0) "bpy_lib", /* tp_name */ sizeof(BPy_Library), /* tp_basicsize */ 0, /* tp_itemsize */ /* methods */ (destructor)bpy_lib_dealloc, /* tp_dealloc */ NULL, /* printfunc tp_print; */ NULL, /* getattrfunc tp_getattr; */ NULL, /* setattrfunc tp_setattr; */ NULL, /* tp_compare */ /* DEPRECATED in python 3.0! */ NULL, /* tp_repr */ /* Method suites for standard classes */ NULL, /* PyNumberMethods *tp_as_number; */ NULL, /* PySequenceMethods *tp_as_sequence; */
(self->destructor)(self->cobject); } PyObject_DEL(self); } PyDoc_STRVAR(PyCObject_Type__doc__, "C objects to be exported from one extension module to another\n\ \n\ C objects are used for communication between extension modules. They\n\ provide a way for an extension module to export a C interface to other\n\ extension modules, so that extension modules can use the Python import\n\ mechanism to link to one another."); PyTypeObject PyCObject_Type = { PyVarObject_HEAD_INIT(/* Pyston change: &PyType_Type */ NULL, 0) "PyCObject", /*tp_name*/ sizeof(PyCObject), /*tp_basicsize*/ 0, /*tp_itemsize*/ /* methods */ (destructor)PyCObject_dealloc, /*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*/
static wchar_t program_name[] = L"qrenderdoc"; static wchar_t python_home[1024] = {0}; struct OutputRedirector { PyObject_HEAD; union { // we union with a uint64_t to ensure it's always a ulonglong even on 32-bit uint64_t dummy; PythonContext *context; }; int isStdError; }; static PyTypeObject OutputRedirectorType = {PyVarObject_HEAD_INIT(NULL, 0)}; static PyMethodDef OutputRedirector_methods[] = { {"write", NULL, METH_VARARGS, "Writes to the output window"}, {"flush", NULL, METH_NOARGS, "Does nothing - only provided for compatibility"}, {NULL}}; PyObject *PythonContext::main_dict = NULL; void FetchException(QString &typeStr, QString &valueStr, int &finalLine, QList<QString> &frames) { PyObject *exObj = NULL, *valueObj = NULL, *tracebackObj = NULL; PyErr_Fetch(&exObj, &valueObj, &tracebackObj); PyErr_NormalizeException(&exObj, &valueObj, &tracebackObj);
namespace pyr { struct PyStream { PyObject_HEAD std::ostream *stream; }; PyObject* PyStream_write(PyObject* self, PyObject* args) { std::size_t written(0); PyStream* selfimpl = reinterpret_cast<PyStream*>(self); if (selfimpl->stream) { char* data; if (!PyArg_ParseTuple(args, "s", &data)) return 0; std::string str(data); // TODO: Make log prefix parameterizables *(selfimpl->stream) << std::string("PyR: ") << str << std::endl; written = str.size(); } return PyLong_FromSize_t(written); } PyObject* PyStream_flush(PyObject* self, PyObject* args) { // no-op return Py_BuildValue(""); } PyMethodDef PyStream_methods[] = { {"write", PyStream_write, METH_VARARGS, "sys.PyStream.write"}, {"flush", PyStream_flush, METH_VARARGS, "sys.PyStream.flush"}, {0, 0, 0, 0} // sentinel }; PyTypeObject PyStreamType = { PyVarObject_HEAD_INIT(0, 0) "PyR.PyStreamType", /* tp_name */ sizeof(PyStream), /* tp_basicsize */ 0, /* tp_itemsize */ 0, /* tp_dealloc */ 0, /* tp_print */ 0, /* tp_getattr */ 0, /* tp_setattr */ 0, /* tp_reserved */ 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 */ "PyR.PyStream objects", /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ PyStream_methods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ PyType_GenericNew, /* tp_new */ }; PyMODINIT_FUNC PyInit_PyR(void) { if (PyType_Ready(&PyStreamType) < 0) { return; } //PyObject *mod = PyModule_New("pyr"); PyObject *mod = Py_InitModule("pyr", NULL); if (mod) { Py_INCREF(&PyStreamType); //PyModule_AddObject(mod, "PyStream", (PyObject *)&PyStreamType); } } PyObject *PyStream_FromStream(std::ostream *stream) { PyObject *pystream = PyStreamType.tp_new(&PyStreamType, 0, 0); PyStream* impl = reinterpret_cast<PyStream*>(pystream); impl->stream = stream; return pystream; } PyObject *set_stdstream(std::string name, PyObject *pystream) { PyObject *old_pystream = PySys_GetObject(const_cast<char*>(name.c_str())); // borrowed Py_XINCREF(pystream); PySys_SetObject(const_cast<char*>(name.c_str()), pystream); Py_XDECREF(old_pystream); return old_pystream; } } // end namespace
static const char *kwlist[] = {"sigma", "integration_type", NULL}; PyObject *obj = 0; double d; if (!PyArg_ParseTupleAndKeywords( args, kwds, "d|O!", (char **)kwlist, &d, &IntegrationType_Type, &obj)) return -1; IntegrationType t = (obj) ? IntegrationType_from_BPy_IntegrationType(obj) : MEAN; self->py_uf1D_double.uf1D_double = new Functions1D::LocalAverageDepthF1D(d, t); return 0; } /*-----------------------BPy_LocalAverageDepthF1D type definition ------------------------------*/ PyTypeObject LocalAverageDepthF1D_Type = { PyVarObject_HEAD_INIT(NULL, 0) "LocalAverageDepthF1D", /* tp_name */ sizeof(BPy_LocalAverageDepthF1D), /* tp_basicsize */ 0, /* tp_itemsize */ 0, /* tp_dealloc */ 0, /* tp_print */ 0, /* tp_getattr */ 0, /* tp_setattr */ 0, /* tp_reserved */ 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 */
#endif offsetof(__pyx_GeneratorObject, is_running), READONLY, NULL}, {0, 0, 0, 0, 0} }; static PyMethodDef __pyx_Generator_methods[] = { {__Pyx_NAMESTR("send"), (PyCFunction) __Pyx_Generator_Send, METH_O, 0}, {__Pyx_NAMESTR("throw"), (PyCFunction) __Pyx_Generator_Throw, METH_VARARGS, 0}, {__Pyx_NAMESTR("close"), (PyCFunction) __Pyx_Generator_Close, METH_NOARGS, 0}, {0, 0, 0, 0} }; static PyTypeObject __pyx_GeneratorType_type = { PyVarObject_HEAD_INIT(0, 0) __Pyx_NAMESTR("generator"), /*tp_name*/ sizeof(__pyx_GeneratorObject), /*tp_basicsize*/ 0, /*tp_itemsize*/ (destructor) __Pyx_Generator_dealloc,/*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 0, /*tp_compare*/ #else 0, /*reserved*/ #endif 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/
namespace plang { struct Stdout { PyObject_HEAD Redirector::stdout_write_type write; Redirector::stdout_flush_type flush; }; static PyObject* Stdout_write(PyObject* self, PyObject* args) { std::size_t written(0); Stdout* selfimpl = reinterpret_cast<Stdout*>(self); if (selfimpl->write) { char* data; if (!PyArg_ParseTuple(args, "s", &data)) return 0; std::string str(data); selfimpl->write(str); written = str.size(); } return PyLong_FromSize_t(written); } static PyObject* Stdout_flush(PyObject* self, PyObject* /*args*/) { Stdout *selfimpl = reinterpret_cast<Stdout *>(self); if (selfimpl->flush) { selfimpl->flush(); } return Py_BuildValue(""); } static PyMethodDef Stdout_methods[] = { {"write", Stdout_write, METH_VARARGS, "sys.stdout.write"}, {"flush", Stdout_flush, METH_VARARGS, "sys.stdout.flush"}, {0, 0, 0, 0} // sentinel }; static PyTypeObject StdoutType = { PyVarObject_HEAD_INIT(0, 0) "redirector.StdoutType", /* tp_name */ sizeof(Stdout), /* tp_basicsize */ 0, /* tp_itemsize */ 0, /* tp_dealloc */ 0, /* tp_print */ 0, /* tp_getattr */ 0, /* tp_setattr */ 0, /* tp_reserved */ 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 */ "redirector.Stdout objects", /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ Stdout_methods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ 0, /* tp_free */ 0, /* tp_is_gc */ 0, /* tp_bases */ 0, /* tp_mro */ 0, /* tp_cache */ 0, /* tp_subclasses */ 0, /* tp_weaklist */ 0, /* tp_del */ 0, /* tp_version_tag */ #if PY_MAJOR_VERSION >= 3 0, /* tp_finalilzer */ #endif }; Redirector::Redirector() : m_stdout(NULL) , m_stdout_saved(NULL) { return; } Redirector::~Redirector() { return; } PyMODINIT_FUNC redirector_init(void) { #if PY_MAJOR_VERSION >= 3 return Redirector::init(); #else Redirector::init(); #endif } #if PY_MAJOR_VERSION >= 3 static struct PyModuleDef redirectordef = { PyModuleDef_HEAD_INIT, "redirector", /* m_name */ "redirector.Stdout objects", /* m_doc */ -1, /* m_size */ Stdout_methods, /* m_methods */ NULL, /* m_reload */ NULL, /* m_traverse */ NULL, /* m_clear */ NULL, /* m_free */ }; #endif PyObject* Redirector::init() { StdoutType.tp_new = PyType_GenericNew; if (PyType_Ready(&StdoutType) < 0) return NULL; #if PY_MAJOR_VERSION >= 3 PyObject* m = PyModule_Create(&redirectordef); #else PyObject* m = Py_InitModule3("redirector", 0, 0); #endif if (m) { //ABELL - This is bad code as the type cast is invalid. (type pun // warning.) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wstrict-aliasing" Py_INCREF(reinterpret_cast<PyObject*>(&StdoutType)); PyModule_AddObject(m, "Stdout", reinterpret_cast<PyObject*>(&StdoutType)); #pragma GCC diagnostic pop } return m; } void Redirector::set_stdout(std::ostream* ostr) { stdout_write_type writeFunc = [ostr](std::string msg) { *ostr << msg; }; stdout_flush_type flushFunc = [ostr]{ ostr->flush(); }; this->set_stdout(writeFunc, flushFunc); } void Redirector::set_stdout(stdout_write_type write, stdout_flush_type flush) { if (!m_stdout) { m_stdout_saved = PySys_GetObject(const_cast<char*>("stdout")); // borrowed m_stdout = StdoutType.tp_new(&StdoutType, 0, 0); } Stdout* impl = reinterpret_cast<Stdout*>(m_stdout); impl->write = write; impl->flush = flush; PySys_SetObject(const_cast<char*>("stdout"), m_stdout); } void Redirector::reset_stdout() { if (m_stdout_saved) PySys_SetObject(const_cast<char*>("stdout"), m_stdout_saved); Py_XDECREF(m_stdout); m_stdout = 0; } } //namespace plang
return NULL; } if (self->uf0D_edgenature->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) { if (!PyErr_Occurred()) { string class_name(Py_TYPE(self)->tp_name); PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str()); } return NULL; } return BPy_Nature_from_Nature(self->uf0D_edgenature->result); } /*-----------------------BPy_UnaryFunction0DEdgeNature type definition ------------------------------*/ PyTypeObject UnaryFunction0DEdgeNature_Type = { PyVarObject_HEAD_INIT(NULL, 0) "UnaryFunction0DEdgeNature", /* tp_name */ sizeof(BPy_UnaryFunction0DEdgeNature), /* tp_basicsize */ 0, /* tp_itemsize */ (destructor)UnaryFunction0DEdgeNature___dealloc__, /* tp_dealloc */ 0, /* tp_print */ 0, /* tp_getattr */ 0, /* tp_setattr */ 0, /* tp_reserved */ (reprfunc)UnaryFunction0DEdgeNature___repr__, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ 0, /* tp_hash */ (ternaryfunc)UnaryFunction0DEdgeNature___call__, /* tp_call */ 0, /* tp_str */
{ "getDirection", (PyCFunction) PyOCIO_Transform_getDirection, METH_NOARGS, TRANSFORM_GETDIRECTION__DOC__ }, { "setDirection", PyOCIO_Transform_setDirection, METH_VARARGS, TRANSFORM_SETDIRECTION__DOC__ }, { NULL, NULL, 0, NULL } }; } /////////////////////////////////////////////////////////////////////////// /// PyTypeObject PyOCIO_TransformType = { PyVarObject_HEAD_INIT(NULL, 0) //ob_size OCIO_PYTHON_NAMESPACE(Transform), //tp_name sizeof(PyOCIO_Transform), //tp_basicsize 0, //tp_itemsize (destructor) PyOCIO_Transform_delete, //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 PyOCIO_Transform_str, //tp_str