From f2d60d6a4ebbbbf7eea967781d2bb4482ac0bc96 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 14 Jul 2024 13:29:10 +0530 Subject: [PATCH] Use Python's builtin machinery to prevent creation of Line objects --- kitty/line.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/kitty/line.c b/kitty/line.c index 66b6b4793..29d89bd43 100644 --- a/kitty/line.c +++ b/kitty/line.c @@ -13,12 +13,6 @@ extern PyTypeObject Cursor_Type; -static PyObject * -new_line_object(PyTypeObject UNUSED *type, PyObject UNUSED *args, PyObject UNUSED *kwds) { - PyErr_SetString(PyExc_TypeError, "Line objects cannot be instantiated directly, create them using LineBuf.line()"); - return NULL; -} - static void dealloc(Line* self) { if (self->needs_free) { @@ -976,13 +970,10 @@ PyTypeObject Line_Type = { .tp_richcompare = richcmp, .tp_doc = "Lines", .tp_methods = methods, - .tp_new = new_line_object }; Line *alloc_line(void) { - Line *ans = (Line*)PyType_GenericAlloc(&Line_Type, 0); - ans->needs_free = 0; - return ans; + return (Line*)Line_Type.tp_alloc(&Line_Type, 0); } RICHCMP(Line)