Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 37d2bdf

Browse files
committed
Where a string is desired, test for PyBaseString_Type derived type,
rather than using PyString_Check/PyUnicode_Check.
1 parent 9fa0946 commit 37d2bdf

1 file changed

Lines changed: 6 additions & 15 deletions

File tree

Modules/_csv.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ module instead.
3939
#endif
4040
/* end 2.2 compatibility macros */
4141

42+
#define IS_BASESTRING(o) \
43+
PyObject_TypeCheck(o, &PyBaseString_Type)
44+
4245
static PyObject *error_obj; /* CSV exception */
4346
static PyObject *dialects; /* Dialect registry */
4447

@@ -230,11 +233,7 @@ _set_str(const char *name, PyObject **target, PyObject *src, const char *dflt)
230233
else {
231234
if (src == Py_None)
232235
*target = NULL;
233-
else if (!PyString_Check(src)
234-
#ifdef Py_USING_UNICODE
235-
&& !PyUnicode_Check(src)
236-
#endif
237-
) {
236+
else if (!IS_BASESTRING(src)) {
238237
PyErr_Format(PyExc_TypeError,
239238
"\"%s\" must be an string", name);
240239
return -1;
@@ -298,11 +297,7 @@ dialect_instantiate(PyObject *dialect)
298297
{
299298
Py_INCREF(dialect);
300299
/* If dialect is a string, look it up in our registry */
301-
if (PyString_Check(dialect)
302-
#ifdef Py_USING_UNICODE
303-
|| PyUnicode_Check(dialect)
304-
#endif
305-
) {
300+
if (IS_BASESTRING(dialect)) {
306301
PyObject * new_dia;
307302
new_dia = get_dialect_from_registry(dialect);
308303
Py_DECREF(dialect);
@@ -1372,11 +1367,7 @@ csv_register_dialect(PyObject *module, PyObject *args)
13721367

13731368
if (!PyArg_UnpackTuple(args, "", 2, 2, &name_obj, &dialect_obj))
13741369
return NULL;
1375-
if (!PyString_Check(name_obj)
1376-
#ifdef Py_USING_UNICODE
1377-
&& !PyUnicode_Check(name_obj)
1378-
#endif
1379-
) {
1370+
if (!IS_BASESTRING(name_obj)) {
13801371
PyErr_SetString(PyExc_TypeError,
13811372
"dialect name must be a string or unicode");
13821373
return NULL;

0 commit comments

Comments
 (0)