[parted-devel] [PATCH 2/3] libparted/labels/pt-tools.c: Fix gperf generated function attribute

Shin'ichiro Kawasaki kawasaki at juno.dti.ne.jp
Sat Jun 15 08:00:54 BST 2019


GCC 8 fails to compile libparted/labels/pt-tools.c with an error:

  CC       pt-tools.lo
In file included from pt-tools.c:114:
pt-tools.c: In function 'pt_limit_lookup':
pt-limit.gperf:78:1: error: function might be candidate for attribute 'pure' [-Werror=suggest-attribute=pure]
cc1: all warnings being treated as errors

"Pure" attribute is required for the function pt_limit_lookup() because
it does not change program status other than its return value.

To avoid the build failure, add _GL_ATTRIBUTE_PURE to the function.
The attribute cannot be added in libparted/gperf/pt-limit.c because it
is generated by gperf during the build process. Instead, add the
attribute in libparted/gperf/pt-tools.c which includes the generated
function.

Signed-off-by: Shin'ichiro Kawasaki <kawasaki at juno.dti.ne.jp>
---
 libparted/labels/pt-tools.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libparted/labels/pt-tools.c b/libparted/labels/pt-tools.c
index 8100f32..88703d3 100644
--- a/libparted/labels/pt-tools.c
+++ b/libparted/labels/pt-tools.c
@@ -111,6 +111,7 @@ ptt_geom_clear_sectors (PedGeometry *geom, PedSector start, PedSector n)
   return ptt_clear_sectors (geom->dev, geom->start + start, n);
 }
 
+#define pt_limit_lookup _GL_ATTRIBUTE_PURE __pt_limit_lookup
 #include "pt-limit.c"
 
 /* Throw an exception and return 0 if PART's starting sector number or
@@ -120,7 +121,7 @@ int
 ptt_partition_max_start_len (char const *pt_type, const PedPartition *part)
 {
   struct partition_limit const *pt_lim
-    = pt_limit_lookup (pt_type, strlen (pt_type));
+    = __pt_limit_lookup (pt_type, strlen (pt_type));
 
   /* If we don't have info on the type, return "true".  */
   if (pt_lim == NULL)
@@ -162,7 +163,7 @@ int
 ptt_partition_max_start_sector (char const *pt_type, PedSector *max)
 {
   struct partition_limit const *pt_lim
-    = pt_limit_lookup (pt_type, strlen (pt_type));
+    = __pt_limit_lookup (pt_type, strlen (pt_type));
   if (pt_lim == NULL)
     return -1;
 
@@ -176,7 +177,7 @@ int
 ptt_partition_max_length (char const *pt_type, PedSector *max)
 {
   struct partition_limit const *pt_lim
-    = pt_limit_lookup (pt_type, strlen (pt_type));
+    = __pt_limit_lookup (pt_type, strlen (pt_type));
   if (pt_lim == NULL)
     return -1;
 
-- 
2.22.0




More information about the parted-devel mailing list