cdown / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

Blame SOURCES/0011-tests-break-up-large-strings-for-PySys_WriteStdout.patch

fe1ca8
From c2b650ebe33a001b3bf19912b136dbbff5495600 Mon Sep 17 00:00:00 2001
fe1ca8
From: Frank Schaefer <kelledin@gmail.com>
fe1ca8
Date: Tue, 10 Jul 2018 20:21:02 -0500
fe1ca8
Subject: [PATCH 11/14] tests: break up large strings for PySys_WriteStdout()
fe1ca8
fe1ca8
Addresses: http://bugzilla.redhat.com/show_bug.cgi?id=1656437
fe1ca8
Upstream: http://github.com/karelzak/util-linux/commit/8a12ab57755afc36546834f175ef0b9e9376ba59
fe1ca8
Signed-off-by: Karel Zak <kzak@redhat.com>
fe1ca8
---
fe1ca8
 libmount/python/fs.c | 56 ++++++++++++++++++++++++++++++++++----------
fe1ca8
 1 file changed, 43 insertions(+), 13 deletions(-)
fe1ca8
fe1ca8
diff --git a/libmount/python/fs.c b/libmount/python/fs.c
fe1ca8
index d6490d248..634a914ef 100644
fe1ca8
--- a/libmount/python/fs.c
fe1ca8
+++ b/libmount/python/fs.c
fe1ca8
@@ -63,32 +63,62 @@ static PyObject *Fs_get_devno(FsObject *self)
fe1ca8
 	return PyObjectResultInt(mnt_fs_get_devno(self->fs));
fe1ca8
 }
fe1ca8
 
fe1ca8
+static void _dump_debug_string(const char *lead, const char *s, char quote)
fe1ca8
+{
fe1ca8
+	/* PySys_WriteStdout() will automatically truncate any '%s' token
fe1ca8
+	 * longer than a certain length (documented as 1000 bytes, but we
fe1ca8
+	 * give ourselves some margin here just in case).  The only way I
fe1ca8
+	 * know to get around this is to print such strings in bite-sized
fe1ca8
+	 * chunks.
fe1ca8
+	 */
fe1ca8
+	static const unsigned int _PY_MAX_LEN = 900;
fe1ca8
+	static const char *_PY_MAX_LEN_FMT = "%.900s";
fe1ca8
+	unsigned int len;
fe1ca8
+
fe1ca8
+	if (lead != NULL)
fe1ca8
+		PySys_WriteStdout("%s", lead);
fe1ca8
+
fe1ca8
+	if (quote != 0)
fe1ca8
+		PySys_WriteStdout("%c", quote);
fe1ca8
+
fe1ca8
+	for (len = strlen(s); len > _PY_MAX_LEN; len -= _PY_MAX_LEN, s += _PY_MAX_LEN) 
fe1ca8
+		PySys_WriteStdout(_PY_MAX_LEN_FMT, s);
fe1ca8
+
fe1ca8
+	if (len > 0)
fe1ca8
+		PySys_WriteStdout(_PY_MAX_LEN_FMT, s);
fe1ca8
+
fe1ca8
+	if (quote != 0)
fe1ca8
+		PySys_WriteStdout("%c\n", quote);
fe1ca8
+	else
fe1ca8
+		PySys_WriteStdout("\n");
fe1ca8
+}
fe1ca8
+
fe1ca8
 #define Fs_print_debug_HELP "print_debug()\n\n"
fe1ca8
 static PyObject *Fs_print_debug(FsObject *self)
