Skip to content

Commit 78ea13a

Browse files
authored
record: Compactify the code by using designated initializers (#321)
1 parent 2624bdb commit 78ea13a

File tree

1 file changed

+40
-126
lines changed

1 file changed

+40
-126
lines changed

asyncpg/protocol/record/recordobj.c

Lines changed: 40 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -512,45 +512,21 @@ static PyMethodDef record_methods[] = {
512512

513513
PyTypeObject ApgRecord_Type = {
514514
PyVarObject_HEAD_INIT(NULL, 0)
515-
"asyncpg.Record", /* tp_name */
516-
sizeof(ApgRecordObject) - sizeof(PyObject *), /* tp_basic_size */
517-
sizeof(PyObject *), /* tp_itemsize */
518-
(destructor)record_dealloc, /* tp_dealloc */
519-
0, /* tp_print */
520-
0, /* tp_getattr */
521-
0, /* tp_setattr */
522-
0, /* tp_reserved */
523-
(reprfunc)record_repr, /* tp_repr */
524-
0, /* tp_as_number */
525-
&record_as_sequence, /* tp_as_sequence */
526-
&record_as_mapping, /* tp_as_mapping */
527-
(hashfunc)record_hash, /* tp_hash */
528-
0, /* tp_call */
529-
0, /* tp_str */
530-
PyObject_GenericGetAttr, /* tp_getattro */
531-
0, /* tp_setattro */
532-
0, /* tp_as_buffer */
533-
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
534-
Py_TPFLAGS_BASETYPE, /* tp_flags */
535-
0, /* tp_doc */
536-
(traverseproc)record_traverse, /* tp_traverse */
537-
0, /* tp_clear */
538-
record_richcompare, /* tp_richcompare */
539-
0, /* tp_weaklistoffset */
540-
record_iter, /* tp_iter */
541-
0, /* tp_iternext */
542-
record_methods, /* tp_methods */
543-
0, /* tp_members */
544-
0, /* tp_getset */
545-
0, /* tp_base */
546-
0, /* tp_dict */
547-
0, /* tp_descr_get */
548-
0, /* tp_descr_set */
549-
0, /* tp_dictoffset */
550-
0, /* tp_init */
551-
0, /* tp_alloc */
552-
0, /* tp_new */
553-
PyObject_GC_Del, /* tp_free */
515+
.tp_name = "asyncpg.Record",
516+
.tp_basicsize = sizeof(ApgRecordObject) - sizeof(PyObject *),
517+
.tp_itemsize = sizeof(PyObject *),
518+
.tp_dealloc = (destructor)record_dealloc,
519+
.tp_repr = (reprfunc)record_repr,
520+
.tp_as_sequence = &record_as_sequence,
521+
.tp_as_mapping = &record_as_mapping,
522+
.tp_hash = (hashfunc)record_hash,
523+
.tp_getattro = PyObject_GenericGetAttr,
524+
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,
525+
.tp_traverse = (traverseproc)record_traverse,
526+
.tp_richcompare = record_richcompare,
527+
.tp_iter = record_iter,
528+
.tp_methods = record_methods,
529+
.tp_free = PyObject_GC_Del,
554530
};
555531

556532

@@ -630,35 +606,15 @@ static PyMethodDef record_iter_methods[] = {
630606

631607
PyTypeObject ApgRecordIter_Type = {
632608
PyVarObject_HEAD_INIT(NULL, 0)
633-
"RecordIterator", /* tp_name */
634-
sizeof(ApgRecordIterObject), /* tp_basicsize */
635-
0, /* tp_itemsize */
636-
/* methods */
637-
(destructor)record_iter_dealloc, /* tp_dealloc */
638-
0, /* tp_print */
639-
0, /* tp_getattr */
640-
0, /* tp_setattr */
641-
0, /* tp_reserved */
642-
0, /* tp_repr */
643-
0, /* tp_as_number */
644-
0, /* tp_as_sequence */
645-
0, /* tp_as_mapping */
646-
0, /* tp_hash */
647-
0, /* tp_call */
648-
0, /* tp_str */
649-
PyObject_GenericGetAttr, /* tp_getattro */
650-
0, /* tp_setattro */
651-
0, /* tp_as_buffer */
652-
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
653-
0, /* tp_doc */
654-
(traverseproc)record_iter_traverse, /* tp_traverse */
655-
0, /* tp_clear */
656-
0, /* tp_richcompare */
657-
0, /* tp_weaklistoffset */
658-
PyObject_SelfIter, /* tp_iter */
659-
(iternextfunc)record_iter_next, /* tp_iternext */
660-
record_iter_methods, /* tp_methods */
661-
0,
609+
.tp_name = "RecordIterator",
610+
.tp_basicsize = sizeof(ApgRecordIterObject),
611+
.tp_dealloc = (destructor)record_iter_dealloc,
612+
.tp_getattro = PyObject_GenericGetAttr,
613+
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
614+
.tp_traverse = (traverseproc)record_iter_traverse,
615+
.tp_iter = PyObject_SelfIter,
616+
.tp_iternext = (iternextfunc)record_iter_next,
617+
.tp_methods = record_iter_methods,
662618
};
663619

664620

@@ -787,35 +743,15 @@ static PyMethodDef record_items_methods[] = {
787743

788744
PyTypeObject ApgRecordItems_Type = {
789745
PyVarObject_HEAD_INIT(NULL, 0)
790-
"RecordItemsIterator", /* tp_name */
791-
sizeof(ApgRecordItemsObject), /* tp_basicsize */
792-
0, /* tp_itemsize */
793-
/* methods */
794-
(destructor)record_items_dealloc, /* tp_dealloc */
795-
0, /* tp_print */
796-
0, /* tp_getattr */
797-
0, /* tp_setattr */
798-
0, /* tp_reserved */
799-
0, /* tp_repr */
800-
0, /* tp_as_number */
801-
0, /* tp_as_sequence */
802-
0, /* tp_as_mapping */
803-
0, /* tp_hash */
804-
0, /* tp_call */
805-
0, /* tp_str */
806-
PyObject_GenericGetAttr, /* tp_getattro */
807-
0, /* tp_setattro */
808-
0, /* tp_as_buffer */
809-
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
810-
0, /* tp_doc */
811-
(traverseproc)record_items_traverse, /* tp_traverse */
812-
0, /* tp_clear */
813-
0, /* tp_richcompare */
814-
0, /* tp_weaklistoffset */
815-
PyObject_SelfIter, /* tp_iter */
816-
(iternextfunc)record_items_next, /* tp_iternext */
817-
record_items_methods, /* tp_methods */
818-
0,
746+
.tp_name = "RecordItemsIterator",
747+
.tp_basicsize = sizeof(ApgRecordItemsObject),
748+
.tp_dealloc = (destructor)record_items_dealloc,
749+
.tp_getattro = PyObject_GenericGetAttr,
750+
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
751+
.tp_traverse = (traverseproc)record_items_traverse,
752+
.tp_iter = PyObject_SelfIter,
753+
.tp_iternext = (iternextfunc)record_items_next,
754+
.tp_methods = record_items_methods,
819755
};
820756

821757

@@ -896,35 +832,13 @@ record_desc_traverse(ApgRecordDescObject *o, visitproc visit, void *arg)
896832

897833
PyTypeObject ApgRecordDesc_Type = {
898834
PyVarObject_HEAD_INIT(NULL, 0)
899-
"RecordDescriptor", /* tp_name */
900-
sizeof(ApgRecordDescObject), /* tp_basicsize */
901-
0, /* tp_itemsize */
902-
/* methods */
903-
(destructor)record_desc_dealloc, /* tp_dealloc */
904-
0, /* tp_print */
905-
0, /* tp_getattr */
906-
0, /* tp_setattr */
907-
0, /* tp_reserved */
908-
0, /* tp_repr */
909-
0, /* tp_as_number */
910-
0, /* tp_as_sequence */
911-
0, /* tp_as_mapping */
912-
0, /* tp_hash */
913-
0, /* tp_call */
914-
0, /* tp_str */
915-
PyObject_GenericGetAttr, /* tp_getattro */
916-
0, /* tp_setattro */
917-
0, /* tp_as_buffer */
918-
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
919-
0, /* tp_doc */
920-
(traverseproc)record_desc_traverse, /* tp_traverse */
921-
0, /* tp_clear */
922-
0, /* tp_richcompare */
923-
0, /* tp_weaklistoffset */
924-
PyObject_SelfIter, /* tp_iter */
925-
0, /* tp_iternext */
926-
0, /* tp_methods */
927-
0,
835+
.tp_name = "RecordDescriptor",
836+
.tp_basicsize = sizeof(ApgRecordDescObject),
837+
.tp_dealloc = (destructor)record_desc_dealloc,
838+
.tp_getattro = PyObject_GenericGetAttr,
839+
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
840+
.tp_traverse = (traverseproc)record_desc_traverse,
841+
.tp_iter = PyObject_SelfIter,
928842
};
929843

930844

0 commit comments

Comments
 (0)