gbranden pushed a commit to branch master
in repository groff.

commit 21a5edd438bc3a3b8148e7adb54eb28dac8d290f
Author: G. Branden Robinson <[email protected]>
AuthorDate: Wed Jun 4 08:46:55 2025 -0500

    [libgroff,troff]: Refactor.
    
    * src/include/font.h (class font): Promote constructor from `protected`
      visibility to `public`.  This is so that GNU troff can create a
      `nonexistent_font` object with which to mark font mounting positions
      that fail to mount a font.
    
    * src/roff/troff/node.cpp: Do so at the global scope.
    
      (mount_font_no_translate): Drop `static char a_char` formerly used for
      this purpose.  It felt squicky to me to store an object of the "wrong"
      type in the `font_dictionary`.  Reorder equality comparisons to avoid
      inadvertent lvalue assignment.
---
 ChangeLog               | 14 ++++++++++++++
 src/include/font.h      |  3 +--
 src/roff/troff/node.cpp | 10 +++++-----
 3 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ccd4b24cb..e9739793d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2025-06-04  G. Branden Robinson <[email protected]>
+
+       [libgroff, troff]: Refactor.
+
+       * src/include/font.h (class font): Promote constructor from
+       `protected` visibility to `public`.  This is so that GNU troff
+       can create a `nonexistent_font` object with which to mark font
+       mounting positions that fail to mount a font.
+       * src/roff/troff/node.cpp: Do so at the global scope.
+       (mount_font_no_translate): Drop `static char a_char` formerly
+       used for this purpose.  It felt squicky to me to store an object
+       of the "wrong" type in the `font_dictionary`.  Reorder equality
+       comparisons to avoid inadvertent lvalue assignment.
+
 2025-06-04  G. Branden Robinson <[email protected]>
 
        [libdriver,grohtml,grops]: Revise diagnostic messages.
diff --git a/src/include/font.h b/src/include/font.h
index 9bcf933f0..ba66a226a 100644
--- a/src/include/font.h
+++ b/src/include/font.h
@@ -106,6 +106,7 @@ public:
     LIG_ffl = 16
   };
 
+  font(const char *);  // Load font description from file name.
   virtual ~font();     // Destructor.
   bool contains(glyph *);      // This font contains the given glyph.
   bool is_special();   // This font is searched for glyphs not defined
@@ -342,8 +343,6 @@ private:
   font_char_metric *get_font_wchar_metric(int);
 
 protected:
-  font(const char *);  // Load font description from file name.
-
   // Load the font description file with the name in member variable
   // `name` into this object.  If arg1 is true, only the part of the
   // font description file before the 'charset' and 'kernpairs' sections
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index 28fd3c792..f2477b671 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -6495,6 +6495,9 @@ static symbol get_font_translation(symbol nm)
 }
 
 dictionary font_dictionary(50);
+// We store the address of this font in `font_dictionary` to indicate
+// that we've previously tried to mount the font and failed.
+font nonexistent_font = font("\0");
 
 // Mount font at position `n` with troff identifier `name` and
 // description file name `external_name`.  If `check_only`, just look up
@@ -6504,9 +6507,6 @@ static bool mount_font_no_translate(int n, symbol name,
                                    bool check_only = false)
 {
   assert(n >= 0);
-  // We store the address of this char in `font_dictionary` to indicate
-  // that we've previously tried to mount the font and failed.
-  static char a_char;
   font *fm = 0 /* nullptr */;
   void *p = font_dictionary.lookup(external_name);
   if (0 /* nullptr */ == p) {
@@ -6514,12 +6514,12 @@ static bool mount_font_no_translate(int n, symbol name,
     if (check_only)
       return fm != 0 /* nullptr */;
     if (0 /* nullptr */ == fm) {
-      (void) font_dictionary.lookup(external_name, &a_char);
+      (void) font_dictionary.lookup(external_name, &nonexistent_font);
       return false;
     }
     (void) font_dictionary.lookup(name, fm);
   }
-  else if (p == &a_char) {
+  else if (&nonexistent_font == p) {
     return false;
   }
   else

_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to