summaryrefslogtreecommitdiff
path: root/ext/File-Glob/Glob.xs
Commit message (Collapse)AuthorAgeFilesLines
* (perl #131746) avoid undefined behaviour in Copy() etcTony Cook2017-09-041-1/+1
| | | | | | | | | | | | | | | | | 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.
* remove multi-eval problem from File::GlobDaniel Dragan2015-01-191-5/+6
| | | | get_sv would be called upto 3 times, now it will be called just once
* File::Glob: fix warnings and non-\0-ended stringsDavid Mitchell2013-11-131-3/+13
| | | | | | | | | | | 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.
* File::Glob: Dup glob state in CLONE()Brian Fraser2013-09-271-0/+33
| | | | | | | | | | | 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();'
* [perl #117265] do most glob \0 checks in the same placeTony Cook2013-09-091-30/+38
| | | | and before we do much processing
* [perl #117265] correctly handle overloaded stringsTony Cook2013-09-091-5/+6
|
* [perl #117265] safesyscalls: check embedded nul in syscall argsTony Cook2013-08-261-1/+3
| | | | | | | | | | | | | | | | 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.
* {Dos,}Glob.xs: Skip freeing during global destructionFather Chrysostomos2012-12-121-0/+3
| | | | | | | | | | | | 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.
* Glob.xs: PL_opfreehook is an interpreter variableFather Chrysostomos2012-12-111-7/+4
| | | | | | 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.
* Don’t leak when partly iterated glob op is freedFather Chrysostomos2012-12-091-0/+17
| | | | | | | | | | 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.
* Stop using PL_glob_index for PL_globhookFather Chrysostomos2012-12-091-10/+2
| | | | | | 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.
* File::Glob: Don’t use the magic 2nd arg to globFather Chrysostomos2012-12-091-10/+8
| | | | | | | 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.
* [perl #114984] Glob.xs: Extend stack when returningFather Chrysostomos2012-09-201-0/+1
| | | | | | | | | 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.
* expunge gratuitous Unicode punctuation in commentsZefram2011-11-161-1/+1
|
* Glob.xs: remove unused varsFather Chrysostomos2011-11-051-4/+0
| | | | | These are left over from the refactoring that took place with commit 1bb8785a.
* Glob.xs: Remove dMY_CXT from bsd_globFather Chrysostomos2011-10-291-2/+0
| | | | | It has been redundant since 1bb8785a (when bsd_glob was still called doglob).
* Glob.xs: Clarify commentFather Chrysostomos2011-10-291-1/+2
|
* Glob.xs: Remove commentFather Chrysostomos2011-10-291-4/+0
| | | | This was obsoleted by commit f4cbf9907d.
* Glob.xs: constingFather Chrysostomos2011-10-291-2/+2
|
* Glob.xs: Be more parsimonious with SVsFather Chrysostomos2011-10-291-16/+7
| | | | | Since this is XS code, we don’t have to store array references in a hash. We can just store the arrays themselves.
* Glob.xs: Remove commentFather Chrysostomos2011-10-291-1/+0
| | | | This not longer applies really, as I’ve significantly modified it.
* Oops: Fix Glob.xs assertion failureFather Chrysostomos2011-10-291-2/+4
| | | | This happens under :bsd_glob when <>/glob is called in list context.
* Glob.xs: Eliminate x_GLOB_ITERFather Chrysostomos2011-10-291-11/+2
| | | | | There is no need to keep a separate scalar to remember the number of items in an array. We can just use the array.
* Add :bsd_glob export tag to File::Glob [perl #96116]Father Chrysostomos2011-10-291-0/+48
| | | | | | | | | | | | | | | | | | 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.
* Glob.xs: Refactor iteration into separate functionFather Chrysostomos2011-10-281-32/+54
| | | | | | 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.
* Stop csh_glob from reading past end of stringFather Chrysostomos2011-10-271-1/+1
| | | | | It was reading one byte too far, and looking at the trailing null. This happened only in the case of an unmatched quote.
* Make csh_glob remove quote-escaping backslashesFather Chrysostomos2011-10-271-3/+23
| | | | | | | | | | | | | | | | | | | | | 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.
* File::Glob: short-circuit earlier for list cxFather Chrysostomos2011-10-271-2/+2
| | | | | | | | | | | 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.
* File::Glob: Eliminate the doglob alias to bsd_globFather Chrysostomos2011-10-271-6/+2
| | | | | | | | 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.
* Fix CORE::globFather Chrysostomos2011-10-261-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | 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.
* Rewrite csh_glob in C; fix two quoting bugsFather Chrysostomos2011-10-261-17/+256
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* In Glob.xs, use memset() instead of bzero()Nicholas Clark2011-09-061-1/+1
| | | | 3c97495f56fb647c used bzero(), which isn't available on some platforms.
* Plug segfault in bsd_glob() with unsupported ALTDIRFUNC flag.Craig A. Berry2011-09-031-0/+3
| | | | | | | | | 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>.
* Add PERL_NO_GET_CONTEXT to File::GlobNicholas Clark2011-03-191-0/+2
| | | | | For threaded platforms, this reduces the object code size, and should slightly reduce CPU usage.
* fix various compiler warnings from XS codeZefram2010-12-111-0/+1
| | | | | | | | | | | 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)
* MY_CXT_INIT happens to contain a variable declaration, so give it its own blockNicholas Clark2010-10-211-0/+3
| | | | | Without this, Glob.xs won't build on any compiler which enforces this part of C89.
* Convert File::Glob::bsd_glob to XS.Nicholas Clark2010-10-211-5/+11
| | | | | Unlike doglob, it has no prototype, so it's not possible to use a simple ALIAS directive to make it and doglob aliases.
* File::Glob::GLOB_ERROR is a real subroutine, not a constant().Nicholas Clark2010-10-151-0/+9
| | | | | Previously it was bodged as a constant(), with an explicit wrapper subroutine in Glob.pm to call each time to get the value.
* Replace sv_2mortal(newSVpvn(...)) with newSVpvn_flags(..., SVs_TEMP)Nicholas Clark2009-10-151-2/+2
|
* Rename ext/File/Glob to ext/File-GlobNicholas Clark2009-02-091-0/+72