/*************************************************1* Perl-Compatible Regular Expressions *2*************************************************/34/* PCRE2 is a library of functions to support regular expressions whose syntax5and semantics are as close as possible to those of the Perl 5 language.67Written by Philip Hazel8Original API code Copyright (c) 1997-2012 University of Cambridge9New API code Copyright (c) 2016-2024 University of Cambridge1011-----------------------------------------------------------------------------12Redistribution and use in source and binary forms, with or without13modification, are permitted provided that the following conditions are met:1415* Redistributions of source code must retain the above copyright notice,16this list of conditions and the following disclaimer.1718* Redistributions in binary form must reproduce the above copyright19notice, this list of conditions and the following disclaimer in the20documentation and/or other materials provided with the distribution.2122* Neither the name of the University of Cambridge nor the names of its23contributors may be used to endorse or promote products derived from24this software without specific prior written permission.2526THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"27AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE28IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE29ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE30LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR31CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF32SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS33INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN34CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)35ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE36POSSIBILITY OF SUCH DAMAGE.37-----------------------------------------------------------------------------38*/3940#ifndef PCRE2_UTIL_H_IDEMPOTENT_GUARD41#define PCRE2_UTIL_H_IDEMPOTENT_GUARD4243/* Assertion macros */4445#ifdef PCRE2_DEBUG4647#if defined(HAVE_ASSERT_H) && !defined(NDEBUG)48#include <assert.h>49#endif5051/* PCRE2_ASSERT(x) can be used to inject an assert() for conditions52that the code below doesn't support. It is a NOP for non debug builds53but in debug builds will print information about the location of the54code where it triggered and crash.5556It is meant to work like assert(), and therefore the expression used57should indicate what the expected state is, and shouldn't have any58side-effects. */5960#if defined(HAVE_ASSERT_H) && !defined(NDEBUG)61#define PCRE2_ASSERT(x) assert(x)62#else63#define PCRE2_ASSERT(x) do \64{ \65if (!(x)) \66{ \67fprintf(stderr, "Assertion failed at " __FILE__ ":%d\n", __LINE__); \68abort(); \69} \70} while(0)71#endif7273/* PCRE2_UNREACHABLE() can be used to mark locations on the code that74shouldn't be reached. In non debug builds is defined as a hint for75the compiler to eliminate any code after it, so it is useful also for76performance reasons, but should be used with care because if it is77ever reached will trigger Undefined Behaviour and if you are lucky a78crash. In debug builds it will report the location where it was triggered79and crash. One important point to consider when using this macro, is80that it is only implemented for a few compilers, and therefore can't81be relied on to always be active either, so if it is followed by some82code it is important to make sure that the whole thing is safe to83use even if the macro is not there (ex: make sure there is a `break`84after it if used at the end of a `case`) and to test your code also85with a configuration where the macro will be a NOP. */8687#if defined(HAVE_ASSERT_H) && !defined(NDEBUG)88#define PCRE2_UNREACHABLE() \89assert(((void)"Execution reached unexpected point", 0))90#else91#define PCRE2_UNREACHABLE() do \92{ \93fprintf(stderr, "Execution reached unexpected point at " __FILE__ \94":%d\n", __LINE__); \95abort(); \96} while(0)97#endif9899/* PCRE2_DEBUG_UNREACHABLE() is a debug only version of the previous100macro. It is meant to be used in places where the code is handling101an error situation in code that shouldn't be reached, but that has102some sort of fallback code to normally handle the error. When in103doubt you should use this instead of the previous macro. Like in104the previous case, it is a good idea to document as much as possible105the reason and the actions that should be taken if it ever triggers. */106107#define PCRE2_DEBUG_UNREACHABLE() PCRE2_UNREACHABLE()108109#endif /* PCRE2_DEBUG */110111#ifndef PCRE2_DEBUG_UNREACHABLE112#define PCRE2_DEBUG_UNREACHABLE() do {} while(0)113#endif114115#ifndef PCRE2_UNREACHABLE116#ifdef HAVE_BUILTIN_UNREACHABLE117#define PCRE2_UNREACHABLE() __builtin_unreachable()118#elif defined(HAVE_BUILTIN_ASSUME)119#define PCRE2_UNREACHABLE() __assume(0)120#else121#define PCRE2_UNREACHABLE() do {} while(0)122#endif123#endif /* !PCRE2_UNREACHABLE */124125#ifndef PCRE2_ASSERT126#define PCRE2_ASSERT(x) do {} while(0)127#endif128129#endif /* PCRE2_UTIL_H_IDEMPOTENT_GUARD */130131/* End of pcre2_util.h */132133134