[Python-checkins] bpo-46670: Define all macros for stringlib (GH-31176)

vstinner webhook-mailer at python.org
Sun Feb 6 19:27:02 EST 2022


https://github.com/python/cpython/commit/097f74a5a37e2a8a26d529cede456ede7011b66f
commit: 097f74a5a37e2a8a26d529cede456ede7011b66f
branch: main
author: Victor Stinner <vstinner at python.org>
committer: vstinner <vstinner at python.org>
date: 2022-02-07T01:26:58+01:00
summary:

bpo-46670: Define all macros for stringlib (GH-31176)

bytesobject.c, bytearrayobject.c and unicodeobject.c now define all
macros used by stringlib, to avoid using undefined macros.
Fix "gcc -Wundef" warnings.

files:
M Objects/bytearrayobject.c
M Objects/bytesobject.c
M Objects/stringlib/asciilib.h
M Objects/stringlib/join.h
M Objects/stringlib/split.h
M Objects/stringlib/ucs1lib.h
M Objects/stringlib/ucs2lib.h
M Objects/stringlib/ucs4lib.h
M Objects/stringlib/undef.h
M Objects/stringlib/unicodedefs.h

diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index a6009854221ff..8fce83dbfb50b 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -1074,6 +1074,7 @@ bytearray_dealloc(PyByteArrayObject *self)
 /* -------------------------------------------------------------------- */
 /* Methods */
 
+#define STRINGLIB_IS_UNICODE 0
 #define FASTSEARCH fastsearch
 #define STRINGLIB(F) stringlib_##F
 #define STRINGLIB_CHAR char
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index b6edfb9acb2db..cfc358f4deba2 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -1235,6 +1235,7 @@ PyBytes_AsStringAndSize(PyObject *obj,
 #define STRINGLIB_GET_EMPTY() bytes_get_empty()
 
 #include "stringlib/stringdefs.h"
+#define STRINGLIB_MUTABLE 0
 
 #include "stringlib/fastsearch.h"
 #include "stringlib/count.h"
diff --git a/Objects/stringlib/asciilib.h b/Objects/stringlib/asciilib.h
index 7749e8fb33982..eebe888e411e0 100644
--- a/Objects/stringlib/asciilib.h
+++ b/Objects/stringlib/asciilib.h
@@ -20,6 +20,7 @@
 #define STRINGLIB_NEW(STR,LEN)   _PyUnicode_FromASCII((const char*)(STR),(LEN))
 #define STRINGLIB_CHECK          PyUnicode_Check
 #define STRINGLIB_CHECK_EXACT    PyUnicode_CheckExact
+#define STRINGLIB_MUTABLE 0
 
 #define STRINGLIB_TOSTR          PyObject_Str
 #define STRINGLIB_TOASCII        PyObject_ASCII
diff --git a/Objects/stringlib/join.h b/Objects/stringlib/join.h
index 62e4c98de7f25..bb011f7db796d 100644
--- a/Objects/stringlib/join.h
+++ b/Objects/stringlib/join.h
@@ -32,7 +32,7 @@ STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable)
         Py_DECREF(seq);
         return STRINGLIB_NEW(NULL, 0);
     }
-#ifndef STRINGLIB_MUTABLE
+#if !STRINGLIB_MUTABLE
     if (seqlen == 1) {
         item = PySequence_Fast_GET_ITEM(seq, 0);
         if (STRINGLIB_CHECK_EXACT(item)) {
diff --git a/Objects/stringlib/split.h b/Objects/stringlib/split.h
index 068047f9874a0..0c11b7214e9b0 100644
--- a/Objects/stringlib/split.h
+++ b/Objects/stringlib/split.h
@@ -70,7 +70,7 @@ STRINGLIB(split_whitespace)(PyObject* str_obj,
         j = i; i++;
         while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
             i++;
-#ifndef STRINGLIB_MUTABLE
+#if !STRINGLIB_MUTABLE
         if (j == 0 && i == str_len && STRINGLIB_CHECK_EXACT(str_obj)) {
             /* No whitespace in str_obj, so just use it as list[0] */
             Py_INCREF(str_obj);
@@ -122,7 +122,7 @@ STRINGLIB(split_char)(PyObject* str_obj,
             }
         }
     }
-#ifndef STRINGLIB_MUTABLE
+#if !STRINGLIB_MUTABLE
     if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
         /* ch not in str_obj, so just use str_obj as list[0] */
         Py_INCREF(str_obj);
@@ -170,7 +170,7 @@ STRINGLIB(split)(PyObject* str_obj,
         SPLIT_ADD(str, i, j);
         i = j + sep_len;
     }
-#ifndef STRINGLIB_MUTABLE
+#if !STRINGLIB_MUTABLE
     if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
         /* No match in str_obj, so just use it as list[0] */
         Py_INCREF(str_obj);
@@ -209,7 +209,7 @@ STRINGLIB(rsplit_whitespace)(PyObject* str_obj,
         j = i; i--;
         while (i >= 0 && !STRINGLIB_ISSPACE(str[i]))
             i--;
-#ifndef STRINGLIB_MUTABLE
+#if !STRINGLIB_MUTABLE
         if (j == str_len - 1 && i < 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
             /* No whitespace in str_obj, so just use it as list[0] */
             Py_INCREF(str_obj);
@@ -262,7 +262,7 @@ STRINGLIB(rsplit_char)(PyObject* str_obj,
             }
         }
     }
-#ifndef STRINGLIB_MUTABLE
+#if !STRINGLIB_MUTABLE
     if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
         /* ch not in str_obj, so just use str_obj as list[0] */
         Py_INCREF(str_obj);
@@ -311,7 +311,7 @@ STRINGLIB(rsplit)(PyObject* str_obj,
         SPLIT_ADD(str, pos + sep_len, j);
         j = pos;
     }
-#ifndef STRINGLIB_MUTABLE
+#if !STRINGLIB_MUTABLE
     if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
         /* No match in str_obj, so just use it as list[0] */
         Py_INCREF(str_obj);
@@ -370,7 +370,7 @@ STRINGLIB(splitlines)(PyObject* str_obj,
             if (keepends)
                 eol = i;
         }
-#ifndef STRINGLIB_MUTABLE
+#if !STRINGLIB_MUTABLE
         if (j == 0 && eol == str_len && STRINGLIB_CHECK_EXACT(str_obj)) {
             /* No linebreak in str_obj, so just use it as list[0] */
             if (PyList_Append(list, str_obj))
diff --git a/Objects/stringlib/ucs1lib.h b/Objects/stringlib/ucs1lib.h
index 5b0b8a025e808..026ab11f1f7b8 100644
--- a/Objects/stringlib/ucs1lib.h
+++ b/Objects/stringlib/ucs1lib.h
@@ -20,6 +20,7 @@
 #define STRINGLIB_NEW            _PyUnicode_FromUCS1
 #define STRINGLIB_CHECK          PyUnicode_Check
 #define STRINGLIB_CHECK_EXACT    PyUnicode_CheckExact
+#define STRINGLIB_MUTABLE 0
 
 #define STRINGLIB_TOSTR          PyObject_Str
 #define STRINGLIB_TOASCII        PyObject_ASCII
diff --git a/Objects/stringlib/ucs2lib.h b/Objects/stringlib/ucs2lib.h
index 6af01511c5f8a..75f11bc290508 100644
--- a/Objects/stringlib/ucs2lib.h
+++ b/Objects/stringlib/ucs2lib.h
@@ -20,6 +20,7 @@
 #define STRINGLIB_NEW            _PyUnicode_FromUCS2
 #define STRINGLIB_CHECK          PyUnicode_Check
 #define STRINGLIB_CHECK_EXACT    PyUnicode_CheckExact
+#define STRINGLIB_MUTABLE 0
 
 #define STRINGLIB_TOSTR          PyObject_Str
 #define STRINGLIB_TOASCII        PyObject_ASCII
diff --git a/Objects/stringlib/ucs4lib.h b/Objects/stringlib/ucs4lib.h
index 39071a0cdf0cd..57344f235b659 100644
--- a/Objects/stringlib/ucs4lib.h
+++ b/Objects/stringlib/ucs4lib.h
@@ -20,6 +20,7 @@
 #define STRINGLIB_NEW            _PyUnicode_FromUCS4
 #define STRINGLIB_CHECK          PyUnicode_Check
 #define STRINGLIB_CHECK_EXACT    PyUnicode_CheckExact
+#define STRINGLIB_MUTABLE 0
 
 #define STRINGLIB_TOSTR          PyObject_Str
 #define STRINGLIB_TOASCII        PyObject_ASCII
diff --git a/Objects/stringlib/undef.h b/Objects/stringlib/undef.h
index c41e254fde6f4..bf32298505ed7 100644
--- a/Objects/stringlib/undef.h
+++ b/Objects/stringlib/undef.h
@@ -1,10 +1,10 @@
-#undef  FASTSEARCH
-#undef  STRINGLIB
-#undef  STRINGLIB_SIZEOF_CHAR
-#undef  STRINGLIB_MAX_CHAR
-#undef  STRINGLIB_CHAR
-#undef  STRINGLIB_STR
-#undef  STRINGLIB_LEN
-#undef  STRINGLIB_NEW
+#undef FASTSEARCH
+#undef STRINGLIB
+#undef STRINGLIB_SIZEOF_CHAR
+#undef STRINGLIB_MAX_CHAR
+#undef STRINGLIB_CHAR
+#undef STRINGLIB_STR
+#undef STRINGLIB_LEN
+#undef STRINGLIB_NEW
 #undef STRINGLIB_IS_UNICODE
-
+#undef STRINGLIB_MUTABLE
diff --git a/Objects/stringlib/unicodedefs.h b/Objects/stringlib/unicodedefs.h
index 5ea79cd4f50ac..ba2ce0aeea1cc 100644
--- a/Objects/stringlib/unicodedefs.h
+++ b/Objects/stringlib/unicodedefs.h
@@ -22,6 +22,7 @@
 #define STRINGLIB_NEW            PyUnicode_FromUnicode
 #define STRINGLIB_CHECK          PyUnicode_Check
 #define STRINGLIB_CHECK_EXACT    PyUnicode_CheckExact
+#define STRINGLIB_MUTABLE 0
 
 #define STRINGLIB_TOSTR          PyObject_Str
 #define STRINGLIB_TOASCII        PyObject_ASCII



More information about the Python-checkins mailing list