Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use member names to initialize PyTypeObjects #8741

Merged
merged 2 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 18 additions & 104 deletions src/_imaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -3769,102 +3769,26 @@ static PySequenceMethods image_as_sequence = {
/* type description */

static PyTypeObject Imaging_Type = {
PyVarObject_HEAD_INIT(NULL, 0) "ImagingCore", /*tp_name*/
sizeof(ImagingObject), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
(destructor)_dealloc, /*tp_dealloc*/
0, /*tp_vectorcall_offset*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_as_async*/
0, /*tp_repr*/
0, /*tp_as_number*/
&image_as_sequence, /*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*/
PyVarObject_HEAD_INIT(NULL, 0).tp_name = "ImagingCore",
.tp_basicsize = sizeof(ImagingObject),
.tp_dealloc = (destructor)_dealloc,
.tp_as_sequence = &image_as_sequence,
.tp_methods = methods,
.tp_getset = getsetters,
};

static PyTypeObject ImagingFont_Type = {
PyVarObject_HEAD_INIT(NULL, 0) "ImagingFont", /*tp_name*/
sizeof(ImagingFontObject), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
(destructor)_font_dealloc, /*tp_dealloc*/
0, /*tp_vectorcall_offset*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_as_async*/
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*/
PyVarObject_HEAD_INIT(NULL, 0).tp_name = "ImagingFont",
.tp_basicsize = sizeof(ImagingFontObject),
.tp_dealloc = (destructor)_font_dealloc,
.tp_methods = _font_methods,
};

static PyTypeObject ImagingDraw_Type = {
PyVarObject_HEAD_INIT(NULL, 0) "ImagingDraw", /*tp_name*/
sizeof(ImagingDrawObject), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
(destructor)_draw_dealloc, /*tp_dealloc*/
0, /*tp_vectorcall_offset*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_as_async*/
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*/
PyVarObject_HEAD_INIT(NULL, 0).tp_name = "ImagingDraw",
.tp_basicsize = sizeof(ImagingDrawObject),
.tp_dealloc = (destructor)_draw_dealloc,
.tp_methods = _draw_methods,
};

static PyMappingMethods pixel_access_as_mapping = {
Expand All @@ -3876,20 +3800,10 @@ static PyMappingMethods pixel_access_as_mapping = {
/* type description */

static PyTypeObject PixelAccess_Type = {
PyVarObject_HEAD_INIT(NULL, 0) "PixelAccess", /*tp_name*/
sizeof(PixelAccessObject), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
(destructor)pixel_access_dealloc, /*tp_dealloc*/
0, /*tp_vectorcall_offset*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_as_async*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
&pixel_access_as_mapping, /*tp_as_mapping*/
0 /*tp_hash*/
PyVarObject_HEAD_INIT(NULL, 0).tp_name = "PixelAccess",
.tp_basicsize = sizeof(PixelAccessObject),
.tp_dealloc = (destructor)pixel_access_dealloc,
.tp_as_mapping = &pixel_access_as_mapping,
};

/* -------------------------------------------------------------------- */
Expand Down
69 changes: 9 additions & 60 deletions src/_imagingcms.c
Original file line number Diff line number Diff line change
Expand Up @@ -1410,73 +1410,22 @@ static struct PyGetSetDef cms_profile_getsetters[] = {
};

static PyTypeObject CmsProfile_Type = {
PyVarObject_HEAD_INIT(NULL, 0) "PIL.ImageCms.core.CmsProfile", /*tp_name*/
sizeof(CmsProfileObject), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
(destructor)cms_profile_dealloc, /*tp_dealloc*/
0, /*tp_vectorcall_offset*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_as_async*/
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*/
PyVarObject_HEAD_INIT(NULL, 0).tp_name = "PIL.ImageCms.core.CmsProfile",
.tp_basicsize = sizeof(CmsProfileObject),
.tp_dealloc = (destructor)cms_profile_dealloc,
.tp_methods = cms_profile_methods,
.tp_getset = cms_profile_getsetters,
};

static struct PyMethodDef cms_transform_methods[] = {
{"apply", (PyCFunction)cms_transform_apply, 1}, {NULL, NULL} /* sentinel */
};

static PyTypeObject CmsTransform_Type = {
PyVarObject_HEAD_INIT(NULL, 0) "PIL.ImageCms.core.CmsTransform", /*tp_name*/
sizeof(CmsTransformObject), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
(destructor)cms_transform_dealloc, /*tp_dealloc*/
0, /*tp_vectorcall_offset*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_as_async*/
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*/
0, /*tp_getset*/
PyVarObject_HEAD_INIT(NULL, 0).tp_name = "PIL.ImageCms.core.CmsTransform",
.tp_basicsize = sizeof(CmsTransformObject),
.tp_dealloc = (destructor)cms_transform_dealloc,
.tp_methods = cms_transform_methods,
};

static int
Expand Down
35 changes: 5 additions & 30 deletions src/_imagingft.c
Original file line number Diff line number Diff line change
Expand Up @@ -1518,36 +1518,11 @@ static struct PyGetSetDef font_getsetters[] = {
};

static PyTypeObject Font_Type = {
PyVarObject_HEAD_INIT(NULL, 0) "Font", /*tp_name*/
sizeof(FontObject), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
(destructor)font_dealloc, /*tp_dealloc*/
0, /*tp_vectorcall_offset*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_as_async*/
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*/
PyVarObject_HEAD_INIT(NULL, 0).tp_name = "Font",
.tp_basicsize = sizeof(FontObject),
.tp_dealloc = (destructor)font_dealloc,
.tp_methods = font_methods,
.tp_getset = font_getsetters,
};

static PyMethodDef _functions[] = {
Expand Down
68 changes: 8 additions & 60 deletions src/_webp.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,36 +530,10 @@ static struct PyMethodDef _anim_encoder_methods[] = {

// WebPAnimEncoder type definition
static PyTypeObject WebPAnimEncoder_Type = {
PyVarObject_HEAD_INIT(NULL, 0) "WebPAnimEncoder", /*tp_name */
sizeof(WebPAnimEncoderObject), /*tp_basicsize */
0, /*tp_itemsize */
/* methods */
(destructor)_anim_encoder_dealloc, /*tp_dealloc*/
0, /*tp_vectorcall_offset*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_as_async*/
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*/
_anim_encoder_methods, /*tp_methods*/
0, /*tp_members*/
0, /*tp_getset*/
PyVarObject_HEAD_INIT(NULL, 0).tp_name = "WebPAnimEncoder",
.tp_basicsize = sizeof(WebPAnimEncoderObject),
.tp_dealloc = (destructor)_anim_encoder_dealloc,
.tp_methods = _anim_encoder_methods,
};

// WebPAnimDecoder methods
Expand All @@ -573,36 +547,10 @@ static struct PyMethodDef _anim_decoder_methods[] = {

// WebPAnimDecoder type definition
static PyTypeObject WebPAnimDecoder_Type = {
PyVarObject_HEAD_INIT(NULL, 0) "WebPAnimDecoder", /*tp_name */
sizeof(WebPAnimDecoderObject), /*tp_basicsize */
0, /*tp_itemsize */
/* methods */
(destructor)_anim_decoder_dealloc, /*tp_dealloc*/
0, /*tp_vectorcall_offset*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_as_async*/
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*/
_anim_decoder_methods, /*tp_methods*/
0, /*tp_members*/
0, /*tp_getset*/
PyVarObject_HEAD_INIT(NULL, 0).tp_name = "WebPAnimDecoder",
.tp_basicsize = sizeof(WebPAnimDecoderObject),
.tp_dealloc = (destructor)_anim_decoder_dealloc,
.tp_methods = _anim_decoder_methods,
};

/* -------------------------------------------------------------------- */
Expand Down
35 changes: 5 additions & 30 deletions src/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,36 +256,11 @@ static struct PyGetSetDef getseters[] = {
};

static PyTypeObject ImagingDecoderType = {
PyVarObject_HEAD_INIT(NULL, 0) "ImagingDecoder", /*tp_name*/
sizeof(ImagingDecoderObject), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
(destructor)_dealloc, /*tp_dealloc*/
0, /*tp_vectorcall_offset*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_as_async*/
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*/
getseters, /*tp_getset*/
PyVarObject_HEAD_INIT(NULL, 0).tp_name = "ImagingDecoder",
.tp_basicsize = sizeof(ImagingDecoderObject),
.tp_dealloc = (destructor)_dealloc,
.tp_methods = methods,
.tp_getset = getseters,
};

/* -------------------------------------------------------------------- */
Expand Down
Loading
Loading