Skip to content

glob and fnmatch - #33

Merged
adh merged 2 commits into
mainfrom
glob-fnmatch
Aug 14, 2026
Merged

adh merged 2 commits into
mainfrom
glob-fnmatch

Conversation

@adh

@adh adh commented Aug 14, 2026

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI lite review requested due to automatic review settings August 14, 2026 20:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds POSIX-style filename pattern matching and globbing to ListTalk, exposing them both as ListTalk:OS module primitives and as convenience methods on String, with accompanying evaluation tests.

Changes:

  • Add ListTalk:OS:fnmatch? (keyword-flagged) and ListTalk:OS:glob primitives backed by libc fnmatch(3) / glob(3).
  • Add String>>fnMatch?: and String>>fnMatchPathname?: methods for common matching modes.
  • Add evaluation tests covering default vs pathname matching and basic glob behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
tests/eval-objects.lt Adds tests for new String pattern-matching methods.
tests/eval-modules-os.lt Adds tests for ListTalk:OS:fnmatch? and ListTalk:OS:glob.
src/modules/os.c Implements fnmatch? and glob primitives and keyword-to-flag mapping.
src/classes/String.c Implements two new String methods backed by fnmatch().
Suppressed comments (1)

src/classes/String.c:1033

  • String>>fnMatchPathname?: also treats any nonzero fnmatch() result as a non-match. Consider distinguishing FNM_NOMATCH from other error returns and raising for the latter so invalid patterns/flags don't get swallowed.
    return fnmatch(
        LT_String_value_cstr(pattern),
        LT_String_value_cstr(self),
        FNM_PATHNAME
    ) == 0 ? LT_TRUE : LT_FALSE;

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/modules/os.c Outdated
Comment on lines +902 to +906
return fnmatch(
LT_String_value_cstr(pattern),
LT_String_value_cstr(string),
flags
) == 0 ? LT_TRUE : LT_FALSE;
Comment thread src/classes/String.c Outdated
Comment on lines +1007 to +1011
return fnmatch(
LT_String_value_cstr(pattern),
LT_String_value_cstr(self),
0
) == 0 ? LT_TRUE : LT_FALSE;
Comment thread src/modules/os.c

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Suppressed comments (3)

src/modules/os.c:954

  • primitive_os_glob currently returns an empty list for all non-zero glob() return codes, which masks real failures (e.g. GLOB_ABORTED/GLOB_NOSPACE) and makes flags like :err ineffective. Only GLOB_NOMATCH should be silently mapped to an empty list; other errors should raise.
    result = glob(LT_String_value_cstr(pattern), flags, NULL, &matches);
    builder = LT_ListBuilder_new();
    if (result == 0){
        for (index = 0; index < matches.gl_pathc; index++){
            LT_ListBuilder_append(

src/modules/os.c:9

  • _GNU_SOURCE is currently defined unconditionally for this translation unit. Elsewhere (e.g. src/classes/Thread.c:6-15) feature-test macros are gated per-platform; defining _GNU_SOURCE on non-glibc targets can inadvertently change header visibility/ABI and may trigger warnings.
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif

src/modules/os.c:931

  • The docstring says "glob errors produce an empty list", but the tests/expected behavior only mention ignoring the no-match case. If non-NOMATCH errors are intended to be surfaced (e.g. :err, OOM, permission errors), the docstring should reflect that more precisely.

This issue also appears on line 950 of the same file.

    "Return paths matching a POSIX glob pattern; glob errors produce an empty list."

@adh
adh merged commit 05ef7e1 into main Aug 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants