diff --git a/buildconfig/Setup.SDL1.in b/buildconfig/Setup.SDL1.in index 5ec44cf390..9f2cc98f63 100644 --- a/buildconfig/Setup.SDL1.in +++ b/buildconfig/Setup.SDL1.in @@ -69,4 +69,4 @@ bufferproxy src_c/bufferproxy.c $(SDL) $(DEBUG) pixelarray src_c/pixelarray.c $(SDL) $(DEBUG) math src_c/math.c $(SDL) $(DEBUG) pixelcopy src_c/pixelcopy.c $(SDL) $(DEBUG) -newbuffer src_c/newbuffer.c $(DEBUG) +newbuffer src_c/newbuffer.c $(SDL) $(DEBUG) diff --git a/buildconfig/Setup.SDL2.in b/buildconfig/Setup.SDL2.in index 1e2e825b1c..bfac9a1a64 100644 --- a/buildconfig/Setup.SDL2.in +++ b/buildconfig/Setup.SDL2.in @@ -72,4 +72,4 @@ bufferproxy src_c/bufferproxy.c $(SDL) $(DEBUG) pixelarray src_c/pixelarray.c $(SDL) $(DEBUG) math src_c/math.c $(SDL) $(DEBUG) pixelcopy src_c/pixelcopy.c $(SDL) $(DEBUG) -newbuffer src_c/newbuffer.c $(DEBUG) +newbuffer src_c/newbuffer.c $(SDL) $(DEBUG) diff --git a/src_c/_freetype.c b/src_c/_freetype.c index 9010136242..62d745954b 100644 --- a/src_c/_freetype.c +++ b/src_c/_freetype.c @@ -1115,6 +1115,8 @@ _ftfont_setsize(pgFontObject *self, PyObject *value, void *closure) { Scale_t face_size; + DEL_ATTR_NOT_SUPPORTED_CHECK("size", value); + if (!obj_to_scale(value, &face_size)) goto error; self->face_size = face_size; @@ -1134,9 +1136,13 @@ static int _ftfont_setunderlineadjustment(pgFontObject *self, PyObject *value, void *closure) { - PyObject *adjustmentobj = PyNumber_Float(value); + PyObject *adjustmentobj; double adjustment; + DEL_ATTR_NOT_SUPPORTED_CHECK("underline_adjustment", value); + + adjustmentobj = PyNumber_Float(value); + if (!adjustmentobj) { return -1; } @@ -1236,6 +1242,9 @@ _ftfont_setrender_flag(pgFontObject *self, PyObject *value, void *closure) { const long render_flag = (long)closure; + /* Generic setter; We do not know the name of the attribute */ + DEL_ATTR_NOT_SUPPORTED_CHECK(NULL, value); + if (!PyBool_Check(value)) { PyErr_SetString(PyExc_TypeError, "The style value must be a boolean"); return -1; @@ -1268,6 +1277,9 @@ _ftfont_getrotation(pgFontObject *self, void *closure) static int _ftfont_setrotation(pgFontObject *self, PyObject *value, void *closure) { + + DEL_ATTR_NOT_SUPPORTED_CHECK("rotation", value); + if (!self->is_scalable) { if (pgFont_IS_ALIVE(self)) { PyErr_SetString(PyExc_AttributeError, @@ -1292,6 +1304,9 @@ _ftfont_getfgcolor(pgFontObject *self, void *closure) static int _ftfont_setfgcolor(pgFontObject *self, PyObject *value, void *closure) { + + DEL_ATTR_NOT_SUPPORTED_CHECK("fgcolor", value); + if (!pg_RGBAFromObj(value, self->fgcolor)) { PyErr_Format(PyExc_AttributeError, "unable to convert %128s object to a color", @@ -1310,6 +1325,9 @@ _ftfont_getbgcolor(pgFontObject *self, void *closure) static int _ftfont_setbgcolor(pgFontObject *self, PyObject *value, void *closure) { + + DEL_ATTR_NOT_SUPPORTED_CHECK("bgcolor", value); + if (!pg_RGBAFromObj(value, self->bgcolor)) { PyErr_Format(PyExc_AttributeError, "unable to convert %128s object to a color", diff --git a/src_c/_pygame.h b/src_c/_pygame.h index 5410193f2b..95875f3bfc 100644 --- a/src_c/_pygame.h +++ b/src_c/_pygame.h @@ -148,6 +148,20 @@ typedef enum { #endif /* ~SDL_VERSION_ATLEAST(2, 0, 0) */ #define RAISE(x, y) (PyErr_SetString((x), (y)), (PyObject *)NULL) +#define DEL_ATTR_NOT_SUPPORTED_CHECK(name, value) \ + do { \ + if (!value) { \ + if (name) { \ + PyErr_Format(PyExc_AttributeError, \ + "Cannot delete attribute %s", \ + name); \ + } else { \ + PyErr_SetString(PyExc_AttributeError, \ + "Cannot delete attribute"); \ + } \ + return -1; \ + } \ + } while (0) /* * Initialization checks diff --git a/src_c/color.c b/src_c/color.c index 79d5232bc7..173ef417ce 100644 --- a/src_c/color.c +++ b/src_c/color.c @@ -924,6 +924,9 @@ static int _color_set_r(pgColorObject *color, PyObject *value, void *closure) { Uint32 c; + + DEL_ATTR_NOT_SUPPORTED_CHECK("r", value); + if (!_get_color(value, &c)) { return -1; } @@ -951,6 +954,9 @@ static int _color_set_g(pgColorObject *color, PyObject *value, void *closure) { Uint32 c; + + DEL_ATTR_NOT_SUPPORTED_CHECK("g", value); + if (!_get_color(value, &c)) { return -1; } @@ -978,6 +984,9 @@ static int _color_set_b(pgColorObject *color, PyObject *value, void *closure) { Uint32 c; + + DEL_ATTR_NOT_SUPPORTED_CHECK("b", value); + if (!_get_color(value, &c)) { return -1; } @@ -1005,6 +1014,9 @@ static int _color_set_a(pgColorObject *color, PyObject *value, void *closure) { Uint32 c; + + DEL_ATTR_NOT_SUPPORTED_CHECK("a", value); + if (!_get_color(value, &c)) { return -1; } @@ -1074,6 +1086,9 @@ _color_set_hsva(pgColorObject *color, PyObject *value, void *closure) double f, p, q, t, v, s; int hi; + + DEL_ATTR_NOT_SUPPORTED_CHECK("hsva", value); + if (!PySequence_Check(value) || PySequence_Size(value) < 3) { PyErr_SetString(PyExc_ValueError, "invalid HSVA value"); return -1; @@ -1237,6 +1252,8 @@ _color_set_hsla(pgColorObject *color, PyObject *value, void *closure) double ht, h, q, p = 0, s, l = 0; static double onethird = 1.0 / 3.0f; + DEL_ATTR_NOT_SUPPORTED_CHECK("hsla", value); + if (!PySequence_Check(value) || PySequence_Size(value) < 3) { PyErr_SetString(PyExc_ValueError, "invalid HSLA value"); return -1; @@ -1400,6 +1417,9 @@ _color_set_i1i2i3(pgColorObject *color, PyObject *value, void *closure) double i1i2i3[3] = {0, 0, 0}; double ar, ag, ab; + + DEL_ATTR_NOT_SUPPORTED_CHECK("i1i2i3", value); + /* I1 */ item = PySequence_GetItem(value, 0); if (!item || !_get_double(item, &(i1i2i3[0])) || i1i2i3[0] < 0 || @@ -1465,6 +1485,8 @@ _color_set_cmy(pgColorObject *color, PyObject *value, void *closure) PyObject *item; double cmy[3] = {0, 0, 0}; + DEL_ATTR_NOT_SUPPORTED_CHECK("cmy", value); + /* I1 */ item = PySequence_GetItem(value, 0); if (!item || !_get_double(item, &(cmy[0])) || cmy[0] < 0 || cmy[0] > 1) { diff --git a/src_c/newbuffer.c b/src_c/newbuffer.c index bc8cc9bea3..f72d8ce4eb 100644 --- a/src_c/newbuffer.c +++ b/src_c/newbuffer.c @@ -18,6 +18,7 @@ */ +#include "pygame.h" #include #include "pgcompat.h" @@ -393,6 +394,8 @@ buffer_set_obj(BufferObject *self, PyObject *value, void *closure) { PyObject *tmp; + DEL_ATTR_NOT_SUPPORTED_CHECK("obj", value); + if (check_view_set(self, (const char *)closure)) { return -1; } @@ -428,6 +431,9 @@ buffer_get_buf(BufferObject *self, void *closure) static int buffer_set_buf(BufferObject *self, PyObject *value, void *closure) { + + DEL_ATTR_NOT_SUPPORTED_CHECK("buf", value); + if (check_view_set(self, (const char *)closure)) { return -1; } @@ -446,6 +452,9 @@ buffer_get_len(BufferObject *self, void *closure) static int buffer_set_len(BufferObject *self, PyObject *value, void *closure) { + + DEL_ATTR_NOT_SUPPORTED_CHECK("len", value); + if (check_view_set(self, (const char *)closure)) { return -1; } @@ -466,6 +475,8 @@ buffer_set_readonly(BufferObject *self, PyObject *value, void *closure) { int readonly = 1; + DEL_ATTR_NOT_SUPPORTED_CHECK("readonly", value); + if (check_view_set(self, (const char *)closure)) { return -1; } @@ -497,6 +508,8 @@ buffer_set_format(BufferObject *self, PyObject *value, void *closure) { void *vp = 0; + DEL_ATTR_NOT_SUPPORTED_CHECK("format", value); + if (check_view_set(self, (const char *)closure)) { return -1; } @@ -521,6 +534,8 @@ buffer_set_ndim(BufferObject *self, PyObject *value, void *closure) { Py_ssize_t ndim = 0; + DEL_ATTR_NOT_SUPPORTED_CHECK("mdim", value); + if (check_view_set(self, (const char *)closure)) { return -1; } @@ -548,6 +563,8 @@ buffer_set_shape(BufferObject *self, PyObject *value, void *closure) { void *vp; + DEL_ATTR_NOT_SUPPORTED_CHECK("shape", value); + if (check_view_set(self, (const char *)closure)) { return -1; } @@ -575,6 +592,8 @@ buffer_set_strides(BufferObject *self, PyObject *value, void *closure) { void *vp; + DEL_ATTR_NOT_SUPPORTED_CHECK("strides", value); + if (check_view_set(self, (const char *)closure)) { return -1; } @@ -602,6 +621,8 @@ buffer_set_suboffsets(BufferObject *self, PyObject *value, void *closure) { void *vp; + DEL_ATTR_NOT_SUPPORTED_CHECK("suboffset", value); + if (check_view_set(self, (const char *)closure)) { return -1; } @@ -624,6 +645,8 @@ buffer_get_itemsize(BufferObject *self, void *closure) static int buffer_set_itemsize(BufferObject *self, PyObject *value, void *closure) { + DEL_ATTR_NOT_SUPPORTED_CHECK("itemsize", value); + if (check_view_set(self, (const char *)closure)) { return -1; } @@ -646,6 +669,8 @@ buffer_get_internal(BufferObject *self, void *closure) static int buffer_set_internal(BufferObject *self, PyObject *value, void *closure) { + DEL_ATTR_NOT_SUPPORTED_CHECK("internal", value); + if (check_view_set(self, (const char *)closure)) { return -1; }