[squid-dev] [PATCH] polish Config2 using C++11 features

Amos Jeffries squid3 at treenet.co.nz
Fri Sep 30 15:38:03 UTC 2016


We now seem to have had several patches successfully use members
declared with default values and/or with the "*this = Foo();" shortcut
for a reset/clear method.

So I think we can start using these to replace old C-style
initialization and clear() functions.

This patch begins by replacing the Config2 use of memset(). I for one am
constantly mistaking which of the Config objects has memset() applied to
it at the global level when reconfigure happens. Now we do not need to
care, each object handles its own clearing one way or another.

Amos
-------------- next part --------------
=== modified file 'src/SquidConfig.h'
--- src/SquidConfig.h	2016-09-20 12:41:25 +0000
+++ src/SquidConfig.h	2016-09-30 14:54:55 +0000
@@ -547,11 +547,15 @@
 class SquidConfig2
 {
 public:
+    void clear() {
+        *this = SquidConfig2();
+    }
+
     struct {
-        int enable_purge;
+        int enable_purge = 0;
     } onoff;
-    uid_t effectiveUserID;
-    gid_t effectiveGroupID;
+    uid_t effectiveUserID = 0;
+    gid_t effectiveGroupID = 0;
 };
 
 extern SquidConfig2 Config2;

=== modified file 'src/cache_cf.cc'
--- src/cache_cf.cc	2016-09-21 18:54:45 +0000
+++ src/cache_cf.cc	2016-09-30 14:52:10 +0000
@@ -613,7 +613,7 @@
 static void
 configDoConfigure(void)
 {
-    memset(&Config2, '\0', sizeof(SquidConfig2));
+    Config2.clear();
     /* init memory as early as possible */
     memConfigure();
     /* Sanity checks */



More information about the squid-dev mailing list