texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]


From: Patrice Dumas
Date: Wed, 22 May 2024 15:43:25 -0400 (EDT)

branch: master
commit fadc7c3c494e303545b377585e9901416b0b6764
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Wed May 22 10:40:25 2024 +0200

    * tp/Texinfo/XS/main/parser_conf.c (parser_conf_list)
    (parser_conf_number, parser_conf_space, retrieve_parser_conf)
    (register_conf, clear_parser_conf), tp/Texinfo/XS/main/parser_conf.h
    (PARSER_CONF), tp/Texinfo/XS/parsetexi/Parsetexi.pm (parser),
    tp/Texinfo/XS/parsetexi/Parsetexi.xs (register_parser_conf),
    tp/Texinfo/XS/parsetexi/conf.c (reset_parser_conf): add
    parser_conf_list, a list of PARSER_CONF and register parser
    configuration setup at the end of Parsetexi.pm parser through the
    reset_parser_conf XS interface.  Clear memory of the global parser
    conf only if it is not registered.
---
 ChangeLog                            | 13 ++++++++
 tp/Texinfo/XS/main/parser_conf.c     | 58 +++++++++++++++++++++++++++++++++++-
 tp/Texinfo/XS/main/parser_conf.h     |  6 ++++
 tp/Texinfo/XS/parsetexi/Parsetexi.pm |  2 ++
 tp/Texinfo/XS/parsetexi/Parsetexi.xs | 13 ++++++++
 tp/Texinfo/XS/parsetexi/conf.c       |  2 ++
 6 files changed, 93 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 038edafd7d..da86d48daf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2024-05-22  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/main/parser_conf.c (parser_conf_list)
+       (parser_conf_number, parser_conf_space, retrieve_parser_conf)
+       (register_conf, clear_parser_conf), tp/Texinfo/XS/main/parser_conf.h
+       (PARSER_CONF), tp/Texinfo/XS/parsetexi/Parsetexi.pm (parser),
+       tp/Texinfo/XS/parsetexi/Parsetexi.xs (register_parser_conf),
+       tp/Texinfo/XS/parsetexi/conf.c (reset_parser_conf): add
+       parser_conf_list, a list of PARSER_CONF and register parser
+       configuration setup at the end of Parsetexi.pm parser through the
+       reset_parser_conf XS interface.  Clear memory of the global parser
+       conf only if it is not registered.
+
 2024-05-22  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/Makefile.am (libtexinfo_la_SOURCES),
diff --git a/tp/Texinfo/XS/main/parser_conf.c b/tp/Texinfo/XS/main/parser_conf.c
index 6a6455a9fc..32aed5dce6 100644
--- a/tp/Texinfo/XS/main/parser_conf.c
+++ b/tp/Texinfo/XS/main/parser_conf.c
@@ -24,6 +24,61 @@
 /* Configuration values. */
 PARSER_CONF global_parser_conf;
 
