summaryrefslogtreecommitdiff
path: root/sys-apps/util-linux/files/util-linux-2.32-python3-tests.patch
blob: 7b8867ba03472fb75546b6582f3257499431bf62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
From 8a12ab57755afc36546834f175ef0b9e9376ba59 Mon Sep 17 00:00:00 2001
From: Frank Schaefer <kelledin@gmail.com>
Date: Tue, 10 Jul 2018 20:21:02 -0500
Subject: [PATCH] * break up large strings for PySys_WriteStdout()

---
 libmount/python/fs.c | 56 ++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 43 insertions(+), 13 deletions(-)

diff --git a/libmount/python/fs.c b/libmount/python/fs.c
index d6490d248..634a914ef 100644
--- a/libmount/python/fs.c
+++ b/libmount/python/fs.c
@@ -63,32 +63,62 @@ static PyObject *Fs_get_devno(FsObject *self)
 	return PyObjectResultInt(mnt_fs_get_devno(self->fs));
 }
 
+static void _dump_debug_string(const char *lead, const char *s, char quote)
+{
+	/* PySys_WriteStdout() will automatically truncate any '%s' token
+	 * longer than a certain length (documented as 1000 bytes, but we
+	 * give ourselves some margin here just in case).  The only way I
+	 * know to get around this is to print such strings in bite-sized
+	 * chunks.
+	 */
+	static const unsigned int _PY_MAX_LEN = 900;
+	static const char *_PY_MAX_LEN_FMT = "%.900s";
+	unsigned int len;
+
+	if (lead != NULL)
+		PySys_WriteStdout("%s", lead);
+
+	if (quote != 0)
+		PySys_WriteStdout("%c", quote);
+
+	for (len = strlen(s); len > _PY_MAX_LEN; len -= _PY_MAX_LEN, s += _PY_MAX_LEN) 
+		PySys_WriteStdout(_PY_MAX_LEN_FMT, s);
+
+	if (len > 0)
+		PySys_WriteStdout(_PY_MAX_LEN_FMT, s);
+
+	if (quote != 0)
+		PySys_WriteStdout("%c\n", quote);
+	else
+		PySys_WriteStdout("\n");
+}
+
 #define Fs_print_debug_HELP "print_debug()\n\n"
 static PyObject *Fs_print_debug(FsObject *self)
 {
 	PySys_WriteStdout("------ fs: %p\n", self->fs);
-	PySys_WriteStdout("source: %s\n", mnt_fs_get_source(self->fs));
-	PySys_WriteStdout("target: %s\n", mnt_fs_get_target(self->fs));
-	PySys_WriteStdout("fstype: %s\n", mnt_fs_get_fstype(self->fs));
+	_dump_debug_string("source: ", mnt_fs_get_source(self->fs), 0);
+	_dump_debug_string("target: ", mnt_fs_get_target(self->fs), 0);
+	_dump_debug_string("fstype: ", mnt_fs_get_fstype(self->fs), 0);
 
 	if (mnt_fs_get_options(self->fs))
-		PySys_WriteStdout("optstr: %s\n", mnt_fs_get_options(self->fs));
+		_dump_debug_string("optstr: ", mnt_fs_get_options(self->fs), 0);
 	if (mnt_fs_get_vfs_options(self->fs))
-		PySys_WriteStdout("VFS-optstr: %s\n", mnt_fs_get_vfs_options(self->fs));
+		_dump_debug_string("VFS-optstr: ", mnt_fs_get_vfs_options(self->fs), 0);
 	if (mnt_fs_get_fs_options(self->fs))
-		PySys_WriteStdout("FS-opstr: %s\n", mnt_fs_get_fs_options(self->fs));
+		_dump_debug_string("FS-opstr: ", mnt_fs_get_fs_options(self->fs), 0);
 	if (mnt_fs_get_user_options(self->fs))
-		PySys_WriteStdout("user-optstr: %s\n", mnt_fs_get_user_options(self->fs));
+		_dump_debug_string("user-optstr: ", mnt_fs_get_user_options(self->fs), 0);
 	if (mnt_fs_get_optional_fields(self->fs))
-		PySys_WriteStdout("optional-fields: '%s'\n", mnt_fs_get_optional_fields(self->fs));
+		_dump_debug_string("optional-fields: ", mnt_fs_get_optional_fields(self->fs), '\'');
 	if (mnt_fs_get_attributes(self->fs))
-		PySys_WriteStdout("attributes: %s\n", mnt_fs_get_attributes(self->fs));
+		_dump_debug_string("attributes: ", mnt_fs_get_attributes(self->fs), 0);
 
 	if (mnt_fs_get_root(self->fs))
-		PySys_WriteStdout("root:   %s\n", mnt_fs_get_root(self->fs));
+		_dump_debug_string("root:   ", mnt_fs_get_root(self->fs), 0);
 
 	if (mnt_fs_get_swaptype(self->fs))
-		PySys_WriteStdout("swaptype: %s\n", mnt_fs_get_swaptype(self->fs));
+		_dump_debug_string("swaptype: ", mnt_fs_get_swaptype(self->fs), 0);
 	if (mnt_fs_get_size(self->fs))
 		PySys_WriteStdout("size: %jd\n", mnt_fs_get_size(self->fs));
 	if (mnt_fs_get_usedsize(self->fs))
@@ -97,7 +127,7 @@ static PyObject *Fs_print_debug(FsObject *self)
 		PySys_WriteStdout("priority: %d\n", mnt_fs_get_priority(self->fs));
 
 	if (mnt_fs_get_bindsrc(self->fs))
-		PySys_WriteStdout("bindsrc: %s\n", mnt_fs_get_bindsrc(self->fs));
+		_dump_debug_string("bindsrc: ", mnt_fs_get_bindsrc(self->fs), 0);
 	if (mnt_fs_get_freq(self->fs))
 		PySys_WriteStdout("freq:   %d\n", mnt_fs_get_freq(self->fs));
 	if (mnt_fs_get_passno(self->fs))
@@ -112,7 +142,7 @@ static PyObject *Fs_print_debug(FsObject *self)
 	if (mnt_fs_get_tid(self->fs))
 		PySys_WriteStdout("tid:    %d\n", mnt_fs_get_tid(self->fs));
 	if (mnt_fs_get_comment(self->fs))
-		PySys_WriteStdout("comment: '%s'\n", mnt_fs_get_comment(self->fs));
+		_dump_debug_string("comment: ", mnt_fs_get_comment(self->fs), '\'');
 	return UL_IncRef(self);
 }
 /*