[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Tue, 29 Oct 2024 06:58:25 -0400 (EDT) |
branch: master
commit 3fd94d022a91c0ec3623f4ac0d5e76a02f3623a0
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Tue Oct 29 11:42:12 2024 +0100
* tp/Texinfo/Convert/Converter.pm (get_conf, set_conf, force_conf),
tp/Texinfo/XS/convert/ConvertXS.xs (get_conf, set_conf, force_conf):
do not abort if an unknown variable is accessed or set. In Perl, call
cluck if TEST is set.
---
ChangeLog | 7 +++++
tp/Texinfo/Convert/Converter.pm | 49 +++++++++++++++++++++++---------
tp/Texinfo/XS/convert/ConvertXS.xs | 58 ++++++++++++++++++++++++++++----------
3 files changed, 85 insertions(+), 29 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 7b898376ed..c238a7ba60 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-10-29 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/Convert/Converter.pm (get_conf, set_conf, force_conf),
+ tp/Texinfo/XS/convert/ConvertXS.xs (get_conf, set_conf, force_conf):
+ do not abort if an unknown variable is accessed or set. In Perl, call
+ cluck if TEST is set.
+
2024-10-28 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/XS/main/customization_options.c (free_options_list): free
diff --git a/tp/Texinfo/Convert/Converter.pm b/tp/Texinfo/Convert/Converter.pm
index 231f902da5..455cbb1ec0 100644
--- a/tp/Texinfo/Convert/Converter.pm
+++ b/tp/Texinfo/Convert/Converter.pm
@@ -561,32 +561,47 @@ sub get_converter_errors($)
# Implementation of the customization API that is used in many
# Texinfo modules
+# Unknown variables can only happen when called from init files. From
+# command-line checks are done before.
+
sub get_conf($$)
{
my $self = shift;
- my $conf = shift;
-
- if (!Texinfo::Common::valid_customization_option($conf)) {
- confess("CBUG: unknown option $conf\n");
+ my $var_name = shift;
+
+ if (!Texinfo::Common::valid_customization_option($var_name)) {
+ $self->converter_document_error(sprintf(__(
+ "unknown customization variable: %s"),
+ $var_name));
+ if ($self->{'conf'}->{'TEST'}) {
+ cluck ("BUG: get_conf: unknown customization variable: $var_name");
+ }
+ return undef;
}
- return $self->{'conf'}->{$conf};
+ return $self->{'conf'}->{$var_name};
}
sub set_conf($$$)
{
my $self = shift;
- my $conf = shift;
+ my $var_name = shift;
my $value = shift;
- if (!Texinfo::Common::valid_customization_option($conf)) {
- die "BUG: set_conf: unknown option $conf\n";
+ if (!Texinfo::Common::valid_customization_option($var_name)) {
+ $self->converter_document_error(sprintf(__(
+ "unknown customization variable: %s"),
+ $var_name));
+ if ($self->{'conf'}->{'TEST'}) {
+ cluck ("BUG: set_conf: unknown customization variable: $var_name");
+ }
+ return 0;
}
- if ($self->{'configured'}->{$conf}) {
+ if ($self->{'configured'}->{$var_name}) {
return 0;
} else {
- $self->{'conf'}->{$conf} = $value;
+ $self->{'conf'}->{$var_name} = $value;
return 1;
}
}
@@ -594,14 +609,20 @@ sub set_conf($$$)
sub force_conf($$$)
{
my $self = shift;
- my $conf = shift;
+ my $var_name = shift;
my $value = shift;
- if (!Texinfo::Common::valid_customization_option($conf)) {
- die "BUG: force_conf: unknown option $conf\n";
+ if (!Texinfo::Common::valid_customization_option($var_name)) {
+ $self->converter_document_error(sprintf(__(
+ "unknown customization variable: %s"),
+ $var_name));
+ if ($self->{'conf'}->{'TEST'}) {
+ cluck ("BUG: force_conf: unknown customization variable: $var_name");
+ }
+ return 0;
}
- $self->{'conf'}->{$conf} = $value;
+ $self->{'conf'}->{$var_name} = $value;
return 1;
}
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs
b/tp/Texinfo/XS/convert/ConvertXS.xs
index a163be60b0..3f153b7859 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -256,12 +256,21 @@ set_conf (SV *converter_in, option_name, SV *value)
= find_option_string (self->sorted_options, option_name);
if (!option)
- croak_nocontext ("BUG: set_conf: unknown option %s\n",
+ message_list_document_error (&self->error_messages,
+ self->conf, 0,
+ "unknown customization variable: %s",
+ option_name);
+ /*
+ croak_nocontext ("XS: BUG: set_conf: unknown option %s\n",
option_name);
-
- get_sv_status = get_sv_option (option, value, 0, self->conf, self);
- if (get_sv_status == 0)
- status = 1;
+ */
+ else
+ {
+ get_sv_status = get_sv_option (option, value, 0,
+ self->conf, self);
+ if (get_sv_status == 0)
+ status = 1;
+ }
}
RETVAL = status;
OUTPUT:
@@ -282,13 +291,22 @@ force_conf (SV *converter_in, option_name, SV *value)
= find_option_string (self->sorted_options, option_name);
if (!option)
- croak_nocontext ("BUG: force_conf: unknown option %s\n",
+ message_list_document_error (&self->error_messages,
+ self->conf, 0,
+ "unknown customization variable: %s",
+ option_name);
+ /*
+ croak_nocontext ("XS: BUG: force_conf: unknown option %s\n",
option_name);
-
- /* only possible error would be a type error */
- get_sv_status = get_sv_option (option, value, 1, self->conf, self);
- if (get_sv_status == 0)
- status = 1;
+ */
+ else
+ {
+ /* only possible failure would be a type error */
+ get_sv_status = get_sv_option (option, value, 1,
+ self->conf, self);
+ if (get_sv_status == 0)
+ status = 1;
+ }
}
RETVAL = status;
OUTPUT:
@@ -307,10 +325,20 @@ get_conf (SV *converter_in, option_name)
= find_option_string (self->sorted_options, option_name);
if (!option)
- /* in Perl confess is called, we do not bother here */
- croak_nocontext ("CBUG: unknown option %s\n", option_name);
-
- RETVAL = build_sv_option (option, self);
+ {
+ message_list_document_error (&self->error_messages,
+ self->conf, 0,
+ "unknown customization variable: %s",
+ option_name);
+ /* in Perl cluck is called, no equivalent here */
+ /*
+ croak_nocontext ("XS: BUG: get_conf: unknown option %s\n",
option_name);
+ */
+
+ RETVAL = newSV (0);
+ }
+ else
+ RETVAL = build_sv_option (option, self);
}
else
RETVAL = newSV (0);