summaryrefslogtreecommitdiff
path: root/perlio.c
Commit message (Collapse)AuthorAgeFilesLines
* Fix segfault in filehandle duplicationLeon Timmermans2013-12-211-1/+1
| | | | | | | | Previously PerlIOBase_dup didn't check if pushing the new layer succeeded before (optionally) setting the utf8 flag. This could cause segfaults-by-nullpointer. (cherry picked from commit df8c7dee25da69fc88678b8949166e08fb686037)
* PerlIO_find_layer should not be using memEQ() off the end of the layer name.Nicholas Clark2013-03-251-1/+2
| | | | | | | PerlIO_find_layer was using memEQ() to compare the name of the desired layer with each layer in the array of known layers. However, it was always using the length of the desired layer for the comparison, whatever the length of the name it was comparing it with, resulting in out-of-bounds reads.
* Ensure only DOSish builds force O_BINARY=1 in the open pathPaul Green2013-03-191-4/+9
|
* PATCH [perl #112244]Leon Timmermans2013-02-181-0/+2
| | | | | | | | | | :crlf currently doesn't fall back on :pending the way :perlio does when the unread data doesn't fit into its own buffer. Instead it just rejects them. This patch resolves that. Tests are coming in a future commit The committer added a cast to get it to compile on Win32, and silence a gcc warning on Linux
* Avoid wraparound when casting unsigned size_t to signed ssize_t.Andy Dougherty2013-01-161-4/+4
| | | | | | Practically, this only affects a perl compiled with 64-bit IVs on a 32-bit system. In that instance a value of count >= 2**31 would turn negative when cast to (ssize_t).
* Change core calls of isALNUM() to isWORDCHAR()Karl Williamson2012-12-311-1/+1
| | | | The latter is more clearly named to indicate it includes the underscore.
* more dTHX optimizationsDaniel Dragan2012-11-121-9/+9
| | | | | Either delay fetching of the context, or move the declaration close to the first usage point, or remove the dependency on a context.
* clean up the users of PL_no_memDaniel Dragan2012-11-121-4/+1
| | | | | | | | | This commit eliminates a couple strlen()s of a literal. "Out of memory!\n" and PL_no_mem did not string pool on Visual C, so PL_no_mem was given a length. This commit removes S_write_no_mem and replaces it with nonstatic. Perl_croak_no_mem was made nocontext to save instructions in it's callers. NORETURN_FUNCTION_END caused a syntax error on Visual C C++ mode and therefore was removed.
* remove various redundant dTHXesDaniel Dragan2012-11-081-2/+4
| | | | | Remove either unused dTHXes, or remove dTHXes where a nocontext func can be used instead. Smaller/faster machine code is the result.
* Add C define to remove taint support from perlSteffen Mueller2012-11-051-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | By defining NO_TAINT_SUPPORT, all the various checks that perl does for tainting become no-ops. It's not an entirely complete change: it doesn't attempt to remove the taint-related interpreter variables, but instead virtually eliminates access to it. Why, you ask? Because it appears to speed up perl's run-time significantly by avoiding various "are we running under taint" checks and the like. This change is not in a state to go into blead yet. The actual way I implemented it might raise some (valid) objections. Basically, I replaced all uses of the global taint variables (but not PL_taint_warn!) with an extra layer of get/set macros (TAINT_get/TAINTING_get). Furthermore, the change is not complete: - PL_taint_warn would likely deserve the same treatment. - Obviously, tests fail. We have tests for -t/-T - Right now, I added a Perl warn() on startup when -t/-T are detected but the perl was not compiled support it. It might be argued that it should be silently ignored! Needs some thinking. - Code quality concerns - needs review. - Configure support required. - Needs thinking: How does this tie in with CPAN XS modules that use PL_taint and friends? It's easy to backport the new macros via PPPort, but that doesn't magically change all code out there. Might be harmless, though, because whenever you're running under NO_TAINT_SUPPORT, any check of PL_taint/etc is going to come up false. Thus, the only CPAN code that SHOULD be adversely affected is code that changes taint state.
* Remove dead code related to the Atari ST port of perl 4.0 patchlevel 19Nicholas Clark2012-07-281-12/+0
| | | | | The subdirectory containing the port specific files was purged when 5.000 was released, but changes made to other files were not removed.
* update the editor hints for spaces, not tabsRicardo Signes2012-05-291-2/+2
| | | | | This updates the editor hints in our files for Emacs and vim to request that tabs be inserted as spaces.
* File scope for VMS-specific #includes.Craig A. Berry2012-05-241-1/+4
| | | | | C++ requires #include directives to be at file scope, but we've been lazy and haven't been doing that.
* Remove gete?[ug]id cachingÆvar Arnfjörð Bjarmason2012-02-181-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently we cache the UID/GID and effective UID/GID similarly to how we used to cache getpid() before v5.14.0-251-g0e21945. Remove this magical behavior in favor of always calling getpid(), getgid() etc. This resolves RT #96208. A minimal testcase for this is the following by Leon Timmermans attached to RT #96208: eval { require 'syscall.ph'; 1 } or eval { require 'sys/syscall.ph'; 1 } or die $@; if (syscall(&SYS_setuid, $ARGV[0] + 0 || 1000) >= 0 or die "$!") { printf "\$< = %d, getuid = %d\n", $<, syscall(&SYS_getuid); } I.e. if we call the sete?[ug]id() functions unbeknownst to perl the $<, $>, $( and $) variables won't be updated. This results in the same sort of issues we had with $$ before v5.14.0-251-g0e21945, and getppid() before my v5.15.7-407-gd7c042c patch. I'm completely eliminating the PL_egid, PL_euid, PL_gid and PL_uid variables as part of this patch, this will break some CPAN modules, but it'll be really easy before the v5.16.0 final to reinstate them. I'd like to remove them to see what breaks, and how easy it is to fix it. These variables are not part of the public API, and the modules using them could either use the Perl_gete?[ug]id() functions or are working around the bug I'm fixing with this commit. The new PL_delaymagic_(egid|euid|gid|uid) variables I'm adding are *only* intended to be used internally in the interpreter to facilitate the delaymagic in Perl_pp_sassign. There's probably some way not to export these to programs that embed perl, but I haven't found out how to do that.
* Moving :mmap out of core binary into a moduleLeon Timmermans2012-01-301-298/+0
|
* Bump several file copyright datesSteffen Schwigon2012-01-191-1/+1
| | | | | | | Sync copyright dates with actual changes according to git history. [Plus run regen_perly.h to update the SHA-256 checksums, and regen/regcharclass.pl to update regcharclass.h]
* diag_listed_as galoreFather Chrysostomos2011-12-281-0/+1
| | | | | In two instances, I actually modified to code to avoid %s for a constant string, as it should be faster that way.
* add a couple missing LEAVEs in perlio_async_run()Chip2011-09-251-1/+4
|
* Don't #include headers already included by perl.hNicholas Clark2011-09-151-7/+0
| | | | | | | | | 097ee67dff1c60f2 didn't need to include <locale.h> in locale.c (then util.c) because it had been included by perl.h since 5.002 beta 1 3f270f98f9305540 missed removing the include of <unistd.h> from perl.c or perlio.c de8ca8af19546d49 changed perl.h to also include <sys/wait.h>, but didn't notice that it code therefore be removed from perl.c, pp_sys.c and util.c
* The Borland Chainsaw MassacreSteve Hay2011-09-101-20/+1
| | | | | Remove support for the Borland C++ compiler on Win32, as agreed here: http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2011-09/msg00034.html
* Make :utf8 and :bytes MULTIARGLeon Timmermans2011-04-071-2/+2
| | | | | | | | | | | | | | | | PerlIO layer types have this property that flags if they can accept multiple arguments or only one. Unfortunately, this always checks the uppermost layer that has an Open method defined. This causes issues when used with utf8 or bytes on top of a layer that uses multiple arguments. For 5.15 I think abolishing this feature may make most sense. It's just flat out wrong IMO, it's the layer that uses the arguments that should validate them, not the topmost, which may not even touch them. In the mean time adding the multiargs flag to :utf8 and :bytes is a reasonable stop-gap. This patch makes perl slightly more permissive, so it shouldn't break any working code out there.
* Update comment for PerlIOCrlf_pushed wrt 7826b36Leon Timmermans2011-03-251-4/+2
| | | | | 7826b36fbbf24cfa659558ee5af3de424faa2d5a changed the behavior of PerlIOCrlf_pushed but its comment wasn't updated along with it.
* add refcnt_inc/dec to perldiagFather Chrysostomos2011-02-151-0/+5
|
* [perl #78494] Pipes cause threads to hang on join()Father Chrysostomos2011-02-151-0/+31
| | | | | | | | | | | | | or on close() in either thread. close() in one thread blocks until close() is called in the other thread, because both closes are waiting for the child process to end. Since we have a reference-counting mechanism for the underlying fileno, we can use that to determine whether close() should wait. This does not solve the problem of close $OUT block when it has been duplicated via open $OUT2, ">&" and $OUT2 is still in scope.
* [perl #38456] binmode FH, ":crlf" only modifies top crlf layerLeon Timmermans2011-01-271-3/+2
| | | | | When pushed on top of the stack, crlf will no longer enable crlf layers lower in the stack. This will prevent unexpected results.
* perlio.c: silence format warningsRobin Barker2011-01-271-6/+6
| | | | Signed-off-by: Ævar Arnfjörð Bjarmason <avar@cpan.org>
* PerlIO_push returns NULL, not -1, on failure.Craig A. Berry2011-01-211-1/+1
| | | | Follow-up to 81fe74fb3f93457df8e864c91546ac6b860657fc.
* Fixes 'raw' layer for perl#80764Leon Timmermans2011-01-201-15/+1
| | | | | Made a ':raw' open do what it advertises to do (first open the file, then binmode it), instead of leaving off the top layer.
* Use PerlIOBase_open for pop, utf8 and bytes layersLeon Timmermans2011-01-201-3/+3
|
* Define PerlIOBase_openLeon Timmermans2011-01-201-0/+18
|
* Fix typos (spelling errors) in Perl sources.Peter J. Acklam) (via RT2011-01-071-5/+5
| | | | | | | | | # New Ticket Created by (Peter J. Acklam) # Please include the string: [perl #81904] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=81904 > Signed-off-by: Abigail <abigail@abigail.be>
* Make PerlIO marginally reentrantDavid Mitchell2010-11-261-15/+84
| | | | | | | | | | | | | | | | | | | | | | Currently if an operation on a file handle is interrupted, and if the signal handler accesses that same file handle (e.g. closes it), then perl will crash. See [perl #75556]. This commit provides some basic infrastructure to avoid segfaults. Basically it adds a lock count field to each handle (by re-purposing the unused flags field in the PL_perlio array), then each time a signal handler is called, the count is incremented. Then various parts of PerlIO use a positive count to change behaviour. Most importantly, when layers are popped, the PerlIOl structure is cleared, but not freed, and is left in the chain of layers. This means that callers still holding pointers to the various layers won't access freed structures. It does however mean that PerlIOl structs may be leaked, and possibly slots in PL_perlio. But this is better than crashing. Not much has been done to give sensible behaviour on re-entrancy; for example, a buffer that has already been written once might get written again. Fixing this sort of thing would require a large-scale audit of perlio.c.
* perlio: always guard against null function tableDavid Mitchell2010-11-261-14/+20
| | | | | | In some places it already checks for a null tab field; extend that coverage. This is in preparation for a commit which may leave active layers with a null tab field.
* add PerlIO_init_table() to initialise PL_perioDavid Mitchell2010-11-261-2/+12
| | | | | | | | | | | Previously, the PL_perio table was initialised by calling PerlIO_allocate, and throwing away the result. Since a slot with a null ->next was regarded as freed, the next call to PerlIO_allocate would reuse that slot, which is important, as STDIN etc are expected to occupy slots 1,2,3. Once reference counting of the slots is introduced, however, the first slot will leak, and STDIN etc will be assigned to the wrong slots. So do it properly now.
* add 'head' field to PerlIOl structDavid Mitchell2010-11-261-0/+31
| | | | | | | | | | | | | This allows any layer to find the top of the layer stack, or more specifically, the entry in PL_perlio that points to the top. Needed for the next commit, which will implement a reference counting scheme. There's currently a bug in MakeMaker which causes several extensions to miss the dependency on perliol.h having changed, so this commit includes a gratuitous whitespace change to perl.h to hopefully force recompilation.
* make PL_perlio an array of PerlIOl, not PerlIO *David Mitchell2010-11-261-37/+42
| | | | | | | | | | | | | | | | | | | | | | | | Layers in PerlIO are implemented as a linked list of PerlIOl structs; eaxch one has a 'next' field pointing to the next layer. Now here's the clever bit: When PerlIO* pointers are passed around to refer to a particular handle, these are actually pointers to the 'next' field of the *parent* layer (so to access the flags field say of a PerlIOl, you have to double-defref it, e.g. (*f)->flags). The big advantage of this is that it's easy for a layer to pop itself; when you call PerlIO_pop(f), f is a pointer to the parent's 'next' field, so pop(f) can just do *f = (*f)->next. This means that there has to be a fake 'next' field above the topmost layer. This is where PL_perlio comes in: it's a pointer to an arena of arrays of pointers, each one capable of pointing to a PerlIOl structure. When a new handle is created, a spare arena slot is grabbed, and the address of that slot is returned. This also allows for a handle with no layers. What this commit does is change PL_perlio from being an array of PerlIO* into an array of PerlIOl structures - i.e. each element in the array goes from being a single pointer, to having several fields. These will be made used of in follow-up commits.
* Make perlio line buffer VMS record-oriented files on output.Craig A. Berry2010-11-171-0/+16
| | | | | | | | | | | | | | | | | | | | | When perlio flushes down to the unix layer, it can introduce a spurious record boundary when writing to a record-oriented file. Perl may create such files when doing edit-in-place or any other context where the file format is inherited from a previous version of the file. The problem can be eliminated by enabling line buffering on such files when they are opened. This was a regression in 5.10.0 since before that stdio's buffering performed the same function. N.B. Lines longer than the size of the perlio buffer will still result in multiple records -- a larger buffer may be necessary. For more details and discussion see: http://www.nntp.perl.org/group/perl.vmsperl/2010/11/msg15419.html Thanks to Martin Zinser for the problem report.
* Rename PERLIO_BUFSIZ to PERLIOBUF_DEFAULT_BUFSIZ.Craig A. Berry2010-11-101-1/+1
| | | | | | | PERLIO_BUFSIZ was already in use by Encode::Unicode for the PerlIOEncode_xxx layer, so it makes sense to specify that this macro is for the PerlIOBuf_xxx layer and that it is a default value that may eventually be settable at run-time.
* Make the buffer size for the perlio layer a macro.Craig A. Berry2010-11-091-1/+1
| | | | | | | | | | | The 4K buffer size was chosen way back in bb9950b. Significant performance improvements are seen with larger buffer sizes, though the optimum size likely varies by architecture and workload. For starters, we'll leave the default as-is but make the buffer size a macro and thus user-configurable via: sh Configure -Accflags=-DPERLIO_BUFSIZ=<number> Choosing a better (larger) default is still TODO.
* localize $@ during binmode (RT#78844)David Golden2010-11-061-0/+3
|
* full API for cop hint hashesZefram2010-10-211-2/+1
| | | | | | | | | | | | | Expose cop hint hashes as a type COPHH, with a cophh_* API which is a macro layer over the refcounted_he_* API. The documentation for cophh_* describes purely API-visible behaviour, whereas the refcounted_he_* documentation describes the functions mainly in terms of the implementation. Revise the cop_hints_* API, using the flags parameter consistently and reimplementing in terms of cophh_*. Use the cophh_* and cop_hints_* functions consistently where appropriate. [Modified by the committer to update two calls to Perl_refcounted_he_fetch recently added to newPMOP.]
* [perl #73754] Better error message for PerlIO layer implementationsTye McQueen2010-09-261-3/+8
| | | | | | | | | | | | | | | | | | | | please find attached a patch against blead originating from [1] , that improves the "Layer does not match this perl" error message by telling the user which IO layer failed and how. I've tested the patch against a recent bleadperl and even without the modifications to perldiag.t all tests pass. Still, for completeness, I've patched perldiag.t as well. The code is not mine, it was written and posted by Tye McQueen, I've just tested it [2] and ferry the information. I'm aware that this patch is too late for 5.12 , but in the sense of improving Perl in the long run, I hope the change still makes it into a version of Perl. -max [1] http://perlmonks.org/?node_id=829815 [2] Certified Works On My Machine, 2010
* [perl #77684] Restore the 5.10/12 behaviour of open $fh, ">", \$glob_copyFather Chrysostomos2010-09-131-1/+1
| | | | | | | | | This restores the perl 5.10/12 behaviour, making open treat \$foo as a scalar reference if it is a glob copy (SvFAKE). It also fixes an existing assertion failure that the test now trig- gers. PerlIOScalar_pushed was not downgrading the sv before set- ting SvCUR.
* [perl #77492] open $fh, ">", \*glob causes SEGVFather Chrysostomos2010-09-011-1/+1
| | | | | PerlIO_layer_from_ref must not treat a real glob as a scalar. This function was not updated when SVt_PVGV was moved before SVt_PVLV.
* Make PerlIOUnix_open honor default permissions on VMS.Craig A. Berry2010-08-281-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When perlio became the default and unixio became the default bottom layer, the most common path for creating files from Perl became PerlIOUnix_open, which has always explicitly used 0666 as the permission mask. This has the following undesireable effects on VMS: 1.) The execute bit is lost regardless of whether it's in the default permissions. 2.) Delete permission (which doesn't exist in the Unix permission mask) is copied from write permission, so granting write permission also grants delete even if it's not in the default permission mask. This can result in an inadvertent widening of permissions. 3.) System permissions (which don't exist in the Unix permission mask) are copied from owner permissions, so any distinction between system and owner is lost. 4.) ACLs are not inherited. For example, setting a default_protection ACE on a directory such that all world access is disallowed will be ignored; world will have the intersection of RWD (the final 6 in 0666) and whatever the default permissions are regardless of what the ACL says. Thus not inheriting ACLs can result in the inadvertent widening of permissions. The way to avoid all of this is to pass 0777 as the permissions to open(). In the VMS CRTL, 0777 has a special meaning over and above intersecting with the current umask; specifically, it allows Unix syscalls to preserve native default permissions. Details currently documented at: http://h71000.www7.hp.com/doc/732final/5763/5763pro_060.html#umask_routine
* fix 'might be used uninitialized' in PerlIO_tmpfileDavid Mitchell2010-08-181-1/+1
| | | | | sv can't actually be used uninitialized, but set it to zero to shut up stupid compilers
* PL_in_load_module only has values 0 and 1, so can be a bool instead of int.Nicholas Clark2010-05-211-3/+2
|
* Possible undefined behaviour, spotted by gcc 4.5.0 and HP's updated compiler.Nicholas Clark2010-04-191-1/+1
|
* Unlink PerlIO's tempfiles for the case of no -T, but bogus $ENV{TMPDIR}Nicholas Clark2010-01-071-2/+4
| | | | | | When -T is enabled, or when $ENV{TMPDIR} is bogus, perlio.c used a pathname matching </tmp/PerlIO_??????>. However, it was only correctly unlinking the file for the case of -T enabled.
* SvREFCNT_dec already checks if the SV is non-NULL (continued)Vincent Pit2009-11-081-12/+6
|