diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-07-26 10:21:09 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-26 10:21:09 (GMT) |
commit | 323748ad7446c76972c80dbbf510534dc5c22ae8 (patch) | |
tree | 8151ef98065a3679e845bbf386a1c3f14c099ea7 /Modules/_csv.c | |
parent | ecf411c59e33d3760dbfebf6d5b4b205bcc29d5a (diff) | |
download | cpython-323748ad7446c76972c80dbbf510534dc5c22ae8.zip cpython-323748ad7446c76972c80dbbf510534dc5c22ae8.tar.gz cpython-323748ad7446c76972c80dbbf510534dc5c22ae8.tar.bz2 |
bpo-34197: Make _csv.Dialect attributes booleans. (GH-8440)
Attributes skipinitialspace, doublequote and strict are now
booleans instead of integers 0 or 1.
Diffstat (limited to 'Modules/_csv.c')
-rw-r--r-- | Modules/_csv.c | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/Modules/_csv.c b/Modules/_csv.c index 610f7bb..f58538c 100644 --- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -12,6 +12,7 @@ module instead. #include "Python.h" #include "structmember.h" +#include <stdbool.h> typedef struct { @@ -74,15 +75,15 @@ static const StyleDesc quote_styles[] = { typedef struct { PyObject_HEAD - int doublequote; /* is " represented by ""? */ - Py_UCS4 delimiter; /* field separator */ - Py_UCS4 quotechar; /* quote character */ - Py_UCS4 escapechar; /* escape character */ - int skipinitialspace; /* ignore spaces following delimiter? */ - PyObject *lineterminator; /* string to write between records */ + char doublequote; /* is " represented by ""? */ + char skipinitialspace; /* ignore spaces following delimiter? */ + char strict; /* raise exception on bad CSV */ int quoting; /* style of quoting to write */ + Py_UCS4 delimiter; /* field separator */ + Py_UCS4 quotechar; /* quote character */ + Py_UCS4 escapechar; /* escape character */ + PyObject *lineterminator; /* string to write between records */ - int strict; /* raise exception on bad CSV */ } DialectObj; static PyTypeObject Dialect_Type; @@ -189,7 +190,7 @@ Dialect_get_quoting(DialectObj *self) } static int -_set_bool(const char *name, int *target, PyObject *src, int dflt) +_set_bool(const char *name, char *target, PyObject *src, bool dflt) { if (src == NULL) *target = dflt; @@ -197,7 +198,7 @@ _set_bool(const char *name, int *target, PyObject *src, int dflt) int b = PyObject_IsTrue(src); if (b < 0) return -1; - *target = b; + *target = (char)b; } return 0; } @@ -292,9 +293,9 @@ dialect_check_quoting(int quoting) #define D_OFF(x) offsetof(DialectObj, x) static struct PyMemberDef Dialect_memberlist[] = { - { "skipinitialspace", T_INT, D_OFF(skipinitialspace), READONLY }, - { "doublequote", T_INT, D_OFF(doublequote), READONLY }, - { "strict", T_INT, D_OFF(strict), READONLY }, + { "skipinitialspace", T_BOOL, D_OFF(skipinitialspace), READONLY }, + { "doublequote", T_BOOL, D_OFF(doublequote), READONLY }, + { "strict", T_BOOL, D_OFF(strict), READONLY }, { NULL } }; @@ -411,13 +412,13 @@ dialect_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) if (meth(name, target, src, dflt)) \ goto err DIASET(_set_char, "delimiter", &self->delimiter, delimiter, ','); - DIASET(_set_bool, "doublequote", &self->doublequote, doublequote, 1); + DIASET(_set_bool, "doublequote", &self->doublequote, doublequote, true); DIASET(_set_char, "escapechar", &self->escapechar, escapechar, 0); DIASET(_set_str, "lineterminator", &self->lineterminator, lineterminator, "\r\n"); DIASET(_set_char, "quotechar", &self->quotechar, quotechar, '"'); DIASET(_set_int, "quoting", &self->quoting, quoting, QUOTE_MINIMAL); - DIASET(_set_bool, "skipinitialspace", &self->skipinitialspace, skipinitialspace, 0); - DIASET(_set_bool, "strict", &self->strict, strict, 0); + DIASET(_set_bool, "skipinitialspace", &self->skipinitialspace, skipinitialspace, false); + DIASET(_set_bool, "strict", &self->strict, strict, false); /* validate options */ if (dialect_check_quoting(self->quoting)) |