Use allocator from code for pcre2_match_data_create_from_pattern if NULL

passed.
This commit is contained in:
Philip.Hazel 2014-11-28 13:23:40 +00:00
parent 161cd17ba0
commit caf78231ec
6 changed files with 39 additions and 24 deletions

View File

@ -35,8 +35,9 @@ the matched string and any captured substrings.
</P>
<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>
<P>
There is a complete description of the PCRE2 native API in the

View File

@ -1709,14 +1709,18 @@ substrings. A minimum of at least 1 pair is imposed by
matched string.
</P>
<P>
For <b>pcre2_match_data_create_from_pattern()</b>, 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 <b>pcre2_match_data_create()</b> 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 <b>malloc()</b> to be used.
</P>
<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 <b>pcre2_match_data_create_from_pattern()</b>, 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>
<P>
A match data block can be used many times, with the same or different compiled

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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);
}