Use Python's builtin machinery to prevent creation of Line objects

This commit is contained in:
Kovid Goyal 2024-07-14 13:29:10 +05:30
parent 8f2b722dd7
commit f2d60d6a4e
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C

View file

@ -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)