[capi-sig] Subtyping builtins in C
Ken Hughes
khughes at pacific.edu
Sun Sep 9 05:48:38 CEST 2007
The work-around for a similar problem with tp_new is described here:
http://docs.python.org/ext/dnt-basics.html
"On some platforms or compilers, we can't statically initialize a
structure member with a function defined in another C module, so,
instead, we'll assign the tp_new slot in the module initialization
function just before calling PyType_Ready()"
So in BPyFloatType_Init(), you put the initialization for
"BPyFloat_Type.tp_base = &PyFloat_Type;"
Ken
Campbell Barton wrote:
> Hi, this compiles fine on linux but on windows with MSVC8 it gives an
> error on this line.
>
> &PyFloat_Type, /* tp_base */
> saying that it cant initialize because &PyFloat_Type is not a constant.
>
> Has anyone else had this problem or know a workaround?
>
> Heres teh pytype,
> source file is here
> http://projects.blender.org/plugins/scmsvn/viewcvs.php/branches/pyapi_devel/source/blender/python/api2_2x/bpy_float.c?root=bf-blender&view=markup
> http://projects.blender.org/plugins/scmsvn/viewcvs.php/branches/pyapi_devel/source/blender/python/api2_2x/bpy_float.h?root=bf-blender&view=markup
>
> PyTypeObject BPyFloat_Type = {
> PyObject_HEAD_INIT(NULL)
> 0,
> "BPyFloat",
> sizeof(BPyFloatObject),
> 0,
> (destructor)BPyFloat_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 */
> 0, /* tp_getattro */
> 0, /* tp_setattro */
> 0, /* tp_as_buffer */
> Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
> 0, /* tp_doc */
> 0, /* tp_traverse */
> 0, /* tp_clear */
> 0, /* tp_richcompare */
> 0, /* tp_weaklistoffset */
> 0, /* tp_iter */
> 0, /* tp_iternext */
> BPyFloat_methods, /* tp_methods */
> 0, /* tp_members */
> BPyFloat_getset, /* tp_getset */
> &PyFloat_Type, /* tp_base */
> 0, /* tp_dict */
> 0, /* tp_descr_get */
> 0, /* tp_descr_set */
> 0, /* tp_dictoffset */
> (initproc)BPyFloat_init, /* tp_init */
> 0, /* tp_alloc */
> 0, /* tp_new */
> };
> _______________________________________________
> capi-sig mailing list
> capi-sig at python.org
> http://mail.python.org/mailman/listinfo/capi-sig
>
>
More information about the capi-sig
mailing list