util-linux-2.32-python3-tests.patch 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. From 8a12ab57755afc36546834f175ef0b9e9376ba59 Mon Sep 17 00:00:00 2001
  2. From: Frank Schaefer <kelledin@gmail.com>
  3. Date: Tue, 10 Jul 2018 20:21:02 -0500
  4. Subject: [PATCH] * break up large strings for PySys_WriteStdout()
  5. ---
  6. libmount/python/fs.c | 56 ++++++++++++++++++++++++++++++++++++++++------------
  7. 1 file changed, 43 insertions(+), 13 deletions(-)
  8. diff --git a/libmount/python/fs.c b/libmount/python/fs.c
  9. index d6490d248..634a914ef 100644
  10. --- a/libmount/python/fs.c
  11. +++ b/libmount/python/fs.c
  12. @@ -63,32 +63,62 @@ static PyObject *Fs_get_devno(FsObject *self)
  13. return PyObjectResultInt(mnt_fs_get_devno(self->fs));
  14. }
  15. +static void _dump_debug_string(const char *lead, const char *s, char quote)
  16. +{
  17. + /* PySys_WriteStdout() will automatically truncate any '%s' token
  18. + * longer than a certain length (documented as 1000 bytes, but we
  19. + * give ourselves some margin here just in case). The only way I
  20. + * know to get around this is to print such strings in bite-sized
  21. + * chunks.
  22. + */
  23. + static const unsigned int _PY_MAX_LEN = 900;
  24. + static const char *_PY_MAX_LEN_FMT = "%.900s";
  25. + unsigned int len;
  26. +
  27. + if (lead != NULL)
  28. + PySys_WriteStdout("%s", lead);
  29. +
  30. + if (quote != 0)
  31. + PySys_WriteStdout("%c", quote);
  32. +
  33. + for (len = strlen(s); len > _PY_MAX_LEN; len -= _PY_MAX_LEN, s += _PY_MAX_LEN)
  34. + PySys_WriteStdout(_PY_MAX_LEN_FMT, s);
  35. +
  36. + if (len > 0)
  37. + PySys_WriteStdout(_PY_MAX_LEN_FMT, s);
  38. +
  39. + if (quote != 0)
  40. + PySys_WriteStdout("%c\n", quote);
  41. + else
  42. + PySys_WriteStdout("\n");
  43. +}
  44. +
  45. #define Fs_print_debug_HELP "print_debug()\n\n"
  46. static PyObject *Fs_print_debug(FsObject *self)
  47. {
  48. PySys_WriteStdout("------ fs: %p\n", self->fs);
  49. - PySys_WriteStdout("source: %s\n", mnt_fs_get_source(self->fs));
  50. - PySys_WriteStdout("target: %s\n", mnt_fs_get_target(self->fs));
  51. - PySys_WriteStdout("fstype: %s\n", mnt_fs_get_fstype(self->fs));
  52. + _dump_debug_string("source: ", mnt_fs_get_source(self->fs), 0);
  53. + _dump_debug_string("target: ", mnt_fs_get_target(self->fs), 0);
  54. + _dump_debug_string("fstype: ", mnt_fs_get_fstype(self->fs), 0);
  55. if (mnt_fs_get_options(self->fs))
  56. - PySys_WriteStdout("optstr: %s\n", mnt_fs_get_options(self->fs));
  57. + _dump_debug_string("optstr: ", mnt_fs_get_options(self->fs), 0);
  58. if (mnt_fs_get_vfs_options(self->fs))
  59. - PySys_WriteStdout("VFS-optstr: %s\n", mnt_fs_get_vfs_options(self->fs));
  60. + _dump_debug_string("VFS-optstr: ", mnt_fs_get_vfs_options(self->fs), 0);
  61. if (mnt_fs_get_fs_options(self->fs))
  62. - PySys_WriteStdout("FS-opstr: %s\n", mnt_fs_get_fs_options(self->fs));
  63. + _dump_debug_string("FS-opstr: ", mnt_fs_get_fs_options(self->fs), 0);
  64. if (mnt_fs_get_user_options(self->fs))
  65. - PySys_WriteStdout("user-optstr: %s\n", mnt_fs_get_user_options(self->fs));
  66. + _dump_debug_string("user-optstr: ", mnt_fs_get_user_options(self->fs), 0);
  67. if (mnt_fs_get_optional_fields(self->fs))
  68. - PySys_WriteStdout("optional-fields: '%s'\n", mnt_fs_get_optional_fields(self->fs));
  69. + _dump_debug_string("optional-fields: ", mnt_fs_get_optional_fields(self->fs), '\'');
  70. if (mnt_fs_get_attributes(self->fs))
  71. - PySys_WriteStdout("attributes: %s\n", mnt_fs_get_attributes(self->fs));
  72. + _dump_debug_string("attributes: ", mnt_fs_get_attributes(self->fs), 0);
  73. if (mnt_fs_get_root(self->fs))
  74. - PySys_WriteStdout("root: %s\n", mnt_fs_get_root(self->fs));
  75. + _dump_debug_string("root: ", mnt_fs_get_root(self->fs), 0);
  76. if (mnt_fs_get_swaptype(self->fs))
  77. - PySys_WriteStdout("swaptype: %s\n", mnt_fs_get_swaptype(self->fs));
  78. + _dump_debug_string("swaptype: ", mnt_fs_get_swaptype(self->fs), 0);
  79. if (mnt_fs_get_size(self->fs))
  80. PySys_WriteStdout("size: %jd\n", mnt_fs_get_size(self->fs));
  81. if (mnt_fs_get_usedsize(self->fs))
  82. @@ -97,7 +127,7 @@ static PyObject *Fs_print_debug(FsObject *self)
  83. PySys_WriteStdout("priority: %d\n", mnt_fs_get_priority(self->fs));
  84. if (mnt_fs_get_bindsrc(self->fs))
  85. - PySys_WriteStdout("bindsrc: %s\n", mnt_fs_get_bindsrc(self->fs));
  86. + _dump_debug_string("bindsrc: ", mnt_fs_get_bindsrc(self->fs), 0);
  87. if (mnt_fs_get_freq(self->fs))
  88. PySys_WriteStdout("freq: %d\n", mnt_fs_get_freq(self->fs));
  89. if (mnt_fs_get_passno(self->fs))
  90. @@ -112,7 +142,7 @@ static PyObject *Fs_print_debug(FsObject *self)
  91. if (mnt_fs_get_tid(self->fs))
  92. PySys_WriteStdout("tid: %d\n", mnt_fs_get_tid(self->fs));
  93. if (mnt_fs_get_comment(self->fs))
  94. - PySys_WriteStdout("comment: '%s'\n", mnt_fs_get_comment(self->fs));
  95. + _dump_debug_string("comment: ", mnt_fs_get_comment(self->fs), '\'');
  96. return UL_IncRef(self);
  97. }
  98. /*