tools/pcre/pcre_refcount.c
author John Schoenick <john@pointysoftware.net>
Wed Jun 01 20:36:16 2011 -0400 (2011-06-01)
changeset 3292 f428ffc8a3fe
parent 2762 d2d467bf1b5a
child 3831 babd0eee3c5e
permissions -rw-r--r--
Fixed regression in FindEntityByClassname from bug 4899 (bug 4941, r=predcrab).
dvander@2762
     1
/*************************************************
dvander@2762
     2
*      Perl-Compatible Regular Expressions       *
dvander@2762
     3
*************************************************/
dvander@2762
     4
dvander@2762
     5
/* PCRE is a library of functions to support regular expressions whose syntax
dvander@2762
     6
and semantics are as close as possible to those of the Perl 5 language.
dvander@2762
     7
dvander@2762
     8
                       Written by Philip Hazel
dvander@2762
     9
           Copyright (c) 1997-2008 University of Cambridge
dvander@2762
    10
dvander@2762
    11
-----------------------------------------------------------------------------
dvander@2762
    12
Redistribution and use in source and binary forms, with or without
dvander@2762
    13
modification, are permitted provided that the following conditions are met:
dvander@2762
    14
dvander@2762
    15
    * Redistributions of source code must retain the above copyright notice,
dvander@2762
    16
      this list of conditions and the following disclaimer.
dvander@2762
    17
dvander@2762
    18
    * Redistributions in binary form must reproduce the above copyright
dvander@2762
    19
      notice, this list of conditions and the following disclaimer in the
dvander@2762
    20
      documentation and/or other materials provided with the distribution.
dvander@2762
    21
dvander@2762
    22
    * Neither the name of the University of Cambridge nor the names of its
dvander@2762
    23
      contributors may be used to endorse or promote products derived from
dvander@2762
    24
      this software without specific prior written permission.
dvander@2762
    25
dvander@2762
    26
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
dvander@2762
    27
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
dvander@2762
    28
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
dvander@2762
    29
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
dvander@2762
    30
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
dvander@2762
    31
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
dvander@2762
    32
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
dvander@2762
    33
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
dvander@2762
    34
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
dvander@2762
    35
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
dvander@2762
    36
POSSIBILITY OF SUCH DAMAGE.
dvander@2762
    37
-----------------------------------------------------------------------------
dvander@2762
    38
*/
dvander@2762
    39
dvander@2762
    40
dvander@2762
    41
/* This module contains the external function pcre_refcount(), which is an
dvander@2762
    42
auxiliary function that can be used to maintain a reference count in a compiled
dvander@2762
    43
pattern data block. This might be helpful in applications where the block is
dvander@2762
    44
shared by different users. */
dvander@2762
    45
dvander@2762
    46
dvander@2762
    47
#ifdef HAVE_CONFIG_H
dvander@2762
    48
#include "config.h"
dvander@2762
    49
#endif
dvander@2762
    50
dvander@2762
    51
#include "pcre_internal.h"
dvander@2762
    52
dvander@2762
    53
dvander@2762
    54
/*************************************************
dvander@2762
    55
*           Maintain reference count             *
dvander@2762
    56
*************************************************/
dvander@2762
    57
dvander@2762
    58
/* The reference count is a 16-bit field, initialized to zero. It is not
dvander@2762
    59
possible to transfer a non-zero count from one host to a different host that
dvander@2762
    60
has a different byte order - though I can't see why anyone in their right mind
dvander@2762
    61
would ever want to do that!
dvander@2762
    62
dvander@2762
    63
Arguments:
dvander@2762
    64
  argument_re   points to compiled code
dvander@2762
    65
  adjust        value to add to the count
dvander@2762
    66
dvander@2762
    67
Returns:        the (possibly updated) count value (a non-negative number), or
dvander@2762
    68
                a negative error number
dvander@2762
    69
*/
dvander@2762
    70
dvander@2762
    71
PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
dvander@2762
    72
pcre_refcount(pcre *argument_re, int adjust)
dvander@2762
    73
{
dvander@2762
    74
real_pcre *re = (real_pcre *)argument_re;
dvander@2762
    75
if (re == NULL) return PCRE_ERROR_NULL;
dvander@2762
    76
re->ref_count = (-adjust > re->ref_count)? 0 :
dvander@2762
    77
                (adjust + re->ref_count > 65535)? 65535 :
dvander@2762
    78
                re->ref_count + adjust;
dvander@2762
    79
return re->ref_count;
dvander@2762
    80
}
dvander@2762
    81
dvander@2762
    82
/* End of pcre_refcount.c */