Name Date Size #Lines LOC

..--

Unicode.tables/H25-Apr-2025-66,57065,043

ucptestdata/H25-Apr-2025-786752

GenerateCommon.pyH A D25-Apr-202511.5 KiB357236

GenerateTest26.pyH A D25-Apr-20255.4 KiB189137

GenerateUcd.pyH A D25-Apr-202533.7 KiB947437

GenerateUcpHeader.pyH A D25-Apr-20253.1 KiB9960

GenerateUcpTables.pyH A D25-Apr-20257.1 KiB20494

ManyConfigTestsH A D25-Apr-202514.4 KiB480348

READMEH A D25-Apr-202521.4 KiB465349

pcre2_chartables.c.non-standardH A D25-Apr-20253.6 KiB148143

ucptest.cH A D25-Apr-202527 KiB1,028797

utf8.cH A D25-Apr-20258.4 KiB348204

README

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.
160  For clang, -fsanitize=address,undefined,integer can be used but
161  -fno-sanitize=unsigned-integer-overflow must be added when compiling with JIT.
162  Another useful clang option is -fsanitize=signed-integer-overflow
163
164. Do a test build using CMake. Remove src/config.h first, lest it override the
165  version that CMake creates. Also do a CMake unity build to check that it
166  still works: [c]cmake -DCMAKE_UNITY_BUILD=ON sets up a unity build.
167
168. Run perltest.sh on the test data for tests 1 and 4. The output should match
169  the PCRE2 test output, apart from the version identification at the start of
170  each test. Sometimes there are other differences in test 4 if PCRE2 and Perl
171  are using different Unicode releases. The other tests are not Perl-compatible
172  (they use various PCRE2-specific features or options).
173
174. It is possible to test with the emulated memmove() function by undefining
175  HAVE_MEMMOVE and HAVE_BCOPY in config.h, though I do not do this often.
176
177. Documentation: check AUTHORS, ChangeLog (check version and date), LICENCE,
178  NEWS (check version and date), NON-AUTOTOOLS-BUILD, and README. Many of these
179  won't need changing, but over the long term things do change.
180
181. I used to test new releases myself on a number of different operating
182  systems. For example, on Solaris it is helpful to test using Sun's cc
183  compiler as a change from gcc. Adding -xarch=v9 to the cc options does a
184  64-bit test, but it also needs -S 64 for pcre2test to increase the stack size
185  for test 2. Since I retired I can no longer do much of this. There are
186  automated tests under Ubuntu, Alpine, and Windows that are now set up as
187  GitHub actions. Check that they are running clean.
188
189. The buildbots at http://buildfarm.opencsw.org/ do some automated testing
190  of PCRE2 and should also be checked before putting out a release.
191
192
193Updating version info for libtool
194=================================
195
196This set of rules for updating library version information came from a web page
197whose URL I have forgotten. The version information consists of three parts:
198(current, revision, age).
199
2001. Start with version information of 0:0:0 for each libtool library.
201
2022. Update the version information only immediately before a public release of
203   your software. More frequent updates are unnecessary, and only guarantee
204   that the current interface number gets larger faster.
205
2063. If the library source code has changed at all since the last update, then
207   increment revision; c:r:a becomes c:r+1:a.
208
2094. If any interfaces have been added, removed, or changed since the last
210   update, increment current, and set revision to 0.
211
2125. If any interfaces have been added since the last public release, then
213   increment age.
214
2156. If any interfaces have been removed or changed since the last public
216   release, then set age to 0.
217
218The following explanation may help in understanding the above rules a bit
219better. Consider that there are three possible kinds of reaction from users to
220changes in a shared library:
221
2221. Programs using the previous version may use the new version as a drop-in
223   replacement, and programs using the new version can also work with the
224   previous one. In other words, no recompiling nor relinking is needed. In
225   this case, increment revision only, don't touch current or age.
226
2272. Programs using the previous version may use the new version as a drop-in
228   replacement, but programs using the new version may use APIs not present in
229   the previous one. In other words, a program linking against the new version
230   may fail if linked against the old version at run time. In this case, set
231   revision to 0, increment current and age.
232
2333. Programs may need to be changed, recompiled, relinked in order to use the
234   new version. Increment current, set revision and age to 0.
235
236
237Making a PCRE2 release
238======================
239
240Run PrepareRelease and commit the files that it changes. The first thing this
241script does is to run CheckMan on the man pages; if it finds any markup errors,
242it reports them and then aborts. Otherwise it removes trailing spaces from
243sources and refreshes the HTML documentation. Update the GitHub repository with
244"git push".
245
246Once PrepareRelease has run clean, run "make distcheck" to create the tarballs
247and the zipball. I then sign these files. Double-check with "git status" that
248the repository is fully up-to-date, then create a new tag and a release on
249GitHub. Upload the tarballs, zipball, and the signatures as "assets" of the
250GitHub release.
251
252When the new release is out, don't forget to tell [email protected] and the
253mailing list.
254
255
256Future ideas (wish list)
257========================
258
259This section records a list of ideas so that they do not get forgotten. They
260vary enormously in their usefulness and potential for implementation. Some are
261very sensible; some are rather wacky. Some have been on this list for many
262years.
263
264. Optimization
265
266  There are always ideas for new optimizations so as to speed up pattern
267  matching. Most of them try to save work by recognizing a non-match without
268  having to scan all the possibilities. These are some that I've recorded:
269
270  * /((A{0,5}){0,5}){0,5}(something complex)/ on a non-matching string is very
271    slow, though Perl is fast. Can we speed up somehow? Convert to {0,125}?
272    OTOH, this is pathological - the user could easily fix it.
273
274  * Turn ={4} into ==== ? (for speed). I once did an experiment, and it seems
275    to have little effect, and maybe makes things worse.
276
277  * "Ends with literal string" - note that a single character doesn't gain much
278    over the existing "required code unit" feature that just remembers one code
279    unit.
280
281  * Remember an initial string rather than just 1 code unit.
282
283  * A required code unit from alternatives - not just the last unit, but an
284    earlier one if common to all alternatives.
285
286  * Friedl contains other ideas.
287
288  * The code does not set initial code unit flags for Unicode property types
289    such as \p; I don't know how much benefit there would be for, for example,
290    setting the bits for 0-9 and all values >= xC0 (in 8-bit mode) when a
291    pattern starts with \p{N}.
292
293. If Perl gets to a consistent state over the settings of capturing sub-
294  patterns inside repeats, see if we can match it. One example of the
295  difference is the matching of /(main(O)?)+/ against mainOmain, where PCRE2
296  leaves $2 set. In Perl, it's unset. Changing this in PCRE2 will be very hard
297  because I think it needs much more state to be remembered.
298
299. A feature to suspend a match via a callout was once requested.
300
301. An option to convert results into character offsets and character lengths.
302
303. A (non-Unix) user wanted pcregrep options to (a) list a file name just once,
304  preceded by a blank line, instead of adding it to every matched line, and (b)
305  support --outputfile=name.
306
307. Define a union for the results from pcre2_pattern_info().
308
309. Provide a "random access to the subject" facility so that the way in which it
310  is stored is independent of PCRE2. For efficiency, it probably isn't possible
311  to switch this dynamically. It would have to be specified when PCRE2 was
312  compiled. PCRE2 would then call a function every time it wanted a character.
313
314. pcre2grep: add -rs for a sorted recurse. Having to store file names and sort
315  them will of course slow it down.
316
317. Someone suggested --disable-callout to save code space when callouts are
318  never wanted. This seems rather marginal.
319
320. A user suggested a parameter to limit the length of string matched, for
321  example if the parameter is N, the current match should fail if the matched
322  substring exceeds N. This could apply to both match functions. The value
323  could be a new field in the match context. Compare the offset_limit feature,
324  which limits where a match must start.
325
326. Write a function that generates random matching strings for a compiled
327  pattern.
328
329. Pcre2grep: an option to specify the output line separator, either as a string
330  or select from a fixed list. This is not straightforward, because at the
331  moment it outputs whatever is in the input file.
332
333. Improve the code for duplicate checking in pcre2_dfa_match(). An incomplete,
334  non-thread-safe patch showed that this can help performance for patterns
335  where there are many alternatives. However, a simple thread-safe
336  implementation that I tried made things worse in many simple cases, so this
337  is not an obviously good thing.
338
339. PCRE2 cannot at present distinguish between subpatterns with different names,
340  but the same number (created by the use of ?|). In order to do so, a way of
341  remembering *which* subpattern numbered n matched is needed. (*MARK) can
342  perhaps be used as a way round this problem. However, note that Perl does not
343  distinguish: like PCRE2, a name is just an alias for a number in Perl.
344
345. Instead of having #ifdef HAVE_CONFIG_H in each module, put #include
346  "something" and the the #ifdef appears only in one place, in "something".
347
348. Implement something like (?(R2+)... to check outer recursions.
349
350. If Perl ever supports the POSIX notation [[.something.]] PCRE2 should try
351  to follow.
352
353. A user wanted a way of ignoring all Unicode "mark" characters so that, for
354  example "a" followed by an accent would, together, match "a". This can only
355  be done clumsily at present by using a lookahead such as /(?=a)\X/, which
356  works for "combining" characters.
357
358. Perl supports [\N{x}-\N{y}] as a Unicode range, even in EBCDIC. PCRE2
359  supports \N{U+dd..} everywhere, but not in EBCDIC.
360
361. Unicode stuff from Perl:
362
363    \b{gcb} or \b{g}    grapheme cluster boundary
364    \b{sb}              sentence boundary
365    \b{wb}              word boundary
366
367  See Unicode TR 29. The last two are very much aimed at natural language.
368
369. Allow a callout to specify a number of characters to skip. This can be done
370  compatibly via an extra callout field.
371
372. Allow callouts to return *PRUNE, *COMMIT, *THEN, *SKIP, with and without
373  continuing (that is, with and without an implied *FAIL). A new option,
374  PCRE2_CALLOUT_EXTENDED say, would be needed. This is unlikely ever to be
375  implemented by JIT, so this could be an option for pcre2_match().
376
377. A limit on substitutions: a user suggested somehow finding a way of making
378  match_limit apply to the whole operation instead of each match separately.
379
380. Some #defines could be replaced with enums to improve robustness.
381
382. There was a request for an option for pcre2_match() to return the longest
383  match. This would mean searching for all possible matches, of course.
384
385. Perl's /a modifier sets Unicode, but restricts \d etc to ASCII characters,
386  which is the PCRE2 default for PCRE2_UTF (use PCRE2_UCP to change). However,
387  Perl also has /aa, which in addition, disables ASCII/non-ASCII caseless
388  matching. Perhaps we need a new option PCRE2_CASELESS_RESTRICT_ASCII. In
389  practice, this just means not using the ucd_caseless_sets[] table.
390
391. There is more that could be done to the oss-fuzz setup (needs some research).
392  A seed corpus could be built. I noted something about $LIB_FUZZING_ENGINE.
393  The test function could make use of get_substrings() to cover more code.
394
395. A neater way of handling recursion file names in pcre2grep, e.g. a single
396  buffer that can grow. See also GitHub issue #2 (recursion looping via
397  symlinks).
398
399. A user suggested that before/after parameters in pcre2grep could have
400  negative values, to list lines near to the matched line, but not necessarily
401  the line itself. For example, --before-context=-1 would list the line *after*
402  each matched line, without showing the matched line. The problem here is what
403  to do with matches that are close together. Maybe a simpler way would be a
404  flag to disable showing matched lines, only valid with either -A or -B?
405
406. There was a suggestiong for a pcre2grep colour default, or possibly a more
407  general PCRE2GREP_OPT, but only for some options - not file names or patterns.
408
409. Breaking loops that match an empty string: perhaps find a way of continuing
410  if *something* has changed, but this might mean remembering additional data.
411  "Something" could be a capture value, but then a list of previous values
412  would be needed to avoid a cycle of changes.
413
414. If a function could be written to find 3-character (or other length) fixed
415  strings, at least one of which must be present for a match, efficient
416  pre-searching of large datasets could be implemented.
417
418. If pcre2grep had --first-line (match only in the first line) it could be
419  efficiently used to find files "starting with xxx". What about --last-line?
420  There was also the suggestion of an option for pcre2grep to scan only the
421  start of a file. I am not keen - this is the job of "head".
422
423. A user requested a means of determining whether a failed match was failed by
424  the start-of-match optimizations, or by running the match engine. Easy enough
425  to define a bit in the match data, but all three matchers would need work.
426
427. Would inlining "simple" recursions provide a useful performance boost for the
428  interpreters? JIT already does some of this, but it may not be worth it for
429  the interpreters.
430
431. Redesign handling of class/nclass/xclass because the compile code logic is
432  currently very contorted and obscure. Also there was a request for a way of
433  re-defining \w (and therefore \W, \b, and \B). An in-pattern sequence such as
434  (?w=[...]) was suggested. Easiest way would be simply to inline the class,
435  with lookarounds for \b and \B. Ideally the setting should last till the end
436  of the group, which means remembering all previous settings; maybe a fixed
437  amount of stack would do - how deep would anyone want to nest these things?
438  See GitHub issue #13 for a compendium of character class issues, including
439  (?[...]) extended classes.
440
441. A user suggested something like --with-build-info to set a build information
442  string that could be retrieved by pcre2_config(). However, there's no
443  facility for a length limit in pcre2_config(), and what would be the
444  encoding?
445
446. Quantified groups with a fixed count currently operate by replicating the
447  group in the compiled bytecode. This may not really matter in these days of
448  gigabyte memory, but perhaps another implementation might be considered.
449  Needs coordination between the interpreters and JIT.
450
451. The POSIX interface is no longer POSIX compatible, because regoff_t is still
452  defined as an int.
453
454. The POSIX interface is not thread safe because it modifies a pcre2_match
455  inside its regex_t while doing matching. A thread safe version that uses
456  a thread local object has been proposed but it will require that the code
457  requires at least C11 compatibility.
458
459. See also any suggestions in the GitHub issues.
460
461Philip Hazel
462Email local part: Philip.Hazel
463Email domain: gmail.com
464Last updated: 30 November 2023
465