/[pcre]/code/trunk/doc/html/pcreprecompile.html
ViewVC logotype

Diff of /code/trunk/doc/html/pcreprecompile.html

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 579 by ph10, Wed Nov 24 17:39:25 2010 UTC revision 903 by ph10, Sat Jan 21 16:37:17 2012 UTC
# Line 28  instead of having to compile them every Line 28  instead of having to compile them every
28  If you are not using any private character tables (see the  If you are not using any private character tables (see the
29  <a href="pcre_maketables.html"><b>pcre_maketables()</b></a>  <a href="pcre_maketables.html"><b>pcre_maketables()</b></a>
30  documentation), this is relatively straightforward. If you are using private  documentation), this is relatively straightforward. If you are using private
31  tables, it is a little bit more complicated.  tables, it is a little bit more complicated. However, if you are using the
32    just-in-time optimization feature, it is not possible to save and reload the
33    JIT data.
34  </P>  </P>
35  <P>  <P>
36  If you save compiled patterns to a file, you can copy them to a different host  If you save compiled patterns to a file, you can copy them to a different host
37  and run them there. This works even if the new host has the opposite endianness  and run them there. If the two hosts have different endianness (byte order),
38  to the one on which the patterns were compiled. There may be a small  you should run the <b>pcre[16]_pattern_to_host_byte_order()</b> function on the
39  performance penalty, but it should be insignificant. However, compiling regular  new host before trying to match the pattern. The matching functions return
40  expressions with one version of PCRE for use with a different version is not  PCRE_ERROR_BADENDIANNESS if they detect a pattern with the wrong endianness.
41  guaranteed to work and may cause crashes.  </P>
42    <P>
43    Compiling regular expressions with one version of PCRE for use with a different
44    version is not guaranteed to work and may cause crashes, and saving and
45    restoring a compiled pattern loses any JIT optimization data.
46  </P>  </P>
47  <br><a name="SEC2" href="#TOC1">SAVING A COMPILED PATTERN</a><br>  <br><a name="SEC2" href="#TOC1">SAVING A COMPILED PATTERN</a><br>
48  <P>  <P>
49  The value returned by <b>pcre_compile()</b> points to a single block of memory  The value returned by <b>pcre[16]_compile()</b> points to a single block of
50  that holds the compiled pattern and associated data. You can find the length of  memory that holds the compiled pattern and associated data. You can find the
51  this block in bytes by calling <b>pcre_fullinfo()</b> with an argument of  length of this block in bytes by calling <b>pcre[16]_fullinfo()</b> with an
52  PCRE_INFO_SIZE. You can then save the data in any appropriate manner. Here is  argument of PCRE_INFO_SIZE. You can then save the data in any appropriate
53  sample code that compiles a pattern and writes it to a file. It assumes that  manner. Here is sample code for the 8-bit library that compiles a pattern and
54  the variable <i>fd</i> refers to a file that is open for output:  writes it to a file. It assumes that the variable <i>fd</i> refers to a file
55    that is open for output:
56  <pre>  <pre>
57    int erroroffset, rc, size;    int erroroffset, rc, size;
58    char *error;    char *error;
# Line 76  some daemon process that passes them via Line 83  some daemon process that passes them via
83  them.  them.
84  </P>  </P>
85  <P>  <P>
86  If the pattern has been studied, it is also possible to save the study data in  If the pattern has been studied, it is also possible to save the normal study
87  a similar way to the compiled pattern itself. When studying generates  data in a similar way to the compiled pattern itself. However, if the
88  additional information, <b>pcre_study()</b> returns a pointer to a  PCRE_STUDY_JIT_COMPILE was used, the just-in-time data that is created cannot
89  <b>pcre_extra</b> data block. Its format is defined in the  be saved because it is too dependent on the current environment. When studying
90    generates additional information, <b>pcre[16]_study()</b> returns a pointer to a
91    <b>pcre[16]_extra</b> data block. Its format is defined in the
92  <a href="pcreapi.html#extradata">section on matching a pattern</a>  <a href="pcreapi.html#extradata">section on matching a pattern</a>
93  in the  in the
94  <a href="pcreapi.html"><b>pcreapi</b></a>  <a href="pcreapi.html"><b>pcreapi</b></a>
95  documentation. The <i>study_data</i> field points to the binary study data, and  documentation. The <i>study_data</i> field points to the binary study data, and
96  this is what you must save (not the <b>pcre_extra</b> block itself). The length  this is what you must save (not the <b>pcre[16]_extra</b> block itself). The
97  of the study data can be obtained by calling <b>pcre_fullinfo()</b> with an  length of the study data can be obtained by calling <b>pcre[16]_fullinfo()</b>
98  argument of PCRE_INFO_STUDYSIZE. Remember to check that <b>pcre_study()</b> did  with an argument of PCRE_INFO_STUDYSIZE. Remember to check that
99  return a non-NULL value before trying to save the study data.  <b>pcre[16]_study()</b> did return a non-NULL value before trying to save the
100    study data.
101  </P>  </P>
102  <br><a name="SEC3" href="#TOC1">RE-USING A PRECOMPILED PATTERN</a><br>  <br><a name="SEC3" href="#TOC1">RE-USING A PRECOMPILED PATTERN</a><br>
103  <P>  <P>
104  Re-using a precompiled pattern is straightforward. Having reloaded it into main  Re-using a precompiled pattern is straightforward. Having reloaded it into main
105  memory, you pass its pointer to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b> in  memory, called <b>pcre[16]_pattern_to_host_byte_order()</b> if necessary,
106  the usual way. This should work even on another host, and even if that host has  you pass its pointer to <b>pcre[16]_exec()</b> or <b>pcre[16]_dfa_exec()</b> in
107  the opposite endianness to the one where the pattern was compiled.  the usual way.
108  </P>  </P>
109  <P>  <P>
110  However, if you passed a pointer to custom character tables when the pattern  However, if you passed a pointer to custom character tables when the pattern
111  was compiled (the <i>tableptr</i> argument of <b>pcre_compile()</b>), you must  was compiled (the <i>tableptr</i> argument of <b>pcre[16]_compile()</b>), you
112  now pass a similar pointer to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>,  must now pass a similar pointer to <b>pcre[16]_exec()</b> or
113  because the value saved with the compiled pattern will obviously be nonsense. A  <b>pcre[16]_dfa_exec()</b>, because the value saved with the compiled pattern
114  field in a <b>pcre_extra()</b> block is used to pass this data, as described in  will obviously be nonsense. A field in a <b>pcre[16]_extra()</b> block is used
115  the  to pass this data, as described in the
116  <a href="pcreapi.html#extradata">section on matching a pattern</a>  <a href="pcreapi.html#extradata">section on matching a pattern</a>
117  in the  in the
118  <a href="pcreapi.html"><b>pcreapi</b></a>  <a href="pcreapi.html"><b>pcreapi</b></a>
# Line 110  documentation. Line 120  documentation.
120  </P>  </P>
121  <P>  <P>
122  If you did not provide custom character tables when the pattern was compiled,  If you did not provide custom character tables when the pattern was compiled,
123  the pointer in the compiled pattern is NULL, which causes <b>pcre_exec()</b> to  the pointer in the compiled pattern is NULL, which causes the matching
124  use PCRE's internal tables. Thus, you do not need to take any special action at  functions to use PCRE's internal tables. Thus, you do not need to take any
125  run time in this case.  special action at run time in this case.
126  </P>  </P>
127  <P>  <P>
128  If you saved study data with the compiled pattern, you need to create your own  If you saved study data with the compiled pattern, you need to create your own
129  <b>pcre_extra</b> data block and set the <i>study_data</i> field to point to the  <b>pcre[16]_extra</b> data block and set the <i>study_data</i> field to point to the
130  reloaded study data. You must also set the PCRE_EXTRA_STUDY_DATA bit in the  reloaded study data. You must also set the PCRE_EXTRA_STUDY_DATA bit in the
131  <i>flags</i> field to indicate that study data is present. Then pass the  <i>flags</i> field to indicate that study data is present. Then pass the
132  <b>pcre_extra</b> block to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b> in the  <b>pcre[16]_extra</b> block to the matching function in the usual way. If the
133  usual way.  pattern was studied for just-in-time optimization, that data cannot be saved,
134    and so is lost by a save/restore cycle.
135  </P>  </P>
136  <br><a name="SEC4" href="#TOC1">COMPATIBILITY WITH DIFFERENT PCRE RELEASES</a><br>  <br><a name="SEC4" href="#TOC1">COMPATIBILITY WITH DIFFERENT PCRE RELEASES</a><br>
137  <P>  <P>
# Line 138  Cambridge CB2 3QH, England. Line 149  Cambridge CB2 3QH, England.
149  </P>  </P>
150  <br><a name="SEC6" href="#TOC1">REVISION</a><br>  <br><a name="SEC6" href="#TOC1">REVISION</a><br>
151  <P>  <P>
152  Last updated: 17 November 2010  Last updated: 10 January 2012
153  <br>  <br>
154  Copyright &copy; 1997-2010 University of Cambridge.  Copyright &copy; 1997-2012 University of Cambridge.
155  <br>  <br>
156  <p>  <p>
157  Return to the <a href="index.html">PCRE index page</a>.  Return to the <a href="index.html">PCRE index page</a>.

Legend:
Removed from v.579  
changed lines
  Added in v.903

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12