1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
/*
This is part of pyahocorasick Python module.
common definitions and includes
Author : Wojciech Muła, wojciech_mula@poczta.onet.pl
WWW : http://0x80.pl
License : public domain
*/
#ifndef ahocorasick_common_h_included__
#define ahocorasick_common_h_included__
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <structmember.h> // PyMemberDef
#include <iso646.h>
#define DEBUG
#if defined(_MSC_VER) // Visual Studio compiler
# include "windows.h"
#else
# if defined(__CYGWIN__)
# include "cygwin.h"
# else
# include "posix.h"
# endif
#endif
#if PY_MAJOR_VERSION >= 3
#define PY3K
#if PY_MINOR_VERSION >= 3 || PY_MAJOR_VERSION > 3
#define PEP393
#ifdef AHOCORASICK_UNICODE
#define PEP393_UNICODE
#endif
#endif
#else
#ifdef AHOCORASICK_UNICODE
#warning "No support for unicode in version for Python2"
#endif
#undef AHOCORASICK_UNICODE
#endif
// setup supported character set
#ifdef AHOCORASICK_UNICODE
# if defined PEP393_UNICODE || defined Py_UNICODE_WIDE
// Either Python uses UCS-4 or we don't know what Python uses,
// but we use UCS-4
# define TRIE_LETTER_TYPE uint32_t
# define TRIE_LETTER_SIZE 4
# else
// Python use UCS-2
# define TRIE_LETTER_TYPE uint16_t
# define TRIE_LETTER_SIZE 2
# define VARIABLE_LEN_CHARCODES 1
# endif
#else
// only bytes are supported
# define TRIE_LETTER_TYPE uint16_t
# define TRIE_LETTER_SIZE 2
#endif
#ifdef __GNUC__
# define LIKELY(x) __builtin_expect(x, 1)
# define UNLIKELY(x) __builtin_expect(x, 0)
# define ALWAYS_INLINE __attribute__((always_inline))
# define PURE __attribute__((pure))
# define UNUSED __attribute__((unused))
#else
# define LIKELY(x) x
# define UNLIKELY(x) x
# define ALWAYS_INLINE
# define PURE
# define UNUSED
#endif
#ifdef DEBUG
# include <assert.h>
# define ASSERT(expr) do {if (!(expr)) {fprintf(stderr, "%s:%s:%d - %s failed!\n", __FILE__, __FUNCTION__, __LINE__, #expr); fflush(stderr); exit(1);} }while(0)
#else
# define ASSERT(expr)
#endif
#if defined(PYCALLS_INJECT_FAULTS) && defined(PY3K)
# include "src/pycallfault/pycallfault.h"
#else
# define F(name) name
#endif
typedef char bool;
#define true 1
#define false 0
#endif
|