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