fe1ca8
 {
fe1ca8
 	PySys_WriteStdout("------ fs: %p\n", self->fs);
fe1ca8
-	PySys_WriteStdout("source: %s\n", mnt_fs_get_source(self->fs));
fe1ca8
-	PySys_WriteStdout("target: %s\n", mnt_fs_get_target(self->fs));
fe1ca8
-	PySys_WriteStdout("fstype: %s\n", mnt_fs_get_fstype(self->fs));
fe1ca8
+	_dump_debug_string("source: ", mnt_fs_get_source(self->fs), 0);
fe1ca8
+	_dump_debug_string("target: ", mnt_fs_get_target(self->fs), 0);
fe1ca8
+	_dump_debug_string("fstype: ", mnt_fs_get_fstype(self->fs), 0);
fe1ca8
 
fe1ca8
 	if (mnt_fs_get_options(self->fs))
fe1ca8
-		PySys_WriteStdout("optstr: %s\n", mnt_fs_get_options(self->fs));
fe1ca8
+		_dump_debug_string("optstr: ", mnt_fs_get_options(self->fs), 0);
fe1ca8
 	if (mnt_fs_get_vfs_options(self->fs))
fe1ca8
-		PySys_WriteStdout("VFS-optstr: %s\n", mnt_fs_get_vfs_options(self->fs));
fe1ca8
+		_dump_debug_string("VFS-optstr: ", mnt_fs_get_vfs_options(self->fs), 0);
fe1ca8
 	if (mnt_fs_get_fs_options(self->fs))
fe1ca8
-		PySys_WriteStdout("FS-opstr: %s\n", mnt_fs_get_fs_options(self->fs));
fe1ca8
+		_dump_debug_string("FS-opstr: ", mnt_fs_get_fs_options(self->fs), 0);
fe1ca8
 	if (mnt_fs_get_user_options(self->fs))
fe1ca8
-		PySys_WriteStdout("user-optstr: %s\n", mnt_fs_get_user_options(self->fs));
fe1ca8
+		_dump_debug_string("user-optstr: ", mnt_fs_get_user_options(self->fs), 0);
fe1ca8
 	if (mnt_fs_get_optional_fields(self->fs))
fe1ca8
-		PySys_WriteStdout("optional-fields: '%s'\n", mnt_fs_get_optional_fields(self->fs));
fe1ca8
+		_dump_debug_string("optional-fields: ", mnt_fs_get_optional_fields(self->fs), '\'');
fe1ca8
 	if (mnt_fs_get_attributes(self->fs))
fe1ca8
-		PySys_WriteStdout("attributes: %s\n", mnt_fs_get_attributes(self->fs));
fe1ca8
+		_dump_debug_string("attributes: ", mnt_fs_get_attributes(self->fs), 0);
fe1ca8
 
fe1ca8
 	if (mnt_fs_get_root(self->fs))
fe1ca8
-		PySys_WriteStdout("root:   %s\n", mnt_fs_get_root(self->fs));
fe1ca8
+		_dump_debug_string("root:   ", mnt_fs_get_root(self->fs), 0);
fe1ca8
 
fe1ca8
 	if (mnt_fs_get_swaptype(self->fs))
fe1ca8
-		PySys_WriteStdout("swaptype: %s\n", mnt_fs_get_swaptype(self->fs));
fe1ca8
+		_dump_debug_string("swaptype: ", mnt_fs_get_swaptype(self->fs), 0);
fe1ca8
 	if (mnt_fs_get_size(self->fs))
fe1ca8
 		PySys_WriteStdout("size: %jd\n", mnt_fs_get_size(self->fs));
fe1ca8
 	if (mnt_fs_get_usedsize(self->fs))
fe1ca8
@@ -97,7 +127,7 @@ static PyObject *Fs_print_debug(FsObject *self)
fe1ca8
 		PySys_WriteStdout("priority: %d\n", mnt_fs_get_priority(self->fs));
fe1ca8
 
fe1ca8
 	if (mnt_fs_get_bindsrc(self->fs))
fe1ca8
-		PySys_WriteStdout("bindsrc: %s\n", mnt_fs_get_bindsrc(self->fs));
fe1ca8
+		_dump_debug_string("bindsrc: ", mnt_fs_get_bindsrc(self->fs), 0);
fe1ca8
 	if (mnt_fs_get_freq(self->fs))
fe1ca8
 		PySys_WriteStdout("freq:   %d\n", mnt_fs_get_freq(self->fs));
fe1ca8
 	if (mnt_fs_get_passno(self->fs))
fe1ca8
@@ -112,7 +142,7 @@ static PyObject *Fs_print_debug(FsObject *self)
fe1ca8
 	if (mnt_fs_get_tid(self->fs))
fe1ca8
 		PySys_WriteStdout("tid:    %d\n", mnt_fs_get_tid(self->fs));
fe1ca8
 	if (mnt_fs_get_comment(self->fs))
fe1ca8
-		PySys_WriteStdout("comment: '%s'\n", mnt_fs_get_comment(self->fs));
fe1ca8
+		_dump_debug_string("comment: ", mnt_fs_get_comment(self->fs), '\'');
fe1ca8
 	return UL_IncRef(self);
fe1ca8
 }
fe1ca8
 /*
fe1ca8
-- 
fe1ca8
2.17.2
fe1ca8