1MAINTENANCE README FOR PCRE2
2============================
3
4The files in the "maint" directory of the PCRE2 source contain data, scripts,
5and programs that are used for the maintenance of PCRE2, but which do not form
6part of the PCRE2 distribution tarballs. This document describes these files
7and also contains some notes for maintainers. Its contents are:
8
9 Files in the maint directory
10 Updating to a new Unicode release
11 Preparing for a PCRE2 release
12 Making a PCRE2 release
13 Long-term ideas (wish list)
14
15
16Files in the maint directory
17============================
18
19GenerateUtt.py A Python script to generate part of the pcre2_tables.c file
20 that contains Unicode script names in a long string with
21 offsets, which is tedious to maintain by hand.
22
23ManyConfigTests A shell script that runs "configure, make, test" a number of
24 times with different configuration settings.
25
26MultiStage2.py A Python script that generates the file pcre2_ucd.c from six
27 Unicode data files, which are themselves downloaded from the
28 Unicode web site. Run this script in the "maint" directory.
29 The generated file is written to stdout. It contains the
30 tables for a 2-stage lookup of Unicode properties, along with
31 some auxiliary tables.
32
33pcre2_chartables.c.non-standard
34 This is a set of character tables that came from a Windows
35 system. It has characters greater than 128 that are set as
36 spaces, amongst other things. I kept it so that it can be
37 used for testing from time to time.
38
39README This file.
40
41Unicode.tables The files in this directory were downloaded from the Unicode
42 web site. They contain information about Unicode characters
43 and scripts. The ones used by the MultiStage2.py script are
44 CaseFolding.txt, DerivedGeneralCategory.txt, Scripts.txt,
45 ScriptExtensions.txt, GraphemeBreakProperty.txt, and
46 emoji-data.txt. I've kept UnicodeData.txt (which is no longer
47 used by the script) because it is useful occasionally for
48 manually looking up the details of certain characters.
49 However, note that character names in this file such as
50 "Arabic sign sanah" do NOT mean that the character is in a
51 particular script (in this case, Arabic). Scripts.txt and
52 ScriptExtensions.txt are where to look for script information.
53
54ucptest.c A short C program for testing the Unicode property macros
55 that do lookups in the pcre2_ucd.c data, mainly useful after
56 rebuilding the Unicode property table. Compile and run this in
57 the "maint" directory (see comments at its head). This program
58 can also be used to find characters with specific properties.
59
60ucptestdata A directory containing four files, testinput{1,2} and
61 testoutput{1,2}, for use in conjunction with the ucptest
62 program.
63
64utf8.c A short, freestanding C program for converting a Unicode code
65 point into a sequence of bytes in the UTF-8 encoding, and vice
66 versa. If its argument is a hex number such as 0x1234, it
67 outputs a list of the equivalent UTF-8 bytes. If its argument
68 is a sequence of concatenated UTF-8 bytes (e.g. e188b4) it
69 treats them as a UTF-8 character and outputs the equivalent
70 code point in hex. See comments at its head for details.
71
72
73Updating to a new Unicode release
74=================================
75
76When there is a new release of Unicode, the files in Unicode.tables must be
77refreshed from the web site. If the new version of Unicode adds new character
78scripts, the source file pcre2_ucp.h and both the MultiStage2.py and the
79GenerateUtt.py scripts must be edited to add the new names. I have been adding
80each new group at the end of the relevant list, with a comment. Note also that
81both the pcre2syntax.3 and pcre2pattern.3 man pages contain lists of Unicode
82script names.
83
84MultiStage2.py has two lists: the full names and the abbreviations that are
85found in the ScriptExtensions.txt file. A list of script names and their
86abbreviations can be found in the PropertyValueAliases.txt file on the
87Unicode web site. There is also a Wikipedia page that lists them, and notes the
88Unicode version in which they were introduced:
89
90https://en.wikipedia.org/wiki/Unicode_scripts#Table_of_Unicode_scripts
91
92Once the script name lists have been updated, MultiStage2.py can be run to
93generate a new version of pcre2_ucd.c, and GenerateUtt.py can be run to
94generate the tricky tables for inclusion in pcre2_tables.c (which must be
95hand-edited). If MultiStage2.py gives the error "ValueError: list.index(x): x
96not in list", the cause is usually a missing (or misspelt) name in one of the
97lists of scripts.
98
99The ucptest program can be compiled and used to check that the new tables in
100pcre2_ucd.c work properly, using the data files in ucptestdata to check a
101number of test characters. It used to be necessary to update the source
102ucptest.c whenever new Unicode scripts were added, but this is no longer
103required because that program now uses the lists in the PCRE2 source. However,
104adding a few tests for new scripts to the files in ucptestdata is a good idea.
105
106
107Preparing for a PCRE2 release
108=============================
109
110This section contains a checklist of things that I consult before building a
111distribution for a new release.
112
113. Ensure that the version number and version date are correct in configure.ac.
114
115. Update the library version numbers in configure.ac according to the rules
116 given below.
117
118. If new build options or new source files have been added, ensure that they
119 are added to the CMake files as well as to the autoconf files. The relevant
120 files are CMakeLists.txt and config-cmake.h.in. After making a release
121 tarball, test it out with CMake if there have been changes here.
122
123. Run ./autogen.sh to ensure everything is up-to-date.
124
125. Compile and test with many different config options, and combinations of
126 options. Also, test with valgrind by running "RunTest valgrind" and
127 "RunGrepTest valgrind" (which takes quite a long time). The script
128 maint/ManyConfigTests now encapsulates this testing. It runs tests with
129 different configurations, and it also runs some of them with valgrind, all of
130 which can take quite some time.
131
132. Run tests in both 32-bit and 64-bit environments if possible. I can no longer
133 run 32-bit tests.
134
135. Run tests with two or more different compilers (e.g. clang and gcc), and
136 make use of -fsanitize=address and friends where possible. For gcc,
137 -fsanitize=undefined -std=gnu99 picks up undefined behaviour at runtime, but
138 needs -fno-sanitize=shift to get rid of warnings for shifts of negative
139 numbers in the JIT compiler. For clang, -fsanitize=address,undefined,integer
140 can be used but -fno-sanitize=alignment,shift,unsigned-integer-overflow must
141 be added when compiling with JIT. Another useful clang option is
142 -fsanitize=signed-integer-overflow
143
144. Do a test build using CMake. Remove src/config.h first, lest it override the
145 version that CMake creates. Do NOT use parallel make.
146
147. Run perltest.sh on the test data for tests 1 and 4. The output should match
148 the PCRE2 test output, apart from the version identification at the start of
149 each test. Sometimes there are other differences in test 4 if PCRE2 and Perl
150 are using different Unicode releases. The other tests are not Perl-compatible
151 (they use various PCRE2-specific features or options).
152
153. It is possible to test with the emulated memmove() function by undefining
154 HAVE_MEMMOVE and HAVE_BCOPY in config.h, though I do not do this often.
155
156. Documentation: check AUTHORS, ChangeLog (check version and date), LICENCE,
157 NEWS (check version and date), NON-AUTOTOOLS-BUILD, and README. Many of these
158 won't need changing, but over the long term things do change.
159
160. I used to test new releases myself on a number of different operating
161 systems. For example, on Solaris it is helpful to test using Sun's cc
162 compiler as a change from gcc. Adding -xarch=v9 to the cc options does a
163 64-bit test, but it also needs -S 64 for pcre2test to increase the stack size
164 for test 2. Since I retired I can no longer do much of this, but instead I
165 rely on putting out release candidates for testing by the community.
166
167. The buildbots at http://buildfarm.opencsw.org/ do some automated testing
168 of PCRE2 and should be checked before putting out a release.
169
170
171Updating version info for libtool
172=================================
173
174This set of rules for updating library version information came from a web page
175whose URL I have forgotten. The version information consists of three parts:
176(current, revision, age).
177
1781. Start with version information of 0:0:0 for each libtool library.
179
1802. Update the version information only immediately before a public release of
181 your software. More frequent updates are unnecessary, and only guarantee
182 that the current interface number gets larger faster.
183
1843. If the library source code has changed at all since the last update, then
185 increment revision; c:r:a becomes c:r+1:a.
186
1874. If any interfaces have been added, removed, or changed since the last
188 update, increment current, and set revision to 0.
189
1905. If any interfaces have been added since the last public release, then
191 increment age.
192
1936. If any interfaces have been removed or changed since the last public
194 release, then set age to 0.
195
196The following explanation may help in understanding the above rules a bit
197better. Consider that there are three possible kinds of reaction from users to
198changes in a shared library:
199
2001. Programs using the previous version may use the new version as a drop-in
201 replacement, and programs using the new version can also work with the
202 previous one. In other words, no recompiling nor relinking is needed. In
203 this case, increment revision only, don't touch current or age.
204
2052. Programs using the previous version may use the new version as a drop-in
206 replacement, but programs using the new version may use APIs not present in
207 the previous one. In other words, a program linking against the new version
208 may fail if linked against the old version at run time. In this case, set
209 revision to 0, increment current and age.
210
2113. Programs may need to be changed, recompiled, relinked in order to use the
212 new version. Increment current, set revision and age to 0.
213
214
215Making a PCRE2 release
216======================
217
218Run PrepareRelease and commit the files that it changes. The first thing this
219script does is to run CheckMan on the man pages; if it finds any markup errors,
220it reports them and then aborts. Otherwise it removes trailing spaces from
221sources and refreshes the HTML documentation. Update the GitHub repository with
222"git push".
223
224Once PrepareRelease has run clean, run "make distcheck" to create the tarball
225and the zipball. I then sign these files. Double-check with "git status" that
226the repository is fully up-to-date, then create a new tag on GitHub. Upload the
227tarball, zipball, and the signatures as "assets" of the GitHub release.
228
229When the new release is out, don't forget to tell webmaster@pcre.org and the
230mailing list.
231
232
233Future ideas (wish list)
234========================
235
236This section records a list of ideas so that they do not get forgotten. They
237vary enormously in their usefulness and potential for implementation. Some are
238very sensible; some are rather wacky. Some have been on this list for many
239years.
240
241. Optimization
242
243 There are always ideas for new optimizations so as to speed up pattern
244 matching. Most of them try to save work by recognizing a non-match without
245 having to scan all the possibilities. These are some that I've recorded:
246
247 * /((A{0,5}){0,5}){0,5}(something complex)/ on a non-matching string is very
248 slow, though Perl is fast. Can we speed up somehow? Convert to {0,125}?
249 OTOH, this is pathological - the user could easily fix it.
250
251 * Turn ={4} into ==== ? (for speed). I once did an experiment, and it seems
252 to have little effect, and maybe makes things worse.
253
254 * "Ends with literal string" - note that a single character doesn't gain much
255 over the existing "required code unit" feature that just remembers one code
256 unit.
257
258 * Remember an initial string rather than just 1 code unit.
259
260 * A required code unit from alternatives - not just the last unit, but an
261 earlier one if common to all alternatives.
262
263 * Friedl contains other ideas.
264
265 * The code does not set initial code unit flags for Unicode property types
266 such as \p; I don't know how much benefit there would be for, for example,
267 setting the bits for 0-9 and all values >= xC0 (in 8-bit mode) when a
268 pattern starts with \p{N}.
269
270. If Perl gets to a consistent state over the settings of capturing sub-
271 patterns inside repeats, see if we can match it. One example of the
272 difference is the matching of /(main(O)?)+/ against mainOmain, where PCRE2
273 leaves $2 set. In Perl, it's unset. Changing this in PCRE2 will be very hard
274 because I think it needs much more state to be remembered.
275
276. A feature to suspend a match via a callout was once requested.
277
278. An option to convert results into character offsets and character lengths.
279
280. A (non-Unix) user wanted pcregrep options to (a) list a file name just once,
281 preceded by a blank line, instead of adding it to every matched line, and (b)
282 support --outputfile=name.
283
284. Define a union for the results from pcre2_pattern_info().
285
286. Provide a "random access to the subject" facility so that the way in which it
287 is stored is independent of PCRE2. For efficiency, it probably isn't possible
288 to switch this dynamically. It would have to be specified when PCRE2 was
289 compiled. PCRE2 would then call a function every time it wanted a character.
290
291. pcre2grep: add -rs for a sorted recurse. Having to store file names and sort
292 them will of course slow it down.
293
294. Someone suggested --disable-callout to save code space when callouts are
295 never wanted. This seems rather marginal.
296
297. A user suggested a parameter to limit the length of string matched, for
298 example if the parameter is N, the current match should fail if the matched
299 substring exceeds N. This could apply to both match functions. The value
300 could be a new field in the match context. Compare the offset_limit feature,
301 which limits where a match must start.
302
303. Write a function that generates random matching strings for a compiled
304 pattern.
305
306. Pcre2grep: an option to specify the output line separator, either as a string
307 or select from a fixed list. This is not straightforward, because at the
308 moment it outputs whatever is in the input file.
309
310. Improve the code for duplicate checking in pcre2_dfa_match(). An incomplete,
311 non-thread-safe patch showed that this can help performance for patterns
312 where there are many alternatives. However, a simple thread-safe
313 implementation that I tried made things worse in many simple cases, so this
314 is not an obviously good thing.
315
316. PCRE2 cannot at present distinguish between subpatterns with different names,
317 but the same number (created by the use of ?|). In order to do so, a way of
318 remembering *which* subpattern numbered n matched is needed. (*MARK) can
319 perhaps be used as a way round this problem. However, note that Perl does not
320 distinguish: like PCRE2, a name is just an alias for a number in Perl.
321
322. Instead of having #ifdef HAVE_CONFIG_H in each module, put #include
323 "something" and the the #ifdef appears only in one place, in "something".
324
325. Implement something like (?(R2+)... to check outer recursions.
326
327. If Perl ever supports the POSIX notation [[.something.]] PCRE2 should try
328 to follow.
329
330. A user wanted a way of ignoring all Unicode "mark" characters so that, for
331 example "a" followed by an accent would, together, match "a". This can only
332 be done clumsily at present by using a lookahead such as /(?=a)\X/, which
333 works for "combining" characters.
334
335. Perl supports [\N{x}-\N{y}] as a Unicode range, even in EBCDIC. PCRE2
336 supports \N{U+dd..} everywhere, but not in EBCDIC.
337
338. Unicode stuff from Perl:
339
340 \b{gcb} or \b{g} grapheme cluster boundary
341 \b{sb} sentence boundary
342 \b{wb} word boundary
343
344 See Unicode TR 29. The last two are very much aimed at natural language.
345
346. (?[...]) extended classes: big project.
347
348. Allow a callout to specify a number of characters to skip. This can be done
349 compatibly via an extra callout field.
350
351. Allow callouts to return *PRUNE, *COMMIT, *THEN, *SKIP, with and without
352 continuing (that is, with and without an implied *FAIL). A new option,
353 PCRE2_CALLOUT_EXTENDED say, would be needed. This is unlikely ever to be
354 implemented by JIT, so this could be an option for pcre2_match().
355
356. A limit on substitutions: a user suggested somehow finding a way of making
357 match_limit apply to the whole operation instead of each match separately.
358
359. Some #defines could be replaced with enums to improve robustness.
360
361. There was a request for an option for pcre2_match() to return the longest
362 match. This would mean searching for all possible matches, of course.
363
364. Perl's /a modifier sets Unicode, but restricts \d etc to ASCII characters,
365 which is the PCRE2 default for PCRE2_UTF (use PCRE2_UCP to change). However,
366 Perl also has /aa, which in addition, disables ASCII/non-ASCII caseless
367 matching. Perhaps we need a new option PCRE2_CASELESS_RESTRICT_ASCII. In
368 practice, this just means not using the ucd_caseless_sets[] table.
369
370. There is more that could be done to the oss-fuzz setup (needs some research).
371 A seed corpus could be built. I noted something about $LIB_FUZZING_ENGINE.
372 The test function could make use of get_substrings() to cover more code.
373
374. A neater way of handling recursion file names in pcre2grep, e.g. a single
375 buffer that can grow. See also GitHub issue #2 (recursion looping via
376 symlinks).
377
378. A user suggested that before/after parameters in pcre2grep could have
379 negative values, to list lines near to the matched line, but not necessarily
380 the line itself. For example, --before-context=-1 would list the line *after*
381 each matched line, without showing the matched line. The problem here is what
382 to do with matches that are close together. Maybe a simpler way would be a
383 flag to disable showing matched lines, only valid with either -A or -B?
384
385. There was a suggestiong for a pcre2grep colour default, or possibly a more
386 general PCRE2GREP_OPT, but only for some options - not file names or patterns.
387
388. Breaking loops that match an empty string: perhaps find a way of continuing
389 if *something* has changed, but this might mean remembering additional data.
390 "Something" could be a capture value, but then a list of previous values
391 would be needed to avoid a cycle of changes.
392
393. If a function could be written to find 3-character (or other length) fixed
394 strings, at least one of which must be present for a match, efficient
395 pre-searching of large datasets could be implemented.
396
397. If pcre2grep had --first-line (match only in the first line) it could be
398 efficiently used to find files "starting with xxx". What about --last-line?
399 There was also the suggestion of an option for pcre2grep to scan only the
400 start of a file. I am not keen - this is the job of "head".
401
402. A user requested a means of determining whether a failed match was failed by
403 the start-of-match optimizations, or by running the match engine. Easy enough
404 to define a bit in the match data, but all three matchers would need work.
405
406. Would inlining "simple" recursions provide a useful performance boost for the
407 interpreters? JIT already does some of this, but it may not be worth it for
408 the interpreters.
409
410. Redesign handling of class/nclass/xclass because the compile code logic is
411 currently very contorted and obscure. Also there was a request for a way of
412 re-defining \w (and therefore \W, \b, and \B). An in-pattern sequence such as
413 (?w=[...]) was suggested. Easiest way would be simply to inline the class,
414 with lookarounds for \b and \B. Ideally the setting should last till the end
415 of the group, which means remembering all previous settings; maybe a fixed
416 amount of stack would do - how deep would anyone want to nest these things?
417 See GitHub issue #13 for a compendium of character class issues.
418
419. Recognize the short script names. They are already listed in maint/
420 Multistage2.py because they are needed for scanning the script extensions
421 file.
422
423. Use script extensions for \p?
424
425. A user suggested something like --with-build-info to set a build information
426 string that could be retrieved by pcre2_config(). However, there's no
427 facility for a length limit in pcre2_config(), and what would be the
428 encoding?
429
430. Quantified groups with a fixed count currently operate by replicating the
431 group in the compiled bytecode. This may not really matter in these days of
432 gigabyte memory, but perhaps another implementation might be considered.
433 Needs coordination between the interpreters and JIT.
434
435. There are regular requests for variable-length lookbehinds.
436
437. See also any suggestions in the GitHub issues.
438
439Philip Hazel
440Email local part: Philip.Hazel
441Email domain: gmail.com
442Last updated: 26 August 2021
443