[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * tp/Texinfo/XS/convert/ConvertXS.xs (generic_con
From: |
Patrice Dumas |
Subject: |
branch master updated: * tp/Texinfo/XS/convert/ConvertXS.xs (generic_converter_init), tp/Texinfo/XS/convert/get_converter_perl_info.c: inline converter_get_info_from_sv in generic_converter_init. |
Date: |
Fri, 04 Oct 2024 19:42:08 -0400 |
This is an automated email from the git hooks/post-receive script.
pertusus pushed a commit to branch master
in repository texinfo.
The following commit(s) were added to refs/heads/master by this push:
new 6d9730e3ae * tp/Texinfo/XS/convert/ConvertXS.xs
(generic_converter_init), tp/Texinfo/XS/convert/get_converter_perl_info.c:
inline converter_get_info_from_sv in generic_converter_init.
6d9730e3ae is described below
commit 6d9730e3ae6e91ef170c8f390caef1b40dd2e03e
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Aug 17 12:45:49 2024 +0200
* tp/Texinfo/XS/convert/ConvertXS.xs (generic_converter_init),
tp/Texinfo/XS/convert/get_converter_perl_info.c: inline
converter_get_info_from_sv in generic_converter_init.
* tp/Texinfo/XS/convert/ConvertXS.xs (generic_converter_init): rename
class variable as class_name.
* tp/Texinfo/XS/convert/converter.c (set_converter_init_information):
call apply_converter_info on user_conf only if user_conf is non-NULL.
* tp/Texinfo/XS/convert/get_converter_perl_info.c
(get_converter_info_from_sv), tp/Texinfo/XS/convert/ConvertXS.xs
(converter_defaults, generic_converter_init): create
CONVERTER_INITIALIZATION_INFO in get_converter_info_from_sv if the
input SV is not undef and return it. Update callers.
* tp/Texinfo/XS/convert/ConvertXS.xs (converter_defaults)
(generic_converter_init), tp/Texinfo/XS/main/converter_types.h
(CONVERTER): add format_defaults field in CONVERTER. If the
converter_defaults argument is a converter, store format_defaults in
converter and return undef to Perl in converter_defaults. In
generic_converter_init, if there is no format_defaults from Perl,
take C converter format_defaults. This avoids building to Perl and
getting from Perl.
---
ChangeLog | 27 +++++++
tp/Texinfo/XS/convert/ConvertXS.xs | 97 ++++++++++++++++++++-----
tp/Texinfo/XS/convert/converter.c | 3 +-
tp/Texinfo/XS/convert/get_converter_perl_info.c | 56 +++-----------
tp/Texinfo/XS/convert/get_converter_perl_info.h | 14 ++--
tp/Texinfo/XS/main/converter_types.h | 25 ++++---
6 files changed, 134 insertions(+), 88 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index a50b7cfffb..2406f46f4e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,30 @@
+2024-08-17 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/XS/convert/ConvertXS.xs (generic_converter_init),
+ tp/Texinfo/XS/convert/get_converter_perl_info.c: inline
+ converter_get_info_from_sv in generic_converter_init.
+
+ * tp/Texinfo/XS/convert/ConvertXS.xs (generic_converter_init): rename
+ class variable as class_name.
+
+ * tp/Texinfo/XS/convert/converter.c (set_converter_init_information):
+ call apply_converter_info on user_conf only if user_conf is non-NULL.
+
+ * tp/Texinfo/XS/convert/get_converter_perl_info.c
+ (get_converter_info_from_sv), tp/Texinfo/XS/convert/ConvertXS.xs
+ (converter_defaults, generic_converter_init): create
+ CONVERTER_INITIALIZATION_INFO in get_converter_info_from_sv if the
+ input SV is not undef and return it. Update callers.
+
+ * tp/Texinfo/XS/convert/ConvertXS.xs (converter_defaults)
+ (generic_converter_init), tp/Texinfo/XS/main/converter_types.h
+ (CONVERTER): add format_defaults field in CONVERTER. If the
+ converter_defaults argument is a converter, store format_defaults in
+ converter and return undef to Perl in converter_defaults. In
+ generic_converter_init, if there is no format_defaults from Perl,
+ take C converter format_defaults. This avoids building to Perl and
+ getting from Perl.
+
2024-08-16 Patrice Dumas <pertusus@free.fr>
No converter information in converter_defaults, and XS override
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs
b/tp/Texinfo/XS/convert/ConvertXS.xs
index ae4210dd11..4d8e64f578 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -97,18 +97,28 @@ init (int texinfo_uninstalled, SV *pkgdatadir_sv, SV
*tp_builddir_sv, SV *top_sr
OUTPUT:
RETVAL
+# this function could be called with a class name or a converter as first
+# argument. In Perl code, the first argument is not used in the functions,
+# it is only used to locate the method to call through inheritance.
+# Here, if the argument is a converter, a C converter is created, the
+# result of converter_defaults is stored in the converter and an empty
+# hash is returned to avoid building to Perl and then getting from Perl
+# in generic_converter_init.
+#
+# NOTE this function is generic, but should only be overriden for formats
+# setting option defaults in C.
SV *
converter_defaults (SV *converter_in, SV *conf_sv)
PREINIT:
CONVERTER_INITIALIZATION_INFO *conf;
CONVERTER_INITIALIZATION_INFO *format_defaults;
+ CONVERTER *self = 0;
/* we need sorted options to be able to find the type of options
in functions called from get_converter_info_from_sv*/
OPTIONS *options;
OPTION **sorted_options;
const char *class_name;
enum converter_format converter_format;
- /* int has_conf; */
CODE:
options = new_options ();
sorted_options = setup_sorted_options (options);
@@ -119,6 +129,7 @@ converter_defaults (SV *converter_in, SV *conf_sv)
{
HV *stash = SvSTASH (SvRV (converter_in));
class_name = HvNAME (stash);
+ self = get_or_create_sv_converter (converter_in, class_name);
}
else
class_name = SvPV_nolen (converter_in);
@@ -127,13 +138,8 @@ converter_defaults (SV *converter_in, SV *conf_sv)
converter_format
= find_perl_converter_class_converter_format (class_name);
- conf = new_converter_initialization_info ();
-
- /*
- has_conf =
- */
- get_converter_info_from_sv (conf_sv, 0, 0,
- sorted_options, conf);
+ conf = get_converter_info_from_sv (conf_sv, class_name, 0,
+ sorted_options);
free (sorted_options);
free_options (options);
@@ -141,36 +147,87 @@ converter_defaults (SV *converter_in, SV *conf_sv)
format_defaults = converter_defaults (converter_format, conf);
- destroy_converter_initialization_info (conf);
+ if (conf)
+ destroy_converter_initialization_info (conf);
+
+ if (self)
+ {
+ const char *key = "converter_descriptor";
+ HV *converter_hv = (HV *)SvRV (converter_in);
+
+ self->format_defaults = format_defaults;
+
+ /* the converter needs to be found, nothing else to pass to
+ Perl */
+ /* FIXME converter->converter_descriptor is size_t, there will be an overflow
+ if > max of IV */
+ hv_store (converter_hv, key, strlen (key),
+ newSViv ((IV)self->converter_descriptor), 0);
- RETVAL = build_sv_options_from_options_list (&format_defaults->conf,
0);
- destroy_converter_initialization_info (format_defaults);
+ RETVAL = newSV (0);
+ }
+ else
+ {
+ RETVAL
+ = build_sv_options_from_options_list (&format_defaults->conf, 0);
+ destroy_converter_initialization_info (format_defaults);
+ }
OUTPUT:
RETVAL
# NOTE not sure what the scope of class is. When tested, valgrind did not
# complain.
void
-generic_converter_init (SV *converter_in, const char *class, SV
*format_defaults_sv, SV *conf_sv=0)
+generic_converter_init (SV *converter_in, const char *class_name, SV
*format_defaults_sv, SV *conf_sv=0)
PREINIT:
CONVERTER *self;
CONVERTER_INITIALIZATION_INFO *format_defaults;
CONVERTER_INITIALIZATION_INFO *conf;
+ HV *converter_hv;
CODE:
- self = get_or_create_sv_converter (converter_in, class);
+ self = get_or_create_sv_converter (converter_in, class_name);
+ converter_hv = (HV *)SvRV (converter_in);
+ self->hv = converter_hv;
- format_defaults = new_converter_initialization_info ();
- conf = new_converter_initialization_info ();
+ format_defaults = get_converter_info_from_sv (format_defaults_sv,
+ class_name, self, self->sorted_options);
+ /* if format_defaults_sv is undef, it means that format_defaults
+ should have been registered in the C converter */
+ if (!format_defaults)
+ {
+ format_defaults = self->format_defaults;
+ self->format_defaults = 0;
+ number_options_list (&format_defaults->conf, self->sorted_options);
+ }
- converter_get_info_from_sv (converter_in, class, self,
- format_defaults_sv,
- conf_sv, format_defaults, conf);
+ conf = get_converter_info_from_sv (conf_sv, class_name, self,
+ self->sorted_options);
set_converter_init_information (self, self->format,
format_defaults, conf);
- destroy_converter_initialization_info (format_defaults);
- destroy_converter_initialization_info (conf);
+
+ if (format_defaults)
+ {
+ /* set directly Perl converter keys with non 'valid' customization info */
+ set_non_customization_sv (converter_hv, format_defaults_sv,
+ &format_defaults->non_valid_customization);
+ destroy_converter_initialization_info (format_defaults);
+ }
+
+ if (conf)
+ {
+ /* set directly Perl converter keys with non 'valid' customization info */
+ set_non_customization_sv (converter_hv, conf_sv,
+ &conf->non_valid_customization);
+
+ destroy_converter_initialization_info (conf);
+ }
+
+ /*
+ fprintf (stderr, "XS|CONVERTER Init from SV: %zu; \n",
+ self->converter_descriptor);
+ */
pass_generic_converter_to_converter_sv (converter_in, self);
diff --git a/tp/Texinfo/XS/convert/converter.c
b/tp/Texinfo/XS/convert/converter.c
index 492a0a4165..a5d0db1217 100644
--- a/tp/Texinfo/XS/convert/converter.c
+++ b/tp/Texinfo/XS/convert/converter.c
@@ -350,7 +350,8 @@ set_converter_init_information (CONVERTER *converter,
if (format_defaults)
apply_converter_info (converter, format_defaults, 0);
- apply_converter_info (converter, user_conf, 1);
+ if (user_conf)
+ apply_converter_info (converter, user_conf, 1);
/* in Perl sets converter_init_conf, but in C we use only one
structure for converter_init_conf and output_init_conf, which
diff --git a/tp/Texinfo/XS/convert/get_converter_perl_info.c
b/tp/Texinfo/XS/convert/get_converter_perl_info.c
index ba49f97c26..0befa60d75 100644
--- a/tp/Texinfo/XS/convert/get_converter_perl_info.c
+++ b/tp/Texinfo/XS/convert/get_converter_perl_info.c
@@ -133,7 +133,7 @@ converter_set_document_from_sv (SV *converter_in, SV
*document_in)
/* add to converter hash the INIT_INFO_SV key values that are
not customization variables, listed in NO_VALID_CUSTOMIZATION */
-static void
+void
set_non_customization_sv (HV *converter_hv, SV *init_info_sv,
STRING_LIST *non_valid_customization)
{
@@ -236,12 +236,13 @@ new_numbered_option_from_sv (SV *option_sv, CONVERTER
*converter,
/* class is Perl converter class for warning message in case the class
cannot be found otherwise */
-int
+CONVERTER_INITIALIZATION_INFO *
get_converter_info_from_sv (SV *conf_sv, const char *class,
CONVERTER *converter,
- OPTION **sorted_options,
- CONVERTER_INITIALIZATION_INFO *initialization_info)
+ OPTION **sorted_options)
{
+ CONVERTER_INITIALIZATION_INFO *initialization_info = 0;
+
dTHX;
if (conf_sv && SvOK (conf_sv))
@@ -251,10 +252,12 @@ get_converter_info_from_sv (SV *conf_sv, const char
*class,
HV *conf_hv = (HV *)SvRV (conf_sv);
+ initialization_info = new_converter_initialization_info ();
+
hv_number = hv_iterinit (conf_hv);
if (!hv_number)
- return 0;
+ return initialization_info;
initialize_options_list (&initialization_info->conf, hv_number);
initialization_info->conf.number = 0;
@@ -318,49 +321,8 @@ get_converter_info_from_sv (SV *conf_sv, const char *class,
}
}
}
- return 1;
}
- return 0;
-}
-
-int
-converter_get_info_from_sv (SV *converter_sv, const char *class,
- CONVERTER *converter,
- SV *format_defaults_sv, SV *conf_sv,
- CONVERTER_INITIALIZATION_INFO *format_defaults,
- CONVERTER_INITIALIZATION_INFO *conf)
-{
- HV *converter_hv;
- int has_format_defaults;
- int has_conf;
-
- dTHX;
-
- converter_hv = (HV *)SvRV (converter_sv);
-
- converter->hv = converter_hv;
-
- has_format_defaults
- = get_converter_info_from_sv (format_defaults_sv, class, converter,
- converter->sorted_options, format_defaults);
-
- has_conf = get_converter_info_from_sv (conf_sv, class, converter,
- converter->sorted_options, conf);
-
- /* set directly Perl converter keys with non 'valid' customization info */
- set_non_customization_sv (converter_hv, format_defaults_sv,
- &format_defaults->non_valid_customization);
-
- set_non_customization_sv (converter_hv, conf_sv,
- &conf->non_valid_customization);
-
- /*
- fprintf (stderr, "XS|CONVERTER Init from SV: %d; %d %d\n",
- converter->converter_descriptor, has_format_defaults,
- has_conf);
- */
-
- return has_format_defaults + has_conf;
+ return initialization_info;
}
void
diff --git a/tp/Texinfo/XS/convert/get_converter_perl_info.h
b/tp/Texinfo/XS/convert/get_converter_perl_info.h
index b641ecef27..d7bd5429e4 100644
--- a/tp/Texinfo/XS/convert/get_converter_perl_info.h
+++ b/tp/Texinfo/XS/convert/get_converter_perl_info.h
@@ -13,15 +13,11 @@
CONVERTER *get_sv_converter (SV *sv_in, const char *warn_string);
CONVERTER *get_or_create_sv_converter (SV *converter_in,
const char *input_class);
-int get_converter_info_from_sv (SV *conf_sv, const char *class,
- CONVERTER *converter,
- OPTION **sorted_options,
- CONVERTER_INITIALIZATION_INFO *initialization_info);
-int converter_get_info_from_sv (SV *converter_sv, const char *class,
- CONVERTER *converter,
- SV *format_defaults_sv, SV *conf_sv,
- CONVERTER_INITIALIZATION_INFO *format_defaults,
- CONVERTER_INITIALIZATION_INFO *conf);
+CONVERTER_INITIALIZATION_INFO * get_converter_info_from_sv (SV *conf_sv,
+ const char *class, CONVERTER *converter,
+ OPTION **sorted_options);
+void set_non_customization_sv (HV *converter_hv, SV *init_info_sv,
+ STRING_LIST *non_valid_customization);
CONVERTER *converter_set_document_from_sv (SV *converter_in, SV *document_in);
TEXT_OPTIONS *copy_sv_options_for_convert_text (SV *sv_in);
diff --git a/tp/Texinfo/XS/main/converter_types.h
b/tp/Texinfo/XS/main/converter_types.h
index 7c0b069cea..b8b129e7bb 100644
--- a/tp/Texinfo/XS/main/converter_types.h
+++ b/tp/Texinfo/XS/main/converter_types.h
@@ -756,6 +756,17 @@ typedef struct PRE_CLASS_TYPE_INFO {
char *pre_class;
} PRE_CLASS_TYPE_INFO;
+/* information on converter configuration from a source of configuration
+ (either output format or user customization) */
+typedef struct CONVERTER_INITIALIZATION_INFO {
+ char *converted_format;
+ char *output_format;
+ TRANSLATED_COMMAND *translated_commands;
+ OPTIONS_LIST conf;
+ /* gather strings that are not customization options */
+ STRING_LIST non_valid_customization;
+} CONVERTER_INITIALIZATION_INFO;
+
typedef struct CONVERTER {
int converter_descriptor;
/* perl converter. This should be HV *hv,
@@ -765,6 +776,9 @@ typedef struct CONVERTER {
/* this is the type of the converter, not of the output. (Similar to
a module name in Perl) */
enum converter_format format;
+ /* used to pass converter_defaults result, if going through XS and
+ destroyed shortly after */
+ CONVERTER_INITIALIZATION_INFO *format_defaults;
OPTIONS *conf;
OPTIONS *init_conf;
/* an array containing the fields of conf ordered by name */
@@ -934,17 +948,6 @@ typedef struct CONVERTER {
void *pl_info_hv; /* converter->{'converter_info'} */
} CONVERTER;
-/* information on converter configuration from a source of configuration
- (either output format or user customization) */
-typedef struct CONVERTER_INITIALIZATION_INFO {
- char *converted_format;
- char *output_format;
- TRANSLATED_COMMAND *translated_commands;
- OPTIONS_LIST conf;
- /* gather strings that are not customization options */
- STRING_LIST non_valid_customization;
-} CONVERTER_INITIALIZATION_INFO;
-
typedef struct TRANSLATED_SUI_ASSOCIATION {
enum special_unit_info_tree tree_type;
enum special_unit_info_type string_type;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * tp/Texinfo/XS/convert/ConvertXS.xs (generic_converter_init), tp/Texinfo/XS/convert/get_converter_perl_info.c: inline converter_get_info_from_sv in generic_converter_init.,
Patrice Dumas <=