-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
155 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
*.pyc | ||
*.py[co] | ||
*.so | ||
*.o | ||
__pycache__/ | ||
build |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[submodule "xxhash"] | ||
path = xxhash | ||
path = c-xxhash | ||
url = https://github.com/Cyan4973/xxHash.git |
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
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 |
---|---|---|
@@ -1,4 +1,7 @@ | ||
include README.rst | ||
include LICENSE | ||
include xxhash/xxhash.h | ||
include xxhash/xxhash.c | ||
include c-xxhash/xxhash.h | ||
include c-xxhash/xxhash.c | ||
graft tests | ||
global-exclude __pycache__ | ||
global-exclude *.py[co] |
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
Submodule c-xxhash
updated
from 000000 to 88c6ee
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 |
---|---|---|
|
@@ -4,7 +4,12 @@ | |
from setuptools import setup, Extension | ||
import os | ||
|
||
VERSION = "0.6.1" | ||
with open('xxhash/__init__.py', 'rb') as f: | ||
for line in f: | ||
if line.startswith('VERSION = '): | ||
VERSION = eval(line.rsplit(None, 1)[-1]) | ||
|
||
USE_CPYTHON = os.getenv('XXHASH_FORCE_CFFI') in (None, '0') | ||
|
||
if os.name == 'posix': | ||
extra_compile_args = [ | ||
|
@@ -23,6 +28,20 @@ | |
('VERSION', VERSION), | ||
] | ||
|
||
if USE_CPYTHON: | ||
ext_modules = [ | ||
Extension( | ||
'xxhash_cpython', | ||
['xxhash/cpython.c', 'c-xxhash/xxhash.c'], | ||
extra_compile_args=extra_compile_args, | ||
define_macros=define_macros, | ||
include_dirs=['c-xxhash'] | ||
) | ||
] | ||
else: | ||
import xxhash.cffi | ||
ext_modules = [xxhash.cffi.ffibuilder.verifier.get_extension()] | ||
|
||
setup( | ||
name='xxhash', | ||
version=VERSION, | ||
|
@@ -32,14 +51,9 @@ | |
author_email='[email protected]', | ||
url='https://github.com/ifduyue/python-xxhash', | ||
license='BSD', | ||
ext_modules=[ | ||
Extension('xxhash', [ | ||
'python-xxhash.c', | ||
'xxhash/xxhash.c', | ||
], | ||
extra_compile_args=extra_compile_args, | ||
define_macros=define_macros) | ||
], | ||
packages=['xxhash'], | ||
ext_package='xxhash', | ||
ext_modules=ext_modules, | ||
setup_requires=["nose>=1.3.0"], | ||
test_suite='nose.collector', | ||
classifiers=[ | ||
|
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#from __future__ import absolute_import | ||
import os | ||
import unittest | ||
import random | ||
|
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,10 @@ | ||
from __future__ import absolute_import | ||
|
||
try: | ||
from xxhash.xxhash_cpython import xxh32, xxh64, XXHASH_VERSION | ||
except ImportError: | ||
from xxhash.cffi import xxh32, xxh64, XXHASH_VERSION | ||
|
||
|
||
VERSION = '1.0.dev0' | ||
__all__ = ['xxh32', 'xxh64', 'VERSION', 'XXHASH_VERSION'] |
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,92 @@ | ||
from __future__ import absolute_import | ||
|
||
import cffi | ||
import struct | ||
import binascii | ||
|
||
ffibuilder = cffi.FFI() | ||
ffibuilder.cdef(''' | ||
#define XXH_VERSION_MAJOR ... | ||
#define XXH_VERSION_MINOR ... | ||
#define XXH_VERSION_RELEASE ... | ||
typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode; | ||
typedef unsigned int XXH32_hash_t; | ||
typedef struct XXH32_state_s XXH32_state_t; /* incomplete type */ | ||
XXH32_state_t* XXH32_createState(void); | ||
XXH_errorcode XXH32_freeState(XXH32_state_t* statePtr); | ||
void XXH32_copyState(XXH32_state_t* restrict dst_state, const XXH32_state_t* restrict src_state); | ||
XXH_errorcode XXH32_reset (XXH32_state_t* statePtr, unsigned int seed); | ||
XXH_errorcode XXH32_update (XXH32_state_t* statePtr, const void* input, size_t length); | ||
XXH32_hash_t XXH32_digest (const XXH32_state_t* statePtr); | ||
typedef unsigned long long XXH64_hash_t; | ||
typedef struct XXH64_state_s XXH64_state_t; /* incomplete type */ | ||
XXH64_state_t* XXH64_createState(void); | ||
XXH_errorcode XXH64_freeState(XXH64_state_t* statePtr); | ||
void XXH64_copyState(XXH64_state_t* restrict dst_state, const XXH64_state_t* restrict src_state); | ||
XXH_errorcode XXH64_reset (XXH64_state_t* statePtr, unsigned long long seed); | ||
XXH_errorcode XXH64_update (XXH64_state_t* statePtr, const void* input, size_t length); | ||
XXH64_hash_t XXH64_digest (const XXH64_state_t* statePtr); | ||
''') | ||
|
||
|
||
lib = ffibuilder.verify( | ||
'''#include "xxhash.h"''', | ||
modulename='xxhash_cffi', | ||
ext_package='xxhash', | ||
sources=['c-xxhash/xxhash.c'], | ||
include_dirs=['c-xxhash'] | ||
) | ||
|
||
|
||
XXHASH_VERSION = "{}.{}.{}".format(lib.XXH_VERSION_MAJOR, | ||
lib.XXH_VERSION_MINOR, | ||
lib.XXH_VERSION_RELEASE) | ||
|
||
|
||
class xxh32(object): | ||
def __init__(self, input=None, seed=0): | ||
self.xxhash_state = ffibuilder.gc(lib.XXH32_createState(), lib.XXH32_freeState) | ||
lib.XXH32_reset(self.xxhash_state, seed) | ||
if input: | ||
lib.XXH32_update(self.xxhash_state, input, len(input)) | ||
|
||
def update(self, input): | ||
lib.XXH32_update(self.xxhash_state, input, len(input)) | ||
|
||
def intdigest(self): | ||
return lib.XXH32_digest(self.xxhash_state) | ||
|
||
def digest(self): | ||
return struct.pack('>I', self.intdigest()) | ||
|
||
def hexdigest(self): | ||
return binascii.hexlify(self.digest()) | ||
|
||
|
||
class xxh64(object): | ||
def __init__(self, input=None, seed=0): | ||
self.xxhash_state = ffibuilder.gc(lib.XXH64_createState(), lib.XXH64_freeState) | ||
lib.XXH64_reset(self.xxhash_state, seed) | ||
if input: | ||
lib.XXH64_update(self.xxhash_state, input, len(input)) | ||
|
||
def update(self, input): | ||
lib.XXH64_update(self.xxhash_state, input, len(input)) | ||
|
||
def intdigest(self): | ||
return lib.XXH64_digest(self.xxhash_state) | ||
|
||
def digest(self): | ||
return struct.pack('>Q', self.intdigest()) | ||
|
||
def hexdigest(self): | ||
return binascii.hexlify(self.digest()) |
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