mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 09:26:16 +03:00
py3k: Modernize type declarations
This updates several Python type definitions and uses to bring us closer to Python 3 compatibility. This includes: * Replacing staticforward and statichere with static. These were a hack for old compilers and are not supported/needed anymore. * Using Py_TYPE() instead of ob_type; ob_type is hidden in Py3. * Replacing getattr with getters/setters. getattr is sort-of supported in Py3, but Py_FindMethod is not. So we just use the newer methods/getsetters mechanisms and start using PyType_Ready everywhere. * Use PyVarObject_HEAD_INIT for types, since types are PyVarObject. * Use PyMODINIT_FUNC for module initialization functions. There are some tab/space issues in this commit. I'm set for spaces; the source is a little schizo.
This commit is contained in:
parent
009eee0577
commit
9519013466
53
Sane/_sane.c
53
Sane/_sane.c
|
@ -51,14 +51,18 @@ PySane_Error(SANE_Status st)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
staticforward PyTypeObject SaneDev_Type;
|
||||
static PyTypeObject SaneDev_Type;
|
||||
|
||||
#define SaneDevObject_Check(v) ((v)->ob_type == &SaneDev_Type)
|
||||
#define SaneDevObject_Check(v) (Py_TYPE(v) == &SaneDev_Type)
|
||||
|
||||
static SaneDevObject *
|
||||
newSaneDevObject(void)
|
||||
{
|
||||
SaneDevObject *self;
|
||||
|
||||
if (PyType_Ready(&SaneDev_Type) < 0)
|
||||
return NULL;
|
||||
|
||||
self = PyObject_NEW(SaneDevObject, &SaneDev_Type);
|
||||
if (self == NULL)
|
||||
return NULL;
|
||||
|
@ -1095,29 +1099,38 @@ static PyMethodDef SaneDev_methods[] = {
|
|||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
static PyObject *
|
||||
SaneDev_getattr(SaneDevObject *self, char *name)
|
||||
{
|
||||
return Py_FindMethod(SaneDev_methods, (PyObject *)self, name);
|
||||
}
|
||||
|
||||
staticforward PyTypeObject SaneDev_Type = {
|
||||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0, /*ob_size*/
|
||||
static PyTypeObject SaneDev_Type = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
"SaneDev", /*tp_name*/
|
||||
sizeof(SaneDevObject), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
/* methods */
|
||||
(destructor)SaneDev_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
(getattrfunc)SaneDev_getattr, /*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_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*/
|
||||
0, /*tp_doc*/
|
||||
0, /*tp_traverse*/
|
||||
0, /*tp_clear*/
|
||||
0, /*tp_richcompare*/
|
||||
0, /*tp_weaklistoffset*/
|
||||
0, /*tp_iter*/
|
||||
0, /*tp_iternext*/
|
||||
SaneDev_methods, /*tp_methods*/
|
||||
0, /*tp_members*/
|
||||
0, /*tp_getset*/
|
||||
};
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
@ -1248,7 +1261,7 @@ insint(PyObject *d, char *name, int value)
|
|||
Py_DECREF(v);
|
||||
}
|
||||
|
||||
void
|
||||
PyMODINIT_FUNC
|
||||
init_sane(void)
|
||||
{
|
||||
PyObject *m, *d;
|
||||
|
|
186
_imaging.c
186
_imaging.c
|
@ -126,7 +126,7 @@ typedef struct {
|
|||
ImagingAccess access;
|
||||
} ImagingObject;
|
||||
|
||||
staticforward PyTypeObject Imaging_Type;
|
||||
static PyTypeObject Imaging_Type;
|
||||
|
||||
#ifdef WITH_IMAGEDRAW
|
||||
|
||||
|
@ -148,7 +148,7 @@ typedef struct {
|
|||
Glyph glyphs[256];
|
||||
} ImagingFontObject;
|
||||
|
||||
staticforward PyTypeObject ImagingFont_Type;
|
||||
static PyTypeObject ImagingFont_Type;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
|
@ -157,7 +157,7 @@ typedef struct {
|
|||
int blend;
|
||||
} ImagingDrawObject;
|
||||
|
||||
staticforward PyTypeObject ImagingDraw_Type;
|
||||
static PyTypeObject ImagingDraw_Type;
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -167,7 +167,7 @@ typedef struct {
|
|||
int readonly;
|
||||
} PixelAccessObject;
|
||||
|
||||
staticforward PyTypeObject PixelAccess_Type;
|
||||
static PyTypeObject PixelAccess_Type;
|
||||
|
||||
PyObject*
|
||||
PyImagingNew(Imaging imOut)
|
||||
|
@ -207,7 +207,7 @@ _dealloc(ImagingObject* imagep)
|
|||
PyObject_Del(imagep);
|
||||
}
|
||||
|
||||
#define PyImaging_Check(op) ((op)->ob_type == &Imaging_Type)
|
||||
#define PyImaging_Check(op) (Py_TYPE(op) == &Imaging_Type)
|
||||
|
||||
Imaging PyImaging_AsImaging(PyObject *op)
|
||||
{
|
||||
|
@ -2232,12 +2232,6 @@ static struct PyMethodDef _font_methods[] = {
|
|||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
static PyObject*
|
||||
_font_getattr(ImagingFontObject* self, char* name)
|
||||
{
|
||||
return Py_FindMethod(_font_methods, (PyObject*) self, name);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
static PyObject*
|
||||
|
@ -2670,12 +2664,6 @@ static struct PyMethodDef _draw_methods[] = {
|
|||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
static PyObject*
|
||||
_draw_getattr(ImagingDrawObject* self, char* name)
|
||||
{
|
||||
return Py_FindMethod(_draw_methods, (PyObject*) self, name);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -2978,29 +2966,44 @@ static struct PyMethodDef methods[] = {
|
|||
|
||||
/* attributes */
|
||||
|
||||
static PyObject*
|
||||
_getattr(ImagingObject* self, char* name)
|
||||
static PyObject*
|
||||
_getattr_mode(ImagingObject* self, void* closure)
|
||||
{
|
||||
PyObject* res;
|
||||
|
||||
res = Py_FindMethod(methods, (PyObject*) self, name);
|
||||
if (res)
|
||||
return res;
|
||||
PyErr_Clear();
|
||||
if (strcmp(name, "mode") == 0)
|
||||
return PyString_FromString(self->image->mode);
|
||||
if (strcmp(name, "size") == 0)
|
||||
return Py_BuildValue("ii", self->image->xsize, self->image->ysize);
|
||||
if (strcmp(name, "bands") == 0)
|
||||
return PyInt_FromLong(self->image->bands);
|
||||
if (strcmp(name, "id") == 0)
|
||||
return PyInt_FromLong((long) self->image);
|
||||
if (strcmp(name, "ptr") == 0)
|
||||
return PyCObject_FromVoidPtrAndDesc(self->image, IMAGING_MAGIC, NULL);
|
||||
PyErr_SetString(PyExc_AttributeError, name);
|
||||
return NULL;
|
||||
return PyString_FromString(self->image->mode);
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
_getattr_size(ImagingObject* self, void* closure)
|
||||
{
|
||||
return Py_BuildValue("ii", self->image->xsize, self->image->ysize);
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
_getattr_bands(ImagingObject* self, void* closure)
|
||||
{
|
||||
return PyInt_FromLong(self->image->bands);
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
_getattr_id(ImagingObject* self, void* closure)
|
||||
{
|
||||
return PyInt_FromLong((long) self->image);
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
_getattr_ptr(ImagingObject* self, void* closure)
|
||||
{
|
||||
return PyCObject_FromVoidPtrAndDesc(self->image, IMAGING_MAGIC, NULL);
|
||||
}
|
||||
|
||||
static struct PyGetSetDef getsetters[] = {
|
||||
{ "mode", (getter) _getattr_mode },
|
||||
{ "size", (getter) _getattr_size },
|
||||
{ "bands", (getter) _getattr_bands },
|
||||
{ "id", (getter) _getattr_id },
|
||||
{ "ptr", (getter) _getattr_ptr },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
/* basic sequence semantics */
|
||||
|
||||
|
@ -3040,49 +3043,108 @@ static PySequenceMethods image_as_sequence = {
|
|||
|
||||
/* type description */
|
||||
|
||||
statichere PyTypeObject Imaging_Type = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /*ob_size*/
|
||||
static PyTypeObject Imaging_Type = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
"ImagingCore", /*tp_name*/
|
||||
sizeof(ImagingObject), /*tp_size*/
|
||||
0, /*tp_itemsize*/
|
||||
/* methods */
|
||||
(destructor)_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
(getattrfunc)_getattr, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number */
|
||||
&image_as_sequence, /*tp_as_sequence */
|
||||
0, /*tp_as_mapping */
|
||||
0 /*tp_hash*/
|
||||
0, /*tp_hash*/
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT, /*tp_flags*/
|
||||
0, /*tp_doc*/
|
||||
0, /*tp_traverse*/
|
||||
0, /*tp_clear*/
|
||||
0, /*tp_richcompare*/
|
||||
0, /*tp_weaklistoffset*/
|
||||
0, /*tp_iter*/
|
||||
0, /*tp_iternext*/
|
||||
methods, /*tp_methods*/
|
||||
0, /*tp_members*/
|
||||
getsetters, /*tp_getset*/
|
||||
};
|
||||
|
||||
#ifdef WITH_IMAGEDRAW
|
||||
|
||||
statichere PyTypeObject ImagingFont_Type = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /*ob_size*/
|
||||
static PyTypeObject ImagingFont_Type = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
"ImagingFont", /*tp_name*/
|
||||
sizeof(ImagingFontObject), /*tp_size*/
|
||||
0, /*tp_itemsize*/
|
||||
/* methods */
|
||||
(destructor)_font_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
(getattrfunc)_font_getattr, /*tp_getattr*/
|
||||
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*/
|
||||
0, /*tp_doc*/
|
||||
0, /*tp_traverse*/
|
||||
0, /*tp_clear*/
|
||||
0, /*tp_richcompare*/
|
||||
0, /*tp_weaklistoffset*/
|
||||
0, /*tp_iter*/
|
||||
0, /*tp_iternext*/
|
||||
_font_methods, /*tp_methods*/
|
||||
0, /*tp_members*/
|
||||
0, /*tp_getset*/
|
||||
};
|
||||
|
||||
statichere PyTypeObject ImagingDraw_Type = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /*ob_size*/
|
||||
static PyTypeObject ImagingDraw_Type = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
"ImagingDraw", /*tp_name*/
|
||||
sizeof(ImagingDrawObject), /*tp_size*/
|
||||
0, /*tp_itemsize*/
|
||||
/* methods */
|
||||
(destructor)_draw_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
(getattrfunc)_draw_getattr, /*tp_getattr*/
|
||||
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*/
|
||||
0, /*tp_doc*/
|
||||
0, /*tp_traverse*/
|
||||
0, /*tp_clear*/
|
||||
0, /*tp_richcompare*/
|
||||
0, /*tp_weaklistoffset*/
|
||||
0, /*tp_iter*/
|
||||
0, /*tp_iternext*/
|
||||
_draw_methods, /*tp_methods*/
|
||||
0, /*tp_members*/
|
||||
0, /*tp_getset*/
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -3095,9 +3157,9 @@ static PyMappingMethods pixel_access_as_mapping = {
|
|||
|
||||
/* type description */
|
||||
|
||||
statichere PyTypeObject PixelAccess_Type = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, "PixelAccess", sizeof(PixelAccessObject), 0,
|
||||
static PyTypeObject PixelAccess_Type = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
"PixelAccess", sizeof(PixelAccessObject), 0,
|
||||
/* methods */
|
||||
(destructor)pixel_access_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
|
@ -3261,19 +3323,19 @@ static PyMethodDef functions[] = {
|
|||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
DL_EXPORT(void)
|
||||
PyMODINIT_FUNC
|
||||
init_imaging(void)
|
||||
{
|
||||
PyObject* m;
|
||||
PyObject* d;
|
||||
|
||||
/* Patch object type */
|
||||
Imaging_Type.ob_type = &PyType_Type;
|
||||
/* Ready object types */
|
||||
PyType_Ready(&Imaging_Type);
|
||||
#ifdef WITH_IMAGEDRAW
|
||||
ImagingFont_Type.ob_type = &PyType_Type;
|
||||
ImagingDraw_Type.ob_type = &PyType_Type;
|
||||
PyType_Ready(&ImagingFont_Type);
|
||||
PyType_Ready(&ImagingDraw_Type);
|
||||
#endif
|
||||
PixelAccess_Type.ob_type = &PyType_Type;
|
||||
PyType_Ready(&PixelAccess_Type);
|
||||
|
||||
ImagingAccessInit();
|
||||
|
||||
|
|
176
_imagingcms.c
176
_imagingcms.c
|
@ -83,9 +83,9 @@ typedef struct {
|
|||
cmsHPROFILE profile;
|
||||
} CmsProfileObject;
|
||||
|
||||
staticforward PyTypeObject CmsProfile_Type;
|
||||
static PyTypeObject CmsProfile_Type;
|
||||
|
||||
#define CmsProfile_Check(op) ((op)->ob_type == &CmsProfile_Type)
|
||||
#define CmsProfile_Check(op) (Py_TYPE(op) == &CmsProfile_Type)
|
||||
|
||||
static PyObject*
|
||||
cms_profile_new(cmsHPROFILE profile)
|
||||
|
@ -158,9 +158,9 @@ typedef struct {
|
|||
cmsHTRANSFORM transform;
|
||||
} CmsTransformObject;
|
||||
|
||||
staticforward PyTypeObject CmsTransform_Type;
|
||||
static PyTypeObject CmsTransform_Type;
|
||||
|
||||
#define CmsTransform_Check(op) ((op)->ob_type == &CmsTransform_Type)
|
||||
#define CmsTransform_Check(op) (Py_TYPE(op) == &CmsTransform_Type)
|
||||
|
||||
static PyObject*
|
||||
cms_transform_new(cmsHTRANSFORM transform, char* mode_in, char* mode_out)
|
||||
|
@ -515,40 +515,83 @@ static struct PyMethodDef cms_profile_methods[] = {
|
|||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
static PyObject*
|
||||
cms_profile_getattr(CmsProfileObject* self, char* name)
|
||||
static PyObject*
|
||||
cms_profile_getattr_product_name(CmsProfileObject* self, void* closure)
|
||||
{
|
||||
if (!strcmp(name, "product_name"))
|
||||
return PyString_FromString(cmsTakeProductName(self->profile));
|
||||
if (!strcmp(name, "product_desc"))
|
||||
return PyString_FromString(cmsTakeProductDesc(self->profile));
|
||||
if (!strcmp(name, "product_info"))
|
||||
return PyString_FromString(cmsTakeProductInfo(self->profile));
|
||||
if (!strcmp(name, "rendering_intent"))
|
||||
return PyInt_FromLong(cmsTakeRenderingIntent(self->profile));
|
||||
if (!strcmp(name, "pcs"))
|
||||
return PyString_FromString(findICmode(cmsGetPCS(self->profile)));
|
||||
if (!strcmp(name, "color_space"))
|
||||
return PyString_FromString(findICmode(cmsGetColorSpace(self->profile)));
|
||||
/* FIXME: add more properties (creation_datetime etc) */
|
||||
|
||||
return Py_FindMethod(cms_profile_methods, (PyObject*) self, name);
|
||||
return PyString_FromString(cmsTakeProductName(self->profile));
|
||||
}
|
||||
|
||||
statichere PyTypeObject CmsProfile_Type = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, "CmsProfile", sizeof(CmsProfileObject), 0,
|
||||
static PyObject*
|
||||
cms_profile_getattr_product_desc(CmsProfileObject* self, void* closure)
|
||||
{
|
||||
return PyString_FromString(cmsTakeProductDesc(self->profile));
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
cms_profile_getattr_product_info(CmsProfileObject* self, void* closure)
|
||||
{
|
||||
return PyString_FromString(cmsTakeProductInfo(self->profile));
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
cms_profile_getattr_rendering_intent(CmsProfileObject* self, void* closure)
|
||||
{
|
||||
return PyInt_FromLong(cmsTakeRenderingIntent(self->profile));
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
cms_profile_getattr_pcs(CmsProfileObject* self, void* closure)
|
||||
{
|
||||
return PyString_FromString(findICmode(cmsGetPCS(self->profile)));
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
cms_profile_getattr_color_space(CmsProfileObject* self, void* closure)
|
||||
{
|
||||
return PyString_FromString(findICmode(cmsGetColorSpace(self->profile)));
|
||||
}
|
||||
|
||||
/* FIXME: add more properties (creation_datetime etc) */
|
||||
static struct PyGetSetDef cms_profile_getsetters[] = {
|
||||
{ "product_name", (getter) cms_profile_getattr_product_name },
|
||||
{ "product_desc", (getter) cms_profile_getattr_product_desc },
|
||||
{ "product_info", (getter) cms_profile_getattr_product_info },
|
||||
{ "rendering_intent", (getter) cms_profile_getattr_rendering_intent },
|
||||
{ "pcs", (getter) cms_profile_getattr_pcs },
|
||||
{ "color_space", (getter) cms_profile_getattr_color_space },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static PyTypeObject CmsProfile_Type = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
"CmsProfile", sizeof(CmsProfileObject), 0,
|
||||
/* methods */
|
||||
(destructor) cms_profile_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
(getattrfunc) cms_profile_getattr, /*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_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*/
|
||||
0, /*tp_doc*/
|
||||
0, /*tp_traverse*/
|
||||
0, /*tp_clear*/
|
||||
0, /*tp_richcompare*/
|
||||
0, /*tp_weaklistoffset*/
|
||||
0, /*tp_iter*/
|
||||
0, /*tp_iternext*/
|
||||
cms_profile_methods, /*tp_methods*/
|
||||
0, /*tp_members*/
|
||||
cms_profile_getsetters, /*tp_getset*/
|
||||
};
|
||||
|
||||
static struct PyMethodDef cms_transform_methods[] = {
|
||||
|
@ -556,43 +599,66 @@ static struct PyMethodDef cms_transform_methods[] = {
|
|||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
static PyObject*
|
||||
cms_transform_getattr(CmsTransformObject* self, char* name)
|
||||
static PyObject*
|
||||
cms_transform_getattr_inputMode(CmsTransformObject* self, void* closure)
|
||||
{
|
||||
if (!strcmp(name, "inputMode"))
|
||||
return PyString_FromString(self->mode_in);
|
||||
if (!strcmp(name, "outputMode"))
|
||||
return PyString_FromString(self->mode_out);
|
||||
|
||||
return Py_FindMethod(cms_transform_methods, (PyObject*) self, name);
|
||||
return PyString_FromString(self->mode_in);
|
||||
}
|
||||
|
||||
statichere PyTypeObject CmsTransform_Type = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, "CmsTransform", sizeof(CmsTransformObject), 0,
|
||||
static PyObject*
|
||||
cms_transform_getattr_outputMode(CmsTransformObject* self, void* closure)
|
||||
{
|
||||
return PyString_FromString(self->mode_out);
|
||||
}
|
||||
|
||||
static struct PyGetSetDef cms_transform_getsetters[] = {
|
||||
{ "inputMode", (getter) cms_transform_getattr_inputMode },
|
||||
{ "outputMode", (getter) cms_transform_getattr_outputMode },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static PyTypeObject CmsTransform_Type = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
"CmsTransform", sizeof(CmsTransformObject), 0,
|
||||
/* methods */
|
||||
(destructor) cms_transform_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
(getattrfunc) cms_transform_getattr, /*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_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*/
|
||||
0, /*tp_doc*/
|
||||
0, /*tp_traverse*/
|
||||
0, /*tp_clear*/
|
||||
0, /*tp_richcompare*/
|
||||
0, /*tp_weaklistoffset*/
|
||||
0, /*tp_iter*/
|
||||
0, /*tp_iternext*/
|
||||
cms_transform_methods, /*tp_methods*/
|
||||
0, /*tp_members*/
|
||||
cms_transform_getsetters, /*tp_getset*/
|
||||
};
|
||||
|
||||
DL_EXPORT(void)
|
||||
PyMODINIT_FUNC
|
||||
init_imagingcms(void)
|
||||
{
|
||||
PyObject *m;
|
||||
PyObject *d;
|
||||
PyObject *v;
|
||||
|
||||
/* Patch up object types */
|
||||
CmsProfile_Type.ob_type = &PyType_Type;
|
||||
CmsTransform_Type.ob_type = &PyType_Type;
|
||||
/* Ready object types */
|
||||
PyType_Ready(&CmsProfile_Type);
|
||||
PyType_Ready(&CmsTransform_Type);
|
||||
|
||||
m = Py_InitModule("_imagingcms", pyCMSdll_methods);
|
||||
d = PyModule_GetDict(m);
|
||||
|
|
112
_imagingft.c
112
_imagingft.c
|
@ -82,7 +82,7 @@ typedef struct {
|
|||
FT_Face face;
|
||||
} FontObject;
|
||||
|
||||
staticforward PyTypeObject Font_Type;
|
||||
static PyTypeObject Font_Type;
|
||||
|
||||
/* round a 26.6 pixel coordinate to the nearest larger integer */
|
||||
#define PIXEL(x) ((((x)+63) & -64)>>6)
|
||||
|
@ -420,49 +420,79 @@ static PyMethodDef font_methods[] = {
|
|||
{NULL, NULL}
|
||||
};
|
||||
|
||||
static PyObject*
|
||||
font_getattr(FontObject* self, char* name)
|
||||
static PyObject*
|
||||
font_getattr_family(FontObject* self, void* closure)
|
||||
{
|
||||
PyObject* res;
|
||||
|
||||
res = Py_FindMethod(font_methods, (PyObject*) self, name);
|
||||
|
||||
if (res)
|
||||
return res;
|
||||
|
||||
PyErr_Clear();
|
||||
|
||||
/* attributes */
|
||||
if (!strcmp(name, "family")) {
|
||||
if (self->face->family_name)
|
||||
return PyString_FromString(self->face->family_name);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
if (!strcmp(name, "style")) {
|
||||
if (self->face->style_name)
|
||||
return PyString_FromString(self->face->style_name);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
if (!strcmp(name, "ascent"))
|
||||
return PyInt_FromLong(PIXEL(self->face->size->metrics.ascender));
|
||||
if (!strcmp(name, "descent"))
|
||||
return PyInt_FromLong(-PIXEL(self->face->size->metrics.descender));
|
||||
|
||||
if (!strcmp(name, "glyphs"))
|
||||
/* number of glyphs provided by this font */
|
||||
return PyInt_FromLong(self->face->num_glyphs);
|
||||
|
||||
PyErr_SetString(PyExc_AttributeError, name);
|
||||
return NULL;
|
||||
if (self->face->family_name)
|
||||
return PyString_FromString(self->face->family_name);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
statichere PyTypeObject Font_Type = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, "Font", sizeof(FontObject), 0,
|
||||
static PyObject*
|
||||
font_getattr_style(FontObject* self, void* closure)
|
||||
{
|
||||
if (self->face->style_name)
|
||||
return PyString_FromString(self->face->style_name);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
font_getattr_ascent(FontObject* self, void* closure)
|
||||
{
|
||||
return PyInt_FromLong(PIXEL(self->face->size->metrics.ascender));
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
font_getattr_descent(FontObject* self, void* closure)
|
||||
{
|
||||
return PyInt_FromLong(-PIXEL(self->face->size->metrics.descender));
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
font_getattr_glyphs(FontObject* self, void* closure)
|
||||
{
|
||||
return PyInt_FromLong(self->face->num_glyphs);
|
||||
}
|
||||
|
||||
static struct PyGetSetDef font_getsetters[] = {
|
||||
{ "family", (getter) font_getattr_family },
|
||||
{ "style", (getter) font_getattr_style },
|
||||
{ "ascent", (getter) font_getattr_ascent },
|
||||
{ "descent", (getter) font_getattr_descent },
|
||||
{ "glyphs", (getter) font_getattr_glyphs },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static PyTypeObject Font_Type = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
"Font", sizeof(FontObject), 0,
|
||||
/* methods */
|
||||
(destructor)font_dealloc, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
(getattrfunc)font_getattr, /* tp_getattr */
|
||||
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*/
|
||||
0, /*tp_doc*/
|
||||
0, /*tp_traverse*/
|
||||
0, /*tp_clear*/
|
||||
0, /*tp_richcompare*/
|
||||
0, /*tp_weaklistoffset*/
|
||||
0, /*tp_iter*/
|
||||
0, /*tp_iternext*/
|
||||
font_methods, /*tp_methods*/
|
||||
0, /*tp_members*/
|
||||
font_getsetters, /*tp_getset*/
|
||||
};
|
||||
|
||||
static PyMethodDef _functions[] = {
|
||||
|
@ -470,7 +500,7 @@ static PyMethodDef _functions[] = {
|
|||
{NULL, NULL}
|
||||
};
|
||||
|
||||
DL_EXPORT(void)
|
||||
PyMODINIT_FUNC
|
||||
init_imagingft(void)
|
||||
{
|
||||
PyObject* m;
|
||||
|
@ -478,8 +508,8 @@ init_imagingft(void)
|
|||
PyObject* v;
|
||||
int major, minor, patch;
|
||||
|
||||
/* Patch object type */
|
||||
Font_Type.ob_type = &PyType_Type;
|
||||
/* Ready object type */
|
||||
PyType_Ready(&Font_Type);
|
||||
|
||||
m = Py_InitModule("_imagingft", _functions);
|
||||
d = PyModule_GetDict(m);
|
||||
|
|
|
@ -227,7 +227,7 @@ install(PyObject *d, char* name, void* value)
|
|||
Py_XDECREF(v);
|
||||
}
|
||||
|
||||
DL_EXPORT(void)
|
||||
PyMODINIT_FUNC
|
||||
init_imagingmath(void)
|
||||
{
|
||||
PyObject* m;
|
||||
|
|
45
decode.c
45
decode.c
|
@ -57,7 +57,7 @@ typedef struct {
|
|||
PyObject* lock;
|
||||
} ImagingDecoderObject;
|
||||
|
||||
staticforward PyTypeObject ImagingDecoderType;
|
||||
static PyTypeObject ImagingDecoderType;
|
||||
|
||||
static ImagingDecoderObject*
|
||||
PyImaging_DecoderNew(int contextsize)
|
||||
|
@ -65,7 +65,8 @@ PyImaging_DecoderNew(int contextsize)
|
|||
ImagingDecoderObject *decoder;
|
||||
void *context;
|
||||
|
||||
ImagingDecoderType.ob_type = &PyType_Type;
|
||||
if(PyType_Ready(&ImagingDecoderType) < 0)
|
||||
return NULL;
|
||||
|
||||
decoder = PyObject_New(ImagingDecoderObject, &ImagingDecoderType);
|
||||
if (decoder == NULL)
|
||||
|
@ -185,26 +186,38 @@ static struct PyMethodDef methods[] = {
|
|||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
static PyObject*
|
||||
_getattr(ImagingDecoderObject* self, char* name)
|
||||
{
|
||||
return Py_FindMethod(methods, (PyObject*) self, name);
|
||||
}
|
||||
|
||||
statichere PyTypeObject ImagingDecoderType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /*ob_size*/
|
||||
static PyTypeObject ImagingDecoderType = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
"ImagingDecoder", /*tp_name*/
|
||||
sizeof(ImagingDecoderObject), /*tp_size*/
|
||||
0, /*tp_itemsize*/
|
||||
/* methods */
|
||||
(destructor)_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
(getattrfunc)_getattr, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_hash*/
|
||||
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*/
|
||||
0, /*tp_doc*/
|
||||
0, /*tp_traverse*/
|
||||
0, /*tp_clear*/
|
||||
0, /*tp_richcompare*/
|
||||
0, /*tp_weaklistoffset*/
|
||||
0, /*tp_iter*/
|
||||
0, /*tp_iternext*/
|
||||
methods, /*tp_methods*/
|
||||
0, /*tp_members*/
|
||||
0, /*tp_getset*/
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
|
66
display.c
66
display.c
|
@ -44,13 +44,16 @@ typedef struct {
|
|||
ImagingDIB dib;
|
||||
} ImagingDisplayObject;
|
||||
|
||||
staticforward PyTypeObject ImagingDisplayType;
|
||||
static PyTypeObject ImagingDisplayType;
|
||||
|
||||
static ImagingDisplayObject*
|
||||
_new(const char* mode, int xsize, int ysize)
|
||||
{
|
||||
ImagingDisplayObject *display;
|
||||
|
||||
if (PyType_Ready(&ImagingDisplayType) < 0)
|
||||
return NULL;
|
||||
|
||||
display = PyObject_New(ImagingDisplayObject, &ImagingDisplayType);
|
||||
if (display == NULL)
|
||||
return NULL;
|
||||
|
@ -217,37 +220,56 @@ static struct PyMethodDef methods[] = {
|
|||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
static PyObject*
|
||||
_getattr(ImagingDisplayObject* self, char* name)
|
||||
static PyObject*
|
||||
_getattr_mode(ImagingDisplayObject* self, void* closure)
|
||||
{
|
||||
PyObject* res;
|
||||
|
||||
res = Py_FindMethod(methods, (PyObject*) self, name);
|
||||
if (res)
|
||||
return res;
|
||||
PyErr_Clear();
|
||||
if (!strcmp(name, "mode"))
|
||||
return Py_BuildValue("s", self->dib->mode);
|
||||
if (!strcmp(name, "size"))
|
||||
return Py_BuildValue("ii", self->dib->xsize, self->dib->ysize);
|
||||
PyErr_SetString(PyExc_AttributeError, name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
statichere PyTypeObject ImagingDisplayType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /*ob_size*/
|
||||
static PyObject*
|
||||
_getattr_size(ImagingDisplayObject* self, void* closure)
|
||||
{
|
||||
return Py_BuildValue("ii", self->dib->xsize, self->dib->ysize);
|
||||
}
|
||||
|
||||
static struct PyGetSetDef getsetters[] = {
|
||||
{ "mode", (getter) _getattr_mode },
|
||||
{ "size", (getter) _getattr_size },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static PyTypeObject ImagingDisplayType = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
"ImagingDisplay", /*tp_name*/
|
||||
sizeof(ImagingDisplayObject), /*tp_size*/
|
||||
0, /*tp_itemsize*/
|
||||
/* methods */
|
||||
(destructor)_delete, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
(getattrfunc)_getattr, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_hash*/
|
||||
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*/
|
||||
0, /*tp_doc*/
|
||||
0, /*tp_traverse*/
|
||||
0, /*tp_clear*/
|
||||
0, /*tp_richcompare*/
|
||||
0, /*tp_weaklistoffset*/
|
||||
0, /*tp_iter*/
|
||||
0, /*tp_iternext*/
|
||||
methods, /*tp_methods*/
|
||||
0, /*tp_members*/
|
||||
getsetters, /*tp_getset*/
|
||||
};
|
||||
|
||||
PyObject*
|
||||
|
|
45
encode.c
45
encode.c
|
@ -49,7 +49,7 @@ typedef struct {
|
|||
PyObject* lock;
|
||||
} ImagingEncoderObject;
|
||||
|
||||
staticforward PyTypeObject ImagingEncoderType;
|
||||
static PyTypeObject ImagingEncoderType;
|
||||
|
||||
static ImagingEncoderObject*
|
||||
PyImaging_EncoderNew(int contextsize)
|
||||
|
@ -57,7 +57,8 @@ PyImaging_EncoderNew(int contextsize)
|
|||
ImagingEncoderObject *encoder;
|
||||
void *context;
|
||||
|
||||
ImagingEncoderType.ob_type = &PyType_Type;
|
||||
if(!PyType_Ready(&ImagingEncoderType) < 0)
|
||||
return NULL;
|
||||
|
||||
encoder = PyObject_New(ImagingEncoderObject, &ImagingEncoderType);
|
||||
if (encoder == NULL)
|
||||
|
@ -241,26 +242,38 @@ static struct PyMethodDef methods[] = {
|
|||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
static PyObject*
|
||||
_getattr(ImagingEncoderObject* self, char* name)
|
||||
{
|
||||
return Py_FindMethod(methods, (PyObject*) self, name);
|
||||
}
|
||||
|
||||
statichere PyTypeObject ImagingEncoderType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /*ob_size*/
|
||||
static PyTypeObject ImagingEncoderType = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
"ImagingEncoder", /*tp_name*/
|
||||
sizeof(ImagingEncoderObject), /*tp_size*/
|
||||
0, /*tp_itemsize*/
|
||||
/* methods */
|
||||
(destructor)_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
(getattrfunc)_getattr, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_hash*/
|
||||
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*/
|
||||
0, /*tp_doc*/
|
||||
0, /*tp_traverse*/
|
||||
0, /*tp_clear*/
|
||||
0, /*tp_richcompare*/
|
||||
0, /*tp_weaklistoffset*/
|
||||
0, /*tp_iter*/
|
||||
0, /*tp_iternext*/
|
||||
methods, /*tp_methods*/
|
||||
0, /*tp_members*/
|
||||
0, /*tp_getset*/
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
|
45
map.c
45
map.c
|
@ -57,14 +57,15 @@ typedef struct {
|
|||
#endif
|
||||
} ImagingMapperObject;
|
||||
|
||||
staticforward PyTypeObject ImagingMapperType;
|
||||
static PyTypeObject ImagingMapperType;
|
||||
|
||||
ImagingMapperObject*
|
||||
PyImaging_MapperNew(const char* filename, int readonly)
|
||||
{
|
||||
ImagingMapperObject *mapper;
|
||||
|
||||
ImagingMapperType.ob_type = &PyType_Type;
|
||||
if (PyType_Ready(&ImagingMapperType) < 0)
|
||||
return NULL;
|
||||
|
||||
mapper = PyObject_New(ImagingMapperObject, &ImagingMapperType);
|
||||
if (mapper == NULL)
|
||||
|
@ -260,26 +261,38 @@ static struct PyMethodDef methods[] = {
|
|||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
static PyObject*
|
||||
mapping_getattr(ImagingMapperObject* self, char* name)
|
||||
{
|
||||
return Py_FindMethod(methods, (PyObject*) self, name);
|
||||
}
|
||||
|
||||
statichere PyTypeObject ImagingMapperType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /*ob_size*/
|
||||
static PyTypeObject ImagingMapperType = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
"ImagingMapper", /*tp_name*/
|
||||
sizeof(ImagingMapperObject), /*tp_size*/
|
||||
0, /*tp_itemsize*/
|
||||
/* methods */
|
||||
(destructor)mapping_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
(getattrfunc)mapping_getattr, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_hash*/
|
||||
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*/
|
||||
0, /*tp_doc*/
|
||||
0, /*tp_traverse*/
|
||||
0, /*tp_clear*/
|
||||
0, /*tp_richcompare*/
|
||||
0, /*tp_weaklistoffset*/
|
||||
0, /*tp_iter*/
|
||||
0, /*tp_iternext*/
|
||||
methods, /*tp_methods*/
|
||||
0, /*tp_members*/
|
||||
0, /*tp_getset*/
|
||||
};
|
||||
|
||||
PyObject*
|
||||
|
|
44
outline.c
44
outline.c
|
@ -35,15 +35,18 @@ typedef struct {
|
|||
ImagingOutline outline;
|
||||
} OutlineObject;
|
||||
|
||||
staticforward PyTypeObject OutlineType;
|
||||
static PyTypeObject OutlineType;
|
||||
|
||||
#define PyOutline_Check(op) ((op)->ob_type == &OutlineType)
|
||||
#define PyOutline_Check(op) (Py_TYPE(op) == &OutlineType)
|
||||
|
||||
static OutlineObject*
|
||||
_outline_new(void)
|
||||
{
|
||||
OutlineObject *self;
|
||||
|
||||
if (PyType_Ready(&OutlineType) < 0)
|
||||
return NULL;
|
||||
|
||||
self = PyObject_New(OutlineObject, &OutlineType);
|
||||
if (self == NULL)
|
||||
return NULL;
|
||||
|
@ -159,21 +162,36 @@ static struct PyMethodDef _outline_methods[] = {
|
|||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
static PyObject*
|
||||
_outline_getattr(OutlineObject* self, char* name)
|
||||
{
|
||||
return Py_FindMethod(_outline_methods, (PyObject*) self, name);
|
||||
}
|
||||
|
||||
statichere PyTypeObject OutlineType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /*ob_size*/
|
||||
static PyTypeObject OutlineType = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
"Outline", /*tp_name*/
|
||||
sizeof(OutlineObject), /*tp_size*/
|
||||
0, /*tp_itemsize*/
|
||||
/* methods */
|
||||
(destructor)_outline_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
(getattrfunc)_outline_getattr, /*tp_getattr*/
|
||||
0 /*tp_setattr*/
|
||||
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*/
|
||||
0, /*tp_doc*/
|
||||
0, /*tp_traverse*/
|
||||
0, /*tp_clear*/
|
||||
0, /*tp_richcompare*/
|
||||
0, /*tp_weaklistoffset*/
|
||||
0, /*tp_iter*/
|
||||
0, /*tp_iternext*/
|
||||
_outline_methods, /*tp_methods*/
|
||||
0, /*tp_members*/
|
||||
0, /*tp_getset*/
|
||||
};
|
||||
|
|
56
path.c
56
path.c
|
@ -59,7 +59,7 @@ typedef struct {
|
|||
int index; /* temporary use, e.g. in decimate */
|
||||
} PyPathObject;
|
||||
|
||||
staticforward PyTypeObject PyPathType;
|
||||
static PyTypeObject PyPathType;
|
||||
|
||||
static double*
|
||||
alloc_array(int count)
|
||||
|
@ -89,6 +89,9 @@ path_new(Py_ssize_t count, double* xy, int duplicate)
|
|||
xy = p;
|
||||
}
|
||||
|
||||
if (PyType_Ready(&PyPathType) < 0)
|
||||
return NULL;
|
||||
|
||||
path = PyObject_New(PyPathObject, &PyPathType);
|
||||
if (path == NULL)
|
||||
return NULL;
|
||||
|
@ -110,7 +113,7 @@ path_dealloc(PyPathObject* path)
|
|||
/* Helpers */
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
#define PyPath_Check(op) ((op)->ob_type == &PyPathType)
|
||||
#define PyPath_Check(op) (Py_TYPE(op) == &PyPathType)
|
||||
|
||||
int
|
||||
PyPath_Flatten(PyObject* data, double **pxy)
|
||||
|
@ -539,24 +542,17 @@ static struct PyMethodDef methods[] = {
|
|||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
static PyObject*
|
||||
path_getattr(PyPathObject* self, char* name)
|
||||
static PyObject*
|
||||
path_getattr_id(PyPathObject* self, void* closure)
|
||||
{
|
||||
PyObject* res;
|
||||
|
||||
res = Py_FindMethod(methods, (PyObject*) self, name);
|
||||
if (res)
|
||||
return res;
|
||||
|
||||
PyErr_Clear();
|
||||
|
||||
if (strcmp(name, "id") == 0)
|
||||
return Py_BuildValue("l", (long) self->xy);
|
||||
|
||||
PyErr_SetString(PyExc_AttributeError, name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct PyGetSetDef getsetters[] = {
|
||||
{ "id", (getter) path_getattr_id },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static PySequenceMethods path_as_sequence = {
|
||||
(lenfunc)path_len, /*sq_length*/
|
||||
(binaryfunc)0, /*sq_concat*/
|
||||
|
@ -567,21 +563,37 @@ static PySequenceMethods path_as_sequence = {
|
|||
(ssizessizeobjargproc)0, /*sq_ass_slice*/
|
||||
};
|
||||
|
||||
statichere PyTypeObject PyPathType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /*ob_size*/
|
||||
static PyTypeObject PyPathType = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
"Path", /*tp_name*/
|
||||
sizeof(PyPathObject), /*tp_size*/
|
||||
0, /*tp_itemsize*/
|
||||
/* methods */
|
||||
(destructor)path_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
(getattrfunc)path_getattr, /*tp_getattr*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number */
|
||||
&path_as_sequence, /*tp_as_sequence */
|
||||
0, /*tp_as_mapping */
|
||||
0, /*tp_hash*/
|
||||
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*/
|
||||
0, /*tp_doc*/
|
||||
0, /*tp_traverse*/
|
||||
0, /*tp_clear*/
|
||||
0, /*tp_richcompare*/
|
||||
0, /*tp_weaklistoffset*/
|
||||
0, /*tp_iter*/
|
||||
0, /*tp_iternext*/
|
||||
methods, /*tp_methods*/
|
||||
0, /*tp_members*/
|
||||
getsetters, /*tp_getset*/
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user