From bca9888a2c2d64af33fb0ba54da827f117cefe88 Mon Sep 17 00:00:00 2001 From: "Philip.Hazel" Date: Tue, 16 Jul 2019 15:50:09 +0000 Subject: [PATCH] Implemented pcre2_get_match_data_size(). --- ChangeLog | 4 ++- Makefile.am | 2 ++ doc/html/index.html | 3 ++ doc/html/pcre2_get_match_data_size.html | 39 +++++++++++++++++++++++++ doc/index.html.src | 3 ++ doc/pcre2_get_match_data_size.3 | 27 +++++++++++++++++ src/pcre2.h.in | 3 ++ src/pcre2_match_data.c | 15 +++++++++- src/pcre2test.c | 12 ++++---- 9 files changed, 101 insertions(+), 7 deletions(-) create mode 100644 doc/html/pcre2_get_match_data_size.html create mode 100644 doc/pcre2_get_match_data_size.3 diff --git a/ChangeLog b/ChangeLog index 562afc6..e9a3cc4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -88,13 +88,15 @@ otherwise), an atomic group, or a recursion. 17. Check for integer overflow when computing lookbehind lengths. Fixes Clusterfuzz issue 15636. -18. Implement non-atomic positive lookaround assertions. +18. Implemented non-atomic positive lookaround assertions. 19. If a lookbehind contained a lookahead that contained another lookbehind within it, the nested lookbehind was not correctly processed. For example, if /(?<=(?=(?<=a)))b/ was matched to "ab" it gave no match instead of matching "b". +20. Implemented pcre2_get_match_data_size(). + Version 10.33 16-April-2019 --------------------------- diff --git a/Makefile.am b/Makefile.am index b5e3635..942ac67 100644 --- a/Makefile.am +++ b/Makefile.am @@ -46,6 +46,7 @@ dist_html_DATA = \ doc/html/pcre2_general_context_free.html \ doc/html/pcre2_get_error_message.html \ doc/html/pcre2_get_mark.html \ + doc/html/pcre2_get_match_data_size.html \ doc/html/pcre2_get_ovector_count.html \ doc/html/pcre2_get_ovector_pointer.html \ doc/html/pcre2_get_startchar.html \ @@ -140,6 +141,7 @@ dist_man_MANS = \ doc/pcre2_general_context_free.3 \ doc/pcre2_get_error_message.3 \ doc/pcre2_get_mark.3 \ + doc/pcre2_get_match_data_size.3 \ doc/pcre2_get_ovector_count.3 \ doc/pcre2_get_ovector_pointer.3 \ doc/pcre2_get_startchar.3 \ diff --git a/doc/html/index.html b/doc/html/index.html index 82b43c3..556965a 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -146,6 +146,9 @@ in the library. pcre2_get_mark   Get a (*MARK) name +pcre2_get_match_data_size +   Get the size of a match data block + pcre2_get_ovector_count   Get the ovector count diff --git a/doc/html/pcre2_get_match_data_size.html b/doc/html/pcre2_get_match_data_size.html new file mode 100644 index 0000000..83a6893 --- /dev/null +++ b/doc/html/pcre2_get_match_data_size.html @@ -0,0 +1,39 @@ + + +pcre2_get_match_data_size specification + + +

pcre2_get_match_data_size man page

+

+Return to the PCRE2 index page. +

+

+This page is part of the PCRE2 HTML documentation. It was generated +automatically from the original man page. If there is any nonsense in it, +please consult the man page, in case the conversion went wrong. +
+
+SYNOPSIS +
+

+#include <pcre2.h> +

+

+PCRE2_SIZE pcre2_get_match_data_size(pcre2_match_data *match_data); +

+
+DESCRIPTION +
+

+This function returns the size, in bytes, of the match data block that is its +argument. +

+

+There is a complete description of the PCRE2 native API in the +pcre2api +page and a description of the POSIX API in the +pcre2posix +page. +

+Return to the PCRE2 index page. +

