cvs commit: modperl-2.0/xs/APR/PerlIO apr_perlio.c
stas2002/08/21 08:40:17 Modified:xs/APR/PerlIO apr_perlio.c Log: - try to go without the dup() in the non-perlio case, leave enough comments to easily reconstruct the dupping code correctly if that proves to be wrong. - add some debug tracing code Revision ChangesPath 1.23 +24 -7 modperl-2.0/xs/APR/PerlIO/apr_perlio.c Index: apr_perlio.c === RCS file: /home/cvs/modperl-2.0/xs/APR/PerlIO/apr_perlio.c,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- apr_perlio.c 21 Aug 2002 04:46:44 - 1.22 +++ apr_perlio.c 21 Aug 2002 15:40:17 - 1.23 -525,15 +525,32 /* convert to the OS representation of file */ rc = apr_os_file_get(os_file, file); if (rc != APR_SUCCESS) { -croak(filedes retrieval failed!); +Perl_croak(aTHX_ filedes retrieval failed!); } - -fd = PerlLIO_dup(os_file); -/* Perl_warn(aTHX_ fd old: %d, new %d\n, os_file, fd); */ - -if (!(retval = PerlIO_fdopen(fd, mode))) { + +#ifdef PERLIO_APR_DEBUG +Perl_warn(aTHX_ converting fd %d\n, os_file); +#endif + +/* let's try without the dup, it seems to work fine: + + fd = PerlLIO_dup(os_file); + Perl_warn(aTHX_ fd old: %d, new %d\n, os_file, fd); + if (!(retval = PerlIO_fdopen(fd, mode))) { + ... + } + + in any case if we later decide to dup, remember to: + + apr_file_close(file); + + after PerlIO_fdopen() or that fh will be leaked + +*/ + +if (!(retval = PerlIO_fdopen(os_file, mode))) { PerlLIO_close(fd); -croak(fdopen failed!); +Perl_croak(aTHX_ fdopen failed!); } return retval;
cvs commit: modperl-2.0/xs/APR/PerlIO apr_perlio.c
stas2002/08/21 08:41:29 Modified:xs/APR/PerlIO apr_perlio.c Log: similar to the perlio case: - IoIFP(io) *must* be always set on the valid io sv, otherwise it'll be never closed and fh and memory leaked. as i saw from doio.c, the solution is to simply copy IoOFP. - add IoTYPE_WRONLY and IoTYPE_RDONLY flags to protect from wrong use Revision ChangesPath 1.24 +4 -1 modperl-2.0/xs/APR/PerlIO/apr_perlio.c Index: apr_perlio.c === RCS file: /home/cvs/modperl-2.0/xs/APR/PerlIO/apr_perlio.c,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- apr_perlio.c 21 Aug 2002 15:40:17 - 1.23 +++ apr_perlio.c 21 Aug 2002 15:41:29 - 1.24 -567,11 +567,14 switch (type) { case APR_PERLIO_HOOK_WRITE: -IoOFP(GvIOp(gv)) = apr_perlio_apr_file_to_FILE(aTHX_ file, type); +IoIFP(GvIOp(gv)) = IoOFP(GvIOp(gv)) = +apr_perlio_apr_file_to_FILE(aTHX_ file, type); IoFLAGS(GvIOp(gv)) |= IOf_FLUSH; +IoTYPE(GvIOp(gv)) = IoTYPE_WRONLY; break; case APR_PERLIO_HOOK_READ: IoIFP(GvIOp(gv)) = apr_perlio_apr_file_to_FILE(aTHX_ file, type); +IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY; break; };
cvs commit: modperl-2.0/xs/APR/PerlIO apr_perlio.c
stas2002/08/20 21:44:14 Modified:xs/APR/PerlIO apr_perlio.c Log: improve errors handling add extended debugging trace Revision ChangesPath 1.21 +34 -11modperl-2.0/xs/APR/PerlIO/apr_perlio.c Index: apr_perlio.c === RCS file: /home/cvs/modperl-2.0/xs/APR/PerlIO/apr_perlio.c,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- apr_perlio.c 5 Jul 2002 05:05:36 - 1.20 +++ apr_perlio.c 21 Aug 2002 04:44:14 - 1.21 -268,13 +268,20 #ifdef PERLIO_APR_DEBUG const char *new_path = NULL; +apr_os_file_t os_file; + if (!PL_dirty) { /* if this is called during perl_destruct we are in trouble */ apr_file_name_get(new_path, st-file); } -Perl_warn(aTHX_ PerlIOAPR_close obj=0x%lx, file=0x%lx, name=%s\n, - (unsigned long)f, (unsigned long)st-file, +rc = apr_os_file_get(os_file, st-file); +if (rc != APR_SUCCESS) { +Perl_croak(aTHX_ filedes retrieval failed!); +} + +Perl_warn(aTHX_ PerlIOAPR_close obj=0x%lx, file=0x%lx, fd=%d, name=%s\n, + (unsigned long)f, (unsigned long)st-file, os_file, new_path ? new_path : (UNKNOWN)); #endif -415,9 +422,11 { char *mode; const char *layers = :APR; +PerlIOAPR *st; PerlIO *f = PerlIO_allocate(aTHX); + if (!f) { -return NULL; +Perl_croak(aTHX_ Failed to allocate PerlIO struct); } switch (type) { -430,19 +439,33 }; PerlIO_apply_layers(aTHX_ f, mode, layers); +if (!f) { +Perl_croak(aTHX_ Failed to apply the ':APR' layer); +} -if (f) { -PerlIOAPR *st = PerlIOSelf(f, PerlIOAPR); +st = PerlIOSelf(f, PerlIOAPR); -/* XXX: should we dup first? the timeout could close the fh! */ -st-pool = pool; -st-file = file; -PerlIOBase(f)-flags |= PERLIO_F_OPEN; +#ifdef PERLIO_APR_DEBUG +{ +apr_status_t rc; +apr_os_file_t os_file; -return f; +/* convert to the OS representation of file */ +rc = apr_os_file_get(os_file, file); +if (rc != APR_SUCCESS) { +croak(filedes retrieval failed!); +} + +Perl_warn(aTHX_ converting to PerlIO fd %d, mode '%s'\n, + os_file, mode); } +#endif + +st-pool = pool; +st-file = file; +PerlIOBase(f)-flags |= PERLIO_F_OPEN; -return NULL; +return f; } static SV *apr_perlio_PerlIO_to_glob(pTHX_ PerlIO *pio, apr_perlio_hook_e type)
cvs commit: modperl-2.0/xs/APR/PerlIO apr_perlio.c
stas2002/08/20 21:46:44 Modified:xs/APR/PerlIO apr_perlio.c Log: - IoIFP(io) *must* be always set on the valid io sv, otherwise it'll be never closed and fh and memory leaked. as i saw from doio.c, the solution is to simply copy IoOFP. - add IoTYPE_WRONLY and IoTYPE_RDONLY flags to protect from wrong use Revision ChangesPath 1.22 +5 -1 modperl-2.0/xs/APR/PerlIO/apr_perlio.c Index: apr_perlio.c === RCS file: /home/cvs/modperl-2.0/xs/APR/PerlIO/apr_perlio.c,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- apr_perlio.c 21 Aug 2002 04:44:14 - 1.21 +++ apr_perlio.c 21 Aug 2002 04:46:44 - 1.22 -478,11 +478,15 switch (type) { case APR_PERLIO_HOOK_WRITE: -IoOFP(GvIOp(gv)) = pio; + /* if IoIFP() is not assigned to it'll be never closed, see + * Perl_io_close() */ +IoIFP(GvIOp(gv)) = IoOFP(GvIOp(gv)) = pio; IoFLAGS(GvIOp(gv)) |= IOf_FLUSH; +IoTYPE(GvIOp(gv)) = IoTYPE_WRONLY; break; case APR_PERLIO_HOOK_READ: IoIFP(GvIOp(gv)) = pio; +IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY; break; };
cvs commit: modperl-2.0/xs/APR/PerlIO apr_perlio.c apr_perlio.h
stas2002/06/21 08:28:44 Modified:t/response/TestAPR perlio.pm xs/APR/PerlIO apr_perlio.c apr_perlio.h Log: APR PerlIO updates: - make the apr layer independent from PerlIOBuf - sync with the latest PerlIO API changes - cleanup - add a new test for buffered write - prepare for the future possible LARGE_FILES_CONFLICT constant, for seek tests Revision ChangesPath 1.11 +20 -8 modperl-2.0/t/response/TestAPR/perlio.pm Index: perlio.pm === RCS file: /home/cvs/modperl-2.0/t/response/TestAPR/perlio.pm,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- perlio.pm 15 Jun 2002 23:48:58 - 1.10 +++ perlio.pm 21 Jun 2002 15:28:43 - 1.11 -12,6 +12,10 use Apache::Const -compile = 'OK'; use constant HAVE_PERLIO = eval { require APR::PerlIO }; +#XXX: feel free to enable if largefile support is not enabled in Perl +#XXX: APR::LARGE_FILES_CONFLICT constant? +use constant LARGE_FILES_CONFLICT = 1; + sub handler { my $r = shift; -22,10 +26,10 return Apache::OK; } -my $tests = 2; #XXX 11; +my $tests = 12; my $lfs_tests = 3; -#$tests += $lfs_tests if USE_LARGE_FILES; #XXX +$tests += $lfs_tests unless LARGE_FILES_CONFLICT; plan $r, tests = $tests, have_perl 'iolayers'; -36,6 +40,7 my $sep = -- sep --\n; my lines = (This is a test: $$\n, test line --sep two\n); + my $expected = $lines[0]; my $expected_all = join $sep, lines; -66,10 +71,9 expected failure); } } -return Apache::OK; #XXX remove when perlio issues are sorted out + # seek/tell() tests -#XXX: feel free to enable if largefile support is not enabled in Perl -if (0) { +unless (LARGE_FILES_CONFLICT) { open my $fh, :APR, $file, $r or die Cannot open $file for reading: $!; -132,7 +136,7 my expect = ($lines[0] . $sep, $lines[1]); ok t_cmp(\@expect, \@got_lines, - adjusted input record sep read); + custom complex input record sep read); close $fh; } -179,17 +183,25 { open my $wfh, :APR, $file, $r or die Cannot open $file for writing: $!; +open my $rfh, :APR, $file, $r +or die Cannot open $file for reading: $!; my $expected = This is an un buffering write test; # unbuffer my $oldfh = select($wfh); $| = 1; select($oldfh); print $wfh $expected; # must be flushed to disk immediately -open my $rfh, :APR, $file, $r -or die Cannot open $file for reading: $!; ok t_cmp($expected, scalar($rfh), file unbuffered write); + +# buffer up +$oldfh = select($wfh); $| = 0; select($oldfh); +print $wfh $expected; # must be flushed to disk immediately + +ok t_cmp(undef, + scalar($rfh), + file buffered write); close $wfh; close $rfh; 1.16 +102 -47 modperl-2.0/xs/APR/PerlIO/apr_perlio.c Index: apr_perlio.c === RCS file: /home/cvs/modperl-2.0/xs/APR/PerlIO/apr_perlio.c,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- apr_perlio.c 21 Jun 2002 02:06:48 - 1.15 +++ apr_perlio.c 21 Jun 2002 15:28:43 - 1.16 -10,23 +10,37 * The PerlIO API is documented in perliol.pod. **/ +/* + * APR::PerlIO implements a PerlIO layer using apr_file_io as the core. + */ + +/* + * XXX: Since we cannot snoop on the internal apr_file_io buffer + * currently the IO is not buffered on the Perl side so every read + * requests a char at a time, which is slow. Consider copying the + * relevant code from PerlIOBuf to implement our own buffer, similar + * to what PerlIOBuf does or push :perlio layer on top of this layer + */ + typedef struct { -PerlIOBuf base;/* PerlIOBuf stuff */ +struct _PerlIO base; apr_file_t *file; apr_pool_t *pool; } PerlIOAPR; -/* clean up any structures linked from PerlIOAPR. a layer can be - * popped without being closed if the program is dynamically managing - * layers on the stream. - */ -static IV PerlIOAPR_popped(pTHX_ PerlIO *f) -{ -/* PerlIOAPR *st = PerlIOSelf(f, PerlIOAPR); */ -return 0; +static IV PerlIOAPR_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg) +{ +IV code = PerlIOBase_pushed(aTHX_ f, mode, arg); +if
cvs commit: modperl-2.0/xs/APR/PerlIO apr_perlio.c
stas2002/06/21 08:53:40 Modified:xs/APR/PerlIO apr_perlio.c Log: a few minor fixes and cleanups Revision ChangesPath 1.17 +3 -7 modperl-2.0/xs/APR/PerlIO/apr_perlio.c Index: apr_perlio.c === RCS file: /home/cvs/modperl-2.0/xs/APR/PerlIO/apr_perlio.c,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- apr_perlio.c 21 Jun 2002 15:28:43 - 1.16 +++ apr_perlio.c 21 Jun 2002 15:53:40 - 1.17 -28,7 +28,6 apr_pool_t *pool; } PerlIOAPR; - static IV PerlIOAPR_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg) { IV code = PerlIOBase_pushed(aTHX_ f, mode, arg); -40,7 +39,6 return code; } - static PerlIO *PerlIOAPR_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers, IV n, const char *mode, int fd, int imode, -147,7 +145,6 return NULL; } - static SSize_t PerlIOAPR_read(pTHX_ PerlIO *f, void *vbuf, Size_t count) { PerlIOAPR *st = PerlIOSelf(f, PerlIOAPR); -159,8 +156,8 return count; } else if (rc != APR_SUCCESS) { -char errbuf[120]; #ifdef PERLIO_APR_DEBUG +char errbuf[120]; /* XXX: need to figure way to map APR errno to normal errno, * so we can use SETERRNO to make the apr errors available to * Perl's $! */ -203,6 +200,7 return 0; } +PerlIOBase(f)-flags |= PERLIO_F_ERROR; return -1; } -225,7 +223,7 /* Flush the fill buffer */ if (PerlIO_flush(f) != 0) { - return -1; +return -1; } switch(whence) { -366,8 +364,6 return -1; } - - static PerlIO_funcs PerlIO_APR = { APR,
cvs commit: modperl-2.0/xs/APR/PerlIO apr_perlio.c
stas2002/06/21 10:37:38 Modified:xs/APR/PerlIO apr_perlio.c Log: adjust for PerlIO bleedperl changes Revision ChangesPath 1.18 +3 -2 modperl-2.0/xs/APR/PerlIO/apr_perlio.c Index: apr_perlio.c === RCS file: /home/cvs/modperl-2.0/xs/APR/PerlIO/apr_perlio.c,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- apr_perlio.c 21 Jun 2002 15:53:40 - 1.17 +++ apr_perlio.c 21 Jun 2002 17:37:38 - 1.18 -28,9 +28,9 apr_pool_t *pool; } PerlIOAPR; -static IV PerlIOAPR_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg) +static IV PerlIOAPR_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab) { -IV code = PerlIOBase_pushed(aTHX_ f, mode, arg); +IV code = PerlIOBase_pushed(aTHX_ f, mode, arg, tab); if (*PerlIONext(f)) { /* XXX: not sure if we can do anything here, but see * PerlIOUnix_pushed for things that it does -366,6 +366,7 } static PerlIO_funcs PerlIO_APR = { +sizeof(PerlIO_funcs), APR, sizeof(PerlIOAPR), PERLIO_K_MULTIARG,
cvs commit: modperl-2.0/xs/APR/PerlIO apr_perlio.c
stas2002/06/21 10:40:18 Modified:xs/APR/PerlIO apr_perlio.c Log: wrap the long args line Revision ChangesPath 1.19 +2 -1 modperl-2.0/xs/APR/PerlIO/apr_perlio.c Index: apr_perlio.c === RCS file: /home/cvs/modperl-2.0/xs/APR/PerlIO/apr_perlio.c,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- apr_perlio.c 21 Jun 2002 17:37:38 - 1.18 +++ apr_perlio.c 21 Jun 2002 17:40:18 - 1.19 -28,7 +28,8 apr_pool_t *pool; } PerlIOAPR; -static IV PerlIOAPR_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab) +static IV PerlIOAPR_pushed(pTHX_ PerlIO *f, const char *mode, + SV *arg, PerlIO_funcs *tab) { IV code = PerlIOBase_pushed(aTHX_ f, mode, arg, tab); if (*PerlIONext(f)) {
cvs commit: modperl-2.0/xs/APR/PerlIO apr_perlio.c
dougm 2002/06/20 19:06:48 Modified:xs/APR/PerlIO apr_perlio.c Log: bleedperl now has a binmode PerlIO function Revision ChangesPath 1.15 +1 -0 modperl-2.0/xs/APR/PerlIO/apr_perlio.c Index: apr_perlio.c === RCS file: /home/cvs/modperl-2.0/xs/APR/PerlIO/apr_perlio.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- apr_perlio.c 31 May 2002 15:41:40 - 1.14 +++ apr_perlio.c 21 Jun 2002 02:06:48 - 1.15 -321,6 +321,7 PerlIOBase_pushed, PerlIOAPR_popped, PerlIOAPR_open, +NULL, /* XXX: binmode? */ NULL, /* no getarg needed */ PerlIOAPR_fileno, PerlIOAPR_dup,
cvs commit: modperl-2.0/xs/APR/PerlIO apr_perlio.c
dougm 2002/05/31 08:41:40 Modified:xs/APR/PerlIO apr_perlio.c Log: seek is ok if both perl and apr have largefiles enabled Revision ChangesPath 1.14 +1 -1 modperl-2.0/xs/APR/PerlIO/apr_perlio.c Index: apr_perlio.c === RCS file: /home/cvs/modperl-2.0/xs/APR/PerlIO/apr_perlio.c,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- apr_perlio.c 31 May 2002 02:20:29 - 1.13 +++ apr_perlio.c 31 May 2002 15:41:40 - 1.14 -152,7 +152,7 IV code; apr_off_t seek_offset = 0; -#ifdef USE_LARGE_FILES +#if MP_LARGE_FILES_PERL_ONLY if (offset != 0) { Perl_croak(aTHX_ PerlIO::APR::seek with non-zero offset not supported with -Duselargefiles);
cvs commit: modperl-2.0/xs/APR/PerlIO apr_perlio.c
dougm 02/01/07 17:06:20 Modified:xs/APR/PerlIO apr_perlio.c Log: add some debug info Revision ChangesPath 1.9 +23 -2 modperl-2.0/xs/APR/PerlIO/apr_perlio.c Index: apr_perlio.c === RCS file: /home/cvs/modperl-2.0/xs/APR/PerlIO/apr_perlio.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- apr_perlio.c 4 Jan 2002 09:29:50 - 1.8 +++ apr_perlio.c 8 Jan 2002 01:06:20 - 1.9 @@ -82,6 +82,13 @@ st-pool = modperl_sv2pool(aTHX_ sv); rc = apr_file_open(st-file, path, apr_flag, APR_OS_DEFAULT, st-pool); + +#ifdef PERLIO_APR_DEBUG +Perl_warn(aTHX_ PerlIOAPR_open obj=0x%lx, file=0x%lx, name=%s, rc=%d\n, + (unsigned long)f, (unsigned long)st-file, + path ? path : (UNKNOWN), rc); +#endif + if (rc != APR_SUCCESS) { PerlIOBase(f)-flags |= PERLIO_F_ERROR; return NULL; @@ -110,6 +117,15 @@ PerlIOAPR *ost = PerlIOSelf(o, PerlIOAPR); rc = apr_file_dup(fst-file, ost-file, ost-pool); + +#ifdef PERLIO_APR_DEBUG +Perl_warn(aTHX_ PerlIOAPR_dup obj=0x%lx, +file=0x%lx = 0x%lx, rc=%d\n, + (unsigned long)f, + (unsigned long)ost-file, + (unsigned long)fst-file, rc); +#endif + if (rc == APR_SUCCESS) { fst-pool = ost-pool; return f; @@ -190,9 +206,14 @@ IV code = PerlIOBase_close(aTHX_ f); apr_status_t rc; -const char *new_path; +const char *new_path = NULL; apr_file_name_get(new_path, st-file); -/* Perl_warn(aTHX_ closing file %s\n, new_path); */ + +#ifdef PERLIO_APR_DEBUG +Perl_warn(aTHX_ PerlIOAPR_close obj=0x%lx, file=0x%lx, name=%s\n, + (unsigned long)f, (unsigned long)st-file, + new_path ? new_path : (UNKNOWN)); +#endif rc = apr_file_flush(st-file); if (rc != APR_SUCCESS) {
cvs commit: modperl-2.0/xs/APR/PerlIO apr_perlio.c
dougm 02/01/07 17:09:19 Modified:xs/APR/PerlIO apr_perlio.c Log: work around bug where some PerlIOAPR filehandles are still open during perl_destruct Revision ChangesPath 1.10 +14 -2 modperl-2.0/xs/APR/PerlIO/apr_perlio.c Index: apr_perlio.c === RCS file: /home/cvs/modperl-2.0/xs/APR/PerlIO/apr_perlio.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- apr_perlio.c 8 Jan 2002 01:06:20 - 1.9 +++ apr_perlio.c 8 Jan 2002 01:09:19 - 1.10 @@ -206,14 +206,26 @@ IV code = PerlIOBase_close(aTHX_ f); apr_status_t rc; +#ifdef PERLIO_APR_DEBUG const char *new_path = NULL; -apr_file_name_get(new_path, st-file); +if (!PL_dirty) { +/* if this is called during perl_destruct we are in trouble */ +apr_file_name_get(new_path, st-file); +} -#ifdef PERLIO_APR_DEBUG Perl_warn(aTHX_ PerlIOAPR_close obj=0x%lx, file=0x%lx, name=%s\n, (unsigned long)f, (unsigned long)st-file, new_path ? new_path : (UNKNOWN)); #endif + +if (PL_dirty) { +/* there should not be any PerlIOAPR handles open + * during perl_destruct + */ +Perl_warn(aTHX_ leaked PerlIOAPR handle 0x%lx, + (unsigned long)f); +return -1; +} rc = apr_file_flush(st-file); if (rc != APR_SUCCESS) {
cvs commit: modperl-2.0/xs/APR/PerlIO apr_perlio.c
stas02/01/04 01:29:50 Modified:xs/APR/PerlIO apr_perlio.c Log: - now APR PerlIO read is buffered by PerlIOBuf layer. Attention: this requires at least bleadperl patch 13978, 14042 seems to be fine too for me. Revision ChangesPath 1.8 +67 -42modperl-2.0/xs/APR/PerlIO/apr_perlio.c Index: apr_perlio.c === RCS file: /home/cvs/modperl-2.0/xs/APR/PerlIO/apr_perlio.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- apr_perlio.c 20 Dec 2001 03:20:33 - 1.7 +++ apr_perlio.c 4 Jan 2002 09:29:50 - 1.8 @@ -4,7 +4,7 @@ #include apr_perlio.h /* XXX: prerequisites to have things working - * pTHX_: perl 5.7.2 patch 13809 is required + * PerlIO_flush patch : perl 5.7.2 patch 13978 is required * dup() : apr cvs date: 2001/12/06 13:43:45 * * XXX: it's not enough to check for PERLIO_LAYERS, some functionality @@ -119,34 +119,16 @@ return NULL; } -/* currrently read is very not-optimized, since in many cases the read - * process happens a char by char. Need to find a way to snoop on APR - * read buffer from PerlIO, or implement our own buffering layer here - */ -static SSize_t PerlIOAPR_read(pTHX_ PerlIO *f, void *vbuf, Size_t count) -{ -PerlIOAPR *st = PerlIOSelf(f, PerlIOAPR); -apr_status_t rc; - -/* fprintf(stderr, in read: count %d, %s\n, - (int)count, (char*) vbuf); */ -rc = apr_file_read(st-file, vbuf, count); -/* fprintf(stderr, out read: count %d, %s\n, - (int)count, (char*) vbuf); */ -if (rc == APR_SUCCESS) { -return (SSize_t) count; -} - -return (SSize_t) -1; -} - static SSize_t PerlIOAPR_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count) { PerlIOAPR *st = PerlIOSelf(f, PerlIOAPR); apr_status_t rc; + +#if 0 + Perl_warn(aTHX_ in write: count %d, %s\n, + (int)count, (char*) vbuf); +#endif -/* fprintf(stderr, in write: count %d, %s\n, - (int)count, (char*) vbuf); */ rc = apr_file_write(st-file, vbuf, count); if (rc == APR_SUCCESS) { return (SSize_t) count; @@ -160,13 +142,14 @@ PerlIOAPR *st = PerlIOSelf(f, PerlIOAPR); apr_seek_where_t where; apr_status_t rc; +IV code; -/* XXX: must flush before seek? */ -rc = apr_file_flush(st-file); -if (rc != APR_SUCCESS) { -return -1; +/* Flush the fill buffer */ +code = PerlIOBuf_flush(aTHX_ f); +if (code != 0) { +return code; } - + switch(whence) { case 0: where = APR_SET; @@ -209,7 +192,7 @@ const char *new_path; apr_file_name_get(new_path, st-file); -/* fprintf(stderr, closing file %s\n, new_path); */ +/* Perl_warn(aTHX_ closing file %s\n, new_path); */ rc = apr_file_flush(st-file); if (rc != APR_SUCCESS) { @@ -239,7 +222,46 @@ static IV PerlIOAPR_fill(pTHX_ PerlIO *f) { -return -1; +PerlIOAPR *st = PerlIOSelf(f, PerlIOAPR); +apr_status_t rc; +SSize_t avail; +Size_t count = st-base.bufsiz; + +if (!st-base.buf) { +PerlIO_get_base(f); /* allocate via vtable */ +} + +#if 0 + Perl_warn(aTHX_ ask to fill %d chars\n, count); +#endif + +rc = apr_file_read(st-file, st-base.ptr, count); +if (rc != APR_SUCCESS) { +/* XXX */ +} + +#if 0 + Perl_warn(aTHX_ got to fill %d chars\n, count); +#endif + +avail = count; /* apr_file_read() sets how many chars were read in count */ +if (avail = 0) { +if (avail == 0) { +PerlIOBase(f)-flags |= PERLIO_F_EOF; +} +else { +PerlIOBase(f)-flags |= PERLIO_F_ERROR; +} + +return -1; +} +st-base.end = st-base.buf + avail; + +/* indicate that the buffer this layer currently holds unconsumed + data read from layer below. */ +PerlIOBase(f)-flags |= PERLIO_F_RDBUF; + +return 0; } static IV PerlIOAPR_eof(pTHX_ PerlIO *f) @@ -262,14 +284,14 @@ static PerlIO_funcs PerlIO_APR = { APR, sizeof(PerlIOAPR), -PERLIO_K_BUFFERED | PERLIO_K_MULTIARG, /* XXX: document the flag in perliol.pod */ +PERLIO_K_BUFFERED | PERLIO_K_FASTGETS | PERLIO_K_MULTIARG, PerlIOBase_pushed, PerlIOAPR_popped, PerlIOAPR_open, NULL, /* no getarg needed */ PerlIOAPR_fileno, PerlIOAPR_dup, -PerlIOAPR_read, +PerlIOBuf_read, PerlIOBuf_unread, PerlIOAPR_write, PerlIOAPR_seek, @@ -308,7 +330,10 @@ char *mode; const char *layers = :APR; PerlIO *f = PerlIO_allocate(aTHX); - +if (!f) { +
cvs commit: modperl-2.0/xs/APR/PerlIO apr_perlio.c
dougm 01/12/19 10:16:41 Modified:xs/APR/PerlIO apr_perlio.c Log: fix win32 5.6.1 compile Revision ChangesPath 1.6 +1 -1 modperl-2.0/xs/APR/PerlIO/apr_perlio.c Index: apr_perlio.c === RCS file: /home/cvs/modperl-2.0/xs/APR/PerlIO/apr_perlio.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- apr_perlio.c 2001/12/18 06:00:14 1.5 +++ apr_perlio.c 2001/12/19 18:16:41 1.6 @@ -372,7 +372,7 @@ type); } -#elif !defined(PERLIO_LAYERS) /* NOT PERLIO_LAYERS (5.6.1) */ +#elif !defined(PERLIO_LAYERS) !defined(WIN32) /* NOT PERLIO_LAYERS (5.6.1) */ static FILE *apr_perlio_apr_file_to_FILE(pTHX_ apr_file_t *file, int type) {
cvs commit: modperl-2.0/xs/APR/PerlIO apr_perlio.c
stas01/12/19 19:20:33 Modified:xs/APR/PerlIO apr_perlio.c Log: - perl 5.7.2 patch 13809 has changed the prototype of all PerlIO vtable functions to start with pTHX_; adjusting for this change and removing dTHX's that aren't needed anymore. Revision ChangesPath 1.7 +14 -16modperl-2.0/xs/APR/PerlIO/apr_perlio.c Index: apr_perlio.c === RCS file: /home/cvs/modperl-2.0/xs/APR/PerlIO/apr_perlio.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- apr_perlio.c 2001/12/19 18:16:41 1.6 +++ apr_perlio.c 2001/12/20 03:20:33 1.7 @@ -4,9 +4,8 @@ #include apr_perlio.h /* XXX: prerequisites to have things working - * open(): perl 5.7.2 patch 13534 is required + * pTHX_: perl 5.7.2 patch 13809 is required * dup() : apr cvs date: 2001/12/06 13:43:45 - * tell(): the patch isn't in yet. * * XXX: it's not enough to check for PERLIO_LAYERS, some functionality * and bug fixes were added only in the late 5.7.2, whereas @@ -30,7 +29,7 @@ * popped without being closed if the program is dynamically managing * layers on the stream. */ -static IV PerlIOAPR_popped(PerlIO *f) +static IV PerlIOAPR_popped(pTHX_ PerlIO *f) { /* PerlIOAPR *st = PerlIOSelf(f, PerlIOAPR); */ @@ -92,7 +91,7 @@ return f; } -static IV PerlIOAPR_fileno(PerlIO *f) +static IV PerlIOAPR_fileno(pTHX_ PerlIO *f) { /* apr_file_t* is an opaque struct, so fileno is not available */ /* XXX: this -1 workaround should be documented in perliol.pod */ @@ -124,13 +123,12 @@ * process happens a char by char. Need to find a way to snoop on APR * read buffer from PerlIO, or implement our own buffering layer here */ -static SSize_t PerlIOAPR_read(PerlIO *f, void *vbuf, Size_t count) +static SSize_t PerlIOAPR_read(pTHX_ PerlIO *f, void *vbuf, Size_t count) { PerlIOAPR *st = PerlIOSelf(f, PerlIOAPR); apr_status_t rc; -dTHX; /* XXX: change Perl so this function has a pTHX_ prototype */ - -/* fprintf(stderr, in read: count %d, %s\n, + +/* fprintf(stderr, in read: count %d, %s\n, (int)count, (char*) vbuf); */ rc = apr_file_read(st-file, vbuf, count); /* fprintf(stderr, out read: count %d, %s\n, @@ -142,7 +140,7 @@ return (SSize_t) -1; } -static SSize_t PerlIOAPR_write(PerlIO *f, const void *vbuf, Size_t count) +static SSize_t PerlIOAPR_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count) { PerlIOAPR *st = PerlIOSelf(f, PerlIOAPR); apr_status_t rc; @@ -157,7 +155,7 @@ return (SSize_t) -1; } -static IV PerlIOAPR_seek(PerlIO *f, Off_t offset, int whence) +static IV PerlIOAPR_seek(pTHX_ PerlIO *f, Off_t offset, int whence) { PerlIOAPR *st = PerlIOSelf(f, PerlIOAPR); apr_seek_where_t where; @@ -189,7 +187,7 @@ return -1; } -static Off_t PerlIOAPR_tell(PerlIO *f) +static Off_t PerlIOAPR_tell(pTHX_ PerlIO *f) { PerlIOAPR *st = PerlIOSelf(f, PerlIOAPR); apr_off_t offset = 0; @@ -203,10 +201,10 @@ return (Off_t) -1; } -static IV PerlIOAPR_close(PerlIO *f) +static IV PerlIOAPR_close(pTHX_ PerlIO *f) { PerlIOAPR *st = PerlIOSelf(f, PerlIOAPR); -IV code = PerlIOBase_close(f); +IV code = PerlIOBase_close(aTHX_ f); apr_status_t rc; const char *new_path; @@ -226,7 +224,7 @@ return code; } -static IV PerlIOAPR_flush(PerlIO *f) +static IV PerlIOAPR_flush(pTHX_ PerlIO *f) { PerlIOAPR *st = PerlIOSelf(f, PerlIOAPR); apr_status_t rc; @@ -239,12 +237,12 @@ return -1; } -static IV PerlIOAPR_fill(PerlIO *f) +static IV PerlIOAPR_fill(pTHX_ PerlIO *f) { return -1; } -static IV PerlIOAPR_eof(PerlIO *f) +static IV PerlIOAPR_eof(pTHX_ PerlIO *f) { PerlIOAPR *st = PerlIOSelf(f, PerlIOAPR); apr_status_t rc;
cvs commit: modperl-2.0/xs/APR/PerlIO apr_perlio.c apr_perlio.h Makefile.PL PerlIO.xs PerlIO.pm
stas01/12/17 08:20:27 Added: t/response/TestAPR perlio.pm xs/APR/PerlIO apr_perlio.c apr_perlio.h Makefile.PL PerlIO.xs PerlIO.pm Log: - implements APR::PerlIO layer - implements apr_file_t to APR::PerlIO conversion hooks (one way) (two different sets for 5.6.1 and 5.7.2+) - tests (conversion hooks are tested in Apache::SubProcess) Revision ChangesPath 1.1 modperl-2.0/t/response/TestAPR/perlio.pm Index: perlio.pm === package TestAPR::perlio; use strict; use warnings;# FATAL = 'all'; use Apache::Const -compile = 'OK'; use Apache::Test; use Apache::TestUtil; use APR::PerlIO (); use Fcntl (); use File::Spec::Functions qw(catfile); sub handler { my $r = shift; plan $r, tests = 9, todo = [5], have_perl 'iolayers'; my $vars = Apache::Test::config()-{vars}; my $dir = catfile $vars-{documentroot}, perlio; t_mkdir($dir); # write file my $file = catfile $dir, test; t_debug open file $file; my $foo = bar; open my $fh, :APR, $file, $r or die Cannot open $file for writing: $!; ok ref($fh) eq 'GLOB'; my $expected = This is a test: $$; t_debug write to a file: $expected; print $fh $expected; close $fh; # open() other tests { # non-existant file my $file = /this/file/does/not/exist; t_write_file(/tmp/testing, some stuff); if (open my $fh, :APR, $file, $r) { t_debug must not be able to open $file!; ok 0; close $fh; } else { t_debug good! cannot open/doesn't exist: $!; ok 1; } } # read() test { open my $fh, :APR, $file, $r or die Cannot open $file for reading: $!; ok ref($fh) eq 'GLOB'; my $received = $fh; close $fh; ok t_cmp($expected, $received, read/write file); } # seek/tell() tests { open my $fh, :APR, $file, $r or die Cannot open $file for reading: $!; my $pos = 3; seek $fh, $pos, Fcntl::SEEK_SET(); # XXX: broken my $got = tell($fh); ok t_cmp($pos, $got, seek/tell the file); # XXX: test Fcntl::SEEK_CUR() Fcntl::SEEK_END() close $fh; } # eof() tests { open my $fh, :APR, $file, $r or die Cannot open $file for reading: $!; ok t_cmp(0, int eof($fh), # returns false, not 0 not end of file); # go to the end and read seek $fh, 0, Fcntl::SEEK_END(); my $received = $fh; ok t_cmp(1, eof($fh), end of file); close $fh; } # dup() test { open my $fh, :APR, $file, $r or die Cannot open $file for reading: $!; open my $dup_fh, :APR, $fh or die Cannot dup $file for reading: $!; close $fh; ok ref($dup_fh) eq 'GLOB'; my $received = $dup_fh; close $dup_fh; ok t_cmp($expected, $received, read/write a dupped file); } # XXX: need tests # - for stdin/out/err as they are handled specially # - unbuffered read $|=1? # XXX: tmpfile is missing: # consider to use 5.8's syntax: # open $fh, +, undef; # cleanup: t_mkdir will remove the whole tree including the file Apache::OK; } 1; 1.1 modperl-2.0/xs/APR/PerlIO/apr_perlio.c Index: apr_perlio.c === #include mod_perl.h #include apr_perlio.h /* XXX: prerequisites to have things working * open(): perl 5.7.2 patch 13534 is required * dup() : apr cvs date: 2001/12/06 13:43:45 * tell(): the patch isn't in yet. * * XXX: it's not enough to check for PERLIO_LAYERS, some functionality * and bug fixes were added only in the late 5.7.2, whereas * PERLIO_LAYERS is available in 5.7.1 */ #ifdef PERLIO_LAYERS /* 5.7.2+ */ /** * The PerlIO APR layer. * The PerlIO API is documented in perliol.pod. **/ typedef struct { PerlIOBuf base;/* PerlIOBuf stuff */ apr_file_t *file; apr_pool_t *pool; } PerlIOAPR; /* clean up any structures linked from PerlIOAPR. a layer can be * popped without being closed if the program is
cvs commit: modperl-2.0/xs/APR/PerlIO apr_perlio.c
stas01/12/17 08:55:46 Modified:xs/APR/PerlIO apr_perlio.c Log: - maintainer mode cleanups Revision ChangesPath 1.2 +3 -4 modperl-2.0/xs/APR/PerlIO/apr_perlio.c Index: apr_perlio.c === RCS file: /home/cvs/modperl-2.0/xs/APR/PerlIO/apr_perlio.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- apr_perlio.c 2001/12/17 16:20:27 1.1 +++ apr_perlio.c 2001/12/17 16:55:46 1.2 @@ -31,7 +31,7 @@ */ static IV PerlIOAPR_popped(PerlIO *f) { -PerlIOAPR *st = PerlIOSelf(f, PerlIOAPR); +//PerlIOAPR *st = PerlIOSelf(f, PerlIOAPR); return 0; } @@ -41,12 +41,10 @@ const char *mode, int fd, int imode, int perm, PerlIO *f, int narg, SV **args) { -AV *av_arg; SV *arg = (narg 0) ? *args : PerlIOArg; PerlIOAPR *st; const char *path; apr_int32_t apr_flag; -int len; apr_status_t rc; SV *sv; @@ -105,7 +103,6 @@ static PerlIO *PerlIOAPR_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags) { -Size_t count; apr_status_t rc; if ( (f = PerlIOBase_dup(aTHX_ f, o, param, flags)) ) { @@ -264,6 +261,8 @@ return 0; case APR_EOF: return 1; + default: +return -1; } }
cvs commit: modperl-2.0/xs/APR/PerlIO apr_perlio.c
dougm 01/12/17 16:37:01 Modified:xs/APR/PerlIO apr_perlio.c Log: allow to compile with older bleedperls Revision ChangesPath 1.3 +9 -2 modperl-2.0/xs/APR/PerlIO/apr_perlio.c Index: apr_perlio.c === RCS file: /home/cvs/modperl-2.0/xs/APR/PerlIO/apr_perlio.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- apr_perlio.c 2001/12/17 16:55:46 1.2 +++ apr_perlio.c 2001/12/18 00:37:01 1.3 @@ -12,7 +12,7 @@ * PERLIO_LAYERS is available in 5.7.1 */ -#ifdef PERLIO_LAYERS /* 5.7.2+ */ +#if defined(PERLIO_LAYERS) defined(PERLIO_K_MULTIARG) /* 5.7.2+ */ /** * The PerlIO APR layer. @@ -377,7 +377,7 @@ type); } -#else /* NOT PERLIO_LAYERS (5.6.1) */ +#elif !defined(PERLIO_LAYERS) /* NOT PERLIO_LAYERS (5.6.1) */ FILE *apr_perlio_apr_file_to_FILE(pTHX_ apr_file_t *file, int type) { @@ -445,6 +445,13 @@ void apr_perlio_init(pTHX) { APR_REGISTER_OPTIONAL_FN(apr_perlio_apr_file_to_glob); +} + +#else + +void apr_perlio_init(pTHX) +{ +Perl_croak(aTHX_ APR::PerlIO not usable with this version of Perl); } #endif /* PERLIO_LAYERS */
cvs commit: modperl-2.0/xs/APR/PerlIO apr_perlio.c
dougm 01/12/17 17:13:15 Modified:xs/APR/PerlIO apr_perlio.c Log: style nits: - no //comments - no else branch where if returns a value - whitespace-- make note that modperl_* functions cannot be used outside of httpd Revision ChangesPath 1.4 +33 -36modperl-2.0/xs/APR/PerlIO/apr_perlio.c Index: apr_perlio.c === RCS file: /home/cvs/modperl-2.0/xs/APR/PerlIO/apr_perlio.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- apr_perlio.c 2001/12/18 00:37:01 1.3 +++ apr_perlio.c 2001/12/18 01:13:15 1.4 @@ -31,7 +31,7 @@ */ static IV PerlIOAPR_popped(PerlIO *f) { -//PerlIOAPR *st = PerlIOSelf(f, PerlIOAPR); +/* PerlIOAPR *st = PerlIOSelf(f, PerlIOAPR); */ return 0; } @@ -48,7 +48,7 @@ apr_status_t rc; SV *sv; -if ( !(SvROK(arg) || SvPOK(arg)) ) { +if (!(SvROK(arg) || SvPOK(arg))) { return NULL; } @@ -78,6 +78,7 @@ st = PerlIOSelf(f, PerlIOAPR); sv = args[narg-1]; +/* XXX: modperl_sv2pool cannot be used outside of httpd */ st-pool = modperl_sv2pool(aTHX_ sv); rc = apr_file_open(st-file, path, apr_flag, APR_OS_DEFAULT, st-pool); @@ -85,10 +86,9 @@ PerlIOBase(f)-flags |= PERLIO_F_ERROR; return NULL; } -else { -PerlIOBase(f)-flags |= PERLIO_F_OPEN; -return f; -} + +PerlIOBase(f)-flags |= PERLIO_F_OPEN; +return f; } static IV PerlIOAPR_fileno(PerlIO *f) @@ -105,7 +105,7 @@ { apr_status_t rc; -if ( (f = PerlIOBase_dup(aTHX_ f, o, param, flags)) ) { +if ((f = PerlIOBase_dup(aTHX_ f, o, param, flags))) { PerlIOAPR *fst = PerlIOSelf(f, PerlIOAPR); PerlIOAPR *ost = PerlIOSelf(o, PerlIOAPR); @@ -117,10 +117,8 @@ } return NULL; - } - /* currrently read is very not-optimized, since in many cases the read * process happens a char by char. Need to find a way to snoop on APR * read buffer from PerlIO, or implement our own buffering layer here @@ -129,33 +127,33 @@ { PerlIOAPR *st = PerlIOSelf(f, PerlIOAPR); apr_status_t rc; -dTHX; +dTHX; /* XXX: change Perl so this function has a pTHX_ prototype */ -//fprintf(stderr, in read: count %d, %s\n, (int)count, (char*) vbuf); +/* fprintf(stderr, in read: count %d, %s\n, + (int)count, (char*) vbuf); */ rc = apr_file_read(st-file, vbuf, count); -//fprintf(stderr, out read: count %d, %s\n, (int)count, (char*) vbuf); +/* fprintf(stderr, out read: count %d, %s\n, + (int)count, (char*) vbuf); */ if (rc == APR_SUCCESS) { return (SSize_t) count; } -else { -return (SSize_t) -1; -} -} +return (SSize_t) -1; +} static SSize_t PerlIOAPR_write(PerlIO *f, const void *vbuf, Size_t count) { PerlIOAPR *st = PerlIOSelf(f, PerlIOAPR); apr_status_t rc; -//fprintf(stderr, in write: count %d, %s\n, (int)count, (char*) vbuf); +/* fprintf(stderr, in write: count %d, %s\n, + (int)count, (char*) vbuf); */ rc = apr_file_write(st-file, vbuf, count); if (rc == APR_SUCCESS) { return (SSize_t) count; } -else { -return (SSize_t) -1; -} + +return (SSize_t) -1; } static IV PerlIOAPR_seek(PerlIO *f, Off_t offset, int whence) @@ -186,9 +184,8 @@ if (rc == APR_SUCCESS) { return 0; } -else { -return -1; -} + +return -1; } static Off_t PerlIOAPR_tell(PerlIO *f) @@ -202,10 +199,9 @@ rc = apr_file_seek(st-file, APR_CUR, offset); if (rc == APR_SUCCESS) { return (Off_t) offset; -} -else { -return (Off_t) -1; } + +return (Off_t) -1; } static IV PerlIOAPR_close(PerlIO *f) @@ -216,7 +212,7 @@ const char *new_path; apr_file_name_get(new_path, st-file); -//fprintf(stderr, closing file %s\n, new_path); +/* fprintf(stderr, closing file %s\n, new_path); */ rc = apr_file_flush(st-file); if (rc != APR_SUCCESS) { @@ -240,9 +236,8 @@ if (rc == APR_SUCCESS) { return 0; } -else { -return -1; -} + +return -1; } static IV PerlIOAPR_fill(PerlIO *f) @@ -262,8 +257,9 @@ case APR_EOF: return 1; default: -return -1; } + +return -1; } static PerlIO_funcs PerlIO_APR = { @@ -338,10 +334,9 @@ PerlIOBase(f)-flags |= PERLIO_F_OPEN; return f; -} -else { -return NULL; } + +return NULL; } /* @@ -349,6