Change 30269 by [EMAIL PROTECTED] on 2007/02/13 21:18:26
Integrate:
[ 28322]
Subject: [PATCH] perlio.c: nobody was freeing PL_perlio_fd_refcnt, now
PerlIO_cleanup() is
From: [EMAIL PROTECTED] (Jarkko Hietaniemi)
Date: Sun, 28 May 2006 18:15:35 +0300 (EEST)
Message-Id: <[EMAIL PROTECTED]>
[ 28329]
Revert change 28322, which makes ithreads panic
[ 29045]
Subject: [PATCH] blead valgrind finding
From: Jarkko Hietaniemi <[EMAIL PROTECTED]>
Date: Wed, 18 Oct 2006 20:07:54 -0400
Message-ID: <[EMAIL PROTECTED]>
[ 29046]
Remove free() part of change #29045, which causes
panics from miniperl in FreeBSD/multithreaded
[ 29050]
Memory leak fix, by Jarkko
[ 29060]
More leak fixes, by Jarkko
[ 29065]
Enable perlio mutexes under threads (by Jarkko)
[ 29066]
Adjustment to symbol lists after latest changes (by Jarkko)
[ 29070]
Fix in perl.h for compiling with g++.
[ 29073]
Always defining PERLIO_TERM, even if it's empty, makes for a simpler
PERL_SYS_TERM
[ 29074]
Add PERLIO_INIT to PERL_SYS_INIT.
I infer that this was accidentally omitted from change 29060
[ 29075]
Semicolon consistency between PERL_FPU_INIT and the other INITs.
[ 29077]
Add PERLIO_INIT and PERLIO_TERM to PERL_SYS_INIT* and PERL_SYS_TERM*
in */*ish.h headers.
[ 29424]
I think #29060 / #29073 missed this
[ 29425]
Don't try to export fd_refcnt symbols when building without USE_PERLIO
to keep the Win32 linker happy
[ 29442]
Subject: Re: [PATCH] Re: [PATCH] Re: [PATCH] abstract mempool header
testing
From: demerphq <[EMAIL PROTECTED]>
Date: Sat, 2 Dec 2006 14:48:54 +0100
Message-ID: <[EMAIL PROTECTED]>
[ 29451]
Change #29424 may well be correct in itself, but currently doesn't
work when perl is built with PERL_IMPLICIT_SYS because PERLIO_TERM
uses PerlMemShared_free() which, in that case, involves the perlhost
that has already been freed itself by perl_free(), which is called
before PERL_SYS_TERM().
The order of perl_destruct(), perl_free(), PERL_SYS_TERM() cannot
be changed (it is advertised in perlembed for a start), so just
revert #29424 and the appropriate parts of #29442 for now.
Perhaps PL_perlio_fd_refcnt needs allocating differently, or else
the perlhost needs freeing later (after PerlIO)?
[ 29465]
Subject: [PATCH] Re: When should PERL_SYS_TERM() be called? [was: Re:
[PATCH] Re: [PATCH] Re: [PATCH] abstract mempool header testing]
From: Jarkko Hietaniemi <[EMAIL PROTECTED]>
Date: Mon, 04 Dec 2006 22:53:03 -0500
Message-ID: <[EMAIL PROTECTED]>
Re-instates #29424 (previously reverted by #29451), now fixed to work
with PERL_IMPLICIT_SYS, thanks to Jan Dubois. Also adds PERLIO_TERM to
the Symbian port.
[ 29477]
Subject: [PATCH] Re: When should PERL_SYS_TERM() be called? [was: Re:
[PATCH] Re: [PATCH] Re: [PATCH] abstract mempool header testing]
From: Jarkko Hietaniemi <[EMAIL PROTECTED]>
Date: Tue, 05 Dec 2006 16:08:33 -0500
Message-ID: <[EMAIL PROTECTED]>
Fixes a problem spotted by Jan Dubois:
The PerlMemShared pool is only shared between the interpreters that
can share data structures (interpreters created by perl_clone(), which
mean pseudo-fork, and threads.xs). The pool is not shared between
interpreters that are created separately by perl_alloc().
[...]
I guess this means PL_perlio_fd_refcnt needs to be allocated and
freed by standard malloc() and not go through any abstraction.
[ 29694]
Update copyright for perlio.c
[ 29700]
Normalize copyright of perlio.c for years >= 2006
[ 29811]
Subject: [PATCH] Symbian/S90 further fixes
From: [EMAIL PROTECTED] (Jarkko Hietaniemi)
Date: Mon, 15 Jan 2007 06:11:52 +0200 (EET)
Message-Id: <[EMAIL PROTECTED]>
[ 29813]
Revert perl.h part of change 29811, which breaks compilation with gcc
[ 29826]
Proper symbian fix (replacing change #29813) by Jarkko
[ 30079]
Subject: [PATCH] one more iteration on PerlIO_teardown prototype
From: [EMAIL PROTECTED] (Jarkko Hietaniemi)
Date: Tue, 30 Jan 2007 04:20:21 +0200 (EET)
Message-Id: <[EMAIL PROTECTED]>
[ 30120]
In vms/gen_shrfls.pl, consider EXTERN_C declarations as function
candidates, not global variable candidates. Currently only needed
for PerlIO_teardown.
plus add dummy HINTS_REFCNT_INIT and HINTS_REFCNT_TERM in hv.h
Affected files ...
... //depot/maint-5.8/perl/dosish.h#14 integrate
... //depot/maint-5.8/perl/embedvar.h#61 edit
... //depot/maint-5.8/perl/epoc/epocish.h#6 integrate
... //depot/maint-5.8/perl/hv.h#27 edit
... //depot/maint-5.8/perl/makedef.pl#39 integrate
... //depot/maint-5.8/perl/mpeix/mpeixish.h#8 integrate
... //depot/maint-5.8/perl/os2/os2ish.h#13 integrate
... //depot/maint-5.8/perl/perl.h#157 integrate
... //depot/maint-5.8/perl/perlapi.h#53 edit
... //depot/maint-5.8/perl/perlio.c#104 integrate
... //depot/maint-5.8/perl/perlio.sym#2 integrate
... //depot/maint-5.8/perl/perliol.h#8 integrate
... //depot/maint-5.8/perl/perlvars.h#21 integrate
... //depot/maint-5.8/perl/plan9/plan9ish.h#7 integrate
... //depot/maint-5.8/perl/unixish.h#11 integrate
... //depot/maint-5.8/perl/vms/gen_shrfls.pl#6 integrate
... //depot/maint-5.8/perl/vms/vmsish.h#15 integrate
... //depot/maint-5.8/perl/win32/perllib.c#4 integrate
... //depot/maint-5.8/perl/win32/win32.c#31 integrate
Differences ...
==== //depot/maint-5.8/perl/dosish.h#14 (text) ====
Index: perl/dosish.h
--- perl/dosish.h#13~28113~ 2006-05-05 14:14:29.000000000 -0700
+++ perl/dosish.h 2007-02-13 13:18:26.000000000 -0800
@@ -16,7 +16,8 @@
#ifdef DJGPP
# define BIT_BUCKET "nul"
# define OP_BINARY O_BINARY
-# define PERL_SYS_INIT(c,v) MALLOC_CHECK_TAINT2(*c,*v) Perl_DJGPP_init(c,v)
+# define PERL_SYS_INIT(c,v) \
+ MALLOC_CHECK_TAINT2(*c,*v) Perl_DJGPP_init(c,v); PERLIO_INIT
# define init_os_extras Perl_init_os_extras
# define HAS_UTIME
# define HAS_KILL
@@ -31,22 +32,25 @@
# define PERL_FS_VER_FMT "%d_%d_%d"
#else /* DJGPP */
# ifdef WIN32
-# define PERL_SYS_INIT(c,v) MALLOC_CHECK_TAINT2(*c,*v) Perl_win32_init(c,v)
+# define PERL_SYS_INIT(c,v) \
+ MALLOC_CHECK_TAINT2(*c,*v) Perl_win32_init(c,v); PERLIO_INIT
# define PERL_SYS_TERM() Perl_win32_term()
# define BIT_BUCKET "nul"
# else
# ifdef NETWARE
-# define PERL_SYS_INIT(c,v) MALLOC_CHECK_TAINT2(*c,*v)
Perl_nw5_init(c,v)
+# define PERL_SYS_INIT(c,v) \
+ MALLOC_CHECK_TAINT2(*c,*v) Perl_nw5_init(c,v); PERLIO_INIT
# define BIT_BUCKET "nwnul"
# else
-# define PERL_SYS_INIT(c,v) MALLOC_CHECK_TAINT2(*c,*v)
+# define PERL_SYS_INIT(c,v) \
+ MALLOC_CHECK_TAINT2(*c,*v); PERLIO_INIT
# define BIT_BUCKET "\\dev\\nul" /* "wanna be like, umm, Newlined, or
somethin?" */
# endif /* NETWARE */
# endif
#endif /* DJGPP */
#ifndef PERL_SYS_TERM
-# define PERL_SYS_TERM() OP_REFCNT_TERM; MALLOC_TERM
+# define PERL_SYS_TERM() HINTS_REFCNT_TERM; OP_REFCNT_TERM; PERLIO_TERM;
MALLOC_TERM
#endif
#define dXSUB_SYS
==== //depot/maint-5.8/perl/embedvar.h#61 (text+w) ====
Index: perl/embedvar.h
--- perl/embedvar.h#60~30263~ 2007-02-13 11:23:41.000000000 -0800
+++ perl/embedvar.h 2007-02-13 13:18:26.000000000 -0800
@@ -1469,6 +1469,7 @@
#define PL_patleave (PL_Vars.Gpatleave)
#define PL_perlio_fd_refcnt (PL_Vars.Gperlio_fd_refcnt)
#define PL_perlio_fd_refcnt_size (PL_Vars.Gperlio_fd_refcnt_size)
+#define PL_perlio_mutex (PL_Vars.Gperlio_mutex)
#define PL_sh_path (PL_Vars.Gsh_path)
#define PL_sigfpe_saved (PL_Vars.Gsigfpe_saved)
#define PL_sv_placeholder (PL_Vars.Gsv_placeholder)
@@ -1489,6 +1490,7 @@
#define PL_Gpatleave PL_patleave
#define PL_Gperlio_fd_refcnt PL_perlio_fd_refcnt
#define PL_Gperlio_fd_refcnt_size PL_perlio_fd_refcnt_size
+#define PL_Gperlio_mutex PL_perlio_mutex
#define PL_Gsh_path PL_sh_path
#define PL_Gsigfpe_saved PL_sigfpe_saved
#define PL_Gsv_placeholder PL_sv_placeholder
==== //depot/maint-5.8/perl/epoc/epocish.h#6 (text) ====
Index: perl/epoc/epocish.h
--- perl/epoc/epocish.h#5~19991~ 2003-07-04 06:54:33.000000000 -0700
+++ perl/epoc/epocish.h 2007-02-13 13:18:26.000000000 -0800
@@ -108,11 +108,13 @@
/* epocemx setenv bug workaround */
#ifndef PERL_SYS_INIT
-# define PERL_SYS_INIT(c,v) MALLOC_CHECK_TAINT2(*c,*v)
putenv(".dummy=foo"); putenv(".dummy"); MALLOC_INIT
+# define PERL_SYS_INIT(c,v) \
+ MALLOC_CHECK_TAINT2(*c,*v) putenv(".dummy=foo"); putenv(".dummy"); \
+ PERLIO_INIT; MALLOC_INIT
#endif
#ifndef PERL_SYS_TERM
-#define PERL_SYS_TERM() MALLOC_TERM
+#define PERL_SYS_TERM() PERLIO_TERM; MALLOC_TERM
#endif
#define BIT_BUCKET "/dev/null"
==== //depot/maint-5.8/perl/hv.h#27 (text) ====
Index: perl/hv.h
--- perl/hv.h#26~29974~ 2007-01-25 09:04:16.000000000 -0800
+++ perl/hv.h 2007-02-13 13:18:26.000000000 -0800
@@ -335,6 +335,12 @@
#define Perl_sharepvn(sv, len, hash) HEK_KEY(share_hek(sv, len, hash))
#define sharepvn(sv, len, hash) Perl_sharepvn(sv, len, hash)
+/* These don't exist for 5.8.x, but there will be fewer merge conflicts in
+ various *ish.h headers if they are defined as no-ops. */
+
+#define HINTS_REFCNT_INIT NOOP
+#define HINTS_REFCNT_TERM NOOP
+
/*
* Local variables:
* c-indentation-style: bsd
==== //depot/maint-5.8/perl/makedef.pl#39 (text) ====
Index: perl/makedef.pl
--- perl/makedef.pl#38~30132~ 2007-02-05 09:37:09.000000000 -0800
+++ perl/makedef.pl 2007-02-13 13:18:26.000000000 -0800
@@ -713,6 +713,7 @@
PL_sharedsv_space
PL_sharedsv_space_mutex
PL_dollarzero_mutex
+ PL_perlio_mutex
Perl_dirp_dup
Perl_cx_dup
Perl_si_dup
@@ -1019,13 +1020,30 @@
emit_symbols [EMAIL PROTECTED];
emit_symbols [qw(perlsio_binmode)];
}
+ if ($define{'USE_ITHREADS'}) {
+ emit_symbols [qw(
+ PL_perlio_mutex
+ )];
+ }
+ else {
+ skip_symbols [qw(
+ PL_perlio_mutex
+ )];
+ }
} else {
# -Uuseperlio
# Skip the PerlIO layer symbols - although
# nothing should have exported them any way
skip_symbols [EMAIL PROTECTED];
- skip_symbols [qw(perlsio_binmode)];
- skip_symbols [qw(PL_def_layerlist PL_known_layers PL_perlio)];
+ skip_symbols [qw(
+ perlsio_binmode
+ PL_def_layerlist
+ PL_known_layers
+ PL_perlio
+ PL_perlio_debug_fd
+ PL_perlio_fd_refcnt
+ PL_perlio_fd_refcnt_size
+ )];
# Also do NOT add abstraction symbols from $perlio_sym
# abstraction is done as #define to stdio
==== //depot/maint-5.8/perl/mpeix/mpeixish.h#8 (text) ====
Index: perl/mpeix/mpeixish.h
--- perl/mpeix/mpeixish.h#7~26834~ 2006-01-13 11:10:42.000000000 -0800
+++ perl/mpeix/mpeixish.h 2007-02-13 13:18:26.000000000 -0800
@@ -111,11 +111,11 @@
#define Mkdir(path,mode) mkdir((path),(mode))
#ifndef PERL_SYS_INIT
-# define PERL_SYS_INIT(c,v) PERL_FPU_INIT MALLOC_INIT
+# define PERL_SYS_INIT(c,v) PERL_FPU_INIT; PERLIO_INIT; MALLOC_INIT
#endif
#ifndef PERL_SYS_TERM
-#define PERL_SYS_TERM() MALLOC_TERM
+#define PERL_SYS_TERM() PERLIO_TERM; MALLOC_TERM
#endif
#define BIT_BUCKET "/dev/null"
==== //depot/maint-5.8/perl/os2/os2ish.h#13 (text) ====
Index: perl/os2/os2ish.h
--- perl/os2/os2ish.h#12~22038~ 2004-01-01 15:35:15.000000000 -0800
+++ perl/os2/os2ish.h 2007-02-13 13:18:26.000000000 -0800
@@ -230,22 +230,26 @@
MALLOC_CHECK_TAINT(*argcp, *argvp, *envp) \
_response(argcp, argvp); \
_wildcard(argcp, argvp); \
- Perl_OS2_init3(*envp, xreg, 0)
+ Perl_OS2_init3(*envp, xreg, 0); \
+ PERLIO_INIT
# define PERL_SYS_INIT(argcp, argvp) { \
{ void *xreg[2]; \
_response(argcp, argvp); \
_wildcard(argcp, argvp); \
- Perl_OS2_init3(NULL, xreg, 0)
+ Perl_OS2_init3(NULL, xreg, 0); \
+ PERLIO_INIT
#else /* Compiling embedded Perl or Perl extension */
# define PERL_SYS_INIT3(argcp, argvp, envp) \
{ void *xreg[2]; \
- Perl_OS2_init3(*envp, xreg, 0)
+ Perl_OS2_init3(*envp, xreg, 0); \
+ PERLIO_INIT
# define PERL_SYS_INIT(argcp, argvp) { \
{ void *xreg[2]; \
- Perl_OS2_init3(NULL, xreg, 0)
+ Perl_OS2_init3(NULL, xreg, 0); \
+ PERLIO_INIT
#endif
#define FORCE_EMX_DEINIT_EXIT 1
@@ -254,6 +258,7 @@
#define PERL_SYS_TERM2(xreg,flags) \
Perl_OS2_term(xreg, 0, flags); \
+ PERLIO_TERM; \
MALLOC_TERM
#define PERL_SYS_TERM1(xreg) \
==== //depot/maint-5.8/perl/perl.h#157 (text) ====
Index: perl/perl.h
--- perl/perl.h#156~30262~ 2007-02-13 10:05:20.000000000 -0800
+++ perl/perl.h 2007-02-13 13:18:26.000000000 -0800
@@ -2491,10 +2491,10 @@
# if HAS_FLOATINGPOINT_H
# include <floatingpoint.h>
# endif
-# define PERL_FPU_INIT fpsetmask(0);
+# define PERL_FPU_INIT fpsetmask(0)
# else
# if defined(SIGFPE) && defined(SIG_IGN) && !defined(PERL_MICRO)
-# define PERL_FPU_INIT PL_sigfpe_saved = (Sighandler_t)
signal(SIGFPE, SIG_IGN);
+# define PERL_FPU_INIT PL_sigfpe_saved = (Sighandler_t)
signal(SIGFPE, SIG_IGN)
# define PERL_FPU_PRE_EXEC { Sigsave_t xfpe; rsignal_save(SIGFPE,
PL_sigfpe_saved, &xfpe);
# define PERL_FPU_POST_EXEC rsignal_restore(SIGFPE, &xfpe); }
# else
@@ -3799,6 +3799,24 @@
# define RUNOPS_DEFAULT Perl_runops_standard
#endif
+#ifdef USE_PERLIO
+EXTERN_C void PerlIO_teardown(pTHX);
+# ifdef USE_ITHREADS
+# define PERLIO_INIT MUTEX_INIT(&PL_perlio_mutex)
+# define PERLIO_TERM \
+ STMT_START { \
+ PerlIO_teardown(aTHX); \
+ MUTEX_DESTROY(&PL_perlio_mutex);\
+ } STMT_END
+# else
+# define PERLIO_INIT
+# define PERLIO_TERM PerlIO_teardown(aTHX)
+# endif
+#else
+# define PERLIO_INIT
+# define PERLIO_TERM
+#endif
+
#ifdef MYMALLOC
# ifdef MUTEX_INIT_CALLS_MALLOC
# define MALLOC_INIT \
==== //depot/maint-5.8/perl/perlapi.h#53 (text+w) ====
Index: perl/perlapi.h
--- perl/perlapi.h#52~30263~ 2007-02-13 11:23:41.000000000 -0800
+++ perl/perlapi.h 2007-02-13 13:18:26.000000000 -0800
@@ -1051,6 +1051,8 @@
#define PL_perlio_fd_refcnt (*Perl_Gperlio_fd_refcnt_ptr(NULL))
#undef PL_perlio_fd_refcnt_size
#define PL_perlio_fd_refcnt_size (*Perl_Gperlio_fd_refcnt_size_ptr(NULL))
+#undef PL_perlio_mutex
+#define PL_perlio_mutex (*Perl_Gperlio_mutex_ptr(NULL))
#undef PL_sh_path
#define PL_sh_path (*Perl_Gsh_path_ptr(NULL))
#undef PL_sigfpe_saved
==== //depot/maint-5.8/perl/perlio.c#104 (text) ====
Index: perl/perlio.c
--- perl/perlio.c#103~30263~ 2007-02-13 11:23:41.000000000 -0800
+++ perl/perlio.c 2007-02-13 13:18:26.000000000 -0800
@@ -1,7 +1,10 @@
/*
- * perlio.c Copyright (c) 1996-2006, Nick Ing-Simmons You may distribute
- * under the terms of either the GNU General Public License or the
- * Artistic License, as specified in the README file.
+ * perlio.c
+ * Copyright (c) 1996-2006, Nick Ing-Simmons
+ * Copyright (c) 2006, 2007, Larry Wall and others
+ *
+ * You may distribute under the terms of either the GNU General Public License
+ * or the Artistic License, as specified in the README file.
*/
/*
@@ -2261,11 +2264,7 @@
return f;
}
-#ifdef USE_THREADS
-perl_mutex PerlIO_mutex;
-#endif
-
-/* Must be called with PerlIO_mutex locked. */
+/* Must be called with PL_perlio_mutex locked. */
static void
S_more_refcounted_fds(pTHX_ const int new_fd) {
const int old_max = PL_perlio_fd_refcnt_size;
@@ -2281,12 +2280,13 @@
assert (new_max > new_fd);
- new_array
- = PerlMemShared_realloc(PL_perlio_fd_refcnt, new_max * sizeof(int));
+ /* Use plain realloc() since we need this memory to be really
+ * global and visible to all the interpreters and/or threads. */
+ new_array = (int*) realloc(PL_perlio_fd_refcnt, new_max * sizeof(int));
if (!new_array) {
-#ifdef USE_THREADS
- MUTEX_UNLOCK(&PerlIO_mutex);
+#ifdef USE_ITHREADS
+ MUTEX_UNLOCK(&PL_perlio_mutex);
#endif
/* Can't use PerlIO to write as it allocates memory */
PerlLIO_write(PerlIO_fileno(Perl_error_log),
@@ -2306,12 +2306,8 @@
void
PerlIO_init(pTHX)
{
- /* Place holder for stdstreams call ??? */
-#ifdef USE_THREADS
- MUTEX_INIT(&PerlIO_mutex);
-#else
+ /* MUTEX_INIT(&PL_perlio_mutex) is done in PERL_SYS_INIT3(). */
PERL_UNUSED_CONTEXT;
-#endif
}
void
@@ -2320,18 +2316,25 @@
dTHX;
if (fd >= 0) {
-#ifdef USE_THREADS
- MUTEX_LOCK(&PerlIO_mutex);
+#ifdef USE_ITHREADS
+ MUTEX_LOCK(&PL_perlio_mutex);
#endif
if (fd >= PL_perlio_fd_refcnt_size)
S_more_refcounted_fds(aTHX_ fd);
PL_perlio_fd_refcnt[fd]++;
- PerlIO_debug("fd %d refcnt=%d\n",fd,PL_perlio_fd_refcnt[fd]);
+ if (PL_perlio_fd_refcnt[fd] <= 0) {
+ Perl_croak(aTHX_ "refcnt_inc: fd %d: %d <= 0\n",
+ fd, PL_perlio_fd_refcnt[fd]);
+ }
+ PerlIO_debug("refcnt_inc: fd %d refcnt=%d\n",
+ fd, PL_perlio_fd_refcnt[fd]);
-#ifdef USE_THREADS
- MUTEX_UNLOCK(&PerlIO_mutex);
+#ifdef USE_ITHREADS
+ MUTEX_UNLOCK(&PL_perlio_mutex);
#endif
+ } else {
+ Perl_croak(aTHX_ "refcnt_inc: fd %d < 0\n", fd);
}
}
@@ -2341,19 +2344,24 @@
dTHX;
int cnt = 0;
if (fd >= 0) {
-#ifdef USE_THREADS
- MUTEX_LOCK(&PerlIO_mutex);
+#ifdef USE_ITHREADS
+ MUTEX_LOCK(&PL_perlio_mutex);
#endif
- /* XXX should this be a panic? */
- if (fd >= PL_perlio_fd_refcnt_size)
- S_more_refcounted_fds(aTHX_ fd);
-
- /* XXX should this be a panic if it drops below 0? */
+ if (fd >= PL_perlio_fd_refcnt_size) {
+ Perl_croak(aTHX_ "refcnt_dec: fd %d >= refcnt_size %d\n",
+ fd, PL_perlio_fd_refcnt_size);
+ }
+ if (PL_perlio_fd_refcnt[fd] <= 0) {
+ Perl_croak(aTHX_ "refcnt_dec: fd %d: %d <= 0\n",
+ fd, PL_perlio_fd_refcnt[fd]);
+ }
cnt = --PL_perlio_fd_refcnt[fd];
- PerlIO_debug("fd %d refcnt=%d\n",fd,cnt);
-#ifdef USE_THREADS
- MUTEX_UNLOCK(&PerlIO_mutex);
+ PerlIO_debug("refcnt_dec: fd %d refcnt=%d\n", fd, cnt);
+#ifdef USE_ITHREADS
+ MUTEX_UNLOCK(&PL_perlio_mutex);
#endif
+ } else {
+ Perl_croak(aTHX_ "refcnt_dec: fd %d < 0\n", fd);
}
return cnt;
}
@@ -2367,6 +2375,7 @@
#else
PerlIO_debug("Cleanup layers\n");
#endif
+
/* Raise STDIN..STDERR refcount so we don't close them */
for (i=0; i < 3; i++)
PerlIOUnix_refcnt_inc(i);
@@ -2385,6 +2394,32 @@
}
}
+void PerlIO_teardown(pTHX) /* Call only from PERL_SYS_TERM(). */
+{
+
+#ifdef DEBUGGING
+ {
+ /* By now all filehandles should have been closed, so any
+ * stray (non-STD-)filehandles indicate *possible* (PerlIO)
+ * errors. */
+ int i;
+ for (i = 3; i < PL_perlio_fd_refcnt_size; i++) {
+ if (PL_perlio_fd_refcnt[i])
+ PerlIO_debug("PerlIO_cleanup: fd %d refcnt=%d\n",
+ i, PL_perlio_fd_refcnt[i]);
+ }
+ }
+#endif
+ /* Not bothering with PL_perlio_mutex since by now
+ * all the interpreters are gone. */
+ if (PL_perlio_fd_refcnt_size /* Assuming initial size of zero. */
+ && PL_perlio_fd_refcnt) {
+ free(PL_perlio_fd_refcnt); /* To match realloc() in
S_more_refcounted_fds(). */
+ PL_perlio_fd_refcnt = NULL;
+ PL_perlio_fd_refcnt_size = 0;
+ }
+}
+
/*--------------------------------------------------------------------------------------*/
==== //depot/maint-5.8/perl/perlio.sym#2 (text) ====
Index: perl/perlio.sym
--- perl/perlio.sym#1~17645~ 2002-07-19 12:29:57.000000000 -0700
+++ perl/perlio.sym 2007-02-13 13:18:26.000000000 -0800
@@ -23,6 +23,7 @@
PerlIO_setpos
PerlIO_sprintf
PerlIO_stdoutf
+PerlIO_teardown
PerlIO_tmpfile
PerlIO_ungetc
PerlIO_vprintf
==== //depot/maint-5.8/perl/perliol.h#8 (text) ====
Index: perl/perliol.h
--- perl/perliol.h#7~25462~ 2005-09-18 03:56:46.000000000 -0700
+++ perl/perliol.h 2007-02-13 13:18:26.000000000 -0800
@@ -168,6 +168,10 @@
PERL_EXPORT_C void PerlIO_list_push(pTHX_ PerlIO_list_t *list, PerlIO_funcs
*funcs, SV *arg);
PERL_EXPORT_C void PerlIO_list_free(pTHX_ PerlIO_list_t *list);
+/* PerlIO_teardown doesn't need exporting, but the EXTERN_C is needed
+ * for compiling as C++. Must also match with what perl.h says. */
+EXTERN_C void PerlIO_teardown(pTHX);
+
/*--------------------------------------------------------------------------------------*/
/* Generic, or stub layer functions */
==== //depot/maint-5.8/perl/perlvars.h#21 (text) ====
Index: perl/perlvars.h
--- perl/perlvars.h#20~30263~ 2007-02-13 11:23:41.000000000 -0800
+++ perl/perlvars.h 2007-02-13 13:18:26.000000000 -0800
@@ -82,3 +82,7 @@
PERLVARI(Gperlio_fd_refcnt, int*, 0) /* Pointer to array of fd refcounts. */
PERLVARI(Gperlio_fd_refcnt_size, int, 0) /* Size of the array */
#endif
+
+#if defined(USE_ITHREADS)
+PERLVAR(Gperlio_mutex, perl_mutex) /* Mutex for perlio fd refcounts */
+#endif
==== //depot/maint-5.8/perl/plan9/plan9ish.h#7 (text) ====
Index: perl/plan9/plan9ish.h
--- perl/plan9/plan9ish.h#6~21926~ 2003-12-18 12:49:11.000000000 -0800
+++ perl/plan9/plan9ish.h 2007-02-13 13:18:26.000000000 -0800
@@ -104,9 +104,10 @@
#define ABORT() kill(PerlProc_getpid(),SIGABRT);
#define BIT_BUCKET "/dev/null"
-#define PERL_SYS_INIT(c,v) MALLOC_CHECK_TAINT2(*c,*v) MALLOC_INIT
+#define PERL_SYS_INIT(c,v) \
+ MALLOC_CHECK_TAINT2(*c,*v) PERLIO_INIT; MALLOC_INIT
#define dXSUB_SYS
-#define PERL_SYS_TERM() MALLOC_TERM
+#define PERL_SYS_TERM() PERLIO_TERM; MALLOC_TERM
/*
* fwrite1() should be a routine with the same calling sequence as fwrite(),
==== //depot/maint-5.8/perl/unixish.h#11 (text) ====
Index: perl/unixish.h
--- perl/unixish.h#10~30036~ 2007-01-27 09:35:47.000000000 -0800
+++ perl/unixish.h 2007-02-13 13:18:26.000000000 -0800
@@ -127,11 +127,12 @@
#define Mkdir(path,mode) mkdir((path),(mode))
#ifndef PERL_SYS_INIT
-# define PERL_SYS_INIT(c,v) MALLOC_CHECK_TAINT2(*c,*v) PERL_FPU_INIT
MALLOC_INIT
+# define PERL_SYS_INIT(c,v) \
+ MALLOC_CHECK_TAINT2(*c,*v) PERL_FPU_INIT; PERLIO_INIT; MALLOC_INIT
#endif
#ifndef PERL_SYS_TERM
-#define PERL_SYS_TERM() OP_REFCNT_TERM; MALLOC_TERM
+# define PERL_SYS_TERM() HINTS_REFCNT_TERM; OP_REFCNT_TERM;
PERLIO_TERM; MALLOC_TERM
#endif
#define BIT_BUCKET "/dev/null"
==== //depot/maint-5.8/perl/vms/gen_shrfls.pl#6 (text) ====
Index: perl/vms/gen_shrfls.pl
--- perl/vms/gen_shrfls.pl#5~30163~ 2007-02-07 12:48:27.000000000 -0800
+++ perl/vms/gen_shrfls.pl 2007-02-13 13:18:26.000000000 -0800
@@ -194,18 +194,18 @@
while (/^#.*vmsish\.h/i .. /^#.*perl\.h/i) {
while (/__VMS_PROTOTYPES__/i .. /__VMS_SEPYTOTORP__/i) {
print "vms_proto>> $_" if $debug > 2;
- if (/^\s*EXT/) { &scan_var($_); }
+ if (/^\s*EXT(CONST|\s+)/) { &scan_var($_); }
else { &scan_func($_); }
last LINE unless defined($_ = <CPP>);
}
print "vmsish.h>> $_" if $debug > 2;
- if (/^\s*EXT/) { &scan_var($_); }
+ if (/^\s*EXT(CONST|\s+)/) { &scan_var($_); }
last LINE unless defined($_ = <CPP>);
}
while (/^#.*opcode\.h/i .. /^#.*perl\.h/i) {
print "opcode.h>> $_" if $debug > 2;
if (/^OP \*\s/) { &scan_func($_); }
- if (/^\s*EXT/) { &scan_var($_); }
+ if (/^\s*EXT(CONST|\s+)/) { &scan_var($_); }
last LINE unless defined($_ = <CPP>);
}
# Check for transition to new header file
@@ -221,12 +221,12 @@
}
if ($ckfunc) {
print "$scanname>> $_" if $debug > 2;
- if (/^\s*EXT/) { &scan_var($_); }
+ if (/^\s*EXT(CONST|\s+)/) { &scan_var($_); }
else { &scan_func($_); }
}
else {
print $_ if $debug > 3 && ($debug > 5 || length($_));
- if (/^\s*EXT/) { &scan_var($_); }
+ if (/^\s*EXT(CONST|\s+)/) { &scan_var($_); }
}
}
close CPP;
==== //depot/maint-5.8/perl/vms/vmsish.h#15 (text) ====
Index: perl/vms/vmsish.h
--- perl/vms/vmsish.h#14~30163~ 2007-02-07 12:48:27.000000000 -0800
+++ perl/vms/vmsish.h 2007-02-13 13:18:26.000000000 -0800
@@ -333,8 +333,8 @@
#endif
#define BIT_BUCKET "_NLA0:"
-#define PERL_SYS_INIT(c,v) MALLOC_CHECK_TAINT2(*c,*v)
vms_image_init((c),(v)); MALLOC_INIT
-#define PERL_SYS_TERM() OP_REFCNT_TERM; MALLOC_TERM
+#define PERL_SYS_INIT(c,v) MALLOC_CHECK_TAINT2(*c,*v)
vms_image_init((c),(v)); PERLIO_INIT; MALLOC_INIT
+#define PERL_SYS_TERM() HINTS_REFCNT_TERM; OP_REFCNT_TERM;
PERLIO_TERM; MALLOC_TERM
#define dXSUB_SYS
#define HAS_KILL
#define HAS_WAIT
==== //depot/maint-5.8/perl/win32/win32.c#31 (text) ====
Index: perl/win32/win32.c
--- perl/win32/win32.c#30~30140~ 2007-02-05 14:01:07.000000000 -0800
+++ perl/win32/win32.c 2007-02-13 13:18:26.000000000 -0800
@@ -4864,7 +4864,9 @@
void
Perl_win32_term(void)
{
+ dTHX;
OP_REFCNT_TERM;
+ PERLIO_TERM;
MALLOC_TERM;
}
End of Patch.