+/* registered parser configurations */
+static PARSER_CONF **parser_conf_list;
+static size_t parser_conf_number;
+static size_t parser_conf_space;
+
+PARSER_CONF *
+retrieve_parser_conf (int parser_conf_descriptor)
+{
+  if (parser_conf_descriptor <= parser_conf_number
+      && parser_conf_list[parser_conf_descriptor -1] != 0)
+    return parser_conf_list[parser_conf_descriptor -1];
+  return 0;
+}
+
+PARSER_CONF *
+register_conf ()
+{
+  size_t parser_conf_index;
+  size_t i;
+  int slot_found = 0;
+
+  PARSER_CONF *parser_conf = (PARSER_CONF *) malloc (sizeof (PARSER_CONF));
+  for (i = 0; i < parser_conf_number; i++)
+    {
+      if (parser_conf_list[i] == 0)
+        {
+          slot_found = 1;
+          parser_conf_index = i;
+        }
+    }
+  if (!slot_found)
+    {
+      if (parser_conf_number == parser_conf_space)
+        {
+          parser_conf_list = realloc (parser_conf_list,
+                         (parser_conf_space += 5) * sizeof (PARSER_CONF *));
+          if (!parser_conf_list)
+            fatal ("realloc failed");
+        }
+      parser_conf_index = parser_conf_number;
+      parser_conf_number++;
+    }
+  parser_conf_list[parser_conf_index] = parser_conf;
+
+  global_parser_conf.descriptor = parser_conf_index + 1;
+
+  memcpy (parser_conf, &global_parser_conf, sizeof (PARSER_CONF));
+
+  /*
+  fprintf (stderr, "Register parser_conf: %d\n", parser_conf->descriptor);
+   */
+
+  return parser_conf;
+}
+
 void
 clear_parser_conf (PARSER_CONF *parser_conf)
 {
@@ -37,6 +92,7 @@ clear_parser_conf (PARSER_CONF *parser_conf)
 void
 clear_global_parser_conf (void)
 {
-  clear_parser_conf (&global_parser_conf);
+  if (!global_parser_conf.descriptor)
+    clear_parser_conf (&global_parser_conf);
 }
 
diff --git a/tp/Texinfo/XS/main/parser_conf.h b/tp/Texinfo/XS/main/parser_conf.h
index d17856489f..89101f3637 100644
--- a/tp/Texinfo/XS/main/parser_conf.h
+++ b/tp/Texinfo/XS/main/parser_conf.h
@@ -37,10 +37,16 @@ typedef struct PARSER_CONF {
 
     EXPANDED_FORMAT expanded_formats[7];
     VALUE_LIST values;
+
+    /* descriptor is the index in the array of registered conf */
+    int descriptor;
 } PARSER_CONF;
 
 extern PARSER_CONF global_parser_conf;
 
+PARSER_CONF *register_conf ();
+PARSER_CONF *retrieve_parser_conf (int parser_conf_descriptor);
+
 void clear_global_parser_conf (void);
 
 #endif
diff --git a/tp/Texinfo/XS/parsetexi/Parsetexi.pm 
b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
index bef56feded..0cf9b10270 100644
--- a/tp/Texinfo/XS/parsetexi/Parsetexi.pm
+++ b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
@@ -164,6 +164,8 @@ sub parser (;$)
     }
   }
 
+  register_parser_conf($parser);
+
   if (not $parser->{'registrar'}) {
     $parser->{'registrar'} = Texinfo::Report::new();
   }
diff --git a/tp/Texinfo/XS/parsetexi/Parsetexi.xs 
b/tp/Texinfo/XS/parsetexi/Parsetexi.xs
index 1e02c37708..af631320d8 100644
--- a/tp/Texinfo/XS/parsetexi/Parsetexi.xs
+++ b/tp/Texinfo/XS/parsetexi/Parsetexi.xs
@@ -31,6 +31,7 @@
 
 #include "api.h"
 #include "conf.h"
+#include "parser_conf.h"
 #include "build_perl_info.h"
 
  /* See the NOTE in build_perl_info.c on use of functions related to
@@ -58,6 +59,18 @@ init (texinfo_uninstalled, builddir)
 void
 reset_parser (int debug_output)
 
+void
+register_parser_conf (SV *parser)
+    PREINIT:
+      HV *hv_in;
+      const char *key = "parser_conf_descriptor";
+      const PARSER_CONF *parser_conf;
+    CODE:
+      hv_in = (HV *)SvRV (parser);
+      parser_conf = register_conf ();
+      hv_store (hv_in, key, strlen (key),
+                newSViv (parser_conf->descriptor), 0);
+
 # file path, can be in any encoding
 int
 parse_file (filename, input_file_name, input_directory)
diff --git a/tp/Texinfo/XS/parsetexi/conf.c b/tp/Texinfo/XS/parsetexi/conf.c
index 8a38c2b3a5..3a74432487 100644
--- a/tp/Texinfo/XS/parsetexi/conf.c
+++ b/tp/Texinfo/XS/parsetexi/conf.c
@@ -132,6 +132,8 @@ reset_parser_conf (void)
 {
   clear_global_parser_conf ();
 
+  global_parser_conf.descriptor = 0;
+
   global_parser_conf.accept_internalvalue = 0;
   global_parser_conf.cpp_line_directives = 1;
   global_parser_conf.debug = 0;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]