From 547253094374ce89bfe43fe4ca6be878d972c05b Mon Sep 17 00:00:00 2001
From: ph10
The second argument points to a general context, for custom memory management, -or is NULL for system memory management. The result of the function is NULL if -the memory for the block could not be obtained. +or is NULL to use the same memory allocator as was used for the compiled +pattern. The result of the function is NULL if the memory for the block could +not be obtained.
There is a complete description of the PCRE2 native API in the diff --git a/doc/html/pcre2api.html b/doc/html/pcre2api.html index 10e458c..94206c7 100644 --- a/doc/html/pcre2api.html +++ b/doc/html/pcre2api.html @@ -1709,14 +1709,18 @@ substrings. A minimum of at least 1 pair is imposed by matched string.
-For pcre2_match_data_create_from_pattern(), the first argument is a -pointer to a compiled pattern. In this case the ovector is created to be -exactly the right size to hold all the substrings a pattern might capture. +The second argument of pcre2_match_data_create() is a pointer to a +general context, which can specify custom memory management for obtaining the +memory for the match data block. If you are not using custom memory management, +pass NULL, which causes malloc() to be used.
-The second argument of both these functions is a pointer to a general context, -which can specify custom memory management for obtaining the memory for the -match data block. If you are not using custom memory management, pass NULL. +For pcre2_match_data_create_from_pattern(), the first argument is a +pointer to a compiled pattern. The ovector is created to be exactly the right +size to hold all the substrings a pattern might capture. The second argument is +again a pointer to a general context, but in this case if NULL is passed, the +memory is obtained using the same allocator that was used for the compiled +pattern (custom or default).
A match data block can be used many times, with the same or different compiled diff --git a/doc/pcre2.txt b/doc/pcre2.txt index 28b2504..7537005 100644 --- a/doc/pcre2.txt +++ b/doc/pcre2.txt @@ -1728,15 +1728,17 @@ THE MATCH DATA BLOCK pcre2_match_data_create(), so it is always possible to return the over- all matched string. - For pcre2_match_data_create_from_pattern(), the first argument is a - pointer to a compiled pattern. In this case the ovector is created to - be exactly the right size to hold all the substrings a pattern might - capture. + The second argument of pcre2_match_data_create() is a pointer to a gen- + eral context, which can specify custom memory management for obtaining + the memory for the match data block. If you are not using custom memory + management, pass NULL, which causes malloc() to be used. - The second argument of both these functions is a pointer to a general - context, which can specify custom memory management for obtaining the - memory for the match data block. If you are not using custom memory - management, pass NULL. + For pcre2_match_data_create_from_pattern(), the first argument is a + pointer to a compiled pattern. The ovector is created to be exactly the + right size to hold all the substrings a pattern might capture. The sec- + ond argument is again a pointer to a general context, but in this case + if NULL is passed, the memory is obtained using the same allocator that + was used for the compiled pattern (custom or default). A match data block can be used many times, with the same or different compiled patterns. When it is no longer needed, it should be freed by diff --git a/doc/pcre2_match_data_create_from_pattern.3 b/doc/pcre2_match_data_create_from_pattern.3 index 8f64b66..83267d6 100644 --- a/doc/pcre2_match_data_create_from_pattern.3 +++ b/doc/pcre2_match_data_create_from_pattern.3 @@ -22,8 +22,9 @@ pairs of offsets that are required in the match data block. These form the the matched string and any captured substrings. .P The second argument points to a general context, for custom memory management, -or is NULL for system memory management. The result of the function is NULL if -the memory for the block could not be obtained. +or is NULL to use the same memory allocator as was used for the compiled +pattern. The result of the function is NULL if the memory for the block could +not be obtained. .P There is a complete description of the PCRE2 native API in the .\" HREF diff --git a/doc/pcre2api.3 b/doc/pcre2api.3 index 4b4c5d6..b0cfc77 100644 --- a/doc/pcre2api.3 +++ b/doc/pcre2api.3 @@ -1700,13 +1700,17 @@ substrings. A minimum of at least 1 pair is imposed by \fBpcre2_match_data_create()\fP, so it is always possible to return the overall matched string. .P -For \fBpcre2_match_data_create_from_pattern()\fP, the first argument is a -pointer to a compiled pattern. In this case the ovector is created to be -exactly the right size to hold all the substrings a pattern might capture. +The second argument of \fBpcre2_match_data_create()\fP is a pointer to a +general context, which can specify custom memory management for obtaining the +memory for the match data block. If you are not using custom memory management, +pass NULL, which causes \fBmalloc()\fP to be used. .P -The second argument of both these functions is a pointer to a general context, -which can specify custom memory management for obtaining the memory for the -match data block. If you are not using custom memory management, pass NULL. +For \fBpcre2_match_data_create_from_pattern()\fP, the first argument is a +pointer to a compiled pattern. The ovector is created to be exactly the right +size to hold all the substrings a pattern might capture. The second argument is +again a pointer to a general context, but in this case if NULL is passed, the +memory is obtained using the same allocator that was used for the compiled +pattern (custom or default). .P A match data block can be used many times, with the same or different compiled patterns. When it is no longer needed, it should be freed by calling diff --git a/src/pcre2_match_data.c b/src/pcre2_match_data.c index 2182326..1f2fb15 100644 --- a/src/pcre2_match_data.c +++ b/src/pcre2_match_data.c @@ -72,10 +72,13 @@ return yield; * Create a match data block using pattern data * *************************************************/ +/* If no context is supplied, use the memory allocator from the code. */ + PCRE2_EXP_DEFN pcre2_match_data * PCRE2_CALL_CONVENTION pcre2_match_data_create_from_pattern(const pcre2_code *code, pcre2_general_context *gcontext) { +if (gcontext == NULL) gcontext = (pcre2_general_context *)code; return pcre2_match_data_create(((pcre2_real_code *)code)->top_bracket + 1, gcontext); }