Skip to content

Commit aff38d3

Browse files
committed
_csv.Dialect AC vectorcall
1 parent 1cc5802 commit aff38d3

2 files changed

Lines changed: 220 additions & 45 deletions

File tree

‎Modules/_csv.c‎

Lines changed: 26 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -457,19 +457,6 @@ Dialect_dealloc(PyObject *self)
457457
Py_DECREF(tp);
458458
}
459459

460-
static char *dialect_kws[] = {
461-
"dialect",
462-
"delimiter",
463-
"doublequote",
464-
"escapechar",
465-
"lineterminator",
466-
"quotechar",
467-
"quoting",
468-
"skipinitialspace",
469-
"strict",
470-
NULL
471-
};
472-
473460
static _csvstate *
474461
_csv_state_from_type(PyTypeObject *type, const char *name)
475462
{
@@ -486,33 +473,31 @@ _csv_state_from_type(PyTypeObject *type, const char *name)
486473
return module_state;
487474
}
488475

476+
/*[clinic input]
477+
@vectorcall
478+
@classmethod
479+
_csv.Dialect.__new__ as dialect_new
480+
dialect: object(c_default="NULL") = None
481+
delimiter: object(c_default="NULL") = None
482+
doublequote: object(c_default="NULL") = None
483+
escapechar: object(c_default="NULL") = None
484+
lineterminator: object(c_default="NULL") = None
485+
quotechar: object(c_default="NULL") = None
486+
quoting: object(c_default="NULL") = None
487+
skipinitialspace: object(c_default="NULL") = None
488+
strict: object(c_default="NULL") = None
489+
[clinic start generated code]*/
490+
489491
static PyObject *
490-
dialect_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
492+
dialect_new_impl(PyTypeObject *type, PyObject *dialect, PyObject *delimiter,
493+
PyObject *doublequote, PyObject *escapechar,
494+
PyObject *lineterminator, PyObject *quotechar,
495+
PyObject *quoting, PyObject *skipinitialspace,
496+
PyObject *strict)
497+
/*[clinic end generated code: output=123393bdc71ddaa6 input=a9977678df813ece]*/
491498
{
492499
DialectObj *self;
493500
PyObject *ret = NULL;
494-
PyObject *dialect = NULL;
495-
PyObject *delimiter = NULL;
496-
PyObject *doublequote = NULL;
497-
PyObject *escapechar = NULL;
498-
PyObject *lineterminator = NULL;
499-
PyObject *quotechar = NULL;
500-
PyObject *quoting = NULL;
501-
PyObject *skipinitialspace = NULL;
502-
PyObject *strict = NULL;
503-
504-
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
505-
"|OOOOOOOOO", dialect_kws,
506-
&dialect,
507-
&delimiter,
508-
&doublequote,
509-
&escapechar,
510-
&lineterminator,
511-
&quotechar,
512-
&quoting,
513-
&skipinitialspace,
514-
&strict))
515-
return NULL;
516501

517502
_csvstate *module_state = _csv_state_from_type(type, "dialect_new");
518503
if (module_state == NULL) {
@@ -676,13 +661,10 @@ static PyObject *
676661
_csv_Dialect___replace___impl(DialectObj *self, PyObject *changes)
677662
/*[clinic end generated code: output=8f692c2c63a61b50 input=154beb565fbabd4c]*/
678663
{
679-
PyObject *newargs = PyTuple_Pack(1, self);
680-
if (newargs == NULL) {
681-
return NULL;
682-
}
683-
PyObject *result = dialect_new(Py_TYPE(self), newargs, changes);
684-
Py_DECREF(newargs);
685-
return result;
664+
PyObject *const args[1] = {(PyObject *)self};
665+
return dialect_new_helper(Py_TYPE(self), args, 1,
666+
changes ? PyDict_GET_SIZE(changes) : 0,
667+
changes, NULL);
686668
}
687669

688670
static struct PyMethodDef dialect_methods[] = {
@@ -719,6 +701,7 @@ static PyType_Slot Dialect_Type_slots[] = {
719701
{Py_tp_members, Dialect_memberlist},
720702
{Py_tp_getset, Dialect_getsetlist},
721703
{Py_tp_new, dialect_new},
704+
{Py_tp_vectorcall, dialect_vectorcall},
722705
{Py_tp_methods, dialect_methods},
723706
{Py_tp_dealloc, Dialect_dealloc},
724707
{Py_tp_clear, Dialect_clear},

‎Modules/clinic/_csv.c.h‎

Lines changed: 194 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)