<commit_before>/*
 * Secret Labs' Regular Expression Engine
 *
 * regular expression matching engine
 *
 * partial history:
 * 99-10-24 fl  created (based on existing template matcher code)
 * 00-03-06 fl  first alpha, sort of (0.5)
 * 00-06-30 fl  added fast search optimization (0.9.3)
 * 00-06-30 fl  added assert (lookahead) primitives, etc (0.9.4)
 * 00-07-02 fl  added charset optimizations, etc (0.9.5)
 * 00-07-03 fl  store code in pattern object, lookbehind, etc
 * 00-07-08 fl  added regs attribute
 * 00-07-21 fl  reset lastindex in scanner methods (0.9.6)
 * 00-08-01 fl  fixes for 1.6b1 (0.9.8)
 * 00-08-03 fl  added recursion limit
 * 00-08-07 fl  use PyOS_CheckStack() if available
 * 00-08-08 fl  changed findall to return empty strings instead of None
 *
 * Copyright (c) 1997-2000 by Secret Labs AB.  All rights reserved.
 *
 * This version of the SRE library can be redistributed under CNRI's
 * Python 1.6 license.  For any other use, please contact Secret Labs
 * AB (<EMAIL>).
 *
 * Portions of this engine have been developed in cooperation with
 * CNRI.  Hewlett-Packard provided funding for 1.6 integration and
 * other compatibility work.
 */

#ifndef SRE_RECURSIVE

char copyright[] = " SRE 0.9.8 Copyright (c) 1997-2000 by Secret Labs AB ";

#include "Python.h"

#include "sre.h"

#if defined(HAVE_LIMITS_H)
#include <limits.h>
#else
#define INT_MAX 2147483647
#endif

#include <ctype.h>

/* name of this module, minus the leading underscore */
#define MODULE "sre"

/* defining this one enables tracing */
#undef VERBOSE

#if PY_VERSION_HEX >= 0x01060000
/* defining this enables unicode support (default under 1.6a1 and later) */
#define HAVE_UNICODE
#endif

/* -------------------------------------------------------------------- */
/* optional features */

/* prevent run-away recursion (bad patterns on long strings) */
#if !defined(USE_STACKCHECK)
#define USE_RECURSION_LIMIT 10000
#endif

/* enables fast searching */
#define USE_FAST_SEARCH

/* enables aggressive inlining (always on for Visual C) */
#undef USE_INLINE

/* -------------------------------------------------------------------- */

#if defined(_MSC_VER)
#pragma optimize("agtw", on) /* doesn't seem to make much difference... */
#pragma warning(disable: 4710) /* who cares if functions are not inlined ;-) */
/* fastest possible local call under MSVC */
#define LOCAL(type) static __inline type __fastcall
#elif defined(USE_INLINE)
#define LOCAL(type) static inline type
#else
#define LOCAL(type) static type
#endif

/* error codes */
#define SRE_ERROR_ILLEGAL -1 /* illegal opcode */
#define SRE_ERROR_STATE -2 /* illegal state */
#define SRE_ERROR_RECURSION_LIMIT -3 /* runaway recursion */
#define SRE_ERROR_MEMORY -9 /* out of memory */

#if defined(VERBOSE)<commit_msg>The sre test suite currently overruns the stack on Win64, Linux64, and Monterey (64-bit AIX) This is because the RECURSION_LIMIT is too low. This patch lowers to recusion limit to 7500 such that the recusion check fires before a segfault.<commit_after>/*
 * Secret Labs' Regular Expression Engine
 *
 * regular expression matching engine
 *
 * partial history:
 * 99-10-24 fl  created (based on existing template matcher code)
 * 00-03-06 fl  first alpha, sort of (0.5)
 * 00-06-30 fl  added fast search optimization (0.9.3)
 * 00-06-30 fl  added assert (lookahead) primitives, etc (0.9.4)
 * 00-07-02 fl  added charset optimizations, etc (0.9.5)
 * 00-07-03 fl  store code in pattern object, lookbehind, etc
 * 00-07-08 fl  added regs attribute
 * 00-07-21 fl  reset lastindex in scanner methods (0.9.6)
 * 00-08-01 fl  fixes for 1.6b1 (0.9.8)
 * 00-08-03 fl  added recursion limit
 * 00-08-07 fl  use PyOS_CheckStack() if available
 * 00-08-08 fl  changed findall to return empty strings instead of None
 *
 * Copyright (c) 1997-2000 by Secret Labs AB.  All rights reserved.
 *
 * This version of the SRE library can be redistributed under CNRI's
 * Python 1.6 license.  For any other use, please contact Secret Labs
 * AB (<EMAIL>).
 *
 * Portions of this engine have been developed in cooperation with
 * CNRI.  Hewlett-Packard provided funding for 1.6 integration and
 * other compatibility work.
 */

#ifndef SRE_RECURSIVE

char copyright[] = " SRE 0.9.8 Copyright (c) 1997-2000 by Secret Labs AB ";

#include "Python.h"

#include "sre.h"

#if defined(HAVE_LIMITS_H)
#include <limits.h>
#else
#define INT_MAX 2147483647
#endif

#include <ctype.h>

/* name of this module, minus the leading underscore */
#define MODULE "sre"

/* defining this one enables tracing */
#undef VERBOSE

#if PY_VERSION_HEX >= 0x01060000
/* defining this enables unicode support (default under 1.6a1 and later) */
#define HAVE_UNICODE
#endif

/* -------------------------------------------------------------------- */
/* optional features */

/* prevent run-away recursion (bad patterns on long strings)
   Require a smaller recursion limit for a number of 64-bit platforms
   to prevent stack overflow:
    Win64 - MS_WIN64, Linux64 - __LP64__, Monterey (64-bit AIX) - _LP64
   XXX Or maybe this should be defined for all SIZEOF_VOIDP>4 platforms?
*/
#if !defined(USE_STACKCHECK)
#	if defined(MS_WIN64) || defined(__LP64__) || defined(_LP64)
#		define USE_RECURSION_LIMIT 7500
#	else
#		define USE_RECURSION_LIMIT 10000
#	endif
#endif

/* enables fast searching */
#define USE_FAST_SEARCH

/* enables aggressive inlining (always on for Visual C) */
#undef USE_INLINE

/* -------------------------------------------------------------------- */

#if defined(_MSC_VER)
#pragma optimize("agtw", on) /* doesn't seem to make much difference... */
#pragma warning(disable: 4710) /* who cares if functions are not inlined ;-) */
/* fastest possible local call under MSVC */
#define LOCAL(type) static __inline type __fastcall
#elif defined(USE_INLINE)
#define LOCAL(type) static inline type
#else
#define LOCAL(type) static type
#endif

/* error codes */
#define SRE_ERROR_ILLEGAL -1 /* illegal opcode */
#define SRE_ERROR_STATE -2 /* illegal state */
#define SRE_ERROR_RECURSION_LIMIT -3 /* runaway recursion */
#define SRE_ERROR_MEMORY -9 /* out of memory */

#if defined(VERBOSE)
{'fraction_non_alphanumeric': 0.14302022178734508, 'fraction_numerical': 0.054631441617742985, 'mean_word_length': 3.143918918918919, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1917723', 'n_tokens_mistral': 2152, 'n_tokens_neox': 1902, 'n_words': 719}