Re: [pcre-dev] PCRE2: Unnecessary substring number checks?

Página superior
Eliminar este mensaje
Autor: Ralf Junker
Fecha:  
A: pcre-dev
Asunto: Re: [pcre-dev] PCRE2: Unnecessary substring number checks?
On 10.12.2014 18:53, ph10@??? wrote:

>> pcre2api.html currently states the opposite:
>>
>> "A match data block can be used many times, with the same or
>> different compiled patterns."
>>
>> Given my findings, this is explicitly NOT true then.
>
> Why do you think it is not true? Once you have used a match data
> block with a pattern, it is "attached" to that pattern for checking
> substrings etc. If you then use it with a different pattern, it
> "switches" to that pattern and that particular match.


Sorry, my mistake. I was under the wrong impression that pcre2_match_data_create_from_pattern() would store the code to the match_data.

> I will add some words to that effect to the documentation.


Much appreciated!

> Essentially, a match block captures the results of a match operation
> for a particular pattern and a particular subject. There is no reason
> to stop you re-using it for a different pattern or subject.


Stimulated by your response I looked closer at the sources and found that match_data->code is set by pcre2_match(). So any new call to pcre2_match() will reset a previous match_data->code to either the same or to another compiled pattern code.

To sum up, here are the ways to "unlink" a compiled pattern code from a match_data:

1. pcre2_code_free()
2. pcre2_match()

3. pcre2_dfa_match() -- No, it does not work like pcre2_match()!

Assuming that pcre2_dfa_match() would work just like pcre2_match(), I next checked if this also links a compiled pattern code to a match_data. Surprisingly, it does not. Pre-filling a match_pattern's memory with NULLs, match_data->code is left unchanged by pcre2_dfa_match().

A consecutive call to pcre2_substring_get_bynumber() et. al. results in an access violation.

Are the pcre2_substring_...() functions not intended for use with pcre2_dfa_match()?

Ralf