| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
These functions depend on C library functions which have undefined
behaviour when passed NULL pointers, even when passed a zero 'n' value.
Some compilers use this information, ie. assume the pointers are
non-NULL when optimizing any following code, so we do need to
prevent such unguarded calls.
My initial thought was to add conditionals to each macro to skip the
call to the library function when n is zero, but this adds a cost to
every use of these macros, even when the n value is always true.
So instead I added asserts() which will give us a much more visible
indicator of such broken code and revealed the pp_caller and Glob.xs
issues also patched here.
|
|
|
|
| |
get_sv would be called upto 3 times, now it will be called just once
|
|
|
|
|
|
|
|
|
|
|
| |
The lower levels of File::Glob expect null-terminated strings, while
the higher levels do s = SvPV(sv,len) and pass the len. Ease the impedance
mismatch by ensuring that s[len] is always \0. Most perl SVs will already
have that \0 anyway, so in practice this hasn't been an issue.
It also ignores the utf8-ness of the string. I've kept that as-is (too big
a can of works to open for now), but I've fixed the 'is_utf8 var not used'
warning and added an XXX comment instead.
|
|
|
|
|
|
|
|
|
|
|
| |
This solves [perl #119897] and [perl #117823], and restores the
behavior of glob() in conjunction with threads of 5.14 and older.
Since 5.16, code that used glob() inside a thread had been
unintentionally sharing state between threads, which lead to things
like this crashing and failing assertions:
./perl -Ilib -Mthreads -e 'scalar glob("*"); threads->create(sub { glob("*") })->join();'
|
|
|
|
| |
and before we do much processing
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Check for the nul char in pathnames and string arguments to
syscalls, return undef and set errno to ENOENT.
Added to the io warnings category syscalls.
Strings with embedded \0 chars were prev. ignored in the syscall but
kept in perl. The hidden payloads in these invalid string args may cause
unnoticed security problems, as they are hard to detect, ignored by
the syscalls but kept around in perl PVs.
Allow an ending \0 though, as several modules add a \0 to
such strings without adjusting the length.
This is based on a change originally by Reini Urban, but pretty much
all of the code has been replaced.
|
|
|
|
|
|
|
|
|
|
|
|
| |
See ticket #116064.
File::Glob and ::DosGlob free data associated with a calling op when
that op is freed.
During global destruction, there is no need to do that, as it will be
freed anyway.
Also, during sv_clean_all dMY_CXT can cause us to read freed memory.
|
|
|
|
|
|
| |
Hence, there is no need to lock a mutex; also storing the old value
in a C static is bad. It needs to be in a spot local to the current
interpreter, which MY_CXT provides.
|
|
|
|
|
|
|
|
|
|
| |
File::Glob keeps its own hash of arrays of file names. Each array corresponds to one call site. When iteration finishes, it deletes
the array. But if iteration never finishes, and the op at the call
site is freed, the array remains. So eval "scalar<*>" will cause a
memory leak.
We already have a mechanism for hooking the freeing of ops. So
File::Glob can use that.
|
|
|
|
|
|
| |
If Glob.xs just uses the address of PL_op as its iterator key all the
time (when called via PL_globhook too, not just via a glob override),
the code is simpler.
|
|
|
|
|
|
|
| |
See the previous commit. The same applies to File::Glob as well.
In short, the easiest way to fix a memory leak involves using the
address of the glob op rather than a special glob index.
|
|
|
|
|
|
|
|
|
| |
If a pattern passed to File::Glob consists of a space-separated list
of patterns, the stack will only be extended by doglob() enough for
the list returned by each subpattern. So iterate() needs to extend
the stack before copying the list of files from an AV to the stack.
This fixes a regression introduced in 5.16.0.
|
| |
|
|
|
|
|
| |
These are left over from the refactoring that took place
with commit 1bb8785a.
|
|
|
|
|
| |
It has been redundant since 1bb8785a (when bsd_glob was still
called doglob).
|
| |
|
|
|
|
| |
This was obsoleted by commit f4cbf9907d.
|
| |
|
|
|
|
|
| |
Since this is XS code, we don’t have to store array references in
a hash. We can just store the arrays themselves.
|
|
|
|
| |
This not longer applies really, as I’ve significantly modified it.
|
|
|
|
| |
This happens under :bsd_glob when <>/glob is called in list context.
|
|
|
|
|
| |
There is no need to keep a separate scalar to remember the number of
items in an array. We can just use the array.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This is intended to replace the :glob export tag. The problem with
:glob is that the glob export (File::Glob::glob) does not support ite-
ration, but tries to return a whole list each time; hence it causes
while(<*>) to loop endlessly, as it is repeatedly returning the last
file (scalar context).
Since there may be code relying on that, we cannot easily change it,
but we can supplant it.
Since bsd_glob is already documented as supporting spaces in patterns
(that match spaces in file names; i.e., that are not separators), this
commit adds a :bsd_glob export tag that only differs from :glob in
that the exported glob() function iterates in scalar context.
An imminent commit will add documentation.
|
|
|
|
|
|
| |
Parsing of a glob pattern and iteration logic are now in separate
functions, so that another function (soon to be added) can share
the same iteration code.
|
|
|
|
|
| |
It was reading one byte too far, and looking at the trailing null.
This happened only in the case of an unmatched quote.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This commit does not change the output on Unix. On Windows, where the
globbing engine does not usually treat backslashes as escapes, this
restores the behaviour to what it was before commit 0b0e6d70, for
cases like glob('a\"b c\"d').
Before 0b0e6d70, the preprocessing done by csh_glob (which it out-
sourced to Text::ParseWords) would remove backslash escapes, so the
globbing engine got to see a"b and c"d.
Since 0b0e6d70, the backslash escapes were no longer removed (because
in most cases they needed to remain, to avoid backslashitis), so the
globbing engine got to see a\"b and c\"d. On Unix that made no dif-
ference, as the globbing engine treats \ as an escape character. But
on Windows it doesn’t usually, so the output changed and produced a
literal a\"b.
This commit strips out quote-escaping backslashes in the prepro-
cessing code.
|
|
|
|
|
|
|
|
|
|
|
| |
For <...> without spaces in list context, don’t even bother adding
file names returned by the glob engine to the cached array. I origin-
ally added a short-circuit that would skip copying the file names from
the cached array on to the stack in that case, because the file names
are already there. But we can also skip putting them in the array to
begin with, as the cached array is about to be deleted.
This should make things even faster.
|
|
|
|
|
|
|
|
| |
I’m referring here to CVs, not C functions.
Actually, bsd_glob is the alias to doglob. doglob is no longer
called, as of commit 1bb8785ab1. So this commit is actually renaming
doglob to bsd_glob and removing the alias.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This commit makes CORE::glob bypassing glob overrides.
A side effect of the fix is that, with the default glob implementa-
tion, undefining *CORE::GLOBAL::glob no longer results in an ‘unde-
fined subroutine’ error.
Another side effect is that compilation of a glob op no longer assumes
that the loading of File::Glob will create the *CORE::GLOB::glob type-
glob. ‘++$INC{"File/Glob.pm"}; sub File::Glob::csh_glob; eval '<*>';’
used to crash.
This is accomplished using a mechanism similar to lock() and
threads::shared. There is a new PL_globhook interpreter varia-
ble that pp_glob calls when there is no override present. Thus,
File::Glob (which is supposed to be transparent, as it *is* the
built-in implementation) no longer interferes with the user mechanism
for overriding glob.
This removes one tier from the five or so hacks that constitute glob’s
implementation, and which work together to make it one of the buggiest
and most inconsistent areas of Perl.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This commit rewrites File::Glob::csh_glob (which implements perl’s
default globbing behaviour) in C.
This fixes a problem introduced by 0b0e6d70f. If there is an
unmatched quotation mark, all attempts to parse the pattern are
discarded and it is treated as a single token. Prior to 0b0e6d70f,
whitespace was stripped from both ends in that case. As of 0b0e6d70f,
it was only stripped from the beginning. This commit restores the
pre-0b0e6d70f behaviour with unmatched quotes. It doesn’t take
'a"b\ ' into account (where the space is escaped), but that wasn’t
handled properly before 0b0e6d70f, either.
This also finishes making csh_glob consistent with regard to quota-
tion marks. Commit 0b0e6d70f attempted to do that, but did not strip
out medial quotation marks, as in a"b"c. Text::ParseWords does not
provide an interface for stripping out quotation marks but leaving
backslashes, which I tried to work around, not fully understanding
the implications. Anyway, this new C implementation doesn’t use
Text::ParseWords.
The latter fix caused a test failure, but that test was there to make
sure the behaviour didn’t change depending on whether File::Glob
was loaded before the first mention of glob(). (In 5.6, loading
File::Glob first would make perl revert to external csh glob, ironic-
ally enough.) This commit modifies the test to test for sameness,
rather than exact output. In fact, this change causes perl and
miniperl to be consistent, and probably also causes glob to be more
consistent across platforms (think of VMS).
Another effect of the translation to C is that the Unicode Bug is
fixed with regard to splitting patterns. The C code effectively does
/\s/a now (which I believe is the only sane behaviour in this case),
instead of treating the string differently depending on the UTF8 flag.
The Unicode Bug is still present with regard to actual globbing.
This commit introduces one regression. This code:
undef %File::Glob::;
glob("nometachars");
will no longer return anything, because csh_glob no longer holds a
reference count on the $File::Glob::DEFAULT_FLAGS glob. Any code that
does that is beyond crazy.
The big advantage to this patch is speed. Something like
‘@files = <*>’ is 18% faster in a folder of 300 files. For smaller
folders there should be an even more notable difference.
|
|
|
|
| |
3c97495f56fb647c used bzero(), which isn't available on some platforms.
|
|
|
|
|
|
|
|
|
| |
First, disable all the unsupported flags just to make sure they aren't
triggering something they shouldn't be. Also, zero the pglob struct
before passing to bsd_glob(); it contains function pointers, and it's
safest if they are null rather than containing random stack data.
Bug reported by Clément Lecigne <clemun@gmail.com>.
|
|
|
|
|
| |
For threaded platforms, this reduces the object code size, and should slightly
reduce CPU usage.
|
|
|
|
|
|
|
|
|
|
|
| |
Trivial changes to fix warnings of types
* unclear precedence
* assignment as conditional
* signed/unsigned mixing
* unused parameter/variable
* value computed not used
* wrong argument type for a printf format
* variable may be used uninitialised (due to unhandled switch case)
|
|
|
|
|
| |
Without this, Glob.xs won't build on any compiler which enforces this part of
C89.
|
|
|
|
|
| |
Unlike doglob, it has no prototype, so it's not possible to use a simple ALIAS
directive to make it and doglob aliases.
|
|
|
|
|
| |
Previously it was bodged as a constant(), with an explicit wrapper subroutine
in Glob.pm to call each time to get the value.
|
| |
|
|
|