/[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 1193 by ph10, Sat Jan 21 16:37:17 2012 UTC revision 1194 by ph10, Wed Oct 31 17:42:29 2012 UTC
# Line 35  JIT data. Line 35  JIT data.
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. If the two hosts have different endianness (byte order),  and run them there. If the two hosts have different endianness (byte order),
38  you should run the <b>pcre[16]_pattern_to_host_byte_order()</b> function on the  you should run the <b>pcre[16|32]_pattern_to_host_byte_order()</b> function on the
39  new host before trying to match the pattern. The matching functions return  new host before trying to match the pattern. The matching functions return
40  PCRE_ERROR_BADENDIANNESS if they detect a pattern with the wrong endianness.  PCRE_ERROR_BADENDIANNESS if they detect a pattern with the wrong endianness.
41  </P>  </P>
# Line 46  restoring a compiled pattern loses any J Line 46  restoring a compiled pattern loses any J
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[16]_compile()</b> points to a single block of  The value returned by <b>pcre[16|32]_compile()</b> points to a single block of
50  memory that holds the compiled pattern and associated data. You can find the  memory that holds the compiled pattern and associated data. You can find the
51  length of this block in bytes by calling <b>pcre[16]_fullinfo()</b> with an  length of this block in bytes by calling <b>pcre[16|32]_fullinfo()</b> with an
52  argument of PCRE_INFO_SIZE. You can then save the data in any appropriate  argument of PCRE_INFO_SIZE. You can then save the data in any appropriate
53  manner. Here is sample code for the 8-bit library that compiles a pattern and  manner. Here is sample code for the 8-bit library that compiles a pattern and
54  writes it to a file. It assumes that the variable <i>fd</i> refers to a file  writes it to a file. It assumes that the variable <i>fd</i> refers to a file
# Line 87  If the pattern has been studied, it is a Line 87  If the pattern has been studied, it is a
87  data in a similar way to the compiled pattern itself. However, if the  data in a similar way to the compiled pattern itself. However, if the
88  PCRE_STUDY_JIT_COMPILE was used, the just-in-time data that is created cannot  PCRE_STUDY_JIT_COMPILE was used, the just-in-time data that is created cannot
89  be saved because it is too dependent on the current environment. When studying  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  generates additional information, <b>pcre[16|32]_study()</b> returns a pointer to a
91  <b>pcre[16]_extra</b> data block. Its format is defined in the  <b>pcre[16|32]_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[16]_extra</b> block itself). The  this is what you must save (not the <b>pcre[16|32]_extra</b> block itself). The
97  length of the study data can be obtained by calling <b>pcre[16]_fullinfo()</b>  length of the study data can be obtained by calling <b>pcre[16|32]_fullinfo()</b>
98  with an argument of PCRE_INFO_STUDYSIZE. Remember to check that  with an argument of PCRE_INFO_STUDYSIZE. Remember to check that
99  <b>pcre[16]_study()</b> did return a non-NULL value before trying to save the  <b>pcre[16|32]_study()</b> did return a non-NULL value before trying to save the
100  study data.  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, called <b>pcre[16]_pattern_to_host_byte_order()</b> if necessary,  memory, called <b>pcre[16|32]_pattern_to_host_byte_order()</b> if necessary,
106  you pass its pointer to <b>pcre[16]_exec()</b> or <b>pcre[16]_dfa_exec()</b> in  you pass its pointer to <b>pcre[16|32]_exec()</b> or <b>pcre[16|32]_dfa_exec()</b> in
107  the usual way.  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[16]_compile()</b>), you  was compiled (the <i>tableptr</i> argument of <b>pcre[16|32]_compile()</b>), you
112  must now pass a similar pointer to <b>pcre[16]_exec()</b> or  must now pass a similar pointer to <b>pcre[16|32]_exec()</b> or
113  <b>pcre[16]_dfa_exec()</b>, because the value saved with the compiled pattern  <b>pcre[16|32]_dfa_exec()</b>, because the value saved with the compiled pattern
114  will obviously be nonsense. A field in a <b>pcre[16]_extra()</b> block is used  will obviously be nonsense. A field in a <b>pcre[16|32]_extra()</b> block is used
115  to pass this data, as described in 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
# Line 126  special action at run time in this case. Line 126  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[16]_extra</b> data block and set the <i>study_data</i> field to point to the  <b>pcre[16|32]_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[16]_extra</b> block to the matching function in the usual way. If the  <b>pcre[16|32]_extra</b> block to the matching function in the usual way. If the
133  pattern was studied for just-in-time optimization, that data cannot be saved,  pattern was studied for just-in-time optimization, that data cannot be saved,
134  and so is lost by a save/restore cycle.  and so is lost by a save/restore cycle.
135  </P>  </P>
# Line 149  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: 10 January 2012  Last updated: 24 June 2012
153  <br>  <br>
154  Copyright &copy; 1997-2012 University of Cambridge.  Copyright &copy; 1997-2012 University of Cambridge.
155  <br>  <br>

Legend:
Removed from v.1193  
changed lines
  Added in v.1194

  ViewVC Help
Powered by ViewVC 1.1.5