[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * tp/Texinfo/Convert/Converter.pm (import, _XS_ge
From: |
Patrice Dumas |
Subject: |
branch master updated: * tp/Texinfo/Convert/Converter.pm (import, _XS_get_unclosed_stream) (get_output_files_XS_unclosed_streams), tp/Texinfo/Convert/HTML.pm (output), tp/Texinfo/XS/convert/ConvertXS.xs (get_unclosed_stream), tp/Texinfo/XS/main/build_perl_info.c (build_output_files_unclosed_files): it is not possible to associate an unclosed stream to a SV from C. However, as found out by Gavin, it is possible to pass a stream through the XS interface. Therefore, in build_output_files_unclosed_files, the unclos [...] |
Date: |
Mon, 06 Nov 2023 18:10:43 -0500 |
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 eebf785cde * tp/Texinfo/Convert/Converter.pm (import,
_XS_get_unclosed_stream) (get_output_files_XS_unclosed_streams),
tp/Texinfo/Convert/HTML.pm (output), tp/Texinfo/XS/convert/ConvertXS.xs
(get_unclosed_stream), tp/Texinfo/XS/main/build_perl_info.c
(build_output_files_unclosed_files): it is not possible to associate an
unclosed stream to a SV from C. However, as found out by Gavin, it is possible
to pass a stream through the XS interface. Therefore, in
build_output_files_unclo [...]
eebf785cde is described below
commit eebf785cdef5f5086209b2b917ce628eb15baceb
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Tue Nov 7 00:10:33 2023 +0100
* tp/Texinfo/Convert/Converter.pm (import, _XS_get_unclosed_stream)
(get_output_files_XS_unclosed_streams), tp/Texinfo/Convert/HTML.pm
(output), tp/Texinfo/XS/convert/ConvertXS.xs (get_unclosed_stream),
tp/Texinfo/XS/main/build_perl_info.c
(build_output_files_unclosed_files): it is not possible to associate
an unclosed stream to a SV from C. However, as found out by Gavin, it
is possible to pass a stream through the XS interface. Therefore, in
build_output_files_unclosed_files, the unclosed file name is
registered, associated to undef, and the stream can then be passed to
perl through a call of the new XS interface
Texinfo::Convert::ConvertXS::get_unclosed_stream. Add get_unclosed_stream
to retrieve the file streams of all the unclosed file paths that came
from XS and are not associated to a stream and associate them to the
unclosed files in output_files_information.
---
ChangeLog | 17 ++++++++
tp/Texinfo/Convert/Converter.pm | 36 ++++++++++++++++
tp/Texinfo/Convert/HTML.pm | 2 +
tp/Texinfo/XS/convert/ConvertXS.xs | 84 +++++++++++++++++++++++++-----------
tp/Texinfo/XS/main/build_perl_info.c | 29 ++++++++++---
tp/Texinfo/XS/main/converter_types.h | 12 ------
6 files changed, 135 insertions(+), 45 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 19a7ade3ef..1f6e983f8f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2023-11-06 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/Convert/Converter.pm (import, _XS_get_unclosed_stream)
+ (get_output_files_XS_unclosed_streams), tp/Texinfo/Convert/HTML.pm
+ (output), tp/Texinfo/XS/convert/ConvertXS.xs (get_unclosed_stream),
+ tp/Texinfo/XS/main/build_perl_info.c
+ (build_output_files_unclosed_files): it is not possible to associate
+ an unclosed stream to a SV from C. However, as found out by Gavin, it
+ is possible to pass a stream through the XS interface. Therefore, in
+ build_output_files_unclosed_files, the unclosed file name is
+ registered, associated to undef, and the stream can then be passed to
+ perl through a call of the new XS interface
+ Texinfo::Convert::ConvertXS::get_unclosed_stream. Add
get_unclosed_stream
+ to retrieve the file streams of all the unclosed file paths that came
+ from XS and are not associated to a stream and associate them to the
+ unclosed files in output_files_information.
+
2023-11-06 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/XS/main/build_perl_info.c,
diff --git a/tp/Texinfo/Convert/Converter.pm b/tp/Texinfo/Convert/Converter.pm
index 2f294413af..9494792977 100644
--- a/tp/Texinfo/Convert/Converter.pm
+++ b/tp/Texinfo/Convert/Converter.pm
@@ -38,6 +38,8 @@ use Carp qw(cluck confess);
use Texinfo::Convert::ConvertXS;
+use Texinfo::XSLoader;
+
use Texinfo::Options;
use Texinfo::Common;
@@ -78,6 +80,9 @@ sub import {
Texinfo::XSLoader::override(
"Texinfo::Convert::Converter::_XS_set_conf",
"Texinfo::Convert::ConvertXS::set_conf");
+ Texinfo::XSLoader::override(
+ "Texinfo::Convert::Converter::_XS_get_unclosed_stream",
+ "Texinfo::Convert::ConvertXS::get_unclosed_stream");
}
$module_loaded = 1;
@@ -1520,6 +1525,37 @@ sub sort_element_counts($$;$$)
return (\@sorted_name_counts_array, $result);
}
+sub _XS_get_unclosed_stream($$)
+{
+ return undef;
+}
+
+# this method retrieves the file streams of all the unclosed file paths
+# that came from XS (normally through build_output_files_unclosed_files)
+# but are not associated to a stream yet, as they can't be directly
+# associated to a stream in C code, but the stream can be returned through
+# an XS interface, here Texinfo::Convert::ConvertXS::get_unclosed_stream.
+sub get_output_files_XS_unclosed_streams($)
+{
+ my $self = shift;
+
+ my $converter_unclosed_files
+ = Texinfo::Common::output_files_unclosed_files(
+ $self->output_files_information());
+ if ($converter_unclosed_files) {
+ foreach my $unclosed_file (keys(%$converter_unclosed_files)) {
+ if (!defined($converter_unclosed_files->{$unclosed_file})) {
+ my $fh = _XS_get_unclosed_stream($self, $unclosed_file);
+ if (defined($fh)) {
+ $converter_unclosed_files->{$unclosed_file} = $fh;
+ } else {
+ delete $converter_unclosed_files->{$unclosed_file};
+ }
+ }
+ }
+ }
+}
+
########################################################################
# XML related methods and variables that may be used in different
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 3e1de802f1..18a50c7d2b 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -11842,6 +11842,8 @@ sub output($$)
$special_units, $output_file, $destination_directory,
$output_filename, $document_name);
+ $self->get_XS_unclosed_streams();
+
if (!defined($text_output)) {
$self->_finalize_output_state();
return undef;
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs
b/tp/Texinfo/XS/convert/ConvertXS.xs
index df661d5e86..cf917ab0a7 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -18,6 +18,8 @@
/* Avoid namespace conflicts. */
#define context perl_context
+#define PERLIO_NOT_STDIO 0
+
#define PERL_NO_GET_CONTEXT
#include "EXTERN.h"
#include "perl.h"
@@ -47,9 +49,62 @@ MODULE = Texinfo::Convert::ConvertXS PACKAGE =
Texinfo::Convert::ConvertXS
# they are enabled, and they can/may need to be overriden in a declaration
PROTOTYPES: ENABLE
+void set_conf(SV *converter_in, conf, SV *value)
+ char *conf = (char *)SvPVbyte_nolen($arg);
+ PREINIT:
+ CONVERTER *self;
+ CODE:
+ /* warn? */
+ self = get_sv_converter (converter_in, 0);
+ if (self)
+ set_conf (self, conf, value);
+
+void
+get_index_entries_sorted_by_letter (SV *converter_in, SV
*index_entries_sorted_by_letter)
+ PREINIT:
+ CONVERTER *self;
+ CODE:
+ self = get_sv_converter (converter_in,
+ "get_index_entries_sorted_by_letter");
+ get_sv_index_entries_sorted_by_letter (self,
+ index_entries_sorted_by_letter);
+
+# pass the stream of an unclosed file path.
+# tried with OutputStream instead of FILE, but it did not work, there
+# was an error with a missing type.
+FILE *
+get_unclosed_stream (SV *converter_in, file_path)
+ char *file_path = (char *)SvPVbyte_nolen($arg);
+ PREINIT:
+ CONVERTER *self;
+ OUTPUT_FILES_INFORMATION *output_files_information;
+ FILE_STREAM_LIST *unclosed_files;
+ FILE *result = 0;
+ CODE:
+ self = get_sv_converter (converter_in,
+ "get_unclosed_stream");
+ output_files_information = &self->output_files_information;
+ unclosed_files = &output_files_information->unclosed_files;
+ if (unclosed_files->number > 0)
+ {
+ int i;
+ for (i = 0; i < unclosed_files->number; i++)
+ {
+ FILE_STREAM *file_stream = &unclosed_files->list[i];
+ if (!strcmp (file_path, file_stream->file_path))
+ {
+ result = file_stream->stream;
+ break;
+ }
+ }
+ }
+ RETVAL = result;
+ OUTPUT:
+ RETVAL
+
+
SV *
-plain_texinfo_convert_tree (tree_in)
- SV *tree_in
+plain_texinfo_convert_tree (SV *tree_in)
PREINIT:
DOCUMENT *document = 0;
CODE:
@@ -68,9 +123,7 @@ plain_texinfo_convert_tree (tree_in)
# unused argument is used in the overriden function if XS is not used
SV *
-text_convert_tree (text_options_in, tree_in, unused=0)
- SV *text_options_in
- SV *tree_in
+text_convert_tree (SV *text_options_in, SV *tree_in, unused=0)
PREINIT:
DOCUMENT *document = 0;
TEXT_OPTIONS *text_options = 0;
@@ -96,16 +149,6 @@ text_convert_tree (text_options_in, tree_in, unused=0)
int
html_converter_initialize_sv (SV *converter_in, SV
*default_formatting_references, SV *default_css_string_formatting_references,
SV *default_commands_open, SV *default_commands_conversion, SV
*default_css_string_commands_conversion, SV *default_types_open, SV
*default_types_conversion, SV *default_css_string_types_conversion, SV
*default_output_units_conversion)
-void set_conf(SV *converter_in, conf, SV *value)
- char *conf = (char *)SvPVbyte_nolen($arg);
- PREINIT:
- CONVERTER *self;
- CODE:
- /* warn? */
- self = get_sv_converter (converter_in, 0);
- if (self)
- set_conf (self, conf, value);
-
void
html_initialize_output_state (SV *converter_in, char *context)
PREINIT:
@@ -210,17 +253,6 @@ html_pop_document_context (SV *converter_in)
}
-void
-get_index_entries_sorted_by_letter (SV *converter_in, SV
*index_entries_sorted_by_letter)
- PREINIT:
- CONVERTER *self;
- CODE:
- /* add warn string? */
- self = get_sv_converter (converter_in,
- "get_index_entries_sorted_by_letter");
- get_sv_index_entries_sorted_by_letter (self,
- index_entries_sorted_by_letter);
-
# my ($output_units, $special_units, $associated_special_units)
# = $self->_prepare_conversion_units($root, $document_name);
void
diff --git a/tp/Texinfo/XS/main/build_perl_info.c
b/tp/Texinfo/XS/main/build_perl_info.c
index 555188208c..7c1df48519 100644
--- a/tp/Texinfo/XS/main/build_perl_info.c
+++ b/tp/Texinfo/XS/main/build_perl_info.c
@@ -1693,15 +1693,30 @@ build_output_files_unclosed_files (HV *hv,
{
FILE_STREAM *file_stream = &unclosed_files->list[i];
char *file_path = file_stream->file_path;
- /* FIXME no way to pass back the FILE *stream see comments in
- converter_types.h. So for now we close here.
+ /* It is not possible to associate the unclosed stream to a SV.
+ It is possible to obtain a PerlIO from a FILE, as described in
+ https://perldoc.perl.org/perlapio
+ with
+ PerlIO * PerlIO_importFILE (FILE *stdio, const char *mode)
+ However, it is not possible to create an IO * SV from the PerlIO
+ or associate to an already existing IO *. An IO * SV is created by
+ IO * newIO()
+ and it is possible to get the associated PerlIO, with
+ PerlIO *IoOFP(IO *io);
+ but not to set it.
+
+ However, it is possible to pass a stream through the XS
+ interface. Therefore here, the unclosed file name is registered,
+ the stream can then be passed to perl through a call of
+ the XS interface Texinfo::Convert::ConvertXS::get_unclosed_stream.
+ This is normally done by calling get_output_files_XS_unclosed_streams
+ as this method retrieves the file streams of all the unclosed file
+ paths that came from XS and are not associated to a stream.
+
+ Register that there is an unclosed file from XS by associating
+ with undef; if from perl, it would be associated with a file handle */
SV *file_path_sv = newSVpv_byte (file_path, 0);
hv_store_ent (unclosed_files_hv, file_path_sv, newSV (0), 0);
- */
- if (strcmp (file_path, "-"))
- {
- fclose (file_stream->stream);
- }
}
}
}
diff --git a/tp/Texinfo/XS/main/converter_types.h
b/tp/Texinfo/XS/main/converter_types.h
index a66eaf5ac3..05e4fb2975 100644
--- a/tp/Texinfo/XS/main/converter_types.h
+++ b/tp/Texinfo/XS/main/converter_types.h
@@ -296,18 +296,6 @@ typedef struct FILE_NAME_PATH_COUNTER_LIST {
typedef struct FILE_STREAM {
char *file_path;
- /* TODO see https://perldoc.perl.org/perlapio to pass to perl
- PerlIO_importFILE. This creates a perl io object.
- PerlIO * PerlIO_importFILE (FILE *stdio, const char *mode)
- A SV is IO *, created by newIO
- IO * newIO()
- the output perolIO of an IO is obtained by:
- PerlIO *IoOFP(IO *io);
- FIXME no way to set the PerlIO associated to an IO corresponding
- to IoOFP?
- From perlguts
- All of these accessors macros are lvalues, there are no distinct _set()
macros to modify the members of the IO object.
- */
FILE *stream;
} FILE_STREAM;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * tp/Texinfo/Convert/Converter.pm (import, _XS_get_unclosed_stream) (get_output_files_XS_unclosed_streams), tp/Texinfo/Convert/HTML.pm (output), tp/Texinfo/XS/convert/ConvertXS.xs (get_unclosed_stream), tp/Texinfo/XS/main/build_perl_info.c (build_output_files_unclosed_files): it is not possible to associate an unclosed stream to a SV from C. However, as found out by Gavin, it is possible to pass a stream through the XS interface. Therefore, in build_output_files_unclosed_files, the unclos [...],
Patrice Dumas <=
- Prev by Date:
branch master updated: * tp/Texinfo/XS/main/build_perl_info.c, tp/Texinfo/XS/main/build_perl_info.c: move code specific of HTML to the end of the files.
- Next by Date:
branch master updated: * tp/Texinfo/XS/Makefile.am (ConvertXS_la_SOURCES), tp/Texinfo/XS/convert/call_html_perl_function.c, tp/Texinfo/XS/main/build_perl_info.c, tp/Texinfo/XS/main/call_perl_function.c, tp/Texinfo/XS/convert/build_html_perl_state.c: new files convert/call_html_perl_function.c and convert/build_html_perl_state.c with HTML specific content of call_perl_function.c and build_perl_info.c.
- Previous by thread:
branch master updated: * tp/Texinfo/XS/main/build_perl_info.c, tp/Texinfo/XS/main/build_perl_info.c: move code specific of HTML to the end of the files.
- Next by thread:
branch master updated: * tp/Texinfo/XS/Makefile.am (ConvertXS_la_SOURCES), tp/Texinfo/XS/convert/call_html_perl_function.c, tp/Texinfo/XS/main/build_perl_info.c, tp/Texinfo/XS/main/call_perl_function.c, tp/Texinfo/XS/convert/build_html_perl_state.c: new files convert/call_html_perl_function.c and convert/build_html_perl_state.c with HTML specific content of call_perl_function.c and build_perl_info.c.
- Index(es):