Skip to contents

dparser 1.3.1-15

  • The installed parse.h now sets USE_FREELISTS and TRACK_PNODES, the switches the library is built with; before, only src/Makevars set them. TRACK_PNODES adds fields to PNode and Parser, so a package that included parse.h through LinkingTo and read PNode fields read them 16 bytes off; rxode2’s syntax-error report crashed R on Windows this way (nlmixr2/rxode2#1903). A package sees the corrected layout once it is rebuilt against this dparser.

  • update_D_Sym() and update_additional_D_Sym() now copy the whole caller-sized symbol into the update. They allocated sizeof_D_Sym bytes but copied only sizeof(D_Sym), so a caller using a larger user symbol (a bigger D_UserSym, or a struct that starts with a D_Sym) lost its extra data and read uninitialised memory. Ported from upstream (#51).

  • A - at the start or end of a bracket class in a terminal regex is now a literal hyphen, so "[a-z-]+", "[A-Za-z0-9_-]+" and "[-a]" match - as intended. build_regex_nfa() always read the character after - as a range end: in [a-] it took the closing ] as the end of an (empty) range and then read the rest of the regex as part of the class, and in [-a] it read -a as an empty range from its 255 placeholder, so the class matched neither - nor a. Ported from upstream (#48).

  • mkdparse() / dparse() build the LR(0) states faster for large grammars: maybe_add_state() now finds an already-built state in a hash set instead of scanning every state built so far (which was quadratic in the number of states), and build_new_states() builds a state’s successors only for the symbols that follow an item of that state, instead of trying every terminal and every production. The successors are still built in the old symbol order, so the state numbering and the generated parser tables are byte-for-byte the same. Ported from upstream (#50). quadratic in the number of states). The generated parser tables are byte-for-byte the same. Ported from upstream (#50).

  • A global scope that holds more than 6275 symbols no longer loses them. When the global symbol table grew, symhash_add() re-inserted the saved symbols with a loop that indexed its temporary vector at the old bucket count instead of walking it, so nearly every symbol was dropped from the table (a later find_D_Sym() returned NULL), the read could run past the end of the vector, and the vector leaked. Ported from upstream (#49).

  • Ambiguous operator-priority parses: when two candidate subtrees have the same height and start, the longer one is now ordered first when their priorities are compared (in both the per-tree priority stacks and when the two trees’ stacks are merged), matching upstream . check_child() also rejects nesting two non-associative (ASSOC_NO) operators of equal priority, and gram.h gains IS_NO_ASSOC(); the grammar reader does not assign ASSOC_NO yet, so this guard has no effect on current grammars (#47).

  • Ties in greedy disambiguation, and the order of parser-state node sets, no longer depend on heap addresses, so an ambiguous parse gives the same tree in every R session. Each internal PNode now records its creation order (serial) and that breaks the remaining ties, as in upstream . The internal PNode and Parser structs each gain one field, so sizeof(PNode) changes; the public D_ParseNode and the dparser.h entry points are unchanged, and grammar actions get the node offset at run time, so compiled parsers keep working. Code outside dparser that uses DPN_TO_PN() or PNode directly must be rebuilt (#47).

  • current_D_Sym(), update_D_Sym() and update_additional_D_Sym() (and so UPDATE_D_SYM()) now return NULL when given a NULL symbol, such as the result of a failed find_D_Sym(), instead of crashing; update_D_Sym() then leaves the scope unchanged. Ported from upstream (#49).

  • A quoted string in a regex production (::=) that contains | or / is now matched literally. When such a production is folded into one regular expression, escape_string_for_regex() escaped ( ) [ ] - ^ * ? + and \ but not | (alternation) or / (trailing context), so bars ::= '||'+; rejected ||||, slash ::= '/'+; rejected /, and x ::= 'a|b'; matched a or b instead of a|b. Ported from upstream (#43).

  • Compiling a grammar with a regex production (::=) whose quoted strings are mostly regex metacharacters, such as x ::= '||||||||'; or x ::= '++++++++';, no longer overflows a heap buffer (with _FORTIFY_SOURCE it aborted the R session). convert_regex_production_one() sized the combined regex from the unescaped string lengths, but escaping can double them (#43).

  • mkdparse(rdebug = TRUE) no longer overflows the stack: the debug grammar printer read the version into a 30-byte buffer although d_version() writes about 46 characters, and d_version() measured an uninitialised buffer. The printer also no longer leaks the double-escaped copy of string and regex terminals (#40, jplevyak/dparser#34).

  • Token locations are now correct for grammars large enough to need 16- or 32-bit scanner tables. scan_buffer() recorded a token’s end line and column before consuming its last character, so positions after it – including syntax error positions – were one column short, or one line short after a token ending in a newline. Small grammars were not affected. Ported from upstream DParser a1f64e7 (#44).

  • A regular expression bracket range that ends at \xff (for example "[\x80-\xff]+") no longer makes mkdparse() / dparse() loop forever while building the scanner. The range counter in build_regex_nfa() was a uint8 that wrapped from 255 back to 0; it is now an int (#42, upstream jplevyak/dparser 6d494a3).

  • Generated parser tables no longer contain raw bytes 0x80-0xff on macOS. escape_string() used isprint(), which macOS treats as true for those bytes in a UTF-8 locale, so a grammar such as "[\x80-\xff]+" produced invalid UTF-8 C source and dparse() failed in gsub() with “‘replacement’ is invalid”; such bytes are now always written as \xNN escapes (#42).

  • In a regular expression term, a * or + loop inside one | alternative no longer leaks into the sibling alternatives: "a*|b" used to also accept "ab" and "aab". build_regex_nfa() now gives each group level and each alternative its own start state (#42, upstream jplevyak/dparser 6d494a3). The tables generated for rxode2’s grammars are unchanged.

  • A case-insensitive regular expression term ("..."/i) now folds case inside bracket classes before negating them, so "[^a]"/i no longer matches A and "[a-c]+"/i matches aBc (#42, upstream jplevyak/dparser 6d494a3).

dparser 1.3.1-14

CRAN release: 2026-10-12

  • Ambiguous parses that depend on operator priorities (for example an if-then / if-then-else written with $unary_op_right priorities) now give the same tree every time. get_unshared_priorities() broke ties between equal-height subtrees by comparing PNode heap addresses, so the chosen grouping could change from one parse, or R session, to the next. It now compares start position and then priority, as in upstream (#39, jplevyak/dparser#31).

  • N-ary productions with a priority ($left N / $right N) are now checked against the right row of the parent/child priority table when they appear as the child of an operator. They were treated as binary, so, for example, an if-then / if-then-else written as X '->' Y $right 5 and X '->' Y '<>' Y $right 6 rejected valid input. This ports upstream (#39); the reduction and compare counts recorded in the g40 and sample.test.g.20/26 test baselines change accordingly.

  • dparse() can now be called from several threads at once, one parser per thread. The first reduction path was a single process-wide static vector, so concurrent parses shared and reallocated it, segfaulting rxode2’s multi-threaded rxOptExpr() (nlmixr2/rxode2#1427); it now lives on the reducing call’s stack. Callers must resolve the dparser.h entry points on the main thread first, and syntax errors, ambiguity errors and R-level callbacks still call the R API, so only error-free parses without R callbacks are safe off the main thread. This is also the reduce_one() global-buffer-overflow / SEGV that R-hub’s clang-asan and clang-ubsan checks of babelmixr2 hit (#33). Only clang builds ever used the shared vector – vec_add(paths, new_VecZNode(paths, ...)) left the order of n++ and the call to the compiler, and gcc builds took a fresh malloc()ed path instead – which is why it showed up on clang platforms only. build_paths() now makes the call first, so every compiler takes the same path and the concurrent test exercises it on gcc too.

  • The grammar compiler’s hash callbacks (lex.c, write_tables.c) now have the exact hash_fn_t / cmp_fn_t types instead of being cast to them, so clang’s -fsanitize=function (part of -fsanitize=undefined) no longer reports “call to function through pointer to incorrect function type” from mkdparse().

  • A manually dispatched R-hub workflow (rhub::rhub_check()) runs the concurrent dparse() tests (NOT_CRAN=true), so sanitizer problems are caught here before they reach rxode2/babelmixr2 checks (#33). One test reproduces rxode2’s parallel common-subexpression parsing – a pool of threads parsing one statement per new parser – in dparser alone, and checks every parse tree against a serial run; it segfaults on 1.3.1-13.

  • buf_read() (and therefore sbuf_read()) is hardened in three ways without changing its int *len ABI:

    • Files larger than INT_MAX - 2 bytes are now rejected with -1 instead of silently truncating off_t -> int and producing a negative *len that the rest of the function then misused as a buffer size. Verified: a 3 GiB sparse file used to SIGSEGV in buf_read at (*buf)[real_size] = 0; after the fix it returns -1 cleanly.
    • read()’s ssize_t return is now stored in ssize_t, not size_t. On a read() error (returning -1), the previous code would index (*buf)[SIZE_MAX] — heap corruption. The new code frees the buffer and returns -1.
    • if (fd <= 0) -> if (fd < 0) so that fd 0 is treated as a valid descriptor (it is the stdin slot, returned by open() if stdin has been closed).
  • d_pass(D_Parser*, D_ParseNode*, int pass_number) now rejects negative pass_number values explicitly. Previously the bound check was upper-only (pass_number >= npasses), so a negative argument fell through to &p->t->passes[pass_number] and a subsequent pp->kind read landed before the passes[] array — typically a SIGSEGV, occasionally a silent garbage dispatch. The fix adds the matching lower bound; the function now calls Rf_error("bad pass number: %d") for any negative argument.

  • udparse() (and therefore the dparse() legacy wrapper) now returns NULL when called with a NULL buffer. Previously a NULL buf was forwarded into exhaustive_parse, where the scanner dereferenced it (*s inside white_space) and crashed. The new guard at the top of udparse short-circuits the call before any state is touched.

  • new_D_Parser() now rejects a negative sizeof_ParseNode_User. Previously a negative argument was stored verbatim, then the per- PNode allocation in make_PNode uint l = sizeof(PNode) - sizeof(d_voidp) + sizeof_user_parse_node underflowed to a small value, and the rest of make_PNode wrote past the resulting tiny buffer. valgrind on the pre-fix build reported 281 invalid writes of size 8, all rooted in make_PNode (parse.c:965). After the fix, new_D_Parser calls Rf_error with a clear message; valgrind reports 0 errors.

  • dparse_sexp() (the entry point used by every per-grammar dparse_<gram>() wrapper) now reads its input file through buf_read() instead of sbuf_read() + strlen(). Two bugs are fixed:

    • If the input file could not be opened, sbuf_read() returned NULL, and the subsequent strlen(NULL) was an immediate SIGSEGV. The new path raises Rf_error("could not read grammar input file: '<path>'").
    • For input >= 2 GiB, strlen() (which returns size_t) was narrowed to the int buf_len parameter of legacy dparse(), silently truncating to a negative value. The new path uses the length returned by buf_read() directly and forwards it to udparse() (full unsigned int range). Once buf_read() is itself promoted to size_t (separate fix), the path will safely handle inputs up to UINT_MAX.
  • Add udparse(D_Parser*, char *buf, unsigned int buf_len) as a memory-safe alternative to dparse(D_Parser*, char *buf, int buf_len). Existing callers of dparse still compile and link unchanged; the ABI of dparse is preserved. Internally, dparse now rejects negative buf_len (returns NULL) and forwards positive values to udparse, which holds the actual parser implementation.

    Previously, callers had to cast strlen(buf) to int, which silently truncated to a wrong (often negative) value when the input exceeded INT_MAX bytes; that negative length then propagated into p->end = buf + buf_len, making the parser read random memory before the buffer.

    New code should call udparse(p, buf, (unsigned int)strlen(buf)) to avoid the cast and safely accept inputs up to UINT_MAX bytes. Both functions are exported and registered via R_RegisterCCallable and re-declared in the consumer headers (src/dparse.h, src/dparser.h, src/dparser2.h, src/dparserPtr.h).

dparser 1.3.1-13

CRAN release: 2024-10-22

  • Changed Makevars header order, strict options so that dparser will compile on older versions of R (#19, #20, #22)

dparser 1.3.1-12

CRAN release: 2024-09-17

  • Changed language access to not use SET_TYPEOF (as required by CRAN)

  • Changed compilation to use strict headers, as requested by CRAN.

  • Changed interface so that functional changes will not cause segmentation faults when other libraries are not recompiled against this library (removed binary linkage). However changes to the dparser parsing C structures will likely cause a segmentation fault. Since the structures have not changed very much over time, but CRAN requests small changes to the functions frequently, this will probably be sufficient for most cases.

dparser 1.3.1-11

CRAN release: 2023-12-07

  • Changed gram.c to handle NULL strings without printing them (as requested by CRAN)

  • Changed util.c to avoid security warnings for error/warnings in R (as requested by CRAN)

  • Parsing errors during dparser() evaluation now give the line number for the error.

dparser 1.3.1-10

CRAN release: 2023-03-16

  • added dparser2.h that declares functions instead of defines them.

dparser 1.3.1-9

CRAN release: 2022-11-10

  • Initialized version string to zero length string to fix valgrind issues

  • Change flags to suppress false positive memory leaks (might be lost errors)

dparser 1.3.1-8

CRAN release: 2022-10-29

  • Removed all sprintf as indicated by some new Mac M1 checks for rxode2.

dparser 1.3.1-7

CRAN release: 2022-10-09

  • Fixed one remaining strict typing issue, as requested by CRAN.

dparser 1.3.1-6

CRAN release: 2022-10-05

  • Updated dparser header to have strict typing, as requested by CRAN.

dparser 1.3.1-4

CRAN release: 2021-04-07

  • Updated dparser to explicitly include R headers in the generated grammars (when requested), which should fix the fedora problem

dparser 1.3.1-3

CRAN release: 2021-04-06

  • Updated R dparser to use system() instead of do.call("system",...)
  • Changed default compile to show the stderr and stdout

dparser 1.3.1-2

CRAN release: 2021-04-03

  • Updated R dparser to use the more recent version of dparser

  • Applied custom changes to fix un-sanitized behavior

  • Added a NEWS.md file to track changes to the package.