Skip to content

Commit be7098d

Browse files
committed
WL#16284: Update the Python Protobuf version
Utilizing an older version than Protobuf 4.25.1 leads to segmentation fault issues as reported in protocolbuffers/protobuf#12047. As a consequence, this work log updates the Python Protobuf version. Change-Id: If3c23a6cd4ff0b0ee0417c333a40ea29d1840968
1 parent c22afa9 commit be7098d

File tree

6 files changed

+91
-29
lines changed

6 files changed

+91
-29
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ v9.0.0
1313

1414
- WL#16350: Update dnspython version
1515
- WL#16318: Deprecate Cursors Prepared Raw and Named Tuple
16+
- WL#16284: Update the Python Protobuf version
1617
- WL#16283: Remove OpenTelemetry Bundled Installation
1718
- BUG#36664998: Packets out of order error is raised while changing user in aio
1819
- BUG#36611371: Update dnspython required versions to allow latest 2.6.1

mysqlx-connector-python/cpydist/__init__.py

Lines changed: 83 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,62 @@
5252

5353
from .utils import ARCH, write_info_bin, write_info_src
5454

55+
# Abseil libraries to link in the later stage
56+
ABSL_LIBS_EXT = "lib" if os.name == "nt" else "a"
57+
ABSL_LIBS = (
58+
"absl_str_format_internal",
59+
"absl_strings",
60+
"absl_strings_internal",
61+
"absl_string_view",
62+
"absl_log_initialize",
63+
"absl_log_entry",
64+
"absl_log_flags",
65+
"absl_log_severity",
66+
"absl_log_internal_check_op",
67+
"absl_log_internal_conditions",
68+
"absl_log_internal_message",
69+
"absl_log_internal_nullguard",
70+
"absl_log_internal_proto",
71+
"absl_log_internal_format",
72+
"absl_log_internal_globals",
73+
"absl_log_internal_log_sink_set",
74+
"absl_log_sink",
75+
"absl_raw_logging_internal",
76+
"absl_log_globals",
77+
"utf8_validity",
78+
"absl_cord",
79+
"absl_cordz_info",
80+
"absl_cordz_handle",
81+
"absl_cordz_functions",
82+
"absl_cord_internal",
83+
"absl_crc_cord_state",
84+
"absl_crc32c",
85+
"absl_crc_internal",
86+
"absl_exponential_biased",
87+
"absl_synchronization",
88+
"absl_graphcycles_internal",
89+
"absl_kernel_timeout_internal",
90+
"absl_time",
91+
"absl_time_zone",
92+
"absl_int128",
93+
"absl_examine_stack",
94+
"absl_stacktrace",
95+
"absl_symbolize",
96+
"absl_demangle_internal",
97+
"absl_debugging_internal",
98+
"absl_malloc_internal",
99+
"absl_throw_delegate",
100+
"absl_strerror",
101+
"absl_raw_hash_set",
102+
"absl_hash",
103+
"absl_city",
104+
"absl_low_level_hash",
105+
"absl_base",
106+
"absl_spinlock_wait",
107+
"absl_status",
108+
"absl_statusor",
109+
"absl_bad_optional_access",
110+
)
55111
# Load version information
56112
VERSION = [999, 0, 0, "a", 0]
57113
VERSION_TEXT = "999.0.0"
@@ -243,7 +299,17 @@ def _finalize_protobuf(self):
243299

244300
self.log.info("Copying Protobuf libraries")
245301

302+
# load protobuf-related static libraries
246303
libs = glob(os.path.join(self.with_protobuf_lib_dir, "libprotobuf*"))
304+
305+
# load absl-related static libraries
306+
libs += glob(
307+
os.path.join(self.with_protobuf_lib_dir, f"*absl_*.{ABSL_LIBS_EXT}")
308+
)
309+
libs += glob(
310+
os.path.join(self.with_protobuf_lib_dir, f"*utf8_*.{ABSL_LIBS_EXT}")
311+
)
312+
247313
for lib in libs:
248314
if os.path.isfile(lib):
249315
self.log.info("copying %s -> %s", lib, self._build_protobuf_lib_dir)
@@ -302,29 +368,25 @@ def run(self):
302368
disabled = [] # Extensions to be disabled
303369
for ext in self.extensions:
304370
# Add Protobuf include and library dirs
305-
if ext.name == "_mysqlxpb":
306-
if not self.with_mysqlxpb_cext:
307-
self.log.warning("The '_mysqlxpb' C extension will not be built")
308-
disabled.append(ext)
309-
continue
310-
if platform.system() == "Darwin":
311-
symbol_file = tempfile.NamedTemporaryFile()
312-
ext.extra_link_args.extend(
313-
["-exported_symbols_list", symbol_file.name]
314-
)
315-
with open(symbol_file.name, "w") as fp:
316-
fp.write("_PyInit__mysqlxpb")
317-
fp.write("\n")
318-
ext.include_dirs.append(self.with_protobuf_include_dir)
319-
ext.library_dirs.append(self._build_protobuf_lib_dir)
320-
ext.libraries.append("libprotobuf" if os.name == "nt" else "protobuf")
321-
# Add -std=c++11 needed for Protobuf 3.6.1
322-
ext.extra_compile_args.append("-std=c++11")
323-
self._run_protoc()
324-
325-
if ext.name != "_mysqlxpb":
371+
if not self.with_mysqlxpb_cext:
372+
self.log.warning("The '_mysqlxpb' C extension will not be built")
326373
disabled.append(ext)
327374
continue
375+
if platform.system() == "Darwin":
376+
symbol_file = tempfile.NamedTemporaryFile()
377+
ext.extra_link_args.extend(["-exported_symbols_list", symbol_file.name])
378+
with open(symbol_file.name, "w") as fp:
379+
fp.write("_PyInit__mysqlxpb")
380+
fp.write("\n")
381+
ext.include_dirs.append(self.with_protobuf_include_dir)
382+
ext.library_dirs.append(self._build_protobuf_lib_dir)
383+
ext.libraries.append("libprotobuf" if os.name == "nt" else "protobuf")
384+
ext.libraries.extend(ABSL_LIBS)
385+
386+
if os.name != "nt":
387+
# Add -std=c++14 needed for Protobuf 4.25.3
388+
ext.extra_compile_args.append("-std=c++14")
389+
self._run_protoc()
328390

329391
# Suppress unknown pragmas
330392
if os.name == "posix":

mysqlx-connector-python/docs/mysqlx/requirements.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Requirements
33

44
* MySQL 8.0.0 or higher, with the X Plugin enabled
55
* Python >= 3.8
6-
* Protobuf C++ (version >= 4.21.1, <= 4.21.12)
7-
* Python Protobuf (version >= 4.21.1, <= 4.21.12)
6+
* Protobuf C++ (version == 4.25.3)
7+
* Python Protobuf (version == 4.25.3)
88
* dnspython (version == 2.6.1) for DNS SRV support
99
* lz4 (version >= 2.1.6, <= 4.3.2) for connection compression support
1010
* zstandard (version >= 0.12.0, <= 0.19.0) for connection compression support

mysqlx-connector-python/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def main() -> None:
141141
ext_modules=EXTENSIONS,
142142
cmdclass=COMMAND_CLASSES,
143143
python_requires=">=3.8",
144-
install_requires=["protobuf>=4.21.1,<=4.21.12"],
144+
install_requires=["protobuf==4.25.3"],
145145
extras_require={
146146
"dns-srv": ["dnspython==2.6.1"],
147147
"compression": ["lz4>=2.1.6,<=4.3.2", "zstandard>=0.12.0,<=0.19.0"],

mysqlx-connector-python/src/mysqlxpb/mysqlxpb.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,14 +440,14 @@ static void AddPyListToMessageRepeatedString(
440440
google::protobuf::Message& message,
441441
const google::protobuf::FieldDescriptor& field,
442442
PyObject* list) {
443-
google::protobuf::MutableRepeatedFieldRef<google::protobuf::string> mutable_field =
443+
google::protobuf::MutableRepeatedFieldRef<std::string> mutable_field =
444444
message.GetReflection()->
445-
GetMutableRepeatedFieldRef<google::protobuf::string>(&message, &field);
445+
GetMutableRepeatedFieldRef<std::string>(&message, &field);
446446
Py_ssize_t list_size = PyList_Size(list);
447447

448448
if (list_size > 0) {
449449
for (Py_ssize_t idx = 0; idx < list_size; ++idx) {
450-
mutable_field.Add(google::protobuf::string(
450+
mutable_field.Add(std::string(
451451
python_cast<std::string>(PyList_GetItem(list, idx))));
452452
}
453453
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
protobuf>=4.21.1,<=4.21.12
1+
protobuf==4.25.3
22
dnspython==2.6.1
33
lz4>=2.1.6,<=4.3.2
44
zstandard>=0.12.0,<=0.19.0
5-

0 commit comments

Comments
 (0)