codekingpro/portable-devtools
114k
1#ifndef Py_HASH_H2#define Py_HASH_H3#ifdef __cplusplus4extern "C" {5#endif6 7/* Cutoff for small string DJBX33A optimization in range [1, cutoff).8 *9 * About 50% of the strings in a typical Python application are smaller than10 * 6 to 7 chars. However DJBX33A is vulnerable to hash collision attacks.11 * NEVER use DJBX33A for long strings!12 *13 * A Py_HASH_CUTOFF of 0 disables small string optimization. 32 bit platforms14 * should use a smaller cutoff because it is easier to create colliding15 * strings. A cutoff of 7 on 64bit platforms and 5 on 32bit platforms should16 * provide a decent safety margin.17 */18#ifndef Py_HASH_CUTOFF19# define Py_HASH_CUTOFF 020#elif (Py_HASH_CUTOFF > 7 || Py_HASH_CUTOFF < 0)21# error Py_HASH_CUTOFF must in range 0...7.22#endif /* Py_HASH_CUTOFF */23 24 25/* Hash algorithm selection26 *27 * The values for Py_HASH_* are hard-coded in the28 * configure script.29 *30 * - FNV and SIPHASH* are available on all platforms and architectures.31 * - With EXTERNAL embedders can provide an alternative implementation with::32 *33 * PyHash_FuncDef PyHash_Func = {...};34 *35 * XXX: Figure out __declspec() for extern PyHash_FuncDef.36 */37#define Py_HASH_EXTERNAL 038#define Py_HASH_SIPHASH24 139#define Py_HASH_FNV 240#define Py_HASH_SIPHASH13 341 42#ifndef Py_HASH_ALGORITHM43# ifndef HAVE_ALIGNED_REQUIRED44# define Py_HASH_ALGORITHM Py_HASH_SIPHASH1345# else46# define Py_HASH_ALGORITHM Py_HASH_FNV47# endif /* uint64_t && uint32_t && aligned */48#endif /* Py_HASH_ALGORITHM */49 50#ifndef Py_LIMITED_API51# define Py_CPYTHON_HASH_H52# include "cpython/pyhash.h"53# undef Py_CPYTHON_HASH_H54#endif55 56#ifdef __cplusplus57}58#endif59#endif // !Py_HASH_H60 