Changelog
Source:NEWS.md
dparser 1.3.1-15
The installed
parse.hnow setsUSE_FREELISTSandTRACK_PNODES, the switches the library is built with; before, onlysrc/Makevarsset them.TRACK_PNODESadds fields toPNodeandParser, so a package that includedparse.hthroughLinkingToand readPNodefields 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()andupdate_additional_D_Sym()now copy the whole caller-sized symbol into the update. They allocatedsizeof_D_Symbytes but copied onlysizeof(D_Sym), so a caller using a larger user symbol (a biggerD_UserSym, or a struct that starts with aD_Sym) lost its extra data and read uninitialised memory. Ported from upstream jplevyak/dparser@2b19d1a (#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-aas an empty range from its 255 placeholder, so the class matched neither-nora. Ported from upstream jplevyak/dparser@8a27e39 (#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), andbuild_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 jplevyak/dparser@88ed194 (#50). quadratic in the number of states). The generated parser tables are byte-for-byte the same. Ported from upstream jplevyak/dparser@88ed194 (#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 laterfind_D_Sym()returned NULL), the read could run past the end of the vector, and the vector leaked. Ported from upstream jplevyak/dparser@f3d5f1e (#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 jplevyak/dparser@ae30c16.
check_child()also rejects nesting two non-associative (ASSOC_NO) operators of equal priority, andgram.hgainsIS_NO_ASSOC(); the grammar reader does not assignASSOC_NOyet, 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
PNodenow records its creation order (serial) and that breaks the remaining ties, as in upstream jplevyak/dparser@ef9b0d3. The internalPNodeandParserstructs each gain one field, sosizeof(PNode)changes; the publicD_ParseNodeand thedparser.hentry points are unchanged, and grammar actions get the node offset at run time, so compiled parsers keep working. Code outside dparser that usesDPN_TO_PN()orPNodedirectly must be rebuilt (#47).current_D_Sym(),update_D_Sym()andupdate_additional_D_Sym()(and soUPDATE_D_SYM()) now return NULL when given a NULL symbol, such as the result of a failedfind_D_Sym(), instead of crashing;update_D_Sym()then leaves the scope unchanged. Ported from upstream jplevyak/dparser@f3d5f1e (#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), sobars ::= '||'+;rejected||||,slash ::= '/'+;rejected/, andx ::= 'a|b';matchedaorbinstead ofa|b. Ported from upstream jplevyak/dparser@51a4d04 (#43).Compiling a grammar with a regex production (
::=) whose quoted strings are mostly regex metacharacters, such asx ::= '||||||||';orx ::= '++++++++';, no longer overflows a heap buffer (with_FORTIFY_SOURCEit 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 althoughd_version()writes about 46 characters, andd_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 makesmkdparse()/dparse()loop forever while building the scanner. The range counter inbuild_regex_nfa()was auint8that wrapped from 255 back to 0; it is now anint(#42, upstream jplevyak/dparser 6d494a3).Generated parser tables no longer contain raw bytes 0x80-0xff on macOS.
escape_string()usedisprint(), 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 anddparse()failed ingsub()with “‘replacement’ is invalid”; such bytes are now always written as\xNNescapes (#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]"/ino longer matchesAand"[a-c]+"/imatchesaBc(#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_rightpriorities) now give the same tree every time.get_unshared_priorities()broke ties between equal-height subtrees by comparingPNodeheap 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 jplevyak/dparser@c0eea8b (#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 asX '->' Y $right 5andX '->' Y '<>' Y $right 6rejected valid input. This ports upstream jplevyak/dparser@5542d84 (#39); the reduction and compare counts recorded in theg40andsample.test.g.20/26test 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-threadedrxOptExpr()(nlmixr2/rxode2#1427); it now lives on the reducing call’s stack. Callers must resolve thedparser.hentry 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 thereduce_one()global-buffer-overflow / SEGV that R-hub’sclang-asanandclang-ubsanchecks of babelmixr2 hit (#33). Only clang builds ever used the shared vector –vec_add(paths, new_VecZNode(paths, ...))left the order ofn++and the call to the compiler, and gcc builds took a freshmalloc()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 exacthash_fn_t/cmp_fn_ttypes 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” frommkdparse().A manually dispatched R-hub workflow (
rhub::rhub_check()) runs the concurrentdparse()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 thereforesbuf_read()) is hardened in three ways without changing itsint *lenABI:- Files larger than
INT_MAX - 2bytes are now rejected with-1instead of silently truncatingoff_t -> intand producing a negative*lenthat the rest of the function then misused as a buffer size. Verified: a 3 GiB sparse file used to SIGSEGV inbuf_readat(*buf)[real_size] = 0; after the fix it returns-1cleanly. -
read()’sssize_treturn is now stored inssize_t, notsize_t. On aread()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 fd0is treated as a valid descriptor (it is the stdin slot, returned byopen()if stdin has been closed).
- Files larger than
d_pass(D_Parser*, D_ParseNode*, int pass_number)now rejects negativepass_numbervalues 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 subsequentpp->kindread landed before thepasses[]array — typically a SIGSEGV, occasionally a silent garbage dispatch. The fix adds the matching lower bound; the function now callsRf_error("bad pass number: %d")for any negative argument.udparse()(and therefore thedparse()legacy wrapper) now returnsNULLwhen called with aNULLbuffer. Previously aNULLbufwas forwarded intoexhaustive_parse, where the scanner dereferenced it (*sinsidewhite_space) and crashed. The new guard at the top ofudparseshort-circuits the call before any state is touched.new_D_Parser()now rejects a negativesizeof_ParseNode_User. Previously a negative argument was stored verbatim, then the per- PNode allocation inmake_PNodeuint l = sizeof(PNode) - sizeof(d_voidp) + sizeof_user_parse_nodeunderflowed to a small value, and the rest ofmake_PNodewrote past the resulting tiny buffer. valgrind on the pre-fix build reported 281 invalid writes of size 8, all rooted inmake_PNode (parse.c:965). After the fix,new_D_ParsercallsRf_errorwith a clear message; valgrind reports 0 errors.-
dparse_sexp()(the entry point used by every per-grammardparse_<gram>()wrapper) now reads its input file throughbuf_read()instead ofsbuf_read() + strlen(). Two bugs are fixed:- If the input file could not be opened,
sbuf_read()returnedNULL, and the subsequentstrlen(NULL)was an immediate SIGSEGV. The new path raisesRf_error("could not read grammar input file: '<path>'"). - For input >= 2 GiB,
strlen()(which returnssize_t) was narrowed to theint buf_lenparameter of legacydparse(), silently truncating to a negative value. The new path uses the length returned bybuf_read()directly and forwards it toudparse()(fullunsigned intrange). Oncebuf_read()is itself promoted tosize_t(separate fix), the path will safely handle inputs up toUINT_MAX.
- If the input file could not be opened,
-
Add
udparse(D_Parser*, char *buf, unsigned int buf_len)as a memory-safe alternative todparse(D_Parser*, char *buf, int buf_len). Existing callers ofdparsestill compile and link unchanged; the ABI ofdparseis preserved. Internally,dparsenow rejects negativebuf_len(returnsNULL) and forwards positive values toudparse, which holds the actual parser implementation.Previously, callers had to cast
strlen(buf)toint, which silently truncated to a wrong (often negative) value when the input exceededINT_MAXbytes; that negative length then propagated intop->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 toUINT_MAXbytes. Both functions are exported and registered viaR_RegisterCCallableand re-declared in the consumer headers (src/dparse.h,src/dparser.h,src/dparser2.h,src/dparserPtr.h).
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.cto handle NULL strings without printing them (as requested by CRAN)Changed
util.cto 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.hthat 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
sprintfas indicated by some new Mac M1 checks forrxode2.
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 ofdo.call("system",...) - Changed default compile to show the
stderrandstdout