diff --git a/src_c/rect.c b/src_c/rect.c index 0cdafa263e..48d793cc4e 100644 --- a/src_c/rect.c +++ b/src_c/rect.c @@ -152,6 +152,7 @@ four_floats_from_obj(PyObject *obj, float *val1, float *val2, float *val3, #define RectImport_TypeObject pgRect_Type #define RectImport_IntersectRectAndLine SDL_IntersectRectAndLine #define RectImport_PyBuildValueFormat "i" +#define RectImport_TupleFromTwoPrimitives pg_tuple_couple_from_values_int #define RectImport_ObjectName "pygame.rect.Rect" #define RectImport_PythonNumberCheck PyLong_Check #define RectImport_PythonNumberAsPrimitiveType PyLong_AsLong @@ -268,6 +269,7 @@ four_floats_from_obj(PyObject *obj, float *val1, float *val2, float *val3, #define RectImport_IntersectRectAndLine PG_IntersectFRectAndLine #define RectImport_TypeObject pgFRect_Type #define RectImport_PyBuildValueFormat "f" +#define RectImport_TupleFromTwoPrimitives pg_tuple_couple_from_values_double #define RectImport_ObjectName "pygame.rect.FRect" #define RectImport_PythonNumberCheck PyFloat_Check #define RectImport_PythonNumberAsPrimitiveType PyFloat_AsDouble diff --git a/src_c/rect_impl.h b/src_c/rect_impl.h index db031fe342..99afafeeb3 100644 --- a/src_c/rect_impl.h +++ b/src_c/rect_impl.h @@ -359,6 +359,9 @@ #ifndef RectImport_PyBuildValueFormat #error RectImport_PyBuildValueFormat needs to be defined #endif +#ifndef RectImport_TupleFromTwoPrimitives +#error RectImport_TupleFromTwoPrimitives needs to be defined +#endif // #endregion // #region RectOptional @@ -399,6 +402,7 @@ #define fourPrimivitesFromObj RectImport_fourPrimiviteFromObj #define PrimitiveFromObj RectImport_PrimitiveFromObj #define TypeFMT RectImport_PyBuildValueFormat +#define TupleFromTwoPrimitives RectImport_TupleFromTwoPrimitives #define ObjectName RectImport_ObjectName #define PythonNumberCheck RectImport_PythonNumberCheck #define PythonNumberAsPrimitiveType RectImport_PythonNumberAsPrimitiveType @@ -1915,8 +1919,29 @@ RectExport_clipline(RectObject *self, PyObject *const *args, Py_ssize_t nargs) } Py_XDECREF(rect_copy); - return Py_BuildValue("((" TypeFMT "" TypeFMT ")(" TypeFMT "" TypeFMT "))", - x1, y1, x2, y2); + + PyObject *subtup1, *subtup2; + subtup1 = TupleFromTwoPrimitives(x1, y1); + if (!subtup1) + return NULL; + + subtup2 = TupleFromTwoPrimitives(x2, y2); + if (!subtup2) { + Py_DECREF(subtup1); + return NULL; + } + + PyObject *tup = PyTuple_New(2); + if (!tup) { + Py_DECREF(subtup1); + Py_DECREF(subtup2); + return NULL; + } + + PyTuple_SET_ITEM(tup, 0, subtup1); + PyTuple_SET_ITEM(tup, 1, subtup2); + + return tup; } static int @@ -2964,6 +2989,7 @@ RectExport_iterator(RectObject *self) #undef RectImport_TypeObject #undef RectImport_PrimitiveFromObj #undef RectImport_PyBuildValueFormat +#undef RectImport_TupleFromTwoPrimitives #undef RectImport_ObjectName #undef PrimitiveType