diff --git a/doc/index.html.src b/doc/index.html.src index 82b43c3..556965a 100644 --- a/doc/index.html.src +++ b/doc/index.html.src @@ -146,6 +146,9 @@ in the library. pcre2_get_mark   Get a (*MARK) name +pcre2_get_match_data_size +   Get the size of a match data block + pcre2_get_ovector_count   Get the ovector count diff --git a/doc/pcre2_get_match_data_size.3 b/doc/pcre2_get_match_data_size.3 new file mode 100644 index 0000000..4f9e272 --- /dev/null +++ b/doc/pcre2_get_match_data_size.3 @@ -0,0 +1,27 @@ +.TH PCRE2_GET_MATCH_DATA_SIZE 3 "16 July 2019" "PCRE2 10.34" +.SH NAME +PCRE2 - Perl-compatible regular expressions (revised API) +.SH SYNOPSIS +.rs +.sp +.B #include +.PP +.nf +.B PCRE2_SIZE pcre2_get_match_data_size(pcre2_match_data *\fImatch_data\fP); +.fi +. +.SH DESCRIPTION +.rs +.sp +This function returns the size, in bytes, of the match data block that is its +argument. +.P +There is a complete description of the PCRE2 native API in the +.\" HREF +\fBpcre2api\fP +.\" +page and a description of the POSIX API in the +.\" HREF +\fBpcre2posix\fP +.\" +page. diff --git a/src/pcre2.h.in b/src/pcre2.h.in index 7a06aee..1c48ae5 100644 --- a/src/pcre2.h.in +++ b/src/pcre2.h.in @@ -679,6 +679,8 @@ PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \ pcre2_match_data_free(pcre2_match_data *); \ PCRE2_EXP_DECL PCRE2_SPTR PCRE2_CALL_CONVENTION \ pcre2_get_mark(pcre2_match_data *); \ +PCRE2_EXP_DECL PCRE2_SIZE PCRE2_CALL_CONVENTION \ + pcre2_get_match_data_size(pcre2_match_data *); \ PCRE2_EXP_DECL uint32_t PCRE2_CALL_CONVENTION \ pcre2_get_ovector_count(pcre2_match_data *); \ PCRE2_EXP_DECL PCRE2_SIZE PCRE2_CALL_CONVENTION \ @@ -842,6 +844,7 @@ pcre2_compile are called by application code. */ #define pcre2_general_context_free PCRE2_SUFFIX(pcre2_general_context_free_) #define pcre2_get_error_message PCRE2_SUFFIX(pcre2_get_error_message_) #define pcre2_get_mark PCRE2_SUFFIX(pcre2_get_mark_) +#define pcre2_get_match_data_size PCRE2_SUFFIX(pcre2_get_match_data_size_) #define pcre2_get_ovector_pointer PCRE2_SUFFIX(pcre2_get_ovector_pointer_) #define pcre2_get_ovector_count PCRE2_SUFFIX(pcre2_get_ovector_count_) #define pcre2_get_startchar PCRE2_SUFFIX(pcre2_get_startchar_) diff --git a/src/pcre2_match_data.c b/src/pcre2_match_data.c index ccc5f67..53e4698 100644 --- a/src/pcre2_match_data.c +++ b/src/pcre2_match_data.c @@ -7,7 +7,7 @@ and semantics are as close as possible to those of the Perl 5 language. Written by Philip Hazel Original API code Copyright (c) 1997-2012 University of Cambridge - New API code Copyright (c) 2016-2018 University of Cambridge + New API code Copyright (c) 2016-2019 University of Cambridge ----------------------------------------------------------------------------- Redistribution and use in source and binary forms, with or without @@ -150,4 +150,17 @@ pcre2_get_startchar(pcre2_match_data *match_data) return match_data->startchar; } + + +/************************************************* +* Get size of match data block * +*************************************************/ + +PCRE2_EXP_DEFN PCRE2_SIZE PCRE2_CALL_CONVENTION +pcre2_get_match_data_size(pcre2_match_data *match_data) +{ +return offsetof(pcre2_match_data, ovector) + + 2 * (match_data->oveccount) * sizeof(PCRE2_SIZE); +} + /* End of pcre2_match_data.c */ diff --git a/src/pcre2test.c b/src/pcre2test.c index 838506b..f4e831b 100644 --- a/src/pcre2test.c +++ b/src/pcre2test.c @@ -3269,7 +3269,7 @@ return 0; -/* This function is no longer used. Keep it around for a while, just in case it +/* This function is no longer used. Keep it around for a while, just in case it needs to be re-instated. */ #ifdef NEVERNEVERNEVER @@ -8662,7 +8662,7 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0) { fprintf(stderr, "** Argument for %s must not be zero\n", arg); exit(1); - } + } if (U32OVERFLOW(uli)) { fprintf(stderr, "** Argument for %s is too big\n", arg); @@ -8820,8 +8820,8 @@ least 128 code units, because it is used for retrieving error messages. */ } /* End of -error handling */ /* Initialize things that cannot be done until we know which test mode we are -running in. Exercise the general context copying function, which is not -otherwise used. */ +running in. Exercise the general context copying and match data size functions, +which are not otherwise used. */ code_unit_size = test_mode/8; max_oveccount = DEFAULT_OVECCOUNT; @@ -8843,7 +8843,9 @@ max_oveccount = DEFAULT_OVECCOUNT; (void)G(pcre2_set_compile_extra_options_,BITS)(G(pat_context,BITS), 0); \ (void)G(pcre2_set_max_pattern_length_,BITS)(G(pat_context,BITS), 0); \ (void)G(pcre2_set_offset_limit_,BITS)(G(dat_context,BITS), 0); \ - (void)G(pcre2_set_recursion_memory_management_,BITS)(G(dat_context,BITS), my_malloc, my_free, NULL) + (void)G(pcre2_set_recursion_memory_management_,BITS)(G(dat_context,BITS), my_malloc, my_free, NULL); \ + (void)G(pcre2_get_match_data_size_,BITS)(G(match_data,BITS)) + /* Call the appropriate functions for the current mode, and exercise some functions that are not otherwise called. */