-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix handling of inputs in bytes-only C extension functions
- Loading branch information
Showing
10 changed files
with
388 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#ifndef _FUZZYSEARCH_C_EXT_BASE_H | ||
#define _FUZZYSEARCH_C_EXT_BASE_H | ||
|
||
#define PY_SSIZE_T_CLEAN | ||
#include <Python.h> | ||
|
||
#if PY_MAJOR_VERSION >= 3 | ||
#define IS_PY3K | ||
#endif | ||
|
||
#ifndef unlikely | ||
#ifdef __GNUC__ | ||
/* Test for GCC > 2.95 */ | ||
#if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)) | ||
#define likely(x) __builtin_expect(!!(x), 1) | ||
#define unlikely(x) __builtin_expect(!!(x), 0) | ||
#else /* __GNUC__ > 2 ... */ | ||
#define likely(x) (x) | ||
#define unlikely(x) (x) | ||
#endif /* __GNUC__ > 2 ... */ | ||
#else /* __GNUC__ */ | ||
#define likely(x) (x) | ||
#define unlikely(x) (x) | ||
#endif /* __GNUC__ */ | ||
#endif | ||
|
||
#if defined(_MSC_VER) | ||
#define inline __inline | ||
#endif | ||
|
||
inline static int is_simple_buffer(Py_buffer pybuf) { | ||
return ( | ||
pybuf.itemsize == 1 && | ||
pybuf.ndim == 1 && | ||
(pybuf.strides == NULL || pybuf.strides[0] == 1) && | ||
pybuf.suboffsets == NULL | ||
); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.