Browse Source

prc: Fix recursion reading notify-timestamp config.prc variable

rdb 3 months ago
parent
commit
212ad7486c

+ 15 - 0
dtool/src/prc/configPageManager.cxx

@@ -492,6 +492,21 @@ reload_implicit_pages() {
   _currently_loading = false;
   invalidate_cache();
 
+  // These important variables are updated here to avoid recursion, since
+  // they may be accessed by the PRC system.
+  ConfigVariableBool notify_timestamp
+    ("notify-timestamp", false,
+     PRC_DESC("Set true to output the date & time with each notify message."));
+  NotifyCategory::_notify_timestamp = notify_timestamp;
+
+#ifndef NDEBUG
+  ConfigVariableBool check_debug_notify_protect
+    ("check-debug-notify-protect", false,
+     PRC_DESC("Set true to issue a warning message if a debug or spam "
+              "notify output is not protected within an if statement."));
+  NotifyCategory::_check_debug_notify_protect = check_debug_notify_protect;
+#endif
+
 #ifdef USE_PANDAFILESTREAM
   // Update this very low-level config variable here, for lack of any better
   // place.

+ 5 - 35
dtool/src/prc/notifyCategory.cxx

@@ -21,6 +21,9 @@
 #include <time.h>  // for strftime().
 #include <assert.h>
 
+bool NotifyCategory::_notify_timestamp = false;
+bool NotifyCategory::_check_debug_notify_protect = false;
+
 long NotifyCategory::_server_delta = 0;
 
 /**
@@ -55,7 +58,7 @@ std::ostream &NotifyCategory::
 out(NotifySeverity severity, bool prefix) const {
   if (is_on(severity)) {
     if (prefix) {
-      if (get_notify_timestamp()) {
+      if (_notify_timestamp) {
         // Format a timestamp to include as a prefix as well.
         time_t now = time(nullptr) + _server_delta;
         struct tm atm;
@@ -79,7 +82,7 @@ out(NotifySeverity severity, bool prefix) const {
       return Notify::out(severity);
     }
 
-  } else if (severity <= NS_debug && get_check_debug_notify_protect()) {
+  } else if (severity <= NS_debug && _check_debug_notify_protect) {
     // Someone issued a debug Notify output statement without protecting it
     // within an if statement.  This can cause a significant runtime
     // performance hit, since it forces the iostream library to fully format
@@ -172,36 +175,3 @@ update_severity_cache() {
 
   mark_cache_valid(_local_modified);
 }
-
-/**
- * Returns the value of the notify-timestamp ConfigVariable.  This is defined
- * using a method accessor rather than a static ConfigVariableBool, to protect
- * against the variable needing to be accessed at static init time.
- */
-bool NotifyCategory::
-get_notify_timestamp() {
-  static ConfigVariableBool *notify_timestamp = nullptr;
-  if (notify_timestamp == nullptr) {
-    notify_timestamp = new ConfigVariableBool
-      ("notify-timestamp", false,
-       "Set true to output the date & time with each notify message.");
-  }
-  return *notify_timestamp;
-}
-
-/**
- * Returns the value of the check-debug-notify-protect ConfigVariable.  This
- * is defined using a method accessor rather than a static ConfigVariableBool,
- * to protect against the variable needing to be accessed at static init time.
- */
-bool NotifyCategory::
-get_check_debug_notify_protect() {
-  static ConfigVariableBool *check_debug_notify_protect = nullptr;
-  if (check_debug_notify_protect == nullptr) {
-    check_debug_notify_protect = new ConfigVariableBool
-      ("check-debug-notify-protect", false,
-       "Set true to issue a warning message if a debug or spam "
-       "notify output is not protected within an if statement.");
-  }
-  return *check_debug_notify_protect;
-}

+ 4 - 2
dtool/src/prc/notifyCategory.h

@@ -76,8 +76,6 @@ PUBLISHED:
 private:
   std::string get_config_name() const;
   void update_severity_cache();
-  static bool get_notify_timestamp();
-  static bool get_check_debug_notify_protect();
 
   std::string _fullname;
   std::string _basename;
@@ -86,12 +84,16 @@ private:
   typedef std::vector<NotifyCategory *> Children;
   Children _children;
 
+  static bool _notify_timestamp;
+  static bool _check_debug_notify_protect;
+
   static long _server_delta; // not a time_t because server delta may be signed.
 
   AtomicAdjust::Integer _local_modified;
   NotifySeverity _severity_cache;
 
   friend class Notify;
+  friend class ConfigPageManager;
 };
 
 INLINE std::ostream &operator << (std::ostream &out, const NotifyCategory &cat);