]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR modula2/122333: m2spellcheck.cc remove memset and tidyup
authorGaius Mulley <gaiusmod2@gmail.com>
Sun, 19 Oct 2025 17:48:18 +0000 (18:48 +0100)
committerGaius Mulley <gaiusmod2@gmail.com>
Sun, 19 Oct 2025 17:48:18 +0000 (18:48 +0100)
This patch removes memset from m2spellcheck_InitCandidates.
It corrects a comment boiler plate and removes an unused local
variable.  Finally it frees up memory used by the candidates_array
in KillCandidates.

gcc/m2/ChangeLog:

PR modula2/122333
* gm2-compiler/M2MetaError.mod (JoinSentances): Remove
unused variable.
* gm2-gcc/m2spellcheck.cc (m2spellcheck_InitCandidates): Rewrite.
(KillCandidates): Deallocate auto_vec candidates_array.
(candidates_array_vec_t): New declaration.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
gcc/m2/gm2-compiler/M2MetaError.mod
gcc/m2/gm2-gcc/m2spellcheck.cc

index 0ae919636c24fbd639e13e0e8cc73a03f126840e..dc14e6b06beae83349c11842df0adac33f164b38 100644 (file)
@@ -1894,8 +1894,6 @@ END IsPunct ;
 *)
 
 PROCEDURE JoinSentances (VAR eb: errorBlock; s: String) ;
-VAR
-   i: INTEGER ;
 BEGIN
    IF (s # NIL) AND (Length (s) > 0)
    THEN
index 22b77ed843d6dc48820e2f47b35df0577ca0019e..c6d0c675a0965fea4376a83d0bd8e26a1c73874d 100644 (file)
@@ -1,4 +1,4 @@
-/* m2spellcheck.cc provides an interface to GCC expression trees.
+/* m2spellcheck.cc provides an interface to the GCC spell checker.
 
 Copyright (C) 2025 Free Software Foundation, Inc.
 Contributed by Gaius Mulley <gaiusmod2@gmail.com>.
@@ -34,9 +34,10 @@ along with GNU Modula-2; see the file COPYING3.  If not see
 
 
 /* Define the hidden type Candidates declared in the definition module.  */
+typedef auto_vec<const char *> candidates_array_vec_t;
 
 typedef struct Candidates_t {
-  auto_vec<const char *> candidates_array;
+  candidates_array_vec_t candidates_array;
   struct Candidates_t *next;
 } Candidates;
 
@@ -57,12 +58,13 @@ m2spellcheck_InitCandidates (void)
       c = freeList;
       freeList = freeList->next;
     }
-  memset (c, 0, sizeof (Candidates));
+  :: new (&c->candidates_array) auto_vec<const char *> ();
+  c->next = NULL;
   return c;
 }
 
 /* Push a string to the Candidates array.
-   The candidates array will contain str at the end.  */
+   The candidates array will contain the string name at the end.  */
 
 static
 void
@@ -80,12 +82,15 @@ m2spellcheck_Push (void *cand, const char *name)
   Push (static_cast<Candidates *> (cand), name);
 }
 
+/* Return the Candidates structure to the freeList and deallocate
+   the auto_vec candidates_array.  */
+
 static
 void
 KillCandidates (Candidates **cand)
 {
-  // --fixme-- deallocate and zero the candidates_array.
   (*cand)->next = freeList;
+  (*cand)->candidates_array.~candidates_array_vec_t ();
   freeList = *cand;
   (*cand) = NULL;
 }