From 417729e8b86606282c017183355bcc377e812c34 Mon Sep 17 00:00:00 2001 From: Eugene Scherba Date: Tue, 28 Dec 2021 12:37:31 -0800 Subject: [PATCH 1/7] compiles and runs with python3 --- .gitignore | 9 +- .ycm_extra_conf.py | 190 -- MANIFEST.in | 1 + Makefile | 8 +- README.rst | 8 +- cpp.mk | 11 +- cpuinfo.py | 1588 ++++++++++ dev-requirements.txt | 7 - .travis.yml => old-configs/.travis.yml | 0 circle.yml => old-configs/circle.yml | 0 pip-freeze.txt | 3 + python.mk | 101 +- requirements.txt | 9 +- setup.cfg | 14 + setup.py | 50 +- src/metrohash.cpp | 3769 ++++++++++++++++++------ src/metrohash.pyx | 42 +- tests/test_metrohash.py | 76 +- 18 files changed, 4695 insertions(+), 1191 deletions(-) delete mode 100644 .ycm_extra_conf.py create mode 100644 cpuinfo.py delete mode 100644 dev-requirements.txt rename .travis.yml => old-configs/.travis.yml (100%) rename circle.yml => old-configs/circle.yml (100%) create mode 100644 pip-freeze.txt diff --git a/.gitignore b/.gitignore index 1fef27d..ed56b7c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,12 +10,10 @@ __pycache__/ .DS_Store tags .cache/ -*.egg-info/ -*.swp +*.sw[op] # Exclude these directories bin/ -lib/ data/ # Distribution / packaging @@ -68,3 +66,8 @@ docs/_build/ # PyBuilder target/ + +# IDE and editor stuff +.idea/ +.vscode/ +.ropeproject/ diff --git a/.ycm_extra_conf.py b/.ycm_extra_conf.py deleted file mode 100644 index dcea5a4..0000000 --- a/.ycm_extra_conf.py +++ /dev/null @@ -1,190 +0,0 @@ -# This file is NOT licensed under the GPLv3, which is the license for the rest -# of YouCompleteMe. -# -# Here's the license text for this file: -# -# This is free and unencumbered software released into the public domain. -# -# Anyone is free to copy, modify, publish, use, compile, sell, or -# distribute this software, either in source code form or as a compiled -# binary, for any purpose, commercial or non-commercial, and by any -# means. -# -# In jurisdictions that recognize copyright laws, the author or authors -# of this software dedicate any and all copyright interest in the -# software to the public domain. We make this dedication for the benefit -# of the public at large and to the detriment of our heirs and -# successors. We intend this dedication to be an overt act of -# relinquishment in perpetuity of all present and future rights to this -# software under copyright law. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR -# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -# OTHER DEALINGS IN THE SOFTWARE. -# -# For more information, please refer to - -import os -import ycm_core - -# These are the compilation flags that will be used in case there's no -# compilation database set (by default, one is not set). -# CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR. -flags = [ -'-Wall', -'-Wextra', -'-Werror', -#'-Wc++98-compat', -'-Wno-long-long', -'-Wno-variadic-macros', -'-fexceptions', -'-DNDEBUG', -# You 100% do NOT need -DUSE_CLANG_COMPLETER in your flags; only the YCM -# source code needs it. -'-DUSE_CLANG_COMPLETER', -# THIS IS IMPORTANT! Without a "-std=" flag, clang won't know which -# language to use when compiling headers. So it will guess. Badly. So C++ -# headers will be compiled as C headers. You don't want that so ALWAYS specify -# a "-std=". -# For a C project, you would set this to something like 'c99' instead of -# 'c++11'. -'-msse4.2', -# ...and the same thing goes for the magic -x option which specifies the -# language that the files to be compiled are written in. This is mostly -# relevant for c++ headers. -# For a C project, you would set this to 'c' instead of 'c++'. -'-x', -'c++', -'-isystem', -'../BoostParts', -'-isystem', -# This path will only work on OS X, but extra paths that don't exist are not -# harmful -'/System/Library/Frameworks/Python.framework/Headers', -'-isystem', -'../llvm/include', -'-isystem', -'../llvm/tools/clang/include', -'-I', -'.', -'-I', -'./include', -'-I', -'./ClangCompleter', -'-isystem', -'./tests/gmock/gtest', -'-isystem', -'./tests/gmock/gtest/include', -'-isystem', -'./tests/gmock', -'-isystem', -'./tests/gmock/include', -] - - -# Set this to the absolute path to the folder (NOT the file!) containing the -# compile_commands.json file to use that instead of 'flags'. See here for -# more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html -# -# You can get CMake to generate this file for you by adding: -# set( CMAKE_EXPORT_COMPILE_COMMANDS 1 ) -# to your CMakeLists.txt file. -# -# Most projects will NOT need to set this to anything; you can just change the -# 'flags' list of compilation flags. Notice that YCM itself uses that approach. -compilation_database_folder = '' - -if os.path.exists( compilation_database_folder ): - database = ycm_core.CompilationDatabase( compilation_database_folder ) -else: - database = None - -SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ] - -def DirectoryOfThisScript(): - return os.path.dirname( os.path.abspath( __file__ ) ) - - -def MakeRelativePathsInFlagsAbsolute( flags, working_directory ): - if not working_directory: - return list( flags ) - new_flags = [] - make_next_absolute = False - path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ] - for flag in flags: - new_flag = flag - - if make_next_absolute: - make_next_absolute = False - if not flag.startswith( '/' ): - new_flag = os.path.join( working_directory, flag ) - - for path_flag in path_flags: - if flag == path_flag: - make_next_absolute = True - break - - if flag.startswith( path_flag ): - path = flag[ len( path_flag ): ] - new_flag = path_flag + os.path.join( working_directory, path ) - break - - if new_flag: - new_flags.append( new_flag ) - return new_flags - - -def IsHeaderFile( filename ): - extension = os.path.splitext( filename )[ 1 ] - return extension in [ '.h', '.hxx', '.hpp', '.hh' ] - - -def GetCompilationInfoForFile( filename ): - # The compilation_commands.json file generated by CMake does not have entries - # for header files. So we do our best by asking the db for flags for a - # corresponding source file, if any. If one exists, the flags for that file - # should be good enough. - if IsHeaderFile( filename ): - basename = os.path.splitext( filename )[ 0 ] - for extension in SOURCE_EXTENSIONS: - replacement_file = basename + extension - if os.path.exists( replacement_file ): - compilation_info = database.GetCompilationInfoForFile( - replacement_file ) - if compilation_info.compiler_flags_: - return compilation_info - return None - return database.GetCompilationInfoForFile( filename ) - - -def FlagsForFile( filename, **kwargs ): - if database: - # Bear in mind that compilation_info.compiler_flags_ does NOT return a - # python list, but a "list-like" StringVec object - compilation_info = GetCompilationInfoForFile( filename ) - if not compilation_info: - return None - - final_flags = MakeRelativePathsInFlagsAbsolute( - compilation_info.compiler_flags_, - compilation_info.compiler_working_dir_ ) - - # NOTE: This is just for YouCompleteMe; it's highly likely that your project - # does NOT need to remove the stdlib flag. DO NOT USE THIS IN YOUR - # ycm_extra_conf IF YOU'RE NOT 100% SURE YOU NEED IT. - try: - final_flags.remove( '-stdlib=libc++' ) - except ValueError: - pass - else: - relative_to = DirectoryOfThisScript() - final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to ) - - return { - 'flags': final_flags, - 'do_cache': True - } diff --git a/MANIFEST.in b/MANIFEST.in index b357a82..85ec854 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,6 @@ include LICENSE include README.rst +include cpuinfo.py include include/*.h include src/*.cc include src/*.cpp diff --git a/Makefile b/Makefile index fb28562..a111311 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,8 @@ -include cpp.mk include python.mk +include cpp.mk + +.PHONY: help +help: ## show this message and exit + @grep -E '^[a-zA-Z_0-9%-]+:.*?## .*$$' $(MAKEFILE_LIST) \ + | awk -F':' '{print $$(NF-1)":"$$NF}' | sort \ + | awk 'BEGIN {FS = ":.*?## "}; {printf "$(BOLD)%-24s$(END) %s\n", $$1, $$2}' diff --git a/README.rst b/README.rst index 5020f54..51e69d1 100644 --- a/README.rst +++ b/README.rst @@ -41,9 +41,9 @@ an optional ``seed`` parameter: >>> import metrohash ... >>> metrohash.metrohash64("abc", seed=0) - 17099979927131455419L + 17099979927131455419 >>> metrohash.metrohash128("abc") - 182995299641628952910564950850867298725L + 182995299641628952910564950850867298725 For incremental hashing, use ``MetroHash64`` and ``MetroHash128`` classes. @@ -57,7 +57,7 @@ processing large inputs and stream data. Example with two slices: >>> mh.update("Nobody inspects") >>> mh.update(" the spammish repetition") >>> mh.intdigest() - 7851180100622203313L + 7851180100622203313 Note that the resulting hash value above is the same as in: @@ -66,7 +66,7 @@ Note that the resulting hash value above is the same as in: >>> mh = metrohash.MetroHash64() >>> mh.update("Nobody inspects the spammish repetition") >>> mh.intdigest() - 7851180100622203313L + 7851180100622203313 Development diff --git a/cpp.mk b/cpp.mk index 801e8c8..b311eb0 100644 --- a/cpp.mk +++ b/cpp.mk @@ -24,8 +24,6 @@ TEST_TARGETS := $(patsubst $(BUILDDIR)/%.o, $(BINDIR)/%, $(TEST_OBJECTS)) SOURCES := $(filter-out $(RUN_SOURCES) $(TEST_SOURCES), $(ALL_SOURCES)) OBJECTS := $(patsubst %, $(BUILDDIR)/%, $(SOURCES:.$(SRCEXT)=.o)) -.PHONY: clean_cpp test_cpp run_cpp - .SECONDARY: $(RUN_OBJECTS) $(TEST_OBJECTS) $(OBJECTS) $(BUILDDIR)/%.o: %.$(SRCEXT) @@ -36,16 +34,19 @@ $(BINDIR)/%: $(BUILDDIR)/%.o $(OBJECTS) @mkdir -p $(dir $@) $(CXX) $(LIB) $(LDFLAGS) $^ -o $@ -clean_cpp: +.PHONY: cpp-clean +cpp-clean: ## clean up C++ project rm -rf ./$(BINDIR)/ ./$(BUILDDIR)/ -run_cpp: $(RUN_TARGETS) +.PHONY: cpp-run +cpp-run: $(RUN_TARGETS) ## compile and run C++ program @for target in $(RUN_TARGETS); do \ echo $$target >&2; \ time ./$$target $(INPUT); \ done -test_cpp: $(TEST_TARGETS) +.PHONY: cpp-test +cpp-test: $(TEST_TARGETS) ## run C++ tests @for target in $(TEST_TARGETS); do \ echo $$target >&2; \ ./$$target; \ diff --git a/cpuinfo.py b/cpuinfo.py new file mode 100644 index 0000000..9b353ed --- /dev/null +++ b/cpuinfo.py @@ -0,0 +1,1588 @@ +#!/usr/bin/env python +# -*- coding: UTF-8 -*- + +# Copyright (c) 2014-2016, Matthew Brennan Jones +# Py-cpuinfo is a Python module to show the cpuinfo of a processor +# It uses a MIT style license +# It is hosted at: https://github.com/workhorsy/py-cpuinfo +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +import os +import sys +import re +import time +import platform +import multiprocessing +import ctypes +import pickle +import base64 +import subprocess + +try: + import _winreg as winreg +except ImportError as err: + try: + import winreg + except ImportError as err: + winreg = None + +PY2 = sys.version_info[0] == 2 + + +class DataSource(object): + bits = platform.architecture()[0] + cpu_count = multiprocessing.cpu_count() + is_windows = platform.system().lower() == 'windows' + raw_arch_string = platform.machine() + + @staticmethod + def has_proc_cpuinfo(): + return os.path.exists('/proc/cpuinfo') + + @staticmethod + def has_dmesg(): + return len(program_paths('dmesg')) > 0 + + @staticmethod + def has_cpufreq_info(): + return len(program_paths('cpufreq-info')) > 0 + + @staticmethod + def has_sestatus(): + return len(program_paths('sestatus')) > 0 + + @staticmethod + def has_sysctl(): + return len(program_paths('sysctl')) > 0 + + @staticmethod + def has_isainfo(): + return len(program_paths('isainfo')) > 0 + + @staticmethod + def has_kstat(): + return len(program_paths('kstat')) > 0 + + @staticmethod + def has_sysinfo(): + return len(program_paths('sysinfo')) > 0 + + @staticmethod + def has_lscpu(): + return len(program_paths('lscpu')) > 0 + + @staticmethod + def cat_proc_cpuinfo(): + return run_and_get_stdout(['cat', '/proc/cpuinfo']) + + @staticmethod + def cpufreq_info(): + return run_and_get_stdout(['cpufreq-info']) + + @staticmethod + def sestatus_allow_execheap(): + return run_and_get_stdout(['sestatus', '-b'], ['grep', '-i', '"allow_execheap"'])[1].strip().lower().endswith('on') + + @staticmethod + def sestatus_allow_execmem(): + return run_and_get_stdout(['sestatus', '-b'], ['grep', '-i', '"allow_execmem"'])[1].strip().lower().endswith('on') + + @staticmethod + def dmesg_a(): + return run_and_get_stdout(['dmesg', '-a']) + + @staticmethod + def sysctl_machdep_cpu_hw_cpufrequency(): + return run_and_get_stdout(['sysctl', 'machdep.cpu', 'hw.cpufrequency']) + + @staticmethod + def isainfo_vb(): + return run_and_get_stdout(['isainfo', '-vb']) + + @staticmethod + def kstat_m_cpu_info(): + return run_and_get_stdout(['kstat', '-m', 'cpu_info']) + + @staticmethod + def sysinfo_cpu(): + return run_and_get_stdout(['sysinfo', '-cpu']) + + @staticmethod + def lscpu(): + return run_and_get_stdout(['lscpu']) + + @staticmethod + def winreg_processor_brand(): + key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"Hardware\Description\System\CentralProcessor\0") + processor_brand = winreg.QueryValueEx(key, "ProcessorNameString")[0] + winreg.CloseKey(key) + return processor_brand + + @staticmethod + def winreg_vendor_id(): + key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"Hardware\Description\System\CentralProcessor\0") + vendor_id = winreg.QueryValueEx(key, "VendorIdentifier")[0] + winreg.CloseKey(key) + return vendor_id + + @staticmethod + def winreg_raw_arch_string(): + key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SYSTEM\CurrentControlSet\Control\Session Manager\Environment") + raw_arch_string = winreg.QueryValueEx(key, "PROCESSOR_ARCHITECTURE")[0] + winreg.CloseKey(key) + return raw_arch_string + + @staticmethod + def winreg_hz_actual(): + key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"Hardware\Description\System\CentralProcessor\0") + hz_actual = winreg.QueryValueEx(key, "~Mhz")[0] + winreg.CloseKey(key) + hz_actual = to_hz_string(hz_actual) + return hz_actual + + @staticmethod + def winreg_feature_bits(): + key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"Hardware\Description\System\CentralProcessor\0") + feature_bits = winreg.QueryValueEx(key, "FeatureSet")[0] + winreg.CloseKey(key) + return feature_bits + + +def obj_to_b64(thing): + a = thing + b = pickle.dumps(a) + c = base64.b64encode(b) + d = c.decode('utf8') + return d + + +def b64_to_obj(thing): + a = base64.b64decode(thing) + b = pickle.loads(a) + return b + + +def run_and_get_stdout(command, pipe_command=None): + if not pipe_command: + p1 = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + output = p1.communicate()[0] + if not PY2: + output = output.decode(encoding='UTF-8') + return p1.returncode, output + else: + p1 = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + p2 = subprocess.Popen(pipe_command, stdin=p1.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + p1.stdout.close() + output = p2.communicate()[0] + if not PY2: + output = output.decode(encoding='UTF-8') + return p2.returncode, output + + +def program_paths(program_name): + paths = [] + exts = filter(None, os.environ.get('PATHEXT', '').split(os.pathsep)) + for p in os.environ['PATH'].split(os.pathsep): + p = os.path.join(p, program_name) + if os.access(p, os.X_OK): + paths.append(p) + for e in exts: + pext = p + e + if os.access(pext, os.X_OK): + paths.append(pext) + return paths + + +def _get_field_actual(cant_be_number, raw_string, field_names): + for line in raw_string.splitlines(): + for field_name in field_names: + field_name = field_name.lower() + if ':' in line: + left, right = line.split(':', 1) + left = left.strip().lower() + right = right.strip() + if left == field_name and len(right) > 0: + if cant_be_number: + if not right.isdigit(): + return right + else: + return right + + return None + + +def _get_field(cant_be_number, raw_string, convert_to, default_value, *field_names): + retval = _get_field_actual(cant_be_number, raw_string, field_names) + + # Convert the return value + if retval and convert_to: + try: + retval = convert_to(retval) + except Exception: + retval = default_value + + # Return the default if there is no return value + if retval is None: + retval = default_value + + return retval + + +def _get_hz_string_from_brand(processor_brand): + # Just return 0 if the processor brand does not have the Hz + if 'hz' not in processor_brand.lower(): + return 1, '0.0' + + hz_brand = processor_brand.lower() + scale = 1 + + if hz_brand.endswith('mhz'): + scale = 6 + elif hz_brand.endswith('ghz'): + scale = 9 + if '@' in hz_brand: + hz_brand = hz_brand.split('@')[1] + else: + hz_brand = hz_brand.rsplit(None, 1)[1] + + hz_brand = hz_brand.rstrip('mhz').rstrip('ghz').strip() + hz_brand = to_hz_string(hz_brand) + + return scale, hz_brand + + +def _get_hz_string_from_beagle_bone(): + scale, hz_brand = 1, '0.0' + + if not DataSource.has_cpufreq_info(): + return scale, hz_brand + + returncode, output = DataSource.cpufreq_info() + if returncode != 0: + return scale, hz_brand + + hz_brand = output.split('current CPU frequency is')[1].split('.')[0].lower() + + if hz_brand.endswith('mhz'): + scale = 6 + elif hz_brand.endswith('ghz'): + scale = 9 + hz_brand = hz_brand.rstrip('mhz').rstrip('ghz').strip() + hz_brand = to_hz_string(hz_brand) + + return scale, hz_brand + + +def _get_hz_string_from_lscpu(): + scale, hz_brand = 1, '0.0' + + if not DataSource.has_lscpu(): + return scale, hz_brand + + returncode, output = DataSource.lscpu() + if returncode != 0: + return scale, hz_brand + + new_hz = _get_field(False, output, None, None, 'CPU max MHz', 'CPU MHz') + if new_hz is None: + return scale, hz_brand + + new_hz = to_hz_string(new_hz) + scale = 6 + + return scale, new_hz + + +def to_friendly_hz(ticks, scale): + # Get the raw Hz as a string + left, right = to_raw_hz(ticks, scale) + ticks = '{0}.{1}'.format(left, right) + + # Get the location of the dot, and remove said dot + dot_index = ticks.index('.') + ticks = ticks.replace('.', '') + + # Get the Hz symbol and scale + symbol = "Hz" + scale = 0 + if dot_index > 9: + symbol = "GHz" + scale = 9 + elif dot_index > 6: + symbol = "MHz" + scale = 6 + elif dot_index > 3: + symbol = "KHz" + scale = 3 + + # Get the Hz with the dot at the new scaled point + ticks = '{0}.{1}'.format(ticks[:-scale-1], ticks[-scale-1:]) + + # Format the ticks to have 4 numbers after the decimal + # and remove any superfluous zeroes. + ticks = '{0:.4f} {1}'.format(float(ticks), symbol) + ticks = ticks.rstrip('0') + + return ticks + + +def to_raw_hz(ticks, scale): + # Scale the numbers + ticks = ticks.lstrip('0') + old_index = ticks.index('.') + ticks = ticks.replace('.', '') + ticks = ticks.ljust(scale + old_index+1, '0') + new_index = old_index + scale + ticks = '{0}.{1}'.format(ticks[:new_index], ticks[new_index:]) + left, right = ticks.split('.') + left, right = int(left), int(right) + return left, right + + +def to_hz_string(ticks): + # Convert to string + ticks = '{0}'.format(ticks) + + # Add decimal if missing + if '.' not in ticks: + ticks = '{0}.0'.format(ticks) + + # Remove trailing zeros + ticks = ticks.rstrip('0') + + # Add one trailing zero for empty right side + if ticks.endswith('.'): + ticks = '{0}0'.format(ticks) + + return ticks + + +def parse_arch(raw_arch_string): + arch, bits = None, None + raw_arch_string = raw_arch_string.lower() + + # X86 + if re.match('^i\d86$|^x86$|^x86_32$|^i86pc$|^ia32$|^ia-32$|^bepc$', raw_arch_string): + arch = 'X86_32' + bits = 32 + elif re.match('^x64$|^x86_64$|^x86_64t$|^i686-64$|^amd64$|^ia64$|^ia-64$', raw_arch_string): + arch = 'X86_64' + bits = 64 + # ARM + elif re.match('^armv8-a$', raw_arch_string): + arch = 'ARM_8' + bits = 64 + elif re.match('^armv7$|^armv7[a-z]$|^armv7-[a-z]$|^armv6[a-z]$', raw_arch_string): + arch = 'ARM_7' + bits = 32 + elif re.match('^armv8$|^armv8[a-z]$|^armv8-[a-z]$', raw_arch_string): + arch = 'ARM_8' + bits = 32 + # PPC + elif re.match('^ppc32$|^prep$|^pmac$|^powermac$', raw_arch_string): + arch = 'PPC_32' + bits = 32 + elif re.match('^powerpc$|^ppc64$', raw_arch_string): + arch = 'PPC_64' + bits = 64 + # SPARC + elif re.match('^sparc32$|^sparc$', raw_arch_string): + arch = 'SPARC_32' + bits = 32 + elif re.match('^sparc64$|^sun4u$|^sun4v$', raw_arch_string): + arch = 'SPARC_64' + bits = 64 + + return arch, bits + + +def is_bit_set(reg, bit): + mask = 1 << bit + is_set = reg & mask > 0 + return is_set + + +class CPUID(object): + def __init__(self): + # Figure info if SE Linux is on and in enforcing mode + self.is_selinux_enforcing = False + + # Just return if the SE Linux Status Tool is not installed + if not DataSource.has_sestatus(): + return + + # Figure info if we can execute heap and execute memory + can_selinux_exec_heap = DataSource.sestatus_allow_execheap() + can_selinux_exec_memory = DataSource.sestatus_allow_execmem() + self.is_selinux_enforcing = (not can_selinux_exec_heap or not can_selinux_exec_memory) + + def _asm_func(self, restype=None, argtypes=None, byte_code=None): + if argtypes is None: + argtypes = [] + if byte_code is None: + byte_code = [] + byte_code = bytes.join(b'', byte_code) + + if DataSource.is_windows: + # Allocate a memory segment the size of the byte code, and make it executable + size = len(byte_code) + MEM_COMMIT = ctypes.c_ulong(0x1000) + PAGE_EXECUTE_READWRITE = ctypes.c_ulong(0x40) + address = ctypes.windll.kernel32.VirtualAlloc( + ctypes.c_int(0), ctypes.c_size_t(size), MEM_COMMIT, PAGE_EXECUTE_READWRITE) + if not address: + raise Exception("Failed to VirtualAlloc") + + # Copy the byte code into the memory segment + memmove = ctypes.CFUNCTYPE( + ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_size_t)(ctypes._memmove_addr) + if memmove(address, byte_code, size) < 0: + raise Exception("Failed to memmove") + else: + # Allocate a memory segment the size of the byte code + size = len(byte_code) + address = ctypes.pythonapi.valloc(size) + if not address: + raise Exception("Failed to valloc") + + # Mark the memory segment as writeable only + if not self.is_selinux_enforcing: + WRITE = 0x2 + if ctypes.pythonapi.mprotect(address, size, WRITE) < 0: + raise Exception("Failed to mprotect") + + # Copy the byte code into the memory segment + if ctypes.pythonapi.memmove(address, byte_code, size) < 0: + raise Exception("Failed to memmove") + + # Mark the memory segment as writeable and executable only + if not self.is_selinux_enforcing: + WRITE_EXECUTE = 0x2 | 0x4 + if ctypes.pythonapi.mprotect(address, size, WRITE_EXECUTE) < 0: + raise Exception("Failed to mprotect") + + # Cast the memory segment into a function + functype = ctypes.CFUNCTYPE(restype, *argtypes) + fun = functype(address) + return fun, address + + def _run_asm(self, *byte_code): + # Convert the byte code into a function that returns an int + if DataSource.bits == '64bit': + restype = ctypes.c_uint64 + else: + restype = ctypes.c_uint32 + argtypes = () + func, address = self._asm_func(restype, argtypes, byte_code) + + # Call the byte code like a function + retval = func() + + size = ctypes.c_size_t(len(byte_code)) + + # Free the function memory segment + if DataSource.is_windows: + MEM_RELEASE = ctypes.c_ulong(0x8000) + ctypes.windll.kernel32.VirtualFree(address, size, MEM_RELEASE) + else: + # Remove the executable tag on the memory + READ_WRITE = 0x1 | 0x2 + if ctypes.pythonapi.mprotect(address, size, READ_WRITE) < 0: + raise Exception("Failed to mprotect") + + ctypes.pythonapi.free(address) + + return retval + + # FIXME: We should not have to use different instructions to + # set eax to 0 or 1, on 32bit and 64bit machines. + def _zero_eax(self): + if DataSource.bits == '64bit': + return ( + b"\x66\xB8\x00\x00" # mov eax,0x0" + ) + else: + return ( + b"\x31\xC0" # xor ax,ax + ) + + def _one_eax(self): + if DataSource.bits == '64bit': + return ( + b"\x66\xB8\x01\x00" # mov eax,0x1" + ) + else: + return ( + b"\x31\xC0" # xor ax,ax + b"\x40" # inc ax + ) + + # http://en.wikipedia.org/wiki/CPUID#EAX.3D0:_Get_vendor_ID + def get_vendor_id(self): + # EBX + ebx = self._run_asm( + self._zero_eax(), + b"\x0F\xA2" # cpuid + b"\x89\xD8" # mov ax,bx + b"\xC3" # ret + ) + + # ECX + ecx = self._run_asm( + self._zero_eax(), + b"\x0f\xa2" # cpuid + b"\x89\xC8" # mov ax,cx + b"\xC3" # ret + ) + + # EDX + edx = self._run_asm( + self._zero_eax(), + b"\x0f\xa2" # cpuid + b"\x89\xD0" # mov ax,dx + b"\xC3" # ret + ) + + # Each 4bits is an ascii letter in the name + vendor_id = [] + for reg in [ebx, edx, ecx]: + for n in [0, 8, 16, 24]: + vendor_id.append(chr((reg >> n) & 0xFF)) + vendor_id = ''.join(vendor_id) + + return vendor_id + + # http://en.wikipedia.org/wiki/CPUID#EAX.3D1:_Processor_Info_and_Feature_Bits + def get_info(self): + # EAX + eax = self._run_asm( + self._one_eax(), + b"\x0f\xa2" # cpuid + b"\xC3" # ret + ) + + # Get the CPU info + stepping = (eax >> 0) & 0xF # 4 bits + model = (eax >> 4) & 0xF # 4 bits + family = (eax >> 8) & 0xF # 4 bits + processor_type = (eax >> 12) & 0x3 # 2 bits + extended_model = (eax >> 16) & 0xF # 4 bits + extended_family = (eax >> 20) & 0xFF # 8 bits + + return { + 'stepping': stepping, + 'model': model, + 'family': family, + 'processor_type': processor_type, + 'extended_model': extended_model, + 'extended_family': extended_family + } + + # https://en.wikipedia.org/wiki/CPUID#EAX.3D80000000h:_Get_Highest_Extended_Function_Supported + def get_max_extension_support(self): + # Check for extension support + max_extension_support = self._run_asm( + b"\xB8\x00\x00\x00\x80" # mov ax,0x80000000 + b"\x0f\xa2" # cpuid + b"\xC3" # ret + ) + + return max_extension_support + + # http://en.wikipedia.org/wiki/CPUID#EAX.3D1:_Processor_Info_and_Feature_Bits + def get_flags(self, max_extension_support): + # EDX + edx = self._run_asm( + self._one_eax(), + b"\x0f\xa2" # cpuid + b"\x89\xD0" # mov ax,dx + b"\xC3" # ret + ) + + # ECX + ecx = self._run_asm( + self._one_eax(), + b"\x0f\xa2" # cpuid + b"\x89\xC8" # mov ax,cx + b"\xC3" # ret + ) + + # Get the CPU flags + flags = { + 'fpu': is_bit_set(edx, 0), + 'vme': is_bit_set(edx, 1), + 'de': is_bit_set(edx, 2), + 'pse': is_bit_set(edx, 3), + 'tsc': is_bit_set(edx, 4), + 'msr': is_bit_set(edx, 5), + 'pae': is_bit_set(edx, 6), + 'mce': is_bit_set(edx, 7), + 'cx8': is_bit_set(edx, 8), + 'apic': is_bit_set(edx, 9), + # 'reserved1': is_bit_set(edx, 10), + 'sep': is_bit_set(edx, 11), + 'mtrr': is_bit_set(edx, 12), + 'pge': is_bit_set(edx, 13), + 'mca': is_bit_set(edx, 14), + 'cmov': is_bit_set(edx, 15), + 'pat': is_bit_set(edx, 16), + 'pse36': is_bit_set(edx, 17), + 'pn': is_bit_set(edx, 18), + 'clflush': is_bit_set(edx, 19), + # 'reserved2': is_bit_set(edx, 20), + 'dts': is_bit_set(edx, 21), + 'acpi': is_bit_set(edx, 22), + 'mmx': is_bit_set(edx, 23), + 'fxsr': is_bit_set(edx, 24), + 'sse': is_bit_set(edx, 25), + 'sse2': is_bit_set(edx, 26), + 'ss': is_bit_set(edx, 27), + 'ht': is_bit_set(edx, 28), + 'tm': is_bit_set(edx, 29), + 'ia64': is_bit_set(edx, 30), + 'pbe': is_bit_set(edx, 31), + + 'pni': is_bit_set(ecx, 0), + 'pclmulqdq': is_bit_set(ecx, 1), + 'dtes64': is_bit_set(ecx, 2), + 'monitor': is_bit_set(ecx, 3), + 'ds_cpl': is_bit_set(ecx, 4), + 'vmx': is_bit_set(ecx, 5), + 'smx': is_bit_set(ecx, 6), + 'est': is_bit_set(ecx, 7), + 'tm2': is_bit_set(ecx, 8), + 'ssse3': is_bit_set(ecx, 9), + 'cid': is_bit_set(ecx, 10), + # 'reserved3': is_bit_set(ecx, 11), + 'fma': is_bit_set(ecx, 12), + 'cx16': is_bit_set(ecx, 13), + 'xtpr': is_bit_set(ecx, 14), + 'pdcm': is_bit_set(ecx, 15), + # 'reserved4': is_bit_set(ecx, 16), + 'pcid': is_bit_set(ecx, 17), + 'dca': is_bit_set(ecx, 18), + 'sse4_1': is_bit_set(ecx, 19), + 'sse4_2': is_bit_set(ecx, 20), + 'x2apic': is_bit_set(ecx, 21), + 'movbe': is_bit_set(ecx, 22), + 'popcnt': is_bit_set(ecx, 23), + 'tscdeadline': is_bit_set(ecx, 24), + 'aes': is_bit_set(ecx, 25), + 'xsave': is_bit_set(ecx, 26), + 'osxsave': is_bit_set(ecx, 27), + 'avx': is_bit_set(ecx, 28), + 'f16c': is_bit_set(ecx, 29), + 'rdrnd': is_bit_set(ecx, 30), + 'hypervisor': is_bit_set(ecx, 31) + } + + # Get a list of only the flags that are true + flags = [k for k, v in flags.items() if v] + + # Get the Extended CPU flags + extended_flags = {} + + # https://en.wikipedia.org/wiki/CPUID#EAX.3D7.2C_ECX.3D0:_Extended_Features + if max_extension_support == 7: + pass + # FIXME: Are we missing all these flags too? + # avx2 et cetera ... + + # https://en.wikipedia.org/wiki/CPUID#EAX.3D80000001h:_Extended_Processor_Info_and_Feature_Bits + if max_extension_support >= 0x80000001: + # EBX # FIXME: This may need to be EDX instead + ebx = self._run_asm( + b"\xB8\x01\x00\x00\x80" # mov ax,0x80000001 + b"\x0f\xa2" # cpuid + b"\x89\xD8" # mov ax,bx + b"\xC3" # ret + ) + + # ECX + ecx = self._run_asm( + b"\xB8\x01\x00\x00\x80" # mov ax,0x80000001 + b"\x0f\xa2" # cpuid + b"\x89\xC8" # mov ax,cx + b"\xC3" # ret + ) + + # Get the extended CPU flags + extended_flags = { + 'fpu': is_bit_set(ebx, 0), + 'vme': is_bit_set(ebx, 1), + 'de': is_bit_set(ebx, 2), + 'pse': is_bit_set(ebx, 3), + 'tsc': is_bit_set(ebx, 4), + 'msr': is_bit_set(ebx, 5), + 'pae': is_bit_set(ebx, 6), + 'mce': is_bit_set(ebx, 7), + 'cx8': is_bit_set(ebx, 8), + 'apic': is_bit_set(ebx, 9), + # 'reserved': is_bit_set(ebx, 10), + 'syscall': is_bit_set(ebx, 11), + 'mtrr': is_bit_set(ebx, 12), + 'pge': is_bit_set(ebx, 13), + 'mca': is_bit_set(ebx, 14), + 'cmov': is_bit_set(ebx, 15), + 'pat': is_bit_set(ebx, 16), + 'pse36': is_bit_set(ebx, 17), + # 'reserved': is_bit_set(ebx, 18), + 'mp': is_bit_set(ebx, 19), + 'nx': is_bit_set(ebx, 20), + # 'reserved': is_bit_set(ebx, 21), + 'mmxext': is_bit_set(ebx, 22), + 'mmx': is_bit_set(ebx, 23), + 'fxsr': is_bit_set(ebx, 24), + 'fxsr_opt': is_bit_set(ebx, 25), + 'pdpe1gp': is_bit_set(ebx, 26), + 'rdtscp': is_bit_set(ebx, 27), + # 'reserved': is_bit_set(ebx, 28), + 'lm': is_bit_set(ebx, 29), + '3dnowext': is_bit_set(ebx, 30), + '3dnow': is_bit_set(ebx, 31), + + 'lahf_lm': is_bit_set(ecx, 0), + 'cmp_legacy': is_bit_set(ecx, 1), + 'svm': is_bit_set(ecx, 2), + 'extapic': is_bit_set(ecx, 3), + 'cr8_legacy': is_bit_set(ecx, 4), + 'abm': is_bit_set(ecx, 5), + 'sse4a': is_bit_set(ecx, 6), + 'misalignsse': is_bit_set(ecx, 7), + '3dnowprefetch': is_bit_set(ecx, 8), + 'osvw': is_bit_set(ecx, 9), + 'ibs': is_bit_set(ecx, 10), + 'xop': is_bit_set(ecx, 11), + 'skinit': is_bit_set(ecx, 12), + 'wdt': is_bit_set(ecx, 13), + # 'reserved': is_bit_set(ecx, 14), + 'lwp': is_bit_set(ecx, 15), + 'fma4': is_bit_set(ecx, 16), + 'tce': is_bit_set(ecx, 17), + # 'reserved': is_bit_set(ecx, 18), + 'nodeid_msr': is_bit_set(ecx, 19), + # 'reserved': is_bit_set(ecx, 20), + 'tbm': is_bit_set(ecx, 21), + 'topoext': is_bit_set(ecx, 22), + 'perfctr_core': is_bit_set(ecx, 23), + 'perfctr_nb': is_bit_set(ecx, 24), + # 'reserved': is_bit_set(ecx, 25), + 'dbx': is_bit_set(ecx, 26), + 'perftsc': is_bit_set(ecx, 27), + 'pci_l2i': is_bit_set(ecx, 28), + # 'reserved': is_bit_set(ecx, 29), + # 'reserved': is_bit_set(ecx, 30), + # 'reserved': is_bit_set(ecx, 31) + } + + # Get a list of only the flags that are true + extended_flags = [k for k, v in extended_flags.items() if v] + flags += extended_flags + + flags.sort() + return flags + + # https://en.wikipedia.org/wiki/CPUID#EAX.3D80000002h.2C80000003h.2C80000004h:_Processor_Brand_String + def get_processor_brand(self, max_extension_support): + processor_brand = "" + + # Processor brand string + if max_extension_support >= 0x80000004: + instructions = [ + b"\xB8\x02\x00\x00\x80", # mov ax,0x80000002 + b"\xB8\x03\x00\x00\x80", # mov ax,0x80000003 + b"\xB8\x04\x00\x00\x80" # mov ax,0x80000004 + ] + for instruction in instructions: + # EAX + eax = self._run_asm( + instruction, # mov ax,0x8000000? + b"\x0f\xa2" # cpuid + b"\x89\xC0" # mov ax,ax + b"\xC3" # ret + ) + + # EBX + ebx = self._run_asm( + instruction, # mov ax,0x8000000? + b"\x0f\xa2" # cpuid + b"\x89\xD8" # mov ax,bx + b"\xC3" # ret + ) + + # ECX + ecx = self._run_asm( + instruction, # mov ax,0x8000000? + b"\x0f\xa2" # cpuid + b"\x89\xC8" # mov ax,cx + b"\xC3" # ret + ) + + # EDX + edx = self._run_asm( + instruction, # mov ax,0x8000000? + b"\x0f\xa2" # cpuid + b"\x89\xD0" # mov ax,dx + b"\xC3" # ret + ) + + # Combine each of the 4 bytes in each register into the string + for reg in [eax, ebx, ecx, edx]: + for n in [0, 8, 16, 24]: + processor_brand += chr((reg >> n) & 0xFF) + + # Strip off any trailing NULL terminators and white space + processor_brand = processor_brand.strip("\0").strip() + + return processor_brand + + # https://en.wikipedia.org/wiki/CPUID#EAX.3D80000006h:_Extended_L2_Cache_Features + def get_cache(self, max_extension_support): + cache_info = {} + + # Just return if the cache feature is not supported + if max_extension_support < 0x80000006: + return cache_info + + # ECX + ecx = self._run_asm( + b"\xB8\x06\x00\x00\x80" # mov ax,0x80000006 + b"\x0f\xa2" # cpuid + b"\x89\xC8" # mov ax,cx + b"\xC3" # ret + ) + + cache_info = { + 'size_kb': ecx & 0xFF, + 'line_size_b': (ecx >> 12) & 0xF, + 'associativity': (ecx >> 16) & 0xFFFF + } + + return cache_info + + def get_ticks(self): + retval = None + + if DataSource.bits == '32bit': + # Works on x86_32 + restype = None + argtypes = (ctypes.POINTER(ctypes.c_uint), ctypes.POINTER(ctypes.c_uint)) + get_ticks_x86_32, address = self._asm_func( + restype, + argtypes, + [ + b"\x55", # push bp + b"\x89\xE5", # mov bp,sp + b"\x31\xC0", # xor ax,ax + b"\x0F\xA2", # cpuid + b"\x0F\x31", # rdtsc + b"\x8B\x5D\x08", # mov bx,[di+0x8] + b"\x8B\x4D\x0C", # mov cx,[di+0xc] + b"\x89\x13", # mov [bp+di],dx + b"\x89\x01", # mov [bx+di],ax + b"\x5D", # pop bp + b"\xC3" # ret + ] + ) + + high = ctypes.c_uint32(0) + low = ctypes.c_uint32(0) + + get_ticks_x86_32(ctypes.byref(high), ctypes.byref(low)) + retval = ((high.value << 32) & 0xFFFFFFFF00000000) | low.value + elif DataSource.bits == '64bit': + # Works on x86_64 + restype = ctypes.c_uint64 + argtypes = () + get_ticks_x86_64, address = self._asm_func( + restype, + argtypes, + [ + b"\x48", # dec ax + b"\x31\xC0", # xor ax,ax + b"\x0F\xA2", # cpuid + b"\x0F\x31", # rdtsc + b"\x48", # dec ax + b"\xC1\xE2\x20", # shl dx,byte 0x20 + b"\x48", # dec ax + b"\x09\xD0", # or ax,dx + b"\xC3", # ret + ] + ) + retval = get_ticks_x86_64() + + return retval + + def get_raw_hz(self): + start = self.get_ticks() + time.sleep(1) + end = self.get_ticks() + ticks = (end - start) + return ticks + + +def get_cpu_info_from_cpuid(): + """ + Returns the CPU info gathered by querying the X86 cpuid register in a new process. + Returns None of non X86 cpus. + Returns None if SELinux is in enforcing mode. + """ + + returncode, output = run_and_get_stdout([sys.executable, "-c", "import cpuinfo; print(cpuinfo.actual_get_cpu_info_from_cpuid())"]) + if returncode != 0: + return None + info = b64_to_obj(output) + return info + + +def actual_get_cpu_info_from_cpuid(): + # Get the CPU arch and bits + arch, bits = parse_arch(DataSource.raw_arch_string) + + # Return none if this is not an X86 CPU + if arch not in ['X86_32', 'X86_64']: + return None + + # Return none if SE Linux is in enforcing mode + cpuid = CPUID() + if cpuid.is_selinux_enforcing: + return None + + # Get the cpu info from the CPUID register + max_extension_support = cpuid.get_max_extension_support() + cache_info = cpuid.get_cache(max_extension_support) + info = cpuid.get_info() + + processor_brand = cpuid.get_processor_brand(max_extension_support) + + # Get the Hz and scale + hz_actual = cpuid.get_raw_hz() + hz_actual = to_hz_string(hz_actual) + + # Get the Hz and scale + scale, hz_advertised = _get_hz_string_from_brand(processor_brand) + + info = { + 'vendor_id': cpuid.get_vendor_id(), + 'hardware': '', + 'brand': processor_brand, + + 'hz_advertised': to_friendly_hz(hz_advertised, scale), + 'hz_actual': to_friendly_hz(hz_actual, 6), + 'hz_advertised_raw': to_raw_hz(hz_advertised, scale), + 'hz_actual_raw': to_raw_hz(hz_actual, 6), + + 'arch': arch, + 'bits': bits, + 'count': DataSource.cpu_count, + 'raw_arch_string': DataSource.raw_arch_string, + + 'l2_cache_size': cache_info['size_kb'], + 'l2_cache_line_size': cache_info['line_size_b'], + 'l2_cache_associativity': hex(cache_info['associativity']), + + 'stepping': info['stepping'], + 'model': info['model'], + 'family': info['family'], + 'processor_type': info['processor_type'], + 'extended_model': info['extended_model'], + 'extended_family': info['extended_family'], + 'flags': cpuid.get_flags(max_extension_support) + } + return obj_to_b64(info) + + +def get_cpu_info_from_proc_cpuinfo(): + """ + Returns the CPU info gathered from /proc/cpuinfo. Will return None if + /proc/cpuinfo is not found. + """ + try: + # Just return None if there is no cpuinfo + if not DataSource.has_proc_cpuinfo(): + return None + + returncode, output = DataSource.cat_proc_cpuinfo() + if returncode != 0: + return None + + # Various fields + vendor_id = _get_field(False, output, None, '', 'vendor_id', 'vendor id', 'vendor') + processor_brand = _get_field(True, output, None, None, 'model name', 'cpu', 'processor') + cache_size = _get_field(False, output, None, '', 'cache size') + stepping = _get_field(False, output, int, 0, 'stepping') + model = _get_field(False, output, int, 0, 'model') + family = _get_field(False, output, int, 0, 'cpu family') + hardware = _get_field(False, output, None, '', 'Hardware') + # Flags + flags = _get_field(False, output, None, None, 'flags', 'Features').split() + flags.sort() + + # Convert from MHz string to Hz + hz_actual = _get_field(False, output, None, '', 'cpu MHz', 'cpu speed', 'clock') + hz_actual = hz_actual.lower().rstrip('mhz').strip() + hz_actual = to_hz_string(hz_actual) + + # Convert from GHz/MHz string to Hz + scale, hz_advertised = _get_hz_string_from_brand(processor_brand) + + # Try getting the Hz for a BeagleBone + if hz_advertised == '0.0': + scale, hz_advertised = _get_hz_string_from_beagle_bone() + hz_actual = hz_advertised + + # Try getting the Hz for a lscpu + if hz_advertised == '0.0': + scale, hz_advertised = _get_hz_string_from_lscpu() + hz_actual = hz_advertised + + # Get the CPU arch and bits + arch, bits = parse_arch(DataSource.raw_arch_string) + + return { + 'vendor_id': vendor_id, + 'hardware': hardware, + 'brand': processor_brand, + + 'hz_advertised': to_friendly_hz(hz_advertised, scale), + 'hz_actual': to_friendly_hz(hz_actual, 6), + 'hz_advertised_raw': to_raw_hz(hz_advertised, scale), + 'hz_actual_raw': to_raw_hz(hz_actual, 6), + + 'arch': arch, + 'bits': bits, + 'count': DataSource.cpu_count, + 'raw_arch_string': DataSource.raw_arch_string, + + 'l2_cache_size': cache_size, + 'l2_cache_line_size': 0, + 'l2_cache_associativity': 0, + + 'stepping': stepping, + 'model': model, + 'family': family, + 'processor_type': 0, + 'extended_model': 0, + 'extended_family': 0, + 'flags': flags + } + except Exception: + # raise # NOTE: To have this throw on error, uncomment this line + return None + + +def get_cpu_info_from_dmesg(): + """ + Returns the CPU info gathered from dmesg. Will return None if + dmesg is not found or does not have the desired info. + """ + try: + # Just return None if there is no dmesg + if not DataSource.has_dmesg(): + return None + + # If dmesg fails return None + returncode, output = DataSource.dmesg_a() + if output is None or returncode != 0: + return None + + # Processor Brand + long_brand = output.split('CPU: ')[1].split('\n')[0] + processor_brand = long_brand.rsplit('(', 1)[0] + processor_brand = processor_brand.strip() + + # Hz + hz_actual = long_brand.rsplit('(', 1)[1].split(' ')[0].lower() + hz_actual = hz_actual.split('-')[0] + hz_actual = to_hz_string(hz_actual) + + # Various fields + fields = output.split('CPU: ')[1].split('\n')[1].split('\n')[0].strip().split(' ') + vendor_id = None + stepping = None + model = None + family = None + for field in fields: + name, value = field.split('=') + name = name.strip().lower() + value = value.strip() + if name == 'origin': + vendor_id = value.strip('"') + elif name == 'stepping': + stepping = int(value) + elif name == 'model': + model = int(value, 16) + elif name == 'family': + family = int(value, 16) + + # Flags + flag_lines = [] + for category in [' Features=', ' Features2=', ' AMD Features=', ' AMD Features2=']: + if category in output: + flag_lines.append(output.split(category)[1].split('\n')[0]) + + flags = [] + for line in flag_lines: + line = line.split('<')[1].split('>')[0].lower() + for flag in line.split(','): + flags.append(flag) + flags.sort() + + # Convert from GHz/MHz string to Hz + scale, hz_advertised = _get_hz_string_from_brand(processor_brand) + + # Get the CPU arch and bits + arch, bits = parse_arch(DataSource.raw_arch_string) + + return { + 'vendor_id': vendor_id, + 'hardware': '', + 'brand': processor_brand, + + 'hz_advertised': to_friendly_hz(hz_advertised, scale), + 'hz_actual': to_friendly_hz(hz_actual, 6), + 'hz_advertised_raw': to_raw_hz(hz_advertised, scale), + 'hz_actual_raw': to_raw_hz(hz_actual, 6), + + 'arch': arch, + 'bits': bits, + 'count': DataSource.cpu_count, + 'raw_arch_string': DataSource.raw_arch_string, + + 'l2_cache_size': 0, + 'l2_cache_line_size': 0, + 'l2_cache_associativity': 0, + + 'stepping': stepping, + 'model': model, + 'family': family, + 'processor_type': 0, + 'extended_model': 0, + 'extended_family': 0, + 'flags': flags + } + except Exception: + return None + + +def get_cpu_info_from_sysctl(): + """ + Returns the CPU info gathered from sysctl. Will return None if + sysctl is not found. + """ + try: + # Just return None if there is no sysctl + if not DataSource.has_sysctl(): + return None + + # If sysctl fails return None + returncode, output = DataSource.sysctl_machdep_cpu_hw_cpufrequency() + if output is None or returncode != 0: + return None + + # Various fields + vendor_id = _get_field(False, output, None, None, 'machdep.cpu.vendor') + processor_brand = _get_field(True, output, None, None, 'machdep.cpu.brand_string') + cache_size = _get_field(False, output, None, None, 'machdep.cpu.cache.size') + stepping = _get_field(False, output, int, 0, 'machdep.cpu.stepping') + model = _get_field(False, output, int, 0, 'machdep.cpu.model') + family = _get_field(False, output, int, 0, 'machdep.cpu.family') + + # Flags + flags = _get_field(False, output, None, None, 'machdep.cpu.features').lower().split() + flags.sort() + + # Convert from GHz/MHz string to Hz + scale, hz_advertised = _get_hz_string_from_brand(processor_brand) + hz_actual = _get_field(False, output, None, None, 'hw.cpufrequency') + hz_actual = to_hz_string(hz_actual) + + # Get the CPU arch and bits + arch, bits = parse_arch(DataSource.raw_arch_string) + + return { + 'vendor_id': vendor_id, + 'hardware': '', + 'brand': processor_brand, + + 'hz_advertised': to_friendly_hz(hz_advertised, scale), + 'hz_actual': to_friendly_hz(hz_actual, 0), + 'hz_advertised_raw': to_raw_hz(hz_advertised, scale), + 'hz_actual_raw': to_raw_hz(hz_actual, 0), + + 'arch': arch, + 'bits': bits, + 'count': DataSource.cpu_count, + 'raw_arch_string': DataSource.raw_arch_string, + + 'l2_cache_size': cache_size, + 'l2_cache_line_size': 0, + 'l2_cache_associativity': 0, + + 'stepping': stepping, + 'model': model, + 'family': family, + 'processor_type': 0, + 'extended_model': 0, + 'extended_family': 0, + 'flags': flags + } + except Exception: + return None + + +def get_cpu_info_from_sysinfo(): + """ + Returns the CPU info gathered from sysinfo. Will return None if + sysinfo is not found. + """ + try: + # Just return None if there is no sysinfo + if not DataSource.has_sysinfo(): + return None + + # If sysinfo fails return None + returncode, output = DataSource.sysinfo_cpu() + if output is None or returncode != 0: + return None + + # Various fields + vendor_id = '' # _get_field(False, output, None, None, 'CPU #0: ') + processor_brand = output.split('CPU #0: "')[1].split('"\n')[0] + cache_size = '' # _get_field(False, output, None, None, 'machdep.cpu.cache.size') + stepping = int(output.split(', stepping ')[1].split(',')[0].strip()) + model = int(output.split(', model ')[1].split(',')[0].strip()) + family = int(output.split(', family ')[1].split(',')[0].strip()) + + # Flags + flags = [] + for line in output.split('\n'): + if line.startswith('\t\t'): + for flag in line.strip().lower().split(): + flags.append(flag) + flags.sort() + + # Convert from GHz/MHz string to Hz + scale, hz_advertised = _get_hz_string_from_brand(processor_brand) + hz_actual = hz_advertised + + # Get the CPU arch and bits + arch, bits = parse_arch(DataSource.raw_arch_string) + + return { + 'vendor_id': vendor_id, + 'hardware': '', + 'brand': processor_brand, + + 'hz_advertised': to_friendly_hz(hz_advertised, scale), + 'hz_actual': to_friendly_hz(hz_actual, scale), + 'hz_advertised_raw': to_raw_hz(hz_advertised, scale), + 'hz_actual_raw': to_raw_hz(hz_actual, scale), + + 'arch': arch, + 'bits': bits, + 'count': DataSource.cpu_count, + 'raw_arch_string': DataSource.raw_arch_string, + + 'l2_cache_size': cache_size, + 'l2_cache_line_size': 0, + 'l2_cache_associativity': 0, + + 'stepping': stepping, + 'model': model, + 'family': family, + 'processor_type': 0, + 'extended_model': 0, + 'extended_family': 0, + 'flags': flags + } + except Exception: + return None + + +def get_cpu_info_from_registry(): + """ + FIXME: Is missing many of the newer CPU flags like sse3 + Returns the CPU info gathered from the Windows Registry. Will return None if + not on Windows. + """ + try: + # Just return None if not on Windows + if not DataSource.is_windows: + return None + + # Get the CPU name + processor_brand = DataSource.winreg_processor_brand() + + # Get the CPU vendor id + vendor_id = DataSource.winreg_vendor_id() + + # Get the CPU arch and bits + raw_arch_string = DataSource.winreg_raw_arch_string() + arch, bits = parse_arch(raw_arch_string) + + # Get the actual CPU Hz + hz_actual = DataSource.winreg_hz_actual() + hz_actual = to_hz_string(hz_actual) + + # Get the advertised CPU Hz + scale, hz_advertised = _get_hz_string_from_brand(processor_brand) + + # Get the CPU features + feature_bits = DataSource.winreg_feature_bits() + + def is_set(bit): + mask = 0x80000000 >> bit + retval = mask & feature_bits > 0 + return retval + + # http://en.wikipedia.org/wiki/CPUID + # http://unix.stackexchange.com/questions/43539/what-do-the-flags-in-proc-cpuinfo-mean + # http://www.lohninger.com/helpcsuite/public_constants_cpuid.htm + flags = { + 'fpu': is_set(0), # Floating Point Unit + 'vme': is_set(1), # V86 Mode Extensions + 'de': is_set(2), # Debug Extensions - I/O breakpoints supported + 'pse': is_set(3), # Page Size Extensions (4 MB pages supported) + 'tsc': is_set(4), # Time Stamp Counter and RDTSC instruction are available + 'msr': is_set(5), # Model Specific Registers + 'pae': is_set(6), # Physical Address Extensions (36 bit address, 2MB pages) + 'mce': is_set(7), # Machine Check Exception supported + 'cx8': is_set(8), # Compare Exchange Eight Byte instruction available + 'apic': is_set(9), # Local APIC present (multiprocessor operation support) + 'sepamd': is_set(10), # Fast system calls (AMD only) + 'sep': is_set(11), # Fast system calls + 'mtrr': is_set(12), # Memory Type Range Registers + 'pge': is_set(13), # Page Global Enable + 'mca': is_set(14), # Machine Check Architecture + 'cmov': is_set(15), # Conditional MOVe instructions + 'pat': is_set(16), # Page Attribute Table + 'pse36': is_set(17), # 36 bit Page Size Extensions + 'serial': is_set(18), # Processor Serial Number + 'clflush': is_set(19), # Cache Flush + # 'reserved1': is_set(20), # reserved + 'dts': is_set(21), # Debug Trace Store + 'acpi': is_set(22), # ACPI support + 'mmx': is_set(23), # MultiMedia Extensions + 'fxsr': is_set(24), # FXSAVE and FXRSTOR instructions + 'sse': is_set(25), # SSE instructions + 'sse2': is_set(26), # SSE2 (WNI) instructions + 'ss': is_set(27), # self snoop + # 'reserved2': is_set(28), # reserved + 'tm': is_set(29), # Automatic clock control + 'ia64': is_set(30), # IA64 instructions + '3dnow': is_set(31) # 3DNow! instructions available + } + + # Get a list of only the flags that are true + flags = [k for k, v in flags.items() if v] + flags.sort() + + return { + 'vendor_id': vendor_id, + 'hardware': '', + 'brand': processor_brand, + + 'hz_advertised': to_friendly_hz(hz_advertised, scale), + 'hz_actual': to_friendly_hz(hz_actual, 6), + 'hz_advertised_raw': to_raw_hz(hz_advertised, scale), + 'hz_actual_raw': to_raw_hz(hz_actual, 6), + + 'arch': arch, + 'bits': bits, + 'count': DataSource.cpu_count, + 'raw_arch_string': raw_arch_string, + + 'l2_cache_size': 0, + 'l2_cache_line_size': 0, + 'l2_cache_associativity': 0, + + 'stepping': 0, + 'model': 0, + 'family': 0, + 'processor_type': 0, + 'extended_model': 0, + 'extended_family': 0, + 'flags': flags + } + except Exception: + return None + + +def get_cpu_info_from_kstat(): + """ + Returns the CPU info gathered from isainfo and kstat. Will + return None if isainfo or kstat are not found. + """ + try: + # Just return None if there is no isainfo or kstat + if not DataSource.has_isainfo() or not DataSource.has_kstat(): + return None + + # If isainfo fails return None + returncode, flag_output = DataSource.isainfo_vb() + if flag_output is None or returncode != 0: + return None + + # If kstat fails return None + returncode, kstat = DataSource.kstat_m_cpu_info() + if kstat is None or returncode != 0: + return None + + # Various fields + vendor_id = kstat.split('\tvendor_id ')[1].split('\n')[0].strip() + processor_brand = kstat.split('\tbrand ')[1].split('\n')[0].strip() + cache_size = 0 + stepping = int(kstat.split('\tstepping ')[1].split('\n')[0].strip()) + model = int(kstat.split('\tmodel ')[1].split('\n')[0].strip()) + family = int(kstat.split('\tfamily ')[1].split('\n')[0].strip()) + + # Flags + flags = flag_output.strip().split('\n')[-1].strip().lower().split() + flags.sort() + + # Convert from GHz/MHz string to Hz + scale = 6 + hz_advertised = kstat.split('\tclock_MHz ')[1].split('\n')[0].strip() + hz_advertised = to_hz_string(hz_advertised) + + # Convert from GHz/MHz string to Hz + hz_actual = kstat.split('\tcurrent_clock_Hz ')[1].split('\n')[0].strip() + hz_actual = to_hz_string(hz_actual) + + # Get the CPU arch and bits + arch, bits = parse_arch(DataSource.raw_arch_string) + + return { + 'vendor_id': vendor_id, + 'hardware': '', + 'brand': processor_brand, + + 'hz_advertised': to_friendly_hz(hz_advertised, scale), + 'hz_actual': to_friendly_hz(hz_actual, 0), + 'hz_advertised_raw': to_raw_hz(hz_advertised, scale), + 'hz_actual_raw': to_raw_hz(hz_actual, 0), + + 'arch': arch, + 'bits': bits, + 'count': DataSource.cpu_count, + 'raw_arch_string': DataSource.raw_arch_string, + + 'l2_cache_size': cache_size, + 'l2_cache_line_size': 0, + 'l2_cache_associativity': 0, + + 'stepping': stepping, + 'model': model, + 'family': family, + 'processor_type': 0, + 'extended_model': 0, + 'extended_family': 0, + 'flags': flags + } + except Exception: + return None + + +def get_cpu_info(): + info = None + + # Try the Windows registry + if not info: + info = get_cpu_info_from_registry() + + # Try /proc/cpuinfo + if not info: + info = get_cpu_info_from_proc_cpuinfo() + + # Try sysctl + if not info: + info = get_cpu_info_from_sysctl() + + # Try kstat + if not info: + info = get_cpu_info_from_kstat() + + # Try dmesg + if not info: + info = get_cpu_info_from_dmesg() + + # Try sysinfo + if not info: + info = get_cpu_info_from_sysinfo() + + # Try querying the CPU cpuid register + if not info: + info = get_cpu_info_from_cpuid() + + return info + + +def _check_arch(): + """Make sure we are running on a supported system""" + arch, bits = parse_arch(DataSource.raw_arch_string) + if arch not in ['X86_32', 'X86_64', 'ARM_7', 'ARM_8']: + raise Exception("py-cpuinfo currently only works on X86 and some ARM CPUs.") + + +def main(): + try: + _check_arch() + except Exception as exc: + sys.stderr.write(str(exc) + "\n") + sys.exit(1) + + info = get_cpu_info() + if info: + print('Vendor ID: {0}'.format(info.get('vendor_id', ''))) + print('Hardware Raw: {0}'.format(info.get('hardware', ''))) + print('Brand: {0}'.format(info.get('brand', ''))) + print('Hz Advertised: {0}'.format(info.get('hz_advertised', ''))) + print('Hz Actual: {0}'.format(info.get('hz_actual', ''))) + print('Hz Advertised Raw: {0}'.format(info.get('hz_advertised_raw', ''))) + print('Hz Actual Raw: {0}'.format(info.get('hz_actual_raw', ''))) + print('Arch: {0}'.format(info.get('arch', ''))) + print('Bits: {0}'.format(info.get('bits', ''))) + print('Count: {0}'.format(info.get('count', ''))) + + print('Raw Arch String: {0}'.format(info.get('raw_arch_string', ''))) + + print('L2 Cache Size: {0}'.format(info.get('l2_cache_size', ''))) + print('L2 Cache Line Size: {0}'.format(info.get('l2_cache_line_size', ''))) + print('L2 Cache Associativity: {0}'.format(info.get('l2_cache_associativity', ''))) + + print('Stepping: {0}'.format(info.get('stepping', ''))) + print('Model: {0}'.format(info.get('model', ''))) + print('Family: {0}'.format(info.get('family', ''))) + print('Processor Type: {0}'.format(info.get('processor_type', ''))) + print('Extended Model: {0}'.format(info.get('extended_model', ''))) + print('Extended Family: {0}'.format(info.get('extended_family', ''))) + print('Flags: {0}'.format(', '.join(info.get('flags', '')))) + else: + sys.stderr.write("Failed to find cpu info\n") + sys.exit(1) + + +if __name__ == '__main__': + main() +else: + _check_arch() diff --git a/dev-requirements.txt b/dev-requirements.txt deleted file mode 100644 index f24c998..0000000 --- a/dev-requirements.txt +++ /dev/null @@ -1,7 +0,0 @@ -nose -coverage -nosexcover -mock -pytest -ipython>=4.0.0 -ipdb>=0.8 diff --git a/.travis.yml b/old-configs/.travis.yml similarity index 100% rename from .travis.yml rename to old-configs/.travis.yml diff --git a/circle.yml b/old-configs/circle.yml similarity index 100% rename from circle.yml rename to old-configs/circle.yml diff --git a/pip-freeze.txt b/pip-freeze.txt new file mode 100644 index 0000000..85aad11 --- /dev/null +++ b/pip-freeze.txt @@ -0,0 +1,3 @@ +Cython==0.29.26 +markerlib==0.6.0 +-e git+https://github.com/escherba/python-metrohash@3c66ddae69762d7b7872f67ba9ca11d06371a433#egg=metrohash diff --git a/python.mk b/python.mk index 9f147a4..996fd0d 100644 --- a/python.mk +++ b/python.mk @@ -1,69 +1,88 @@ -.PHONY: clean develop env extras package release test virtualenv build_ext - PYMODULE := metrohash EXTENSION := $(PYMODULE).so -EXTENSION_INTERMEDIATE := ./src/$(PYMODULE).cpp -EXTENSION_DEPS := ./src/$(PYMODULE).pyx -PYPI_HOST := pypi -DISTRIBUTE := sdist bdist_wheel -EXTRAS_REQS := dev-requirements.txt $(wildcard extras-*-requirements.txt) +SRC_DIR := src +EXTENSION_INTERMEDIATE := ./$(SRC_DIR)/$(PYMODULE).cpp +EXTENSION_DEPS := ./$(SRC_DIR)/$(PYMODULE).pyx +PYPI_URL := https://upload.pypi.org/legacy/ + +DISTRIBUTE := sdist +ifeq ($(shell uname -s),Darwin) +DISTRIBUTE += bdist_wheel +endif -PYENV := . env/bin/activate; -PYTHON := $(PYENV) python -PIP := $(PYENV) pip +PYENV := PYTHONPATH=. . env/bin/activate; +INTERPRETER := python3 +PACKAGE_MGR := pip3 +PYVERSION := $(shell $(INTERPRETER) --version 2>&1) +PYTHON := $(PYENV) $(INTERPRETER) +PIP := $(PYENV) $(PACKAGE_MGR) + +VENV_OPTS := --python="$(shell which $(INTERPRETER))" +ifeq ($(PIP_SYSTEM_SITE_PACKAGES),1) +VENV_OPTS += --system-site-packages +endif +BOLD := $(shell tput bold) +END := $(shell tput sgr0) -package: env build_ext +.PHONY: package +package: env build_ext ## build package + @echo "Packaging using $(PYVERSION)" $(PYTHON) setup.py $(DISTRIBUTE) -release: env build_ext - $(PYTHON) setup.py $(DISTRIBUTE) upload -r $(PYPI_HOST) +# See https://packaging.python.org/guides/migrating-to-pypi-org/ +.PHONY: release +release: env build_ext ## upload package to PyPI + @echo "Releasing using $(PYVERSION)" + $(PYTHON) setup.py $(DISTRIBUTE) upload -r $(PYPI_URL) -shell: extras build_ext +.PHONY: shell +shell: build_ext ## open IPython shell within the virtualenv + @echo "Using $(PYVERSION)" $(PYENV) $(ENV_EXTRA) ipython -build_ext: $(EXTENSION) +.PHONY: build_ext +build_ext: $(EXTENSION) ## build C extension(s) @echo "done building '$(EXTENSION)' extension" $(EXTENSION): env $(EXTENSION_DEPS) + @echo "Building using $(PYVERSION)" $(PYTHON) setup.py build_ext --inplace -test: extras build_ext | test_cpp - $(PYENV) nosetests $(NOSEARGS) - $(PYENV) py.test README.rst +.PHONY: test +test: build_ext ## run Python unit tests + $(PYENV) pytest + $(PYENV) pytest README.rst -nuke: clean +.PHONY: nuke +nuke: clean ## clean and remove virtual environment rm -f $(EXTENSION_INTERMEDIATE) rm -rf *.egg *.egg-info env + find $(SRC_DIR) -depth -type d -name *.egg-info -exec rm -rf {} \; -clean: | clean_cpp +.PHONY: clean +clean: ## remove temporary files python setup.py clean - rm -rf dist build - rm -f $(EXTENSION) - find . -path ./env -prune -o -type f -name "*.pyc" -exec rm {} \; + rm -rf dist build __pycache__ + rm -f *.so + find $(SRC_DIR) -type f -name "*.pyc" -exec rm {} \; + find $(SRC_DIR) -type f -name "*.cpp" -exec rm {} \; + find $(SRC_DIR) -type f -name "*.so" -exec rm {} \; -develop: +.PHONY: install +install: build_ext ## install package @echo "Installing for " `which pip` -pip uninstall --yes $(PYMODULE) pip install -e . -extras: env/make.extras -env/make.extras: $(EXTRAS_REQS) | env - rm -rf env/build - $(PYENV) for req in $?; do pip install -r $$req; done - touch $@ - -ifeq ($(PIP_SYSTEM_SITE_PACKAGES),1) -VENV_OPTS="--system-site-packages" -else -VENV_OPTS="--no-site-packages" -endif - -env virtualenv: env/bin/activate +.PHONY: env +env: env/bin/activate ## set up a virtual environment env/bin/activate: setup.py test -f $@ || virtualenv $(VENV_OPTS) env - $(PYENV) easy_install -U pip - $(PYENV) curl https://bootstrap.pypa.io/ez_setup.py | python - $(PIP) install -U setuptools distribute wheel cython + export SETUPTOOLS_USE_DISTUTILS=stdlib; $(PYENV) curl https://bootstrap.pypa.io/ez_setup.py | $(INTERPRETER) + $(PIP) install -U pip + $(PIP) install -U markerlib + $(PIP) install -U wheel + $(PIP) install -U cython $(PIP) install -e . - touch $@ + $(PIP) freeze > pip-freeze.txt diff --git a/requirements.txt b/requirements.txt index a36439c..5a03a86 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,8 @@ -virtualenv -setuptools +cython distribute +ipdb +ipython +pytest +setuptools +virtualenv wheel -cython diff --git a/setup.cfg b/setup.cfg index 5aef279..43b4615 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,16 @@ +[options] +package_dir = + =src + [metadata] +version = attr:cityhash.__version__ description-file = README.rst + +[tool:pytest] +addopts = --doctest-modules +testpaths = + src tests + +[flake8] +extend-ignore = E203,W503,W504 +max-line-length = 120 diff --git a/setup.py b/setup.py index d92073a..cf9853a 100644 --- a/setup.py +++ b/setup.py @@ -1,34 +1,42 @@ +from os.path import join, dirname from setuptools import setup from setuptools.extension import Extension from setuptools.dist import Distribution -from pkg_resources import resource_string +try: + from cpuinfo import get_cpu_info + cpu_info = get_cpu_info() + have_sse42 = 'sse4.2' in cpu_info['flags'] +except Exception: + have_sse42 = False try: from Cython.Distutils import build_ext except ImportError: - USE_CYTHON = False -else: - USE_CYTHON = True + build_ext = None + +USE_CYTHON = build_ext is not None class BinaryDistribution(Distribution): """ Subclass the setuptools Distribution to flip the purity flag to false. - See http://lucumr.pocoo.org/2014/1/27/python-on-wheels/ + See https://lucumr.pocoo.org/2014/1/27/python-on-wheels/ """ def is_pure(self): - # TODO: check if this is still necessary with Python v2.7 + """Returns purity flag""" return False -CXXFLAGS = u""" +CXXFLAGS = """ -O3 --msse4.2 -Wno-unused-value -Wno-unused-function """.split() +if have_sse42: + CXXFLAGS.append('-msse4.2') + INCLUDE_DIRS = ['include'] CXXHEADERS = [ @@ -69,9 +77,25 @@ def is_pure(self): include_dirs=INCLUDE_DIRS) ) -VERSION = '0.0.13' + +VERSION = '0.1.0' URL = "https://github.com/escherba/python-metrohash" + +LONG_DESCRIPTION = """ + +""" + + +def get_long_description(): + fname = join(dirname(__file__), 'README.rst') + try: + with open(fname, 'rb') as fh: + return fh.read().decode('utf-8') + except Exception: + return LONG_DESCRIPTION + + setup( version=VERSION, description="Python bindings for MetroHash, a fast non-cryptographic hash algorithm", @@ -94,6 +118,12 @@ def is_pure(self): 'Programming Language :: C++', 'Programming Language :: Cython', 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', 'Topic :: Internet', 'Topic :: Scientific/Engineering', 'Topic :: Scientific/Engineering :: Information Analysis', @@ -101,6 +131,6 @@ def is_pure(self): 'Topic :: Software Development :: Libraries :: Python Modules', 'Topic :: Utilities' ], - long_description=resource_string(__name__, 'README.rst'), + long_description=get_long_description(), distclass=BinaryDistribution, ) diff --git a/src/metrohash.cpp b/src/metrohash.cpp index 7f9c601..8bfe4d5 100644 --- a/src/metrohash.cpp +++ b/src/metrohash.cpp @@ -1,16 +1,20 @@ -/* Generated by Cython 0.23.4 */ +/* Generated by Cython 0.29.26 */ +#ifndef PY_SSIZE_T_CLEAN #define PY_SSIZE_T_CLEAN +#endif /* PY_SSIZE_T_CLEAN */ #include "Python.h" #ifndef Py_PYTHON_H #error Python headers needed to compile C extensions, please install development version of Python. -#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03020000) - #error Cython requires Python 2.6+ or Python 3.2+. +#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000) + #error Cython requires Python 2.6+ or Python 3.3+. #else -#define CYTHON_ABI "0_23_4" +#define CYTHON_ABI "0_29_26" +#define CYTHON_HEX_VERSION 0x001D1AF0 +#define CYTHON_FUTURE_DIVISION 1 #include #ifndef offsetof -#define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) + #define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) #endif #if !defined(WIN32) && !defined(MS_WINDOWS) #ifndef __stdcall @@ -29,6 +33,12 @@ #ifndef DL_EXPORT #define DL_EXPORT(t) t #endif +#define __PYX_COMMA , +#ifndef HAVE_LONG_LONG + #if PY_VERSION_HEX >= 0x02070000 + #define HAVE_LONG_LONG + #endif +#endif #ifndef PY_LONG_LONG #define PY_LONG_LONG LONG_LONG #endif @@ -36,17 +46,278 @@ #define Py_HUGE_VAL HUGE_VAL #endif #ifdef PYPY_VERSION -#define CYTHON_COMPILING_IN_PYPY 1 -#define CYTHON_COMPILING_IN_CPYTHON 0 + #define CYTHON_COMPILING_IN_PYPY 1 + #define CYTHON_COMPILING_IN_PYSTON 0 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #undef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 0 + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #if PY_VERSION_HEX < 0x03050000 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #elif !defined(CYTHON_USE_ASYNC_SLOTS) + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #undef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 0 + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #undef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 1 + #undef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 0 + #undef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 0 + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #undef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 0 + #undef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 0 + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 +#elif defined(PYSTON_VERSION) + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_PYSTON 1 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #ifndef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 1 + #endif + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #ifndef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 1 + #endif + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #ifndef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 1 + #endif + #ifndef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 1 + #endif + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #undef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 0 + #undef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 0 + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 +#else + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_PYSTON 0 + #define CYTHON_COMPILING_IN_CPYTHON 1 + #ifndef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 1 + #endif + #if PY_VERSION_HEX < 0x02070000 + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #elif !defined(CYTHON_USE_PYTYPE_LOOKUP) + #define CYTHON_USE_PYTYPE_LOOKUP 1 + #endif + #if PY_MAJOR_VERSION < 3 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #elif !defined(CYTHON_USE_ASYNC_SLOTS) + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #if PY_VERSION_HEX < 0x02070000 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #elif !defined(CYTHON_USE_PYLONG_INTERNALS) + #define CYTHON_USE_PYLONG_INTERNALS 1 + #endif + #ifndef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 1 + #endif + #ifndef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 1 + #endif + #if PY_VERSION_HEX < 0x030300F0 || PY_VERSION_HEX >= 0x030B00A2 + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #elif !defined(CYTHON_USE_UNICODE_WRITER) + #define CYTHON_USE_UNICODE_WRITER 1 + #endif + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #ifndef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 1 + #endif + #ifndef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 1 + #endif + #ifndef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 1 + #endif + #ifndef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL (PY_VERSION_HEX < 0x030B00A1) + #endif + #ifndef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT (PY_VERSION_HEX >= 0x03050000) + #endif + #ifndef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1) + #endif + #ifndef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1) + #endif + #ifndef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK (PY_VERSION_HEX >= 0x030700A3) + #endif +#endif +#if !defined(CYTHON_FAST_PYCCALL) +#define CYTHON_FAST_PYCCALL (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1) +#endif +#if CYTHON_USE_PYLONG_INTERNALS + #if PY_MAJOR_VERSION < 3 + #include "longintrepr.h" + #endif + #undef SHIFT + #undef BASE + #undef MASK + #ifdef SIZEOF_VOID_P + enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) }; + #endif +#endif +#ifndef __has_attribute + #define __has_attribute(x) 0 +#endif +#ifndef __has_cpp_attribute + #define __has_cpp_attribute(x) 0 +#endif +#ifndef CYTHON_RESTRICT + #if defined(__GNUC__) + #define CYTHON_RESTRICT __restrict__ + #elif defined(_MSC_VER) && _MSC_VER >= 1400 + #define CYTHON_RESTRICT __restrict + #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define CYTHON_RESTRICT restrict + #else + #define CYTHON_RESTRICT + #endif +#endif +#ifndef CYTHON_UNUSED +# if defined(__GNUC__) +# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +#endif +#ifndef CYTHON_MAYBE_UNUSED_VAR +# if defined(__cplusplus) + template void CYTHON_MAYBE_UNUSED_VAR( const T& ) { } +# else +# define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x) +# endif +#endif +#ifndef CYTHON_NCP_UNUSED +# if CYTHON_COMPILING_IN_CPYTHON +# define CYTHON_NCP_UNUSED +# else +# define CYTHON_NCP_UNUSED CYTHON_UNUSED +# endif +#endif +#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None) +#ifdef _MSC_VER + #ifndef _MSC_STDINT_H_ + #if _MSC_VER < 1300 + typedef unsigned char uint8_t; + typedef unsigned int uint32_t; + #else + typedef unsigned __int8 uint8_t; + typedef unsigned __int32 uint32_t; + #endif + #endif #else -#define CYTHON_COMPILING_IN_PYPY 0 -#define CYTHON_COMPILING_IN_CPYTHON 1 + #include +#endif +#ifndef CYTHON_FALLTHROUGH + #if defined(__cplusplus) && __cplusplus >= 201103L + #if __has_cpp_attribute(fallthrough) + #define CYTHON_FALLTHROUGH [[fallthrough]] + #elif __has_cpp_attribute(clang::fallthrough) + #define CYTHON_FALLTHROUGH [[clang::fallthrough]] + #elif __has_cpp_attribute(gnu::fallthrough) + #define CYTHON_FALLTHROUGH [[gnu::fallthrough]] + #endif + #endif + #ifndef CYTHON_FALLTHROUGH + #if __has_attribute(fallthrough) + #define CYTHON_FALLTHROUGH __attribute__((fallthrough)) + #else + #define CYTHON_FALLTHROUGH + #endif + #endif + #if defined(__clang__ ) && defined(__apple_build_version__) + #if __apple_build_version__ < 7000000 + #undef CYTHON_FALLTHROUGH + #define CYTHON_FALLTHROUGH + #endif + #endif +#endif + +#ifndef __cplusplus + #error "Cython files generated with the C++ option must be compiled with a C++ compiler." #endif -#if !defined(CYTHON_USE_PYLONG_INTERNALS) && CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x02070000 -#define CYTHON_USE_PYLONG_INTERNALS 1 +#ifndef CYTHON_INLINE + #if defined(__clang__) + #define CYTHON_INLINE __inline__ __attribute__ ((__unused__)) + #else + #define CYTHON_INLINE inline + #endif #endif +template +void __Pyx_call_destructor(T& x) { + x.~T(); +} +template +class __Pyx_FakeReference { + public: + __Pyx_FakeReference() : ptr(NULL) { } + __Pyx_FakeReference(const T& ref) : ptr(const_cast(&ref)) { } + T *operator->() { return ptr; } + T *operator&() { return ptr; } + operator T&() { return *ptr; } + template bool operator ==(U other) { return *ptr == other; } + template bool operator !=(U other) { return *ptr != other; } + private: + T *ptr; +}; + #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag) -#define Py_OptimizeFlag 0 + #define Py_OptimizeFlag 0 #endif #define __PYX_BUILD_PY_SSIZE_T "n" #define CYTHON_FORMAT_SSIZE_T "z" @@ -57,8 +328,72 @@ #define __Pyx_DefaultClassType PyClass_Type #else #define __Pyx_BUILTIN_MODULE_NAME "builtins" + #define __Pyx_DefaultClassType PyType_Type +#if PY_VERSION_HEX >= 0x030B00A1 + static CYTHON_INLINE PyCodeObject* __Pyx_PyCode_New(int a, int k, int l, int s, int f, + PyObject *code, PyObject *c, PyObject* n, PyObject *v, + PyObject *fv, PyObject *cell, PyObject* fn, + PyObject *name, int fline, PyObject *lnos) { + PyObject *kwds=NULL, *argcount=NULL, *posonlyargcount=NULL, *kwonlyargcount=NULL; + PyObject *nlocals=NULL, *stacksize=NULL, *flags=NULL, *replace=NULL, *call_result=NULL, *empty=NULL; + const char *fn_cstr=NULL; + const char *name_cstr=NULL; + PyCodeObject* co=NULL; + PyObject *type, *value, *traceback; + PyErr_Fetch(&type, &value, &traceback); + if (!(kwds=PyDict_New())) goto end; + if (!(argcount=PyLong_FromLong(a))) goto end; + if (PyDict_SetItemString(kwds, "co_argcount", argcount) != 0) goto end; + if (!(posonlyargcount=PyLong_FromLong(0))) goto end; + if (PyDict_SetItemString(kwds, "co_posonlyargcount", posonlyargcount) != 0) goto end; + if (!(kwonlyargcount=PyLong_FromLong(k))) goto end; + if (PyDict_SetItemString(kwds, "co_kwonlyargcount", kwonlyargcount) != 0) goto end; + if (!(nlocals=PyLong_FromLong(l))) goto end; + if (PyDict_SetItemString(kwds, "co_nlocals", nlocals) != 0) goto end; + if (!(stacksize=PyLong_FromLong(s))) goto end; + if (PyDict_SetItemString(kwds, "co_stacksize", stacksize) != 0) goto end; + if (!(flags=PyLong_FromLong(f))) goto end; + if (PyDict_SetItemString(kwds, "co_flags", flags) != 0) goto end; + if (PyDict_SetItemString(kwds, "co_code", code) != 0) goto end; + if (PyDict_SetItemString(kwds, "co_consts", c) != 0) goto end; + if (PyDict_SetItemString(kwds, "co_names", n) != 0) goto end; + if (PyDict_SetItemString(kwds, "co_varnames", v) != 0) goto end; + if (PyDict_SetItemString(kwds, "co_freevars", fv) != 0) goto end; + if (PyDict_SetItemString(kwds, "co_cellvars", cell) != 0) goto end; + if (PyDict_SetItemString(kwds, "co_linetable", lnos) != 0) goto end; + if (!(fn_cstr=PyUnicode_AsUTF8AndSize(fn, NULL))) goto end; + if (!(name_cstr=PyUnicode_AsUTF8AndSize(name, NULL))) goto end; + if (!(co = PyCode_NewEmpty(fn_cstr, name_cstr, fline))) goto end; + if (!(replace = PyObject_GetAttrString((PyObject*)co, "replace"))) goto cleanup_code_too; + if (!(empty = PyTuple_New(0))) goto cleanup_code_too; // unfortunately __pyx_empty_tuple isn't available here + if (!(call_result = PyObject_Call(replace, empty, kwds))) goto cleanup_code_too; + Py_XDECREF((PyObject*)co); + co = (PyCodeObject*)call_result; + call_result = NULL; + if (0) { + cleanup_code_too: + Py_XDECREF((PyObject*)co); + co = NULL; + } + end: + Py_XDECREF(kwds); + Py_XDECREF(argcount); + Py_XDECREF(posonlyargcount); + Py_XDECREF(kwonlyargcount); + Py_XDECREF(nlocals); + Py_XDECREF(stacksize); + Py_XDECREF(replace); + Py_XDECREF(call_result); + Py_XDECREF(empty); + if (type) { + PyErr_Restore(type, value, traceback); + } + return co; + } +#else #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#endif #define __Pyx_DefaultClassType PyType_Type #endif #ifndef Py_TPFLAGS_CHECKTYPES @@ -73,23 +408,137 @@ #ifndef Py_TPFLAGS_HAVE_FINALIZE #define Py_TPFLAGS_HAVE_FINALIZE 0 #endif +#ifndef METH_STACKLESS + #define METH_STACKLESS 0 +#endif +#if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL) + #ifndef METH_FASTCALL + #define METH_FASTCALL 0x80 + #endif + typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs); + typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args, + Py_ssize_t nargs, PyObject *kwnames); +#else + #define __Pyx_PyCFunctionFast _PyCFunctionFast + #define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords +#endif +#if CYTHON_FAST_PYCCALL +#define __Pyx_PyFastCFunction_Check(func)\ + ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS))))) +#else +#define __Pyx_PyFastCFunction_Check(func) 0 +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc) + #define PyObject_Malloc(s) PyMem_Malloc(s) + #define PyObject_Free(p) PyMem_Free(p) + #define PyObject_Realloc(p) PyMem_Realloc(p) +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030400A1 + #define PyMem_RawMalloc(n) PyMem_Malloc(n) + #define PyMem_RawRealloc(p, n) PyMem_Realloc(p, n) + #define PyMem_RawFree(p) PyMem_Free(p) +#endif +#if CYTHON_COMPILING_IN_PYSTON + #define __Pyx_PyCode_HasFreeVars(co) PyCode_HasFreeVars(co) + #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno) +#else + #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0) + #define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno) +#endif +#if !CYTHON_FAST_THREAD_STATE || PY_VERSION_HEX < 0x02070000 + #define __Pyx_PyThreadState_Current PyThreadState_GET() +#elif PY_VERSION_HEX >= 0x03060000 + #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet() +#elif PY_VERSION_HEX >= 0x03000000 + #define __Pyx_PyThreadState_Current PyThreadState_GET() +#else + #define __Pyx_PyThreadState_Current _PyThreadState_Current +#endif +#if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT) +#include "pythread.h" +#define Py_tss_NEEDS_INIT 0 +typedef int Py_tss_t; +static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) { + *key = PyThread_create_key(); + return 0; +} +static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) { + Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t)); + *key = Py_tss_NEEDS_INIT; + return key; +} +static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) { + PyObject_Free(key); +} +static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) { + return *key != Py_tss_NEEDS_INIT; +} +static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) { + PyThread_delete_key(*key); + *key = Py_tss_NEEDS_INIT; +} +static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) { + return PyThread_set_key_value(*key, value); +} +static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { + return PyThread_get_key_value(*key); +} +#endif +#if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized) +#define __Pyx_PyDict_NewPresized(n) ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n)) +#else +#define __Pyx_PyDict_NewPresized(n) PyDict_New() +#endif +#if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION + #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) +#else + #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS +#define __Pyx_PyDict_GetItemStr(dict, name) _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash) +#else +#define __Pyx_PyDict_GetItemStr(dict, name) PyDict_GetItem(dict, name) +#endif #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) #define CYTHON_PEP393_ENABLED 1 + #if defined(PyUnicode_IS_READY) #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\ 0 : _PyUnicode_Ready((PyObject *)(op))) + #else + #define __Pyx_PyUnicode_READY(op) (0) + #endif #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) + #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) PyUnicode_MAX_CHAR_VALUE(u) #define __Pyx_PyUnicode_KIND(u) PyUnicode_KIND(u) #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u) #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) + #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, ch) + #if defined(PyUnicode_IS_READY) && defined(PyUnicode_GET_SIZE) + #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03090000 + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : ((PyCompactUnicodeObject *)(u))->wstr_length)) + #else + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) + #endif + #else + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_LENGTH(u)) + #endif #else #define CYTHON_PEP393_ENABLED 0 + #define PyUnicode_1BYTE_KIND 1 + #define PyUnicode_2BYTE_KIND 2 + #define PyUnicode_4BYTE_KIND 4 #define __Pyx_PyUnicode_READY(op) (0) #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i])) + #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111) #define __Pyx_PyUnicode_KIND(u) (sizeof(Py_UNICODE)) #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u)) #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i])) + #define __Pyx_PyUnicode_WRITE(k, d, i, ch) (((void)(k)), ((Py_UNICODE*)d)[i] = ch) + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_SIZE(u)) #endif #if CYTHON_COMPILING_IN_PYPY #define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b) @@ -102,19 +551,31 @@ #if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains) #define PyUnicode_Contains(u, s) PySequence_Contains(u, s) #endif -#define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b)) -#define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b)) +#if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check) + #define PyByteArray_Check(obj) PyObject_TypeCheck(obj, &PyByteArray_Type) +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format) + #define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt) +#endif +#define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyString_Check(b) && !PyString_CheckExact(b)))) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b)) +#define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b)) #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b) #else #define __Pyx_PyString_Format(a, b) PyString_Format(a, b) #endif +#if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII) + #define PyObject_ASCII(o) PyObject_Repr(o) +#endif #if PY_MAJOR_VERSION >= 3 #define PyBaseString_Type PyUnicode_Type #define PyStringObject PyUnicodeObject #define PyString_Type PyUnicode_Type #define PyString_Check PyUnicode_Check #define PyString_CheckExact PyUnicode_CheckExact +#ifndef PyObject_Unicode + #define PyObject_Unicode PyObject_Str +#endif #endif #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj) @@ -126,7 +587,18 @@ #ifndef PySet_CheckExact #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) #endif -#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) +#if PY_VERSION_HEX >= 0x030900A4 + #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt) + #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size) +#else + #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt) + #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size) +#endif +#if CYTHON_ASSUME_SAFE_MACROS + #define __Pyx_PySequence_SIZE(seq) Py_SIZE(seq) +#else + #define __Pyx_PySequence_SIZE(seq) PySequence_Size(seq) +#endif #if PY_MAJOR_VERSION >= 3 #define PyIntObject PyLongObject #define PyInt_Type PyLong_Type @@ -155,62 +627,33 @@ #if PY_VERSION_HEX < 0x030200A4 typedef long Py_hash_t; #define __Pyx_PyInt_FromHash_t PyInt_FromLong - #define __Pyx_PyInt_AsHash_t PyInt_AsLong + #define __Pyx_PyInt_AsHash_t __Pyx_PyIndex_AsHash_t #else #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t - #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t + #define __Pyx_PyInt_AsHash_t __Pyx_PyIndex_AsSsize_t #endif #if PY_MAJOR_VERSION >= 3 - #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func)) + #define __Pyx_PyMethod_New(func, self, klass) ((self) ? ((void)(klass), PyMethod_New(func, self)) : __Pyx_NewRef(func)) #else #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass) #endif -#if PY_VERSION_HEX >= 0x030500B1 -#define __Pyx_PyAsyncMethodsStruct PyAsyncMethods -#define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async) -#elif CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 -typedef struct { - unaryfunc am_await; - unaryfunc am_aiter; - unaryfunc am_anext; -} __Pyx_PyAsyncMethodsStruct; -#define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved)) -#else -#define __Pyx_PyType_AsAsync(obj) NULL -#endif -#ifndef CYTHON_RESTRICT - #if defined(__GNUC__) - #define CYTHON_RESTRICT __restrict__ - #elif defined(_MSC_VER) && _MSC_VER >= 1400 - #define CYTHON_RESTRICT __restrict - #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - #define CYTHON_RESTRICT restrict +#if CYTHON_USE_ASYNC_SLOTS + #if PY_VERSION_HEX >= 0x030500B1 + #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods + #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async) #else - #define CYTHON_RESTRICT + #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved)) #endif +#else + #define __Pyx_PyType_AsAsync(obj) NULL #endif -#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None) - -#ifndef __cplusplus - #error "Cython files generated with the C++ option must be compiled with a C++ compiler." -#endif -#ifndef CYTHON_INLINE - #define CYTHON_INLINE inline +#ifndef __Pyx_PyAsyncMethodsStruct + typedef struct { + unaryfunc am_await; + unaryfunc am_aiter; + unaryfunc am_anext; + } __Pyx_PyAsyncMethodsStruct; #endif -template -void __Pyx_call_destructor(T& x) { - x.~T(); -} -template -class __Pyx_FakeReference { - public: - __Pyx_FakeReference() : ptr(NULL) { } - __Pyx_FakeReference(const T& ref) : ptr(const_cast(&ref)) { } - T *operator->() { return ptr; } - operator T&() { return *ptr; } - private: - T *ptr; -}; #if defined(WIN32) || defined(MS_WINDOWS) #define _USE_MATH_DEFINES @@ -225,16 +668,17 @@ static CYTHON_INLINE float __PYX_NAN() { return value; } #endif - - -#if PY_MAJOR_VERSION >= 3 - #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) - #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) +#if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL) +#define __Pyx_truncl trunc #else - #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) - #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) +#define __Pyx_truncl truncl #endif +#define __PYX_MARK_ERR_POS(f_index, lineno) \ + { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; } +#define __PYX_ERR(f_index, lineno, Ln_error) \ + { __PYX_MARK_ERR_POS(f_index, lineno) goto Ln_error; } + #ifndef __PYX_EXTERN_C #ifdef __cplusplus #define __PYX_EXTERN_C extern "C" @@ -245,44 +689,26 @@ static CYTHON_INLINE float __PYX_NAN() { #define __PYX_HAVE__metrohash #define __PYX_HAVE_API__metrohash +/* Early includes */ #include #include "metro.h" -#include "string.h" -#include "stdio.h" +#include +#include #include "pythread.h" #ifdef _OPENMP #include #endif /* _OPENMP */ -#ifdef PYREX_WITHOUT_ASSERTIONS +#if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS) #define CYTHON_WITHOUT_ASSERTIONS #endif -#ifndef CYTHON_UNUSED -# if defined(__GNUC__) -# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) -# define CYTHON_UNUSED __attribute__ ((__unused__)) -# else -# define CYTHON_UNUSED -# endif -# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) -# define CYTHON_UNUSED __attribute__ ((__unused__)) -# else -# define CYTHON_UNUSED -# endif -#endif -#ifndef CYTHON_NCP_UNUSED -# if CYTHON_COMPILING_IN_CPYTHON -# define CYTHON_NCP_UNUSED -# else -# define CYTHON_NCP_UNUSED CYTHON_UNUSED -# endif -#endif -typedef struct {PyObject **p; char *s; const Py_ssize_t n; const char* encoding; +typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding; const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; #define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0 -#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 0 +#define __PYX_DEFAULT_STRING_ENCODING_IS_UTF8 0 +#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8) #define __PYX_DEFAULT_STRING_ENCODING "" #define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString #define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize @@ -298,6 +724,9 @@ typedef struct {PyObject **p; char *s; const Py_ssize_t n; const char* encoding; (sizeof(type) == sizeof(Py_ssize_t) &&\ (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\ v == (type)PY_SSIZE_T_MAX))) ) +static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) { + return (size_t) i < (size_t) limit; +} #if defined (__cplusplus) && __cplusplus >= 201103L #include #define __Pyx_sst_abs(value) std::abs(value) @@ -305,8 +734,8 @@ typedef struct {PyObject **p; char *s; const Py_ssize_t n; const char* encoding; #define __Pyx_sst_abs(value) abs(value) #elif SIZEOF_LONG >= SIZEOF_SIZE_T #define __Pyx_sst_abs(value) labs(value) -#elif defined (_MSC_VER) && defined (_M_X64) - #define __Pyx_sst_abs(value) _abs64(value) +#elif defined (_MSC_VER) + #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value)) #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L #define __Pyx_sst_abs(value) llabs(value) #elif defined (__GNUC__) @@ -314,8 +743,8 @@ typedef struct {PyObject **p; char *s; const Py_ssize_t n; const char* encoding; #else #define __Pyx_sst_abs(value) ((value<0) ? -value : value) #endif -static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject*); -static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length); +static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*); +static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length); #define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s)) #define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l) #define __Pyx_PyBytes_FromString PyBytes_FromString @@ -328,39 +757,53 @@ static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*); #define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize #endif -#define __Pyx_PyObject_AsSString(s) ((signed char*) __Pyx_PyObject_AsString(s)) -#define __Pyx_PyObject_AsUString(s) ((unsigned char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyBytes_AsWritableString(s) ((char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsWritableSString(s) ((signed char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsWritableUString(s) ((unsigned char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsString(s) ((const char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsSString(s) ((const signed char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsUString(s) ((const unsigned char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyObject_AsWritableString(s) ((char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsWritableSString(s) ((signed char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsWritableUString(s) ((unsigned char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsSString(s) ((const signed char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsUString(s) ((const unsigned char*) __Pyx_PyObject_AsString(s)) #define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s) #define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s) #define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s) #define __Pyx_PyStr_FromCString(s) __Pyx_PyStr_FromString((const char*)s) #define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s) -#if PY_MAJOR_VERSION < 3 -static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) -{ +static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) { const Py_UNICODE *u_end = u; while (*u_end++) ; return (size_t)(u_end - u - 1); } -#else -#define __Pyx_Py_UNICODE_strlen Py_UNICODE_strlen -#endif #define __Pyx_PyUnicode_FromUnicode(u) PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u)) #define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode #define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode #define __Pyx_NewRef(obj) (Py_INCREF(obj), obj) #define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None) -#define __Pyx_PyBool_FromLong(b) ((b) ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False)) +static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b); static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); -static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x); +static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*); +static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x); +#define __Pyx_PySequence_Tuple(obj)\ + (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj)) static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); -#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject*); +#if CYTHON_ASSUME_SAFE_MACROS #define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) #else #define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x) #endif #define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) +#if PY_MAJOR_VERSION >= 3 +#define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x)) +#else +#define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x)) +#endif +#define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x)) #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII static int __Pyx_sys_getdefaultencoding_not_ascii; static int __Pyx_init_sys_getdefaultencoding_params(void) { @@ -424,7 +867,7 @@ static int __Pyx_init_sys_getdefaultencoding_params(void) { if (!default_encoding) goto bad; default_encoding_c = PyBytes_AsString(default_encoding); if (!default_encoding_c) goto bad; - __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c)); + __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c) + 1); if (!__PYX_DEFAULT_STRING_ENCODING) goto bad; strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c); Py_DECREF(default_encoding); @@ -445,12 +888,15 @@ static int __Pyx_init_sys_getdefaultencoding_params(void) { #define likely(x) (x) #define unlikely(x) (x) #endif /* __GNUC__ */ +static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; } -static PyObject *__pyx_m; +static PyObject *__pyx_m = NULL; static PyObject *__pyx_d; static PyObject *__pyx_b; +static PyObject *__pyx_cython_runtime = NULL; static PyObject *__pyx_empty_tuple; static PyObject *__pyx_empty_bytes; +static PyObject *__pyx_empty_unicode; static int __pyx_lineno; static int __pyx_clineno = 0; static const char * __pyx_cfilenm= __FILE__; @@ -459,9 +905,10 @@ static const char *__pyx_filename; static const char *__pyx_f[] = { "src/metrohash.pyx", - "env/lib/python2.7/site-packages/Cython/Includes/cpython/type.pxd", - "env/lib/python2.7/site-packages/Cython/Includes/cpython/bool.pxd", - "env/lib/python2.7/site-packages/Cython/Includes/cpython/complex.pxd", + "stringsource", + "env/lib/python3.8/site-packages/Cython/Includes/cpython/type.pxd", + "env/lib/python3.8/site-packages/Cython/Includes/cpython/bool.pxd", + "env/lib/python3.8/site-packages/Cython/Includes/cpython/complex.pxd", }; /*--- Type declarations ---*/ @@ -470,7 +917,7 @@ struct __pyx_obj_9metrohash_MetroHash128; struct __pyx_opt_args_9metrohash_metrohash64; struct __pyx_opt_args_9metrohash_metrohash128; -/* "metrohash.pyx":80 +/* "metrohash.pyx":86 * * * cpdef metrohash64(data, uint64 seed=0ULL): # <<<<<<<<<<<<<< @@ -482,7 +929,7 @@ struct __pyx_opt_args_9metrohash_metrohash64 { uint64 seed; }; -/* "metrohash.pyx":102 +/* "metrohash.pyx":108 * * * cpdef metrohash128(data, uint64 seed=0ULL): # <<<<<<<<<<<<<< @@ -494,7 +941,7 @@ struct __pyx_opt_args_9metrohash_metrohash128 { uint64 seed; }; -/* "metrohash.pyx":125 +/* "metrohash.pyx":131 * * * cdef class MetroHash64(object): # <<<<<<<<<<<<<< @@ -507,7 +954,7 @@ struct __pyx_obj_9metrohash_MetroHash64 { }; -/* "metrohash.pyx":168 +/* "metrohash.pyx":174 * * * cdef class MetroHash128(object): # <<<<<<<<<<<<<< @@ -521,6 +968,7 @@ struct __pyx_obj_9metrohash_MetroHash128 { /* --- Runtime support code (head) --- */ +/* Refnanny.proto */ #ifndef CYTHON_REFNANNY #define CYTHON_REFNANNY 0 #endif @@ -583,46 +1031,204 @@ struct __pyx_obj_9metrohash_MetroHash128 { #define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0) #define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0) -#if CYTHON_COMPILING_IN_CPYTHON -static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) { - PyTypeObject* tp = Py_TYPE(obj); - if (likely(tp->tp_getattro)) - return tp->tp_getattro(obj, attr_name); -#if PY_MAJOR_VERSION < 3 - if (likely(tp->tp_getattr)) - return tp->tp_getattr(obj, PyString_AS_STRING(attr_name)); -#endif - return PyObject_GetAttr(obj, attr_name); -} +/* PyObjectGetAttrStr.proto */ +#if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name); #else #define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n) #endif +/* GetBuiltinName.proto */ static PyObject *__Pyx_GetBuiltinName(PyObject *name); +/* PyUnicode_Unicode.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_Unicode(PyObject *obj); + +/* PyObjectFormatAndDecref.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatSimpleAndDecref(PyObject* s, PyObject* f); +static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatAndDecref(PyObject* s, PyObject* f); + +/* IncludeStringH.proto */ +#include + +/* JoinPyUnicode.proto */ +static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength, + Py_UCS4 max_char); + +/* PyCFunctionFastCall.proto */ +#if CYTHON_FAST_PYCCALL +static CYTHON_INLINE PyObject *__Pyx_PyCFunction_FastCall(PyObject *func, PyObject **args, Py_ssize_t nargs); +#else +#define __Pyx_PyCFunction_FastCall(func, args, nargs) (assert(0), NULL) +#endif + +/* PyFunctionFastCall.proto */ +#if CYTHON_FAST_PYCALL +#define __Pyx_PyFunction_FastCall(func, args, nargs)\ + __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL) +#if 1 || PY_VERSION_HEX < 0x030600B1 +static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs); +#else +#define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs) +#endif +#define __Pyx_BUILD_ASSERT_EXPR(cond)\ + (sizeof(char [1 - 2*!(cond)]) - 1) +#ifndef Py_MEMBER_SIZE +#define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member) +#endif +#if CYTHON_FAST_PYCALL + static size_t __pyx_pyframe_localsplus_offset = 0; + #include "frameobject.h" + #define __Pxy_PyFrame_Initialize_Offsets()\ + ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)),\ + (void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus))) + #define __Pyx_PyFrame_GetLocalsplus(frame)\ + (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset)) +#endif // CYTHON_FAST_PYCALL +#endif + +/* PyObjectCall.proto */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw); #else #define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw) #endif -static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb); -static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb); +/* PyObjectCallMethO.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg); +#endif -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); +/* PyObjectCallOneArg.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg); -static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); +/* PyThreadStateGet.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyThreadState_declare PyThreadState *__pyx_tstate; +#define __Pyx_PyThreadState_assign __pyx_tstate = __Pyx_PyThreadState_Current; +#define __Pyx_PyErr_Occurred() __pyx_tstate->curexc_type +#else +#define __Pyx_PyThreadState_declare +#define __Pyx_PyThreadState_assign +#define __Pyx_PyErr_Occurred() PyErr_Occurred() +#endif -static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\ - PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\ +/* PyErrFetchRestore.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL) +#define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb) +#define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb) +#define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb) +#define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); +static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#if CYTHON_COMPILING_IN_CPYTHON +#define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL)) +#else +#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) +#endif +#else +#define __Pyx_PyErr_Clear() PyErr_Clear() +#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) +#define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb) +#define __Pyx_ErrRestoreInState(tstate, type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetchInState(tstate, type, value, tb) PyErr_Fetch(type, value, tb) +#define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb) +#endif + +/* RaiseException.proto */ +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); + +/* RaiseDoubleKeywords.proto */ +static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); + +/* ParseKeywords.proto */ +static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\ + PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\ const char* function_name); +/* RaiseArgTupleInvalid.proto */ static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); +/* PyObject_GenericGetAttrNoDict.proto */ +#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name); +#else +#define __Pyx_PyObject_GenericGetAttrNoDict PyObject_GenericGetAttr +#endif + +/* PyObject_GenericGetAttr.proto */ +#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name); +#else +#define __Pyx_PyObject_GenericGetAttr PyObject_GenericGetAttr +#endif + +/* PyErrExceptionMatches.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyErr_ExceptionMatches(err) __Pyx_PyErr_ExceptionMatchesInState(__pyx_tstate, err) +static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err); +#else +#define __Pyx_PyErr_ExceptionMatches(err) PyErr_ExceptionMatches(err) +#endif + +/* PyObjectGetAttrStrNoError.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name); + +/* SetupReduce.proto */ +static int __Pyx_setup_reduce(PyObject* type_obj); + +/* TypeImport.proto */ +#ifndef __PYX_HAVE_RT_ImportType_proto +#define __PYX_HAVE_RT_ImportType_proto +enum __Pyx_ImportType_CheckSize { + __Pyx_ImportType_CheckSize_Error = 0, + __Pyx_ImportType_CheckSize_Warn = 1, + __Pyx_ImportType_CheckSize_Ignore = 2 +}; +static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size); +#endif + +/* PyDictVersioning.proto */ +#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS +#define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1) +#define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag) +#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\ + (version_var) = __PYX_GET_DICT_VERSION(dict);\ + (cache_var) = (value); +#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\ + static PY_UINT64_T __pyx_dict_version = 0;\ + static PyObject *__pyx_dict_cached_value = NULL;\ + if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\ + (VAR) = __pyx_dict_cached_value;\ + } else {\ + (VAR) = __pyx_dict_cached_value = (LOOKUP);\ + __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\ + }\ +} +static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj); +static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj); +static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version); +#else +#define __PYX_GET_DICT_VERSION(dict) (0) +#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var) +#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) (VAR) = (LOOKUP); +#endif + +/* CLineInTraceback.proto */ +#ifdef CYTHON_CLINE_IN_TRACEBACK +#define __Pyx_CLineForTraceback(tstate, c_line) (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0) +#else +static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line); +#endif + +/* CodeObjectCache.proto */ typedef struct { - int code_line; PyCodeObject* code_object; + int code_line; } __Pyx_CodeObjectCacheEntry; struct __Pyx_CodeObjectCache { int count; @@ -634,36 +1240,52 @@ static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int co static PyCodeObject *__pyx_find_code_object(int code_line); static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object); +/* AddTraceback.proto */ static void __Pyx_AddTraceback(const char *funcname, int c_line, int py_line, const char *filename); +/* GCCDiagnostics.proto */ +#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) +#define __Pyx_HAS_GCC_DIAGNOSTIC +#endif + +/* CIntFromPy.proto */ static CYTHON_INLINE uint64_t __Pyx_PyInt_As_uint64_t(PyObject *); +/* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint64_t(uint64_t value); +/* CIntToPy.proto */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); +/* CIntFromPy.proto */ static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); +/* CIntFromPy.proto */ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); -static int __Pyx_check_binary_version(void); - -#if !defined(__Pyx_PyIdentifier_FromString) -#if PY_MAJOR_VERSION < 3 - #define __Pyx_PyIdentifier_FromString(s) PyString_FromString(s) +/* FastTypeChecks.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +#define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type) +static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b); +static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type); +static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2); #else - #define __Pyx_PyIdentifier_FromString(s) PyUnicode_FromString(s) -#endif +#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) +#define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type) +#define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2)) #endif +#define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception) -static PyObject *__Pyx_ImportModule(const char *name); - -static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, size_t size, int strict); +/* CheckBinaryVersion.proto */ +static int __Pyx_check_binary_version(void); +/* InitStrings.proto */ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); +/* Module declarations from 'cpython.long' */ + /* Module declarations from 'cpython.buffer' */ /* Module declarations from 'cpython.unicode' */ @@ -706,8 +1328,6 @@ static PyTypeObject *__pyx_ptype_7cpython_4type_type = 0; /* Module declarations from 'cpython.bool' */ static PyTypeObject *__pyx_ptype_7cpython_4bool_bool = 0; -/* Module declarations from 'cpython.long' */ - /* Module declarations from 'cpython.float' */ /* Module declarations from '__builtin__' */ @@ -715,6 +1335,8 @@ static PyTypeObject *__pyx_ptype_7cpython_4bool_bool = 0; /* Module declarations from 'cpython.complex' */ static PyTypeObject *__pyx_ptype_7cpython_7complex_complex = 0; +/* Module declarations from 'cpython.string' */ + /* Module declarations from 'cpython.dict' */ /* Module declarations from 'cpython.instance' */ @@ -737,15 +1359,13 @@ static PyTypeObject *__pyx_ptype_7cpython_7complex_complex = 0; /* Module declarations from 'cpython.set' */ -/* Module declarations from 'cpython.bytes' */ - /* Module declarations from 'cpython.pycapsule' */ /* Module declarations from 'cpython' */ /* Module declarations from 'cpython.object' */ -/* Module declarations from 'cpython.string' */ +/* Module declarations from 'cpython.bytes' */ /* Module declarations from 'metrohash' */ static PyTypeObject *__pyx_ptype_9metrohash_MetroHash64 = 0; @@ -754,50 +1374,80 @@ static PyObject *__pyx_f_9metrohash__type_error(PyObject *, PyObject *, PyObject static PyObject *__pyx_f_9metrohash_metrohash64(PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_9metrohash_metrohash64 *__pyx_optional_args); /*proto*/ static PyObject *__pyx_f_9metrohash_metrohash128(PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_9metrohash_metrohash128 *__pyx_optional_args); /*proto*/ #define __Pyx_MODULE_NAME "metrohash" +extern int __pyx_module_is_main_metrohash; int __pyx_module_is_main_metrohash = 0; /* Implementation of 'metrohash' */ static PyObject *__pyx_builtin_TypeError; static PyObject *__pyx_builtin_MemoryError; -static char __pyx_k_all[] = "__all__"; -static char __pyx_k_data[] = "data"; -static char __pyx_k_main[] = "__main__"; -static char __pyx_k_seed[] = "seed"; -static char __pyx_k_test[] = "__test__"; -static char __pyx_k_email[] = "__email__"; -static char __pyx_k_0_0_13[] = "0.0.13"; -static char __pyx_k_author[] = "__author__"; -static char __pyx_k_buffer[] = "buffer"; -static char __pyx_k_version[] = "__version__"; -static char __pyx_k_TypeError[] = "TypeError"; -static char __pyx_k_basestring[] = "basestring"; -static char __pyx_k_MemoryError[] = "MemoryError"; -static char __pyx_k_MetroHash64[] = "MetroHash64"; -static char __pyx_k_metrohash64[] = "metrohash64"; -static char __pyx_k_MetroHash128[] = "MetroHash128"; -static char __pyx_k_metrohash128[] = "metrohash128"; -static char __pyx_k_Eugene_Scherba[] = "Eugene Scherba"; -static char __pyx_k_escherba_metrohash_gmail_com[] = "escherba+metrohash@gmail.com"; -static char __pyx_k_A_Python_wrapper_for_MetroHash[] = "\nA Python wrapper for MetroHash, a fast non-cryptographic hashing algorithm\n"; -static char __pyx_k_Argument_s_has_incorrect_type_ex[] = "Argument '%s' has incorrect type (expected %s, got %s)"; -static PyObject *__pyx_kp_s_0_0_13; -static PyObject *__pyx_kp_s_Argument_s_has_incorrect_type_ex; -static PyObject *__pyx_kp_s_Eugene_Scherba; +static const char __pyx_k_[] = ")"; +static const char __pyx_k_all[] = "__all__"; +static const char __pyx_k_got[] = ", got "; +static const char __pyx_k_None[] = "None"; +static const char __pyx_k_data[] = "data"; +static const char __pyx_k_main[] = "__main__"; +static const char __pyx_k_name[] = "__name__"; +static const char __pyx_k_seed[] = "seed"; +static const char __pyx_k_test[] = "__test__"; +static const char __pyx_k_0_1_0[] = "0.1.0"; +static const char __pyx_k_email[] = "__email__"; +static const char __pyx_k_author[] = "__author__"; +static const char __pyx_k_buffer[] = "buffer"; +static const char __pyx_k_reduce[] = "__reduce__"; +static const char __pyx_k_version[] = "__version__"; +static const char __pyx_k_Argument[] = "Argument '"; +static const char __pyx_k_getstate[] = "__getstate__"; +static const char __pyx_k_setstate[] = "__setstate__"; +static const char __pyx_k_TypeError[] = "TypeError"; +static const char __pyx_k_reduce_ex[] = "__reduce_ex__"; +static const char __pyx_k_basestring[] = "basestring"; +static const char __pyx_k_MemoryError[] = "MemoryError"; +static const char __pyx_k_MetroHash64[] = "MetroHash64"; +static const char __pyx_k_metrohash64[] = "metrohash64"; +static const char __pyx_k_MetroHash128[] = "MetroHash128"; +static const char __pyx_k_metrohash128[] = "metrohash128"; +static const char __pyx_k_reduce_cython[] = "__reduce_cython__"; +static const char __pyx_k_Eugene_Scherba[] = "Eugene Scherba"; +static const char __pyx_k_setstate_cython[] = "__setstate_cython__"; +static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; +static const char __pyx_k_has_incorrect_type_expected[] = "' has incorrect type (expected "; +static const char __pyx_k_escherba_metrohash_gmail_com[] = "escherba+metrohash@gmail.com"; +static const char __pyx_k_A_Python_wrapper_for_MetroHash[] = "\nA Python wrapper for MetroHash, a fast non-cryptographic hashing algorithm\n"; +static const char __pyx_k_no_default___reduce___due_to_non[] = "no default __reduce__ due to non-trivial __cinit__"; +static PyObject *__pyx_kp_u_; +static PyObject *__pyx_kp_u_0_1_0; +static PyObject *__pyx_kp_u_Argument; +static PyObject *__pyx_kp_u_Eugene_Scherba; static PyObject *__pyx_n_s_MemoryError; static PyObject *__pyx_n_s_MetroHash128; +static PyObject *__pyx_n_u_MetroHash128; static PyObject *__pyx_n_s_MetroHash64; +static PyObject *__pyx_n_u_MetroHash64; +static PyObject *__pyx_kp_u_None; static PyObject *__pyx_n_s_TypeError; static PyObject *__pyx_n_s_all; static PyObject *__pyx_n_s_author; -static PyObject *__pyx_n_s_basestring; -static PyObject *__pyx_n_s_buffer; +static PyObject *__pyx_n_u_basestring; +static PyObject *__pyx_n_u_buffer; +static PyObject *__pyx_n_s_cline_in_traceback; static PyObject *__pyx_n_s_data; +static PyObject *__pyx_n_u_data; static PyObject *__pyx_n_s_email; -static PyObject *__pyx_kp_s_escherba_metrohash_gmail_com; +static PyObject *__pyx_kp_u_escherba_metrohash_gmail_com; +static PyObject *__pyx_n_s_getstate; +static PyObject *__pyx_kp_u_got; +static PyObject *__pyx_kp_u_has_incorrect_type_expected; static PyObject *__pyx_n_s_main; -static PyObject *__pyx_n_s_metrohash128; -static PyObject *__pyx_n_s_metrohash64; +static PyObject *__pyx_n_u_metrohash128; +static PyObject *__pyx_n_u_metrohash64; +static PyObject *__pyx_n_s_name; +static PyObject *__pyx_kp_s_no_default___reduce___due_to_non; +static PyObject *__pyx_n_s_reduce; +static PyObject *__pyx_n_s_reduce_cython; +static PyObject *__pyx_n_s_reduce_ex; static PyObject *__pyx_n_s_seed; +static PyObject *__pyx_n_s_setstate; +static PyObject *__pyx_n_s_setstate_cython; static PyObject *__pyx_n_s_test; static PyObject *__pyx_n_s_version; static PyObject *__pyx_pf_9metrohash_metrohash64(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_data, uint64 __pyx_v_seed); /* proto */ @@ -807,16 +1457,25 @@ static void __pyx_pf_9metrohash_11MetroHash64_2__dealloc__(struct __pyx_obj_9met static PyObject *__pyx_pf_9metrohash_11MetroHash64_4initialize(struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self, uint64 __pyx_v_seed); /* proto */ static PyObject *__pyx_pf_9metrohash_11MetroHash64_6update(struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self, PyObject *__pyx_v_data); /* proto */ static PyObject *__pyx_pf_9metrohash_11MetroHash64_8intdigest(struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_9metrohash_11MetroHash64_10__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_9metrohash_11MetroHash64_12__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ static int __pyx_pf_9metrohash_12MetroHash128___cinit__(struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self, uint64 __pyx_v_seed); /* proto */ static void __pyx_pf_9metrohash_12MetroHash128_2__dealloc__(struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_9metrohash_12MetroHash128_4initialize(struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self, uint64 __pyx_v_seed); /* proto */ static PyObject *__pyx_pf_9metrohash_12MetroHash128_6update(struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self, PyObject *__pyx_v_data); /* proto */ static PyObject *__pyx_pf_9metrohash_12MetroHash128_8intdigest(struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_9metrohash_12MetroHash128_10__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_9metrohash_12MetroHash128_12__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ static PyObject *__pyx_tp_new_9metrohash_MetroHash64(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_9metrohash_MetroHash128(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_int_18446744073709551616L; +static PyObject *__pyx_tuple__2; +static PyObject *__pyx_tuple__3; +static PyObject *__pyx_tuple__4; +static PyObject *__pyx_tuple__5; +/* Late includes */ -/* "metrohash.pyx":73 +/* "metrohash.pyx":79 * * * cdef object _type_error(str argname, expected, value): # <<<<<<<<<<<<<< @@ -828,13 +1487,15 @@ static PyObject *__pyx_f_9metrohash__type_error(PyObject *__pyx_v_argname, PyObj PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; + Py_ssize_t __pyx_t_2; + Py_UCS4 __pyx_t_3; + PyObject *__pyx_t_4 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("_type_error", 0); - /* "metrohash.pyx":74 + /* "metrohash.pyx":80 * * cdef object _type_error(str argname, expected, value): * return TypeError( # <<<<<<<<<<<<<< @@ -843,56 +1504,89 @@ static PyObject *__pyx_f_9metrohash__type_error(PyObject *__pyx_v_argname, PyObj */ __Pyx_XDECREF(__pyx_r); - /* "metrohash.pyx":76 + /* "metrohash.pyx":81 + * cdef object _type_error(str argname, expected, value): + * return TypeError( + * "Argument '%s' has incorrect type (expected %s, got %s)" % # <<<<<<<<<<<<<< + * (argname, expected, type(value)) + * ) + */ + __pyx_t_1 = PyTuple_New(7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 81, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = 0; + __pyx_t_3 = 127; + __Pyx_INCREF(__pyx_kp_u_Argument); + __pyx_t_2 += 10; + __Pyx_GIVEREF(__pyx_kp_u_Argument); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_Argument); + + /* "metrohash.pyx":82 * return TypeError( * "Argument '%s' has incorrect type (expected %s, got %s)" % * (argname, expected, type(value)) # <<<<<<<<<<<<<< * ) * */ - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_argname); - __Pyx_GIVEREF(__pyx_v_argname); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_argname); - __Pyx_INCREF(__pyx_v_expected); - __Pyx_GIVEREF(__pyx_v_expected); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_expected); - __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_value))); - __Pyx_GIVEREF(((PyObject *)Py_TYPE(__pyx_v_value))); - PyTuple_SET_ITEM(__pyx_t_1, 2, ((PyObject *)Py_TYPE(__pyx_v_value))); - - /* "metrohash.pyx":75 + __pyx_t_4 = __Pyx_PyUnicode_Unicode(__pyx_v_argname); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 82, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_3) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_3; + __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_4); + __pyx_t_4 = 0; + __Pyx_INCREF(__pyx_kp_u_has_incorrect_type_expected); + __pyx_t_2 += 31; + __Pyx_GIVEREF(__pyx_kp_u_has_incorrect_type_expected); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_kp_u_has_incorrect_type_expected); + __pyx_t_4 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_expected), __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 82, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_3) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_3; + __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_4); + __pyx_t_4 = 0; + __Pyx_INCREF(__pyx_kp_u_got); + __pyx_t_2 += 6; + __Pyx_GIVEREF(__pyx_kp_u_got); + PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_kp_u_got); + __pyx_t_4 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(((PyObject *)Py_TYPE(__pyx_v_value))), __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 82, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_3) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_3; + __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_1, 5, __pyx_t_4); + __pyx_t_4 = 0; + __Pyx_INCREF(__pyx_kp_u_); + __pyx_t_2 += 1; + __Pyx_GIVEREF(__pyx_kp_u_); + PyTuple_SET_ITEM(__pyx_t_1, 6, __pyx_kp_u_); + + /* "metrohash.pyx":81 * cdef object _type_error(str argname, expected, value): * return TypeError( * "Argument '%s' has incorrect type (expected %s, got %s)" % # <<<<<<<<<<<<<< * (argname, expected, type(value)) * ) */ - __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_Argument_s_has_incorrect_type_ex, __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = __Pyx_PyUnicode_Join(__pyx_t_1, 7, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 81, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "metrohash.pyx":74 + /* "metrohash.pyx":80 * * cdef object _type_error(str argname, expected, value): * return TypeError( # <<<<<<<<<<<<<< * "Argument '%s' has incorrect type (expected %s, got %s)" % * (argname, expected, type(value)) */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 80, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; goto __pyx_L0; - /* "metrohash.pyx":73 + /* "metrohash.pyx":79 * * * cdef object _type_error(str argname, expected, value): # <<<<<<<<<<<<<< @@ -903,7 +1597,7 @@ static PyObject *__pyx_f_9metrohash__type_error(PyObject *__pyx_v_argname, PyObj /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("metrohash._type_error", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; @@ -912,7 +1606,7 @@ static PyObject *__pyx_f_9metrohash__type_error(PyObject *__pyx_v_argname, PyObj return __pyx_r; } -/* "metrohash.pyx":80 +/* "metrohash.pyx":86 * * * cpdef metrohash64(data, uint64 seed=0ULL): # <<<<<<<<<<<<<< @@ -942,7 +1636,7 @@ static PyObject *__pyx_f_9metrohash_metrohash64(PyObject *__pyx_v_data, CYTHON_U } } - /* "metrohash.pyx":86 + /* "metrohash.pyx":92 * cdef object obj * cdef uint64 result * if PyUnicode_Check(data): # <<<<<<<<<<<<<< @@ -952,46 +1646,46 @@ static PyObject *__pyx_f_9metrohash_metrohash64(PyObject *__pyx_v_data, CYTHON_U __pyx_t_1 = (PyUnicode_Check(__pyx_v_data) != 0); if (__pyx_t_1) { - /* "metrohash.pyx":87 + /* "metrohash.pyx":93 * cdef uint64 result * if PyUnicode_Check(data): * obj = PyUnicode_AsUTF8String(data) # <<<<<<<<<<<<<< * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) * result = c_metrohash64(buf.buf, buf.len, seed) */ - __pyx_t_2 = PyUnicode_AsUTF8String(__pyx_v_data); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyUnicode_AsUTF8String(__pyx_v_data); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 93, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_obj = __pyx_t_2; __pyx_t_2 = 0; - /* "metrohash.pyx":88 + /* "metrohash.pyx":94 * if PyUnicode_Check(data): * obj = PyUnicode_AsUTF8String(data) * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) # <<<<<<<<<<<<<< * result = c_metrohash64(buf.buf, buf.len, seed) * Py_DECREF(obj) */ - __pyx_t_3 = PyObject_GetBuffer(__pyx_v_obj, (&__pyx_v_buf), PyBUF_SIMPLE); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_GetBuffer(__pyx_v_obj, (&__pyx_v_buf), PyBUF_SIMPLE); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 94, __pyx_L1_error) - /* "metrohash.pyx":89 + /* "metrohash.pyx":95 * obj = PyUnicode_AsUTF8String(data) * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) * result = c_metrohash64(buf.buf, buf.len, seed) # <<<<<<<<<<<<<< * Py_DECREF(obj) - * elif PyString_Check(data): + * elif PyBytes_Check(data): */ __pyx_v_result = metrohash64(((uint8 const *)__pyx_v_buf.buf), __pyx_v_buf.len, __pyx_v_seed); - /* "metrohash.pyx":90 + /* "metrohash.pyx":96 * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) * result = c_metrohash64(buf.buf, buf.len, seed) * Py_DECREF(obj) # <<<<<<<<<<<<<< - * elif PyString_Check(data): - * result = c_metrohash64(PyString_AS_STRING(data), + * elif PyBytes_Check(data): + * result = c_metrohash64(PyBytes_AS_STRING(data), */ Py_DECREF(__pyx_v_obj); - /* "metrohash.pyx":86 + /* "metrohash.pyx":92 * cdef object obj * cdef uint64 result * if PyUnicode_Check(data): # <<<<<<<<<<<<<< @@ -1001,55 +1695,55 @@ static PyObject *__pyx_f_9metrohash_metrohash64(PyObject *__pyx_v_data, CYTHON_U goto __pyx_L3; } - /* "metrohash.pyx":91 + /* "metrohash.pyx":97 * result = c_metrohash64(buf.buf, buf.len, seed) * Py_DECREF(obj) - * elif PyString_Check(data): # <<<<<<<<<<<<<< - * result = c_metrohash64(PyString_AS_STRING(data), - * PyString_GET_SIZE(data), seed) + * elif PyBytes_Check(data): # <<<<<<<<<<<<<< + * result = c_metrohash64(PyBytes_AS_STRING(data), + * PyBytes_GET_SIZE(data), seed) */ - __pyx_t_1 = (PyString_Check(__pyx_v_data) != 0); + __pyx_t_1 = (PyBytes_Check(__pyx_v_data) != 0); if (__pyx_t_1) { - /* "metrohash.pyx":92 + /* "metrohash.pyx":98 * Py_DECREF(obj) - * elif PyString_Check(data): - * result = c_metrohash64(PyString_AS_STRING(data), # <<<<<<<<<<<<<< - * PyString_GET_SIZE(data), seed) + * elif PyBytes_Check(data): + * result = c_metrohash64(PyBytes_AS_STRING(data), # <<<<<<<<<<<<<< + * PyBytes_GET_SIZE(data), seed) * elif PyObject_CheckBuffer(data): */ - __pyx_v_result = metrohash64(((uint8 const *)PyString_AS_STRING(__pyx_v_data)), PyString_GET_SIZE(__pyx_v_data), __pyx_v_seed); + __pyx_v_result = metrohash64(((uint8 const *)PyBytes_AS_STRING(__pyx_v_data)), PyBytes_GET_SIZE(__pyx_v_data), __pyx_v_seed); - /* "metrohash.pyx":91 + /* "metrohash.pyx":97 * result = c_metrohash64(buf.buf, buf.len, seed) * Py_DECREF(obj) - * elif PyString_Check(data): # <<<<<<<<<<<<<< - * result = c_metrohash64(PyString_AS_STRING(data), - * PyString_GET_SIZE(data), seed) + * elif PyBytes_Check(data): # <<<<<<<<<<<<<< + * result = c_metrohash64(PyBytes_AS_STRING(data), + * PyBytes_GET_SIZE(data), seed) */ goto __pyx_L3; } - /* "metrohash.pyx":94 - * result = c_metrohash64(PyString_AS_STRING(data), - * PyString_GET_SIZE(data), seed) + /* "metrohash.pyx":100 + * result = c_metrohash64(PyBytes_AS_STRING(data), + * PyBytes_GET_SIZE(data), seed) * elif PyObject_CheckBuffer(data): # <<<<<<<<<<<<<< * PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) * result = c_metrohash64(buf.buf, buf.len, seed) */ __pyx_t_1 = (PyObject_CheckBuffer(__pyx_v_data) != 0); - if (__pyx_t_1) { + if (likely(__pyx_t_1)) { - /* "metrohash.pyx":95 - * PyString_GET_SIZE(data), seed) + /* "metrohash.pyx":101 + * PyBytes_GET_SIZE(data), seed) * elif PyObject_CheckBuffer(data): * PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) # <<<<<<<<<<<<<< * result = c_metrohash64(buf.buf, buf.len, seed) * else: */ - __pyx_t_3 = PyObject_GetBuffer(__pyx_v_data, (&__pyx_v_buf), PyBUF_SIMPLE); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_GetBuffer(__pyx_v_data, (&__pyx_v_buf), PyBUF_SIMPLE); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 101, __pyx_L1_error) - /* "metrohash.pyx":96 + /* "metrohash.pyx":102 * elif PyObject_CheckBuffer(data): * PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) * result = c_metrohash64(buf.buf, buf.len, seed) # <<<<<<<<<<<<<< @@ -1058,9 +1752,9 @@ static PyObject *__pyx_f_9metrohash_metrohash64(PyObject *__pyx_v_data, CYTHON_U */ __pyx_v_result = metrohash64(((uint8 const *)__pyx_v_buf.buf), __pyx_v_buf.len, __pyx_v_seed); - /* "metrohash.pyx":94 - * result = c_metrohash64(PyString_AS_STRING(data), - * PyString_GET_SIZE(data), seed) + /* "metrohash.pyx":100 + * result = c_metrohash64(PyBytes_AS_STRING(data), + * PyBytes_GET_SIZE(data), seed) * elif PyObject_CheckBuffer(data): # <<<<<<<<<<<<<< * PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) * result = c_metrohash64(buf.buf, buf.len, seed) @@ -1068,7 +1762,7 @@ static PyObject *__pyx_f_9metrohash_metrohash64(PyObject *__pyx_v_data, CYTHON_U goto __pyx_L3; } - /* "metrohash.pyx":98 + /* "metrohash.pyx":104 * result = c_metrohash64(buf.buf, buf.len, seed) * else: * raise _type_error("data", ["basestring", "buffer"], data) # <<<<<<<<<<<<<< @@ -1076,24 +1770,24 @@ static PyObject *__pyx_f_9metrohash_metrohash64(PyObject *__pyx_v_data, CYTHON_U * */ /*else*/ { - __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 104, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_n_s_basestring); - __Pyx_GIVEREF(__pyx_n_s_basestring); - PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_basestring); - __Pyx_INCREF(__pyx_n_s_buffer); - __Pyx_GIVEREF(__pyx_n_s_buffer); - PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_buffer); - __pyx_t_4 = __pyx_f_9metrohash__type_error(__pyx_n_s_data, __pyx_t_2, __pyx_v_data); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_n_u_basestring); + __Pyx_GIVEREF(__pyx_n_u_basestring); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_u_basestring); + __Pyx_INCREF(__pyx_n_u_buffer); + __Pyx_GIVEREF(__pyx_n_u_buffer); + PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_u_buffer); + __pyx_t_4 = __pyx_f_9metrohash__type_error(__pyx_n_u_data, __pyx_t_2, __pyx_v_data); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 104, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __PYX_ERR(0, 104, __pyx_L1_error) } __pyx_L3:; - /* "metrohash.pyx":99 + /* "metrohash.pyx":105 * else: * raise _type_error("data", ["basestring", "buffer"], data) * return result # <<<<<<<<<<<<<< @@ -1101,13 +1795,13 @@ static PyObject *__pyx_f_9metrohash_metrohash64(PyObject *__pyx_v_data, CYTHON_U * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_PyInt_From_uint64_t(__pyx_v_result); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyInt_From_uint64_t(__pyx_v_result); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 105, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0; - /* "metrohash.pyx":80 + /* "metrohash.pyx":86 * * * cpdef metrohash64(data, uint64 seed=0ULL): # <<<<<<<<<<<<<< @@ -1148,27 +1842,31 @@ static PyObject *__pyx_pw_9metrohash_1metrohash64(PyObject *__pyx_self, PyObject const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: - if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_data)) != 0)) kw_args--; + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_data)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; case 1: if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_seed); + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_seed); if (value) { values[1] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "metrohash64") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "metrohash64") < 0)) __PYX_ERR(0, 86, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); break; default: goto __pyx_L5_argtuple_error; @@ -1176,14 +1874,14 @@ static PyObject *__pyx_pw_9metrohash_1metrohash64(PyObject *__pyx_self, PyObject } __pyx_v_data = values[0]; if (values[1]) { - __pyx_v_seed = __Pyx_PyInt_As_uint64_t(values[1]); if (unlikely((__pyx_v_seed == (uint64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_seed = __Pyx_PyInt_As_uint64_t(values[1]); if (unlikely((__pyx_v_seed == ((uint64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 86, __pyx_L3_error) } else { __pyx_v_seed = ((uint64)0ULL); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("metrohash64", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("metrohash64", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 86, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("metrohash.metrohash64", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -1208,7 +1906,7 @@ static PyObject *__pyx_pf_9metrohash_metrohash64(CYTHON_UNUSED PyObject *__pyx_s __Pyx_XDECREF(__pyx_r); __pyx_t_2.__pyx_n = 1; __pyx_t_2.seed = __pyx_v_seed; - __pyx_t_1 = __pyx_f_9metrohash_metrohash64(__pyx_v_data, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_f_9metrohash_metrohash64(__pyx_v_data, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 86, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -1225,7 +1923,7 @@ static PyObject *__pyx_pf_9metrohash_metrohash64(CYTHON_UNUSED PyObject *__pyx_s return __pyx_r; } -/* "metrohash.pyx":102 +/* "metrohash.pyx":108 * * * cpdef metrohash128(data, uint64 seed=0ULL): # <<<<<<<<<<<<<< @@ -1257,7 +1955,7 @@ static PyObject *__pyx_f_9metrohash_metrohash128(PyObject *__pyx_v_data, CYTHON_ } } - /* "metrohash.pyx":108 + /* "metrohash.pyx":114 * cdef object obj * cdef pair[uint64, uint64] result * if PyUnicode_Check(data): # <<<<<<<<<<<<<< @@ -1267,46 +1965,46 @@ static PyObject *__pyx_f_9metrohash_metrohash128(PyObject *__pyx_v_data, CYTHON_ __pyx_t_1 = (PyUnicode_Check(__pyx_v_data) != 0); if (__pyx_t_1) { - /* "metrohash.pyx":109 + /* "metrohash.pyx":115 * cdef pair[uint64, uint64] result * if PyUnicode_Check(data): * obj = PyUnicode_AsUTF8String(data) # <<<<<<<<<<<<<< * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) * result = c_metrohash128(buf.buf, buf.len, seed) */ - __pyx_t_2 = PyUnicode_AsUTF8String(__pyx_v_data); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyUnicode_AsUTF8String(__pyx_v_data); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 115, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_obj = __pyx_t_2; __pyx_t_2 = 0; - /* "metrohash.pyx":110 + /* "metrohash.pyx":116 * if PyUnicode_Check(data): * obj = PyUnicode_AsUTF8String(data) * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) # <<<<<<<<<<<<<< * result = c_metrohash128(buf.buf, buf.len, seed) * Py_DECREF(obj) */ - __pyx_t_3 = PyObject_GetBuffer(__pyx_v_obj, (&__pyx_v_buf), PyBUF_SIMPLE); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_GetBuffer(__pyx_v_obj, (&__pyx_v_buf), PyBUF_SIMPLE); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 116, __pyx_L1_error) - /* "metrohash.pyx":111 + /* "metrohash.pyx":117 * obj = PyUnicode_AsUTF8String(data) * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) * result = c_metrohash128(buf.buf, buf.len, seed) # <<<<<<<<<<<<<< * Py_DECREF(obj) - * elif PyString_Check(data): + * elif PyBytes_Check(data): */ __pyx_v_result = metrohash128(((uint8 const *)__pyx_v_buf.buf), __pyx_v_buf.len, __pyx_v_seed); - /* "metrohash.pyx":112 + /* "metrohash.pyx":118 * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) * result = c_metrohash128(buf.buf, buf.len, seed) * Py_DECREF(obj) # <<<<<<<<<<<<<< - * elif PyString_Check(data): - * result = c_metrohash128(PyString_AS_STRING(data), + * elif PyBytes_Check(data): + * result = c_metrohash128(PyBytes_AS_STRING(data), */ Py_DECREF(__pyx_v_obj); - /* "metrohash.pyx":108 + /* "metrohash.pyx":114 * cdef object obj * cdef pair[uint64, uint64] result * if PyUnicode_Check(data): # <<<<<<<<<<<<<< @@ -1316,55 +2014,55 @@ static PyObject *__pyx_f_9metrohash_metrohash128(PyObject *__pyx_v_data, CYTHON_ goto __pyx_L3; } - /* "metrohash.pyx":113 + /* "metrohash.pyx":119 * result = c_metrohash128(buf.buf, buf.len, seed) * Py_DECREF(obj) - * elif PyString_Check(data): # <<<<<<<<<<<<<< - * result = c_metrohash128(PyString_AS_STRING(data), - * PyString_GET_SIZE(data), seed) + * elif PyBytes_Check(data): # <<<<<<<<<<<<<< + * result = c_metrohash128(PyBytes_AS_STRING(data), + * PyBytes_GET_SIZE(data), seed) */ - __pyx_t_1 = (PyString_Check(__pyx_v_data) != 0); + __pyx_t_1 = (PyBytes_Check(__pyx_v_data) != 0); if (__pyx_t_1) { - /* "metrohash.pyx":114 + /* "metrohash.pyx":120 * Py_DECREF(obj) - * elif PyString_Check(data): - * result = c_metrohash128(PyString_AS_STRING(data), # <<<<<<<<<<<<<< - * PyString_GET_SIZE(data), seed) + * elif PyBytes_Check(data): + * result = c_metrohash128(PyBytes_AS_STRING(data), # <<<<<<<<<<<<<< + * PyBytes_GET_SIZE(data), seed) * elif PyObject_CheckBuffer(data): */ - __pyx_v_result = metrohash128(((uint8 const *)PyString_AS_STRING(__pyx_v_data)), PyString_GET_SIZE(__pyx_v_data), __pyx_v_seed); + __pyx_v_result = metrohash128(((uint8 const *)PyBytes_AS_STRING(__pyx_v_data)), PyBytes_GET_SIZE(__pyx_v_data), __pyx_v_seed); - /* "metrohash.pyx":113 + /* "metrohash.pyx":119 * result = c_metrohash128(buf.buf, buf.len, seed) * Py_DECREF(obj) - * elif PyString_Check(data): # <<<<<<<<<<<<<< - * result = c_metrohash128(PyString_AS_STRING(data), - * PyString_GET_SIZE(data), seed) + * elif PyBytes_Check(data): # <<<<<<<<<<<<<< + * result = c_metrohash128(PyBytes_AS_STRING(data), + * PyBytes_GET_SIZE(data), seed) */ goto __pyx_L3; } - /* "metrohash.pyx":116 - * result = c_metrohash128(PyString_AS_STRING(data), - * PyString_GET_SIZE(data), seed) + /* "metrohash.pyx":122 + * result = c_metrohash128(PyBytes_AS_STRING(data), + * PyBytes_GET_SIZE(data), seed) * elif PyObject_CheckBuffer(data): # <<<<<<<<<<<<<< * PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) * result = c_metrohash128(buf.buf, buf.len, seed) */ __pyx_t_1 = (PyObject_CheckBuffer(__pyx_v_data) != 0); - if (__pyx_t_1) { + if (likely(__pyx_t_1)) { - /* "metrohash.pyx":117 - * PyString_GET_SIZE(data), seed) + /* "metrohash.pyx":123 + * PyBytes_GET_SIZE(data), seed) * elif PyObject_CheckBuffer(data): * PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) # <<<<<<<<<<<<<< * result = c_metrohash128(buf.buf, buf.len, seed) * else: */ - __pyx_t_3 = PyObject_GetBuffer(__pyx_v_data, (&__pyx_v_buf), PyBUF_SIMPLE); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_GetBuffer(__pyx_v_data, (&__pyx_v_buf), PyBUF_SIMPLE); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 123, __pyx_L1_error) - /* "metrohash.pyx":118 + /* "metrohash.pyx":124 * elif PyObject_CheckBuffer(data): * PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) * result = c_metrohash128(buf.buf, buf.len, seed) # <<<<<<<<<<<<<< @@ -1373,9 +2071,9 @@ static PyObject *__pyx_f_9metrohash_metrohash128(PyObject *__pyx_v_data, CYTHON_ */ __pyx_v_result = metrohash128(((uint8 const *)__pyx_v_buf.buf), __pyx_v_buf.len, __pyx_v_seed); - /* "metrohash.pyx":116 - * result = c_metrohash128(PyString_AS_STRING(data), - * PyString_GET_SIZE(data), seed) + /* "metrohash.pyx":122 + * result = c_metrohash128(PyBytes_AS_STRING(data), + * PyBytes_GET_SIZE(data), seed) * elif PyObject_CheckBuffer(data): # <<<<<<<<<<<<<< * PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) * result = c_metrohash128(buf.buf, buf.len, seed) @@ -1383,7 +2081,7 @@ static PyObject *__pyx_f_9metrohash_metrohash128(PyObject *__pyx_v_data, CYTHON_ goto __pyx_L3; } - /* "metrohash.pyx":120 + /* "metrohash.pyx":126 * result = c_metrohash128(buf.buf, buf.len, seed) * else: * raise _type_error("data", ["basestring", "buffer"], data) # <<<<<<<<<<<<<< @@ -1391,61 +2089,52 @@ static PyObject *__pyx_f_9metrohash_metrohash128(PyObject *__pyx_v_data, CYTHON_ * return final */ /*else*/ { - __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 126, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_n_s_basestring); - __Pyx_GIVEREF(__pyx_n_s_basestring); - PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_basestring); - __Pyx_INCREF(__pyx_n_s_buffer); - __Pyx_GIVEREF(__pyx_n_s_buffer); - PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_buffer); - __pyx_t_4 = __pyx_f_9metrohash__type_error(__pyx_n_s_data, __pyx_t_2, __pyx_v_data); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_n_u_basestring); + __Pyx_GIVEREF(__pyx_n_u_basestring); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_u_basestring); + __Pyx_INCREF(__pyx_n_u_buffer); + __Pyx_GIVEREF(__pyx_n_u_buffer); + PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_u_buffer); + __pyx_t_4 = __pyx_f_9metrohash__type_error(__pyx_n_u_data, __pyx_t_2, __pyx_v_data); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 126, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __PYX_ERR(0, 126, __pyx_L1_error) } __pyx_L3:; - /* "metrohash.pyx":121 + /* "metrohash.pyx":127 * else: * raise _type_error("data", ["basestring", "buffer"], data) * final = 0x10000000000000000L * long(result.first) + long(result.second) # <<<<<<<<<<<<<< * return final * */ - __pyx_t_4 = __Pyx_PyInt_From_uint64_t(__pyx_v_result.first); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyInt_From_uint64_t(__pyx_v_result.first); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 127, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyLong_Type)), __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 127, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)(&PyLong_Type)), __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyNumber_Multiply(__pyx_int_18446744073709551616L, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 127, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyNumber_Multiply(__pyx_int_18446744073709551616L, __pyx_t_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyInt_From_uint64_t(__pyx_v_result.second); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 127, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyInt_From_uint64_t(__pyx_v_result.second); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)(&PyLong_Type)), __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyNumber_Add(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyLong_Type)), __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 127, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyNumber_Add(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 127, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_final = __pyx_t_5; - __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (!(likely(PyLong_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "long", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 127, __pyx_L1_error) + __pyx_v_final = ((PyObject*)__pyx_t_2); + __pyx_t_2 = 0; - /* "metrohash.pyx":122 + /* "metrohash.pyx":128 * raise _type_error("data", ["basestring", "buffer"], data) * final = 0x10000000000000000L * long(result.first) + long(result.second) * return final # <<<<<<<<<<<<<< @@ -1457,7 +2146,7 @@ static PyObject *__pyx_f_9metrohash_metrohash128(PyObject *__pyx_v_data, CYTHON_ __pyx_r = __pyx_v_final; goto __pyx_L0; - /* "metrohash.pyx":102 + /* "metrohash.pyx":108 * * * cpdef metrohash128(data, uint64 seed=0ULL): # <<<<<<<<<<<<<< @@ -1500,27 +2189,31 @@ static PyObject *__pyx_pw_9metrohash_3metrohash128(PyObject *__pyx_self, PyObjec const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: - if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_data)) != 0)) kw_args--; + if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_data)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; case 1: if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_seed); + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_seed); if (value) { values[1] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "metrohash128") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "metrohash128") < 0)) __PYX_ERR(0, 108, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); break; default: goto __pyx_L5_argtuple_error; @@ -1528,14 +2221,14 @@ static PyObject *__pyx_pw_9metrohash_3metrohash128(PyObject *__pyx_self, PyObjec } __pyx_v_data = values[0]; if (values[1]) { - __pyx_v_seed = __Pyx_PyInt_As_uint64_t(values[1]); if (unlikely((__pyx_v_seed == (uint64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_seed = __Pyx_PyInt_As_uint64_t(values[1]); if (unlikely((__pyx_v_seed == ((uint64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 108, __pyx_L3_error) } else { __pyx_v_seed = ((uint64)0ULL); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("metrohash128", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("metrohash128", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 108, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("metrohash.metrohash128", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -1560,7 +2253,7 @@ static PyObject *__pyx_pf_9metrohash_2metrohash128(CYTHON_UNUSED PyObject *__pyx __Pyx_XDECREF(__pyx_r); __pyx_t_2.__pyx_n = 1; __pyx_t_2.seed = __pyx_v_seed; - __pyx_t_1 = __pyx_f_9metrohash_metrohash128(__pyx_v_data, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_f_9metrohash_metrohash128(__pyx_v_data, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 108, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -1577,7 +2270,7 @@ static PyObject *__pyx_pf_9metrohash_2metrohash128(CYTHON_UNUSED PyObject *__pyx return __pyx_r; } -/* "metrohash.pyx":132 +/* "metrohash.pyx":138 * cdef CCMetroHash64* _m * * def __cinit__(self, uint64 seed=0ULL): # <<<<<<<<<<<<<< @@ -1603,6 +2296,7 @@ static int __pyx_pw_9metrohash_11MetroHash64_1__cinit__(PyObject *__pyx_v_self, const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } @@ -1610,29 +2304,30 @@ static int __pyx_pw_9metrohash_11MetroHash64_1__cinit__(PyObject *__pyx_v_self, switch (pos_args) { case 0: if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_seed); + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_seed); if (value) { values[0] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(0, 138, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } } if (values[0]) { - __pyx_v_seed = __Pyx_PyInt_As_uint64_t(values[0]); if (unlikely((__pyx_v_seed == (uint64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_seed = __Pyx_PyInt_As_uint64_t(values[0]); if (unlikely((__pyx_v_seed == ((uint64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 138, __pyx_L3_error) } else { __pyx_v_seed = ((uint64)0ULL); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 138, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("metrohash.MetroHash64.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -1654,7 +2349,7 @@ static int __pyx_pf_9metrohash_11MetroHash64___cinit__(struct __pyx_obj_9metroha int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__cinit__", 0); - /* "metrohash.pyx":133 + /* "metrohash.pyx":139 * * def __cinit__(self, uint64 seed=0ULL): * self._m = new CCMetroHash64(seed) # <<<<<<<<<<<<<< @@ -1663,7 +2358,7 @@ static int __pyx_pf_9metrohash_11MetroHash64___cinit__(struct __pyx_obj_9metroha */ __pyx_v_self->_m = new MetroHash64(__pyx_v_seed); - /* "metrohash.pyx":134 + /* "metrohash.pyx":140 * def __cinit__(self, uint64 seed=0ULL): * self._m = new CCMetroHash64(seed) * if self._m is NULL: # <<<<<<<<<<<<<< @@ -1671,18 +2366,18 @@ static int __pyx_pf_9metrohash_11MetroHash64___cinit__(struct __pyx_obj_9metroha * */ __pyx_t_1 = ((__pyx_v_self->_m == NULL) != 0); - if (__pyx_t_1) { + if (unlikely(__pyx_t_1)) { - /* "metrohash.pyx":135 + /* "metrohash.pyx":141 * self._m = new CCMetroHash64(seed) * if self._m is NULL: * raise MemoryError() # <<<<<<<<<<<<<< * * def __dealloc__(self): */ - PyErr_NoMemory(); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + PyErr_NoMemory(); __PYX_ERR(0, 141, __pyx_L1_error) - /* "metrohash.pyx":134 + /* "metrohash.pyx":140 * def __cinit__(self, uint64 seed=0ULL): * self._m = new CCMetroHash64(seed) * if self._m is NULL: # <<<<<<<<<<<<<< @@ -1691,7 +2386,7 @@ static int __pyx_pf_9metrohash_11MetroHash64___cinit__(struct __pyx_obj_9metroha */ } - /* "metrohash.pyx":132 + /* "metrohash.pyx":138 * cdef CCMetroHash64* _m * * def __cinit__(self, uint64 seed=0ULL): # <<<<<<<<<<<<<< @@ -1710,7 +2405,7 @@ static int __pyx_pf_9metrohash_11MetroHash64___cinit__(struct __pyx_obj_9metroha return __pyx_r; } -/* "metrohash.pyx":137 +/* "metrohash.pyx":143 * raise MemoryError() * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -1734,7 +2429,7 @@ static void __pyx_pf_9metrohash_11MetroHash64_2__dealloc__(struct __pyx_obj_9met int __pyx_t_1; __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "metrohash.pyx":138 + /* "metrohash.pyx":144 * * def __dealloc__(self): * if not self._m is NULL: # <<<<<<<<<<<<<< @@ -1744,7 +2439,7 @@ static void __pyx_pf_9metrohash_11MetroHash64_2__dealloc__(struct __pyx_obj_9met __pyx_t_1 = ((__pyx_v_self->_m != NULL) != 0); if (__pyx_t_1) { - /* "metrohash.pyx":139 + /* "metrohash.pyx":145 * def __dealloc__(self): * if not self._m is NULL: * del self._m # <<<<<<<<<<<<<< @@ -1753,7 +2448,7 @@ static void __pyx_pf_9metrohash_11MetroHash64_2__dealloc__(struct __pyx_obj_9met */ delete __pyx_v_self->_m; - /* "metrohash.pyx":140 + /* "metrohash.pyx":146 * if not self._m is NULL: * del self._m * self._m = NULL # <<<<<<<<<<<<<< @@ -1762,7 +2457,7 @@ static void __pyx_pf_9metrohash_11MetroHash64_2__dealloc__(struct __pyx_obj_9met */ __pyx_v_self->_m = NULL; - /* "metrohash.pyx":138 + /* "metrohash.pyx":144 * * def __dealloc__(self): * if not self._m is NULL: # <<<<<<<<<<<<<< @@ -1771,7 +2466,7 @@ static void __pyx_pf_9metrohash_11MetroHash64_2__dealloc__(struct __pyx_obj_9met */ } - /* "metrohash.pyx":137 + /* "metrohash.pyx":143 * raise MemoryError() * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -1783,7 +2478,7 @@ static void __pyx_pf_9metrohash_11MetroHash64_2__dealloc__(struct __pyx_obj_9met __Pyx_RefNannyFinishContext(); } -/* "metrohash.pyx":142 +/* "metrohash.pyx":148 * self._m = NULL * * def initialize(self, uint64 seed=0ULL): # <<<<<<<<<<<<<< @@ -1809,6 +2504,7 @@ static PyObject *__pyx_pw_9metrohash_11MetroHash64_5initialize(PyObject *__pyx_v const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } @@ -1816,29 +2512,30 @@ static PyObject *__pyx_pw_9metrohash_11MetroHash64_5initialize(PyObject *__pyx_v switch (pos_args) { case 0: if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_seed); + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_seed); if (value) { values[0] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "initialize") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "initialize") < 0)) __PYX_ERR(0, 148, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } } if (values[0]) { - __pyx_v_seed = __Pyx_PyInt_As_uint64_t(values[0]); if (unlikely((__pyx_v_seed == (uint64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_seed = __Pyx_PyInt_As_uint64_t(values[0]); if (unlikely((__pyx_v_seed == ((uint64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 148, __pyx_L3_error) } else { __pyx_v_seed = ((uint64)0ULL); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("initialize", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("initialize", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 148, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("metrohash.MetroHash64.initialize", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -1856,7 +2553,7 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_4initialize(struct __pyx_obj_ __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("initialize", 0); - /* "metrohash.pyx":143 + /* "metrohash.pyx":149 * * def initialize(self, uint64 seed=0ULL): * self._m.Initialize(seed) # <<<<<<<<<<<<<< @@ -1865,7 +2562,7 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_4initialize(struct __pyx_obj_ */ __pyx_v_self->_m->Initialize(__pyx_v_seed); - /* "metrohash.pyx":142 + /* "metrohash.pyx":148 * self._m = NULL * * def initialize(self, uint64 seed=0ULL): # <<<<<<<<<<<<<< @@ -1880,7 +2577,7 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_4initialize(struct __pyx_obj_ return __pyx_r; } -/* "metrohash.pyx":145 +/* "metrohash.pyx":151 * self._m.Initialize(seed) * * def update(self, data): # <<<<<<<<<<<<<< @@ -1915,7 +2612,7 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_6update(struct __pyx_obj_9met int __pyx_clineno = 0; __Pyx_RefNannySetupContext("update", 0); - /* "metrohash.pyx":148 + /* "metrohash.pyx":154 * cdef Py_buffer buf * cdef object obj * if PyUnicode_Check(data): # <<<<<<<<<<<<<< @@ -1925,46 +2622,46 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_6update(struct __pyx_obj_9met __pyx_t_1 = (PyUnicode_Check(__pyx_v_data) != 0); if (__pyx_t_1) { - /* "metrohash.pyx":149 + /* "metrohash.pyx":155 * cdef object obj * if PyUnicode_Check(data): * obj = PyUnicode_AsUTF8String(data) # <<<<<<<<<<<<<< * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) * Py_DECREF(obj) */ - __pyx_t_2 = PyUnicode_AsUTF8String(__pyx_v_data); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyUnicode_AsUTF8String(__pyx_v_data); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 155, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_obj = __pyx_t_2; __pyx_t_2 = 0; - /* "metrohash.pyx":150 + /* "metrohash.pyx":156 * if PyUnicode_Check(data): * obj = PyUnicode_AsUTF8String(data) * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) # <<<<<<<<<<<<<< * Py_DECREF(obj) * self._m.Update(buf.buf, buf.len) */ - __pyx_t_3 = PyObject_GetBuffer(__pyx_v_obj, (&__pyx_v_buf), PyBUF_SIMPLE); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_GetBuffer(__pyx_v_obj, (&__pyx_v_buf), PyBUF_SIMPLE); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 156, __pyx_L1_error) - /* "metrohash.pyx":151 + /* "metrohash.pyx":157 * obj = PyUnicode_AsUTF8String(data) * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) * Py_DECREF(obj) # <<<<<<<<<<<<<< * self._m.Update(buf.buf, buf.len) - * elif PyString_Check(data): + * elif PyBytes_Check(data): */ Py_DECREF(__pyx_v_obj); - /* "metrohash.pyx":152 + /* "metrohash.pyx":158 * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) * Py_DECREF(obj) * self._m.Update(buf.buf, buf.len) # <<<<<<<<<<<<<< - * elif PyString_Check(data): - * self._m.Update(PyString_AS_STRING(data), + * elif PyBytes_Check(data): + * self._m.Update(PyBytes_AS_STRING(data), */ __pyx_v_self->_m->Update(((uint8 const *)__pyx_v_buf.buf), __pyx_v_buf.len); - /* "metrohash.pyx":148 + /* "metrohash.pyx":154 * cdef Py_buffer buf * cdef object obj * if PyUnicode_Check(data): # <<<<<<<<<<<<<< @@ -1974,55 +2671,55 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_6update(struct __pyx_obj_9met goto __pyx_L3; } - /* "metrohash.pyx":153 + /* "metrohash.pyx":159 * Py_DECREF(obj) * self._m.Update(buf.buf, buf.len) - * elif PyString_Check(data): # <<<<<<<<<<<<<< - * self._m.Update(PyString_AS_STRING(data), - * PyString_GET_SIZE(data)) + * elif PyBytes_Check(data): # <<<<<<<<<<<<<< + * self._m.Update(PyBytes_AS_STRING(data), + * PyBytes_GET_SIZE(data)) */ - __pyx_t_1 = (PyString_Check(__pyx_v_data) != 0); + __pyx_t_1 = (PyBytes_Check(__pyx_v_data) != 0); if (__pyx_t_1) { - /* "metrohash.pyx":154 + /* "metrohash.pyx":160 * self._m.Update(buf.buf, buf.len) - * elif PyString_Check(data): - * self._m.Update(PyString_AS_STRING(data), # <<<<<<<<<<<<<< - * PyString_GET_SIZE(data)) + * elif PyBytes_Check(data): + * self._m.Update(PyBytes_AS_STRING(data), # <<<<<<<<<<<<<< + * PyBytes_GET_SIZE(data)) * elif PyObject_CheckBuffer(data): */ - __pyx_v_self->_m->Update(((uint8 const *)PyString_AS_STRING(__pyx_v_data)), PyString_GET_SIZE(__pyx_v_data)); + __pyx_v_self->_m->Update(((uint8 const *)PyBytes_AS_STRING(__pyx_v_data)), PyBytes_GET_SIZE(__pyx_v_data)); - /* "metrohash.pyx":153 + /* "metrohash.pyx":159 * Py_DECREF(obj) * self._m.Update(buf.buf, buf.len) - * elif PyString_Check(data): # <<<<<<<<<<<<<< - * self._m.Update(PyString_AS_STRING(data), - * PyString_GET_SIZE(data)) + * elif PyBytes_Check(data): # <<<<<<<<<<<<<< + * self._m.Update(PyBytes_AS_STRING(data), + * PyBytes_GET_SIZE(data)) */ goto __pyx_L3; } - /* "metrohash.pyx":156 - * self._m.Update(PyString_AS_STRING(data), - * PyString_GET_SIZE(data)) + /* "metrohash.pyx":162 + * self._m.Update(PyBytes_AS_STRING(data), + * PyBytes_GET_SIZE(data)) * elif PyObject_CheckBuffer(data): # <<<<<<<<<<<<<< * PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) * self._m.Update(buf.buf, buf.len) */ __pyx_t_1 = (PyObject_CheckBuffer(__pyx_v_data) != 0); - if (__pyx_t_1) { + if (likely(__pyx_t_1)) { - /* "metrohash.pyx":157 - * PyString_GET_SIZE(data)) + /* "metrohash.pyx":163 + * PyBytes_GET_SIZE(data)) * elif PyObject_CheckBuffer(data): * PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) # <<<<<<<<<<<<<< * self._m.Update(buf.buf, buf.len) * else: */ - __pyx_t_3 = PyObject_GetBuffer(__pyx_v_data, (&__pyx_v_buf), PyBUF_SIMPLE); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_GetBuffer(__pyx_v_data, (&__pyx_v_buf), PyBUF_SIMPLE); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 163, __pyx_L1_error) - /* "metrohash.pyx":158 + /* "metrohash.pyx":164 * elif PyObject_CheckBuffer(data): * PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) * self._m.Update(buf.buf, buf.len) # <<<<<<<<<<<<<< @@ -2031,9 +2728,9 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_6update(struct __pyx_obj_9met */ __pyx_v_self->_m->Update(((uint8 const *)__pyx_v_buf.buf), __pyx_v_buf.len); - /* "metrohash.pyx":156 - * self._m.Update(PyString_AS_STRING(data), - * PyString_GET_SIZE(data)) + /* "metrohash.pyx":162 + * self._m.Update(PyBytes_AS_STRING(data), + * PyBytes_GET_SIZE(data)) * elif PyObject_CheckBuffer(data): # <<<<<<<<<<<<<< * PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) * self._m.Update(buf.buf, buf.len) @@ -2041,7 +2738,7 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_6update(struct __pyx_obj_9met goto __pyx_L3; } - /* "metrohash.pyx":160 + /* "metrohash.pyx":166 * self._m.Update(buf.buf, buf.len) * else: * raise _type_error("data", ["basestring", "buffer"], data) # <<<<<<<<<<<<<< @@ -2049,24 +2746,24 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_6update(struct __pyx_obj_9met * def intdigest(self): */ /*else*/ { - __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 166, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_n_s_basestring); - __Pyx_GIVEREF(__pyx_n_s_basestring); - PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_basestring); - __Pyx_INCREF(__pyx_n_s_buffer); - __Pyx_GIVEREF(__pyx_n_s_buffer); - PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_buffer); - __pyx_t_4 = __pyx_f_9metrohash__type_error(__pyx_n_s_data, __pyx_t_2, __pyx_v_data); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_n_u_basestring); + __Pyx_GIVEREF(__pyx_n_u_basestring); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_u_basestring); + __Pyx_INCREF(__pyx_n_u_buffer); + __Pyx_GIVEREF(__pyx_n_u_buffer); + PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_u_buffer); + __pyx_t_4 = __pyx_f_9metrohash__type_error(__pyx_n_u_data, __pyx_t_2, __pyx_v_data); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 166, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __PYX_ERR(0, 166, __pyx_L1_error) } __pyx_L3:; - /* "metrohash.pyx":145 + /* "metrohash.pyx":151 * self._m.Initialize(seed) * * def update(self, data): # <<<<<<<<<<<<<< @@ -2089,7 +2786,7 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_6update(struct __pyx_obj_9met return __pyx_r; } -/* "metrohash.pyx":162 +/* "metrohash.pyx":168 * raise _type_error("data", ["basestring", "buffer"], data) * * def intdigest(self): # <<<<<<<<<<<<<< @@ -2120,7 +2817,7 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_8intdigest(struct __pyx_obj_9 int __pyx_clineno = 0; __Pyx_RefNannySetupContext("intdigest", 0); - /* "metrohash.pyx":164 + /* "metrohash.pyx":170 * def intdigest(self): * cdef uint8 buf[8] * self._m.Finalize(buf) # <<<<<<<<<<<<<< @@ -2129,7 +2826,7 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_8intdigest(struct __pyx_obj_9 */ __pyx_v_self->_m->Finalize(__pyx_v_buf); - /* "metrohash.pyx":165 + /* "metrohash.pyx":171 * cdef uint8 buf[8] * self._m.Finalize(buf) * return c_bytes2int64(buf) # <<<<<<<<<<<<<< @@ -2137,13 +2834,13 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_8intdigest(struct __pyx_obj_9 * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_uint64_t(bytes2int64(__pyx_v_buf)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyInt_From_uint64_t(bytes2int64(__pyx_v_buf)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "metrohash.pyx":162 + /* "metrohash.pyx":168 * raise _type_error("data", ["basestring", "buffer"], data) * * def intdigest(self): # <<<<<<<<<<<<<< @@ -2162,7 +2859,120 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_8intdigest(struct __pyx_obj_9 return __pyx_r; } -/* "metrohash.pyx":175 +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_9metrohash_11MetroHash64_11__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_9metrohash_11MetroHash64_11__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_9metrohash_11MetroHash64_10__reduce_cython__(((struct __pyx_obj_9metrohash_MetroHash64 *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_9metrohash_11MetroHash64_10__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__reduce_cython__", 0); + + /* "(tree fragment)":2 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(1, 2, __pyx_L1_error) + + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("metrohash.MetroHash64.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_9metrohash_11MetroHash64_13__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static PyObject *__pyx_pw_9metrohash_11MetroHash64_13__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_9metrohash_11MetroHash64_12__setstate_cython__(((struct __pyx_obj_9metrohash_MetroHash64 *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_9metrohash_11MetroHash64_12__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__setstate_cython__", 0); + + /* "(tree fragment)":4 + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(1, 4, __pyx_L1_error) + + /* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("metrohash.MetroHash64.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "metrohash.pyx":181 * cdef CCMetroHash128* _m * * def __cinit__(self, uint64 seed=0ULL): # <<<<<<<<<<<<<< @@ -2188,6 +2998,7 @@ static int __pyx_pw_9metrohash_12MetroHash128_1__cinit__(PyObject *__pyx_v_self, const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } @@ -2195,29 +3006,30 @@ static int __pyx_pw_9metrohash_12MetroHash128_1__cinit__(PyObject *__pyx_v_self, switch (pos_args) { case 0: if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_seed); + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_seed); if (value) { values[0] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(0, 181, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } } if (values[0]) { - __pyx_v_seed = __Pyx_PyInt_As_uint64_t(values[0]); if (unlikely((__pyx_v_seed == (uint64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_seed = __Pyx_PyInt_As_uint64_t(values[0]); if (unlikely((__pyx_v_seed == ((uint64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 181, __pyx_L3_error) } else { __pyx_v_seed = ((uint64)0ULL); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 181, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("metrohash.MetroHash128.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -2239,7 +3051,7 @@ static int __pyx_pf_9metrohash_12MetroHash128___cinit__(struct __pyx_obj_9metroh int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__cinit__", 0); - /* "metrohash.pyx":176 + /* "metrohash.pyx":182 * * def __cinit__(self, uint64 seed=0ULL): * self._m = new CCMetroHash128(seed) # <<<<<<<<<<<<<< @@ -2248,7 +3060,7 @@ static int __pyx_pf_9metrohash_12MetroHash128___cinit__(struct __pyx_obj_9metroh */ __pyx_v_self->_m = new MetroHash128(__pyx_v_seed); - /* "metrohash.pyx":177 + /* "metrohash.pyx":183 * def __cinit__(self, uint64 seed=0ULL): * self._m = new CCMetroHash128(seed) * if self._m is NULL: # <<<<<<<<<<<<<< @@ -2256,18 +3068,18 @@ static int __pyx_pf_9metrohash_12MetroHash128___cinit__(struct __pyx_obj_9metroh * */ __pyx_t_1 = ((__pyx_v_self->_m == NULL) != 0); - if (__pyx_t_1) { + if (unlikely(__pyx_t_1)) { - /* "metrohash.pyx":178 + /* "metrohash.pyx":184 * self._m = new CCMetroHash128(seed) * if self._m is NULL: * raise MemoryError() # <<<<<<<<<<<<<< * * def __dealloc__(self): */ - PyErr_NoMemory(); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + PyErr_NoMemory(); __PYX_ERR(0, 184, __pyx_L1_error) - /* "metrohash.pyx":177 + /* "metrohash.pyx":183 * def __cinit__(self, uint64 seed=0ULL): * self._m = new CCMetroHash128(seed) * if self._m is NULL: # <<<<<<<<<<<<<< @@ -2276,7 +3088,7 @@ static int __pyx_pf_9metrohash_12MetroHash128___cinit__(struct __pyx_obj_9metroh */ } - /* "metrohash.pyx":175 + /* "metrohash.pyx":181 * cdef CCMetroHash128* _m * * def __cinit__(self, uint64 seed=0ULL): # <<<<<<<<<<<<<< @@ -2295,7 +3107,7 @@ static int __pyx_pf_9metrohash_12MetroHash128___cinit__(struct __pyx_obj_9metroh return __pyx_r; } -/* "metrohash.pyx":180 +/* "metrohash.pyx":186 * raise MemoryError() * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -2319,7 +3131,7 @@ static void __pyx_pf_9metrohash_12MetroHash128_2__dealloc__(struct __pyx_obj_9me int __pyx_t_1; __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "metrohash.pyx":181 + /* "metrohash.pyx":187 * * def __dealloc__(self): * if not self._m is NULL: # <<<<<<<<<<<<<< @@ -2329,7 +3141,7 @@ static void __pyx_pf_9metrohash_12MetroHash128_2__dealloc__(struct __pyx_obj_9me __pyx_t_1 = ((__pyx_v_self->_m != NULL) != 0); if (__pyx_t_1) { - /* "metrohash.pyx":182 + /* "metrohash.pyx":188 * def __dealloc__(self): * if not self._m is NULL: * del self._m # <<<<<<<<<<<<<< @@ -2338,7 +3150,7 @@ static void __pyx_pf_9metrohash_12MetroHash128_2__dealloc__(struct __pyx_obj_9me */ delete __pyx_v_self->_m; - /* "metrohash.pyx":183 + /* "metrohash.pyx":189 * if not self._m is NULL: * del self._m * self._m = NULL # <<<<<<<<<<<<<< @@ -2347,7 +3159,7 @@ static void __pyx_pf_9metrohash_12MetroHash128_2__dealloc__(struct __pyx_obj_9me */ __pyx_v_self->_m = NULL; - /* "metrohash.pyx":181 + /* "metrohash.pyx":187 * * def __dealloc__(self): * if not self._m is NULL: # <<<<<<<<<<<<<< @@ -2356,7 +3168,7 @@ static void __pyx_pf_9metrohash_12MetroHash128_2__dealloc__(struct __pyx_obj_9me */ } - /* "metrohash.pyx":180 + /* "metrohash.pyx":186 * raise MemoryError() * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -2368,7 +3180,7 @@ static void __pyx_pf_9metrohash_12MetroHash128_2__dealloc__(struct __pyx_obj_9me __Pyx_RefNannyFinishContext(); } -/* "metrohash.pyx":185 +/* "metrohash.pyx":191 * self._m = NULL * * def initialize(self, uint64 seed=0ULL): # <<<<<<<<<<<<<< @@ -2394,6 +3206,7 @@ static PyObject *__pyx_pw_9metrohash_12MetroHash128_5initialize(PyObject *__pyx_ const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } @@ -2401,29 +3214,30 @@ static PyObject *__pyx_pw_9metrohash_12MetroHash128_5initialize(PyObject *__pyx_ switch (pos_args) { case 0: if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_seed); + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_seed); if (value) { values[0] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "initialize") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "initialize") < 0)) __PYX_ERR(0, 191, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } } if (values[0]) { - __pyx_v_seed = __Pyx_PyInt_As_uint64_t(values[0]); if (unlikely((__pyx_v_seed == (uint64)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_seed = __Pyx_PyInt_As_uint64_t(values[0]); if (unlikely((__pyx_v_seed == ((uint64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 191, __pyx_L3_error) } else { __pyx_v_seed = ((uint64)0ULL); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("initialize", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("initialize", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 191, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("metrohash.MetroHash128.initialize", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -2441,7 +3255,7 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_4initialize(struct __pyx_obj __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("initialize", 0); - /* "metrohash.pyx":186 + /* "metrohash.pyx":192 * * def initialize(self, uint64 seed=0ULL): * self._m.Initialize(seed) # <<<<<<<<<<<<<< @@ -2450,7 +3264,7 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_4initialize(struct __pyx_obj */ __pyx_v_self->_m->Initialize(__pyx_v_seed); - /* "metrohash.pyx":185 + /* "metrohash.pyx":191 * self._m = NULL * * def initialize(self, uint64 seed=0ULL): # <<<<<<<<<<<<<< @@ -2465,7 +3279,7 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_4initialize(struct __pyx_obj return __pyx_r; } -/* "metrohash.pyx":188 +/* "metrohash.pyx":194 * self._m.Initialize(seed) * * def update(self, data): # <<<<<<<<<<<<<< @@ -2500,7 +3314,7 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_6update(struct __pyx_obj_9me int __pyx_clineno = 0; __Pyx_RefNannySetupContext("update", 0); - /* "metrohash.pyx":191 + /* "metrohash.pyx":197 * cdef Py_buffer buf * cdef object obj * if PyUnicode_Check(data): # <<<<<<<<<<<<<< @@ -2510,46 +3324,46 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_6update(struct __pyx_obj_9me __pyx_t_1 = (PyUnicode_Check(__pyx_v_data) != 0); if (__pyx_t_1) { - /* "metrohash.pyx":192 + /* "metrohash.pyx":198 * cdef object obj * if PyUnicode_Check(data): * obj = PyUnicode_AsUTF8String(data) # <<<<<<<<<<<<<< * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) * Py_DECREF(obj) */ - __pyx_t_2 = PyUnicode_AsUTF8String(__pyx_v_data); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyUnicode_AsUTF8String(__pyx_v_data); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 198, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_obj = __pyx_t_2; __pyx_t_2 = 0; - /* "metrohash.pyx":193 + /* "metrohash.pyx":199 * if PyUnicode_Check(data): * obj = PyUnicode_AsUTF8String(data) * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) # <<<<<<<<<<<<<< * Py_DECREF(obj) * self._m.Update(buf.buf, buf.len) */ - __pyx_t_3 = PyObject_GetBuffer(__pyx_v_obj, (&__pyx_v_buf), PyBUF_SIMPLE); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_GetBuffer(__pyx_v_obj, (&__pyx_v_buf), PyBUF_SIMPLE); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 199, __pyx_L1_error) - /* "metrohash.pyx":194 + /* "metrohash.pyx":200 * obj = PyUnicode_AsUTF8String(data) * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) * Py_DECREF(obj) # <<<<<<<<<<<<<< * self._m.Update(buf.buf, buf.len) - * elif PyString_Check(data): + * elif PyBytes_Check(data): */ Py_DECREF(__pyx_v_obj); - /* "metrohash.pyx":195 + /* "metrohash.pyx":201 * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) * Py_DECREF(obj) * self._m.Update(buf.buf, buf.len) # <<<<<<<<<<<<<< - * elif PyString_Check(data): - * self._m.Update(PyString_AS_STRING(data), + * elif PyBytes_Check(data): + * self._m.Update(PyBytes_AS_STRING(data), */ __pyx_v_self->_m->Update(((uint8 const *)__pyx_v_buf.buf), __pyx_v_buf.len); - /* "metrohash.pyx":191 + /* "metrohash.pyx":197 * cdef Py_buffer buf * cdef object obj * if PyUnicode_Check(data): # <<<<<<<<<<<<<< @@ -2559,55 +3373,55 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_6update(struct __pyx_obj_9me goto __pyx_L3; } - /* "metrohash.pyx":196 + /* "metrohash.pyx":202 * Py_DECREF(obj) * self._m.Update(buf.buf, buf.len) - * elif PyString_Check(data): # <<<<<<<<<<<<<< - * self._m.Update(PyString_AS_STRING(data), - * PyString_GET_SIZE(data)) + * elif PyBytes_Check(data): # <<<<<<<<<<<<<< + * self._m.Update(PyBytes_AS_STRING(data), + * PyBytes_GET_SIZE(data)) */ - __pyx_t_1 = (PyString_Check(__pyx_v_data) != 0); + __pyx_t_1 = (PyBytes_Check(__pyx_v_data) != 0); if (__pyx_t_1) { - /* "metrohash.pyx":197 + /* "metrohash.pyx":203 * self._m.Update(buf.buf, buf.len) - * elif PyString_Check(data): - * self._m.Update(PyString_AS_STRING(data), # <<<<<<<<<<<<<< - * PyString_GET_SIZE(data)) + * elif PyBytes_Check(data): + * self._m.Update(PyBytes_AS_STRING(data), # <<<<<<<<<<<<<< + * PyBytes_GET_SIZE(data)) * elif PyObject_CheckBuffer(data): */ - __pyx_v_self->_m->Update(((uint8 const *)PyString_AS_STRING(__pyx_v_data)), PyString_GET_SIZE(__pyx_v_data)); + __pyx_v_self->_m->Update(((uint8 const *)PyBytes_AS_STRING(__pyx_v_data)), PyBytes_GET_SIZE(__pyx_v_data)); - /* "metrohash.pyx":196 + /* "metrohash.pyx":202 * Py_DECREF(obj) * self._m.Update(buf.buf, buf.len) - * elif PyString_Check(data): # <<<<<<<<<<<<<< - * self._m.Update(PyString_AS_STRING(data), - * PyString_GET_SIZE(data)) + * elif PyBytes_Check(data): # <<<<<<<<<<<<<< + * self._m.Update(PyBytes_AS_STRING(data), + * PyBytes_GET_SIZE(data)) */ goto __pyx_L3; } - /* "metrohash.pyx":199 - * self._m.Update(PyString_AS_STRING(data), - * PyString_GET_SIZE(data)) + /* "metrohash.pyx":205 + * self._m.Update(PyBytes_AS_STRING(data), + * PyBytes_GET_SIZE(data)) * elif PyObject_CheckBuffer(data): # <<<<<<<<<<<<<< * PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) * self._m.Update(buf.buf, buf.len) */ __pyx_t_1 = (PyObject_CheckBuffer(__pyx_v_data) != 0); - if (__pyx_t_1) { + if (likely(__pyx_t_1)) { - /* "metrohash.pyx":200 - * PyString_GET_SIZE(data)) + /* "metrohash.pyx":206 + * PyBytes_GET_SIZE(data)) * elif PyObject_CheckBuffer(data): * PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) # <<<<<<<<<<<<<< * self._m.Update(buf.buf, buf.len) * else: */ - __pyx_t_3 = PyObject_GetBuffer(__pyx_v_data, (&__pyx_v_buf), PyBUF_SIMPLE); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_GetBuffer(__pyx_v_data, (&__pyx_v_buf), PyBUF_SIMPLE); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 206, __pyx_L1_error) - /* "metrohash.pyx":201 + /* "metrohash.pyx":207 * elif PyObject_CheckBuffer(data): * PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) * self._m.Update(buf.buf, buf.len) # <<<<<<<<<<<<<< @@ -2616,9 +3430,9 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_6update(struct __pyx_obj_9me */ __pyx_v_self->_m->Update(((uint8 const *)__pyx_v_buf.buf), __pyx_v_buf.len); - /* "metrohash.pyx":199 - * self._m.Update(PyString_AS_STRING(data), - * PyString_GET_SIZE(data)) + /* "metrohash.pyx":205 + * self._m.Update(PyBytes_AS_STRING(data), + * PyBytes_GET_SIZE(data)) * elif PyObject_CheckBuffer(data): # <<<<<<<<<<<<<< * PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) * self._m.Update(buf.buf, buf.len) @@ -2626,7 +3440,7 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_6update(struct __pyx_obj_9me goto __pyx_L3; } - /* "metrohash.pyx":203 + /* "metrohash.pyx":209 * self._m.Update(buf.buf, buf.len) * else: * raise _type_error("data", ["basestring", "buffer"], data) # <<<<<<<<<<<<<< @@ -2634,24 +3448,24 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_6update(struct __pyx_obj_9me * def intdigest(self): */ /*else*/ { - __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 209, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_n_s_basestring); - __Pyx_GIVEREF(__pyx_n_s_basestring); - PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_basestring); - __Pyx_INCREF(__pyx_n_s_buffer); - __Pyx_GIVEREF(__pyx_n_s_buffer); - PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_buffer); - __pyx_t_4 = __pyx_f_9metrohash__type_error(__pyx_n_s_data, __pyx_t_2, __pyx_v_data); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_n_u_basestring); + __Pyx_GIVEREF(__pyx_n_u_basestring); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_u_basestring); + __Pyx_INCREF(__pyx_n_u_buffer); + __Pyx_GIVEREF(__pyx_n_u_buffer); + PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_u_buffer); + __pyx_t_4 = __pyx_f_9metrohash__type_error(__pyx_n_u_data, __pyx_t_2, __pyx_v_data); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 209, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __PYX_ERR(0, 209, __pyx_L1_error) } __pyx_L3:; - /* "metrohash.pyx":188 + /* "metrohash.pyx":194 * self._m.Initialize(seed) * * def update(self, data): # <<<<<<<<<<<<<< @@ -2674,7 +3488,7 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_6update(struct __pyx_obj_9me return __pyx_r; } -/* "metrohash.pyx":205 +/* "metrohash.pyx":211 * raise _type_error("data", ["basestring", "buffer"], data) * * def intdigest(self): # <<<<<<<<<<<<<< @@ -2708,7 +3522,7 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_8intdigest(struct __pyx_obj_ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("intdigest", 0); - /* "metrohash.pyx":207 + /* "metrohash.pyx":213 * def intdigest(self): * cdef uint8 buf[16] * self._m.Finalize(buf) # <<<<<<<<<<<<<< @@ -2717,7 +3531,7 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_8intdigest(struct __pyx_obj_ */ __pyx_v_self->_m->Finalize(__pyx_v_buf); - /* "metrohash.pyx":208 + /* "metrohash.pyx":214 * cdef uint8 buf[16] * self._m.Finalize(buf) * cdef pair[uint64, uint64] result = c_bytes2int128(buf) # <<<<<<<<<<<<<< @@ -2725,44 +3539,34 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_8intdigest(struct __pyx_obj_ */ __pyx_v_result = bytes2int128(__pyx_v_buf); - /* "metrohash.pyx":209 + /* "metrohash.pyx":215 * self._m.Finalize(buf) * cdef pair[uint64, uint64] result = c_bytes2int128(buf) * return 0x10000000000000000L * long(result.first) + long(result.second) # <<<<<<<<<<<<<< */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_uint64_t(__pyx_v_result.first); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyInt_From_uint64_t(__pyx_v_result.first); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 215, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyLong_Type)), __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 215, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)(&PyLong_Type)), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyNumber_Multiply(__pyx_int_18446744073709551616L, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 215, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyNumber_Multiply(__pyx_int_18446744073709551616L, __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyInt_From_uint64_t(__pyx_v_result.second); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 215, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyInt_From_uint64_t(__pyx_v_result.second); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)(&PyLong_Type)), __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyNumber_Add(__pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyLong_Type)), __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 215, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 215, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; goto __pyx_L0; - /* "metrohash.pyx":205 + /* "metrohash.pyx":211 * raise _type_error("data", ["basestring", "buffer"], data) * * def intdigest(self): # <<<<<<<<<<<<<< @@ -2783,41 +3587,157 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_8intdigest(struct __pyx_obj_ return __pyx_r; } -static PyObject *__pyx_tp_new_9metrohash_MetroHash64(PyTypeObject *t, PyObject *a, PyObject *k) { - PyObject *o; - if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { - o = (*t->tp_alloc)(t, 0); - } else { - o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_9metrohash_12MetroHash128_11__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_9metrohash_12MetroHash128_11__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_9metrohash_12MetroHash128_10__reduce_cython__(((struct __pyx_obj_9metrohash_MetroHash128 *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_9metrohash_12MetroHash128_10__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__reduce_cython__", 0); + + /* "(tree fragment)":2 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(1, 2, __pyx_L1_error) + + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("metrohash.MetroHash128.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_9metrohash_12MetroHash128_13__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static PyObject *__pyx_pw_9metrohash_12MetroHash128_13__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + __pyx_r = __pyx_pf_9metrohash_12MetroHash128_12__setstate_cython__(((struct __pyx_obj_9metrohash_MetroHash128 *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_9metrohash_12MetroHash128_12__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__setstate_cython__", 0); + + /* "(tree fragment)":4 + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(1, 4, __pyx_L1_error) + + /* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("metrohash.MetroHash128.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_tp_new_9metrohash_MetroHash64(PyTypeObject *t, PyObject *a, PyObject *k) { + PyObject *o; + if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) { + o = (*t->tp_alloc)(t, 0); + } else { + o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); } if (unlikely(!o)) return 0; - if (unlikely(__pyx_pw_9metrohash_11MetroHash64_1__cinit__(o, a, k) < 0)) { - Py_DECREF(o); o = 0; - } + if (unlikely(__pyx_pw_9metrohash_11MetroHash64_1__cinit__(o, a, k) < 0)) goto bad; return o; + bad: + Py_DECREF(o); o = 0; + return NULL; } static void __pyx_tp_dealloc_9metrohash_MetroHash64(PyObject *o) { - #if PY_VERSION_HEX >= 0x030400a1 - if (unlikely(Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) { + #if CYTHON_USE_TP_FINALIZE + if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) { if (PyObject_CallFinalizerFromDealloc(o)) return; } #endif { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); + __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1); __pyx_pw_9metrohash_11MetroHash64_3__dealloc__(o); - --Py_REFCNT(o); + __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1); PyErr_Restore(etype, eval, etb); } (*Py_TYPE(o)->tp_free)(o); } static PyMethodDef __pyx_methods_9metrohash_MetroHash64[] = { - {"initialize", (PyCFunction)__pyx_pw_9metrohash_11MetroHash64_5initialize, METH_VARARGS|METH_KEYWORDS, 0}, + {"initialize", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_9metrohash_11MetroHash64_5initialize, METH_VARARGS|METH_KEYWORDS, 0}, {"update", (PyCFunction)__pyx_pw_9metrohash_11MetroHash64_7update, METH_O, 0}, {"intdigest", (PyCFunction)__pyx_pw_9metrohash_11MetroHash64_9intdigest, METH_NOARGS, 0}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_9metrohash_11MetroHash64_11__reduce_cython__, METH_NOARGS, 0}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_9metrohash_11MetroHash64_13__setstate_cython__, METH_O, 0}, {0, 0, 0, 0} }; @@ -2827,7 +3747,12 @@ static PyTypeObject __pyx_type_9metrohash_MetroHash64 = { sizeof(struct __pyx_obj_9metrohash_MetroHash64), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_9metrohash_MetroHash64, /*tp_dealloc*/ + #if PY_VERSION_HEX < 0x030800b4 0, /*tp_print*/ + #endif + #if PY_VERSION_HEX >= 0x030800b4 + 0, /*tp_vectorcall_offset*/ + #endif 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 @@ -2877,6 +3802,15 @@ static PyTypeObject __pyx_type_9metrohash_MetroHash64 = { #if PY_VERSION_HEX >= 0x030400a1 0, /*tp_finalize*/ #endif + #if PY_VERSION_HEX >= 0x030800b1 + 0, /*tp_vectorcall*/ + #endif + #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000 + 0, /*tp_print*/ + #endif + #if CYTHON_COMPILING_IN_PYPY && PYPY_VERSION_NUM+0 >= 0x06000000 + 0, /*tp_pypy_flags*/ + #endif }; static PyObject *__pyx_tp_new_9metrohash_MetroHash128(PyTypeObject *t, PyObject *a, PyObject *k) { @@ -2887,33 +3821,36 @@ static PyObject *__pyx_tp_new_9metrohash_MetroHash128(PyTypeObject *t, PyObject o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); } if (unlikely(!o)) return 0; - if (unlikely(__pyx_pw_9metrohash_12MetroHash128_1__cinit__(o, a, k) < 0)) { - Py_DECREF(o); o = 0; - } + if (unlikely(__pyx_pw_9metrohash_12MetroHash128_1__cinit__(o, a, k) < 0)) goto bad; return o; + bad: + Py_DECREF(o); o = 0; + return NULL; } static void __pyx_tp_dealloc_9metrohash_MetroHash128(PyObject *o) { - #if PY_VERSION_HEX >= 0x030400a1 - if (unlikely(Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) { + #if CYTHON_USE_TP_FINALIZE + if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) { if (PyObject_CallFinalizerFromDealloc(o)) return; } #endif { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); + __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1); __pyx_pw_9metrohash_12MetroHash128_3__dealloc__(o); - --Py_REFCNT(o); + __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1); PyErr_Restore(etype, eval, etb); } (*Py_TYPE(o)->tp_free)(o); } static PyMethodDef __pyx_methods_9metrohash_MetroHash128[] = { - {"initialize", (PyCFunction)__pyx_pw_9metrohash_12MetroHash128_5initialize, METH_VARARGS|METH_KEYWORDS, 0}, + {"initialize", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_9metrohash_12MetroHash128_5initialize, METH_VARARGS|METH_KEYWORDS, 0}, {"update", (PyCFunction)__pyx_pw_9metrohash_12MetroHash128_7update, METH_O, 0}, {"intdigest", (PyCFunction)__pyx_pw_9metrohash_12MetroHash128_9intdigest, METH_NOARGS, 0}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_9metrohash_12MetroHash128_11__reduce_cython__, METH_NOARGS, 0}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_9metrohash_12MetroHash128_13__setstate_cython__, METH_O, 0}, {0, 0, 0, 0} }; @@ -2923,7 +3860,12 @@ static PyTypeObject __pyx_type_9metrohash_MetroHash128 = { sizeof(struct __pyx_obj_9metrohash_MetroHash128), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_9metrohash_MetroHash128, /*tp_dealloc*/ + #if PY_VERSION_HEX < 0x030800b4 0, /*tp_print*/ + #endif + #if PY_VERSION_HEX >= 0x030800b4 + 0, /*tp_vectorcall_offset*/ + #endif 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 @@ -2973,84 +3915,378 @@ static PyTypeObject __pyx_type_9metrohash_MetroHash128 = { #if PY_VERSION_HEX >= 0x030400a1 0, /*tp_finalize*/ #endif + #if PY_VERSION_HEX >= 0x030800b1 + 0, /*tp_vectorcall*/ + #endif + #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000 + 0, /*tp_print*/ + #endif + #if CYTHON_COMPILING_IN_PYPY && PYPY_VERSION_NUM+0 >= 0x06000000 + 0, /*tp_pypy_flags*/ + #endif }; static PyMethodDef __pyx_methods[] = { - {"metrohash64", (PyCFunction)__pyx_pw_9metrohash_1metrohash64, METH_VARARGS|METH_KEYWORDS, __pyx_doc_9metrohash_metrohash64}, - {"metrohash128", (PyCFunction)__pyx_pw_9metrohash_3metrohash128, METH_VARARGS|METH_KEYWORDS, __pyx_doc_9metrohash_2metrohash128}, + {"metrohash64", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_9metrohash_1metrohash64, METH_VARARGS|METH_KEYWORDS, __pyx_doc_9metrohash_metrohash64}, + {"metrohash128", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_9metrohash_3metrohash128, METH_VARARGS|METH_KEYWORDS, __pyx_doc_9metrohash_2metrohash128}, {0, 0, 0, 0} }; #if PY_MAJOR_VERSION >= 3 +#if CYTHON_PEP489_MULTI_PHASE_INIT +static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/ +static int __pyx_pymod_exec_metrohash(PyObject* module); /*proto*/ +static PyModuleDef_Slot __pyx_moduledef_slots[] = { + {Py_mod_create, (void*)__pyx_pymod_create}, + {Py_mod_exec, (void*)__pyx_pymod_exec_metrohash}, + {0, NULL} +}; +#endif + static struct PyModuleDef __pyx_moduledef = { - #if PY_VERSION_HEX < 0x03020000 - { PyObject_HEAD_INIT(NULL) NULL, 0, NULL }, - #else PyModuleDef_HEAD_INIT, - #endif "metrohash", __pyx_k_A_Python_wrapper_for_MetroHash, /* m_doc */ + #if CYTHON_PEP489_MULTI_PHASE_INIT + 0, /* m_size */ + #else -1, /* m_size */ + #endif __pyx_methods /* m_methods */, + #if CYTHON_PEP489_MULTI_PHASE_INIT + __pyx_moduledef_slots, /* m_slots */ + #else NULL, /* m_reload */ + #endif NULL, /* m_traverse */ NULL, /* m_clear */ NULL /* m_free */ }; #endif +#ifndef CYTHON_SMALL_CODE +#if defined(__clang__) + #define CYTHON_SMALL_CODE +#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) + #define CYTHON_SMALL_CODE __attribute__((cold)) +#else + #define CYTHON_SMALL_CODE +#endif +#endif static __Pyx_StringTabEntry __pyx_string_tab[] = { - {&__pyx_kp_s_0_0_13, __pyx_k_0_0_13, sizeof(__pyx_k_0_0_13), 0, 0, 1, 0}, - {&__pyx_kp_s_Argument_s_has_incorrect_type_ex, __pyx_k_Argument_s_has_incorrect_type_ex, sizeof(__pyx_k_Argument_s_has_incorrect_type_ex), 0, 0, 1, 0}, - {&__pyx_kp_s_Eugene_Scherba, __pyx_k_Eugene_Scherba, sizeof(__pyx_k_Eugene_Scherba), 0, 0, 1, 0}, + {&__pyx_kp_u_, __pyx_k_, sizeof(__pyx_k_), 0, 1, 0, 0}, + {&__pyx_kp_u_0_1_0, __pyx_k_0_1_0, sizeof(__pyx_k_0_1_0), 0, 1, 0, 0}, + {&__pyx_kp_u_Argument, __pyx_k_Argument, sizeof(__pyx_k_Argument), 0, 1, 0, 0}, + {&__pyx_kp_u_Eugene_Scherba, __pyx_k_Eugene_Scherba, sizeof(__pyx_k_Eugene_Scherba), 0, 1, 0, 0}, {&__pyx_n_s_MemoryError, __pyx_k_MemoryError, sizeof(__pyx_k_MemoryError), 0, 0, 1, 1}, {&__pyx_n_s_MetroHash128, __pyx_k_MetroHash128, sizeof(__pyx_k_MetroHash128), 0, 0, 1, 1}, + {&__pyx_n_u_MetroHash128, __pyx_k_MetroHash128, sizeof(__pyx_k_MetroHash128), 0, 1, 0, 1}, {&__pyx_n_s_MetroHash64, __pyx_k_MetroHash64, sizeof(__pyx_k_MetroHash64), 0, 0, 1, 1}, + {&__pyx_n_u_MetroHash64, __pyx_k_MetroHash64, sizeof(__pyx_k_MetroHash64), 0, 1, 0, 1}, + {&__pyx_kp_u_None, __pyx_k_None, sizeof(__pyx_k_None), 0, 1, 0, 0}, {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1}, {&__pyx_n_s_all, __pyx_k_all, sizeof(__pyx_k_all), 0, 0, 1, 1}, {&__pyx_n_s_author, __pyx_k_author, sizeof(__pyx_k_author), 0, 0, 1, 1}, - {&__pyx_n_s_basestring, __pyx_k_basestring, sizeof(__pyx_k_basestring), 0, 0, 1, 1}, - {&__pyx_n_s_buffer, __pyx_k_buffer, sizeof(__pyx_k_buffer), 0, 0, 1, 1}, + {&__pyx_n_u_basestring, __pyx_k_basestring, sizeof(__pyx_k_basestring), 0, 1, 0, 1}, + {&__pyx_n_u_buffer, __pyx_k_buffer, sizeof(__pyx_k_buffer), 0, 1, 0, 1}, + {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1}, {&__pyx_n_s_data, __pyx_k_data, sizeof(__pyx_k_data), 0, 0, 1, 1}, + {&__pyx_n_u_data, __pyx_k_data, sizeof(__pyx_k_data), 0, 1, 0, 1}, {&__pyx_n_s_email, __pyx_k_email, sizeof(__pyx_k_email), 0, 0, 1, 1}, - {&__pyx_kp_s_escherba_metrohash_gmail_com, __pyx_k_escherba_metrohash_gmail_com, sizeof(__pyx_k_escherba_metrohash_gmail_com), 0, 0, 1, 0}, + {&__pyx_kp_u_escherba_metrohash_gmail_com, __pyx_k_escherba_metrohash_gmail_com, sizeof(__pyx_k_escherba_metrohash_gmail_com), 0, 1, 0, 0}, + {&__pyx_n_s_getstate, __pyx_k_getstate, sizeof(__pyx_k_getstate), 0, 0, 1, 1}, + {&__pyx_kp_u_got, __pyx_k_got, sizeof(__pyx_k_got), 0, 1, 0, 0}, + {&__pyx_kp_u_has_incorrect_type_expected, __pyx_k_has_incorrect_type_expected, sizeof(__pyx_k_has_incorrect_type_expected), 0, 1, 0, 0}, {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, - {&__pyx_n_s_metrohash128, __pyx_k_metrohash128, sizeof(__pyx_k_metrohash128), 0, 0, 1, 1}, - {&__pyx_n_s_metrohash64, __pyx_k_metrohash64, sizeof(__pyx_k_metrohash64), 0, 0, 1, 1}, + {&__pyx_n_u_metrohash128, __pyx_k_metrohash128, sizeof(__pyx_k_metrohash128), 0, 1, 0, 1}, + {&__pyx_n_u_metrohash64, __pyx_k_metrohash64, sizeof(__pyx_k_metrohash64), 0, 1, 0, 1}, + {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1}, + {&__pyx_kp_s_no_default___reduce___due_to_non, __pyx_k_no_default___reduce___due_to_non, sizeof(__pyx_k_no_default___reduce___due_to_non), 0, 0, 1, 0}, + {&__pyx_n_s_reduce, __pyx_k_reduce, sizeof(__pyx_k_reduce), 0, 0, 1, 1}, + {&__pyx_n_s_reduce_cython, __pyx_k_reduce_cython, sizeof(__pyx_k_reduce_cython), 0, 0, 1, 1}, + {&__pyx_n_s_reduce_ex, __pyx_k_reduce_ex, sizeof(__pyx_k_reduce_ex), 0, 0, 1, 1}, {&__pyx_n_s_seed, __pyx_k_seed, sizeof(__pyx_k_seed), 0, 0, 1, 1}, + {&__pyx_n_s_setstate, __pyx_k_setstate, sizeof(__pyx_k_setstate), 0, 0, 1, 1}, + {&__pyx_n_s_setstate_cython, __pyx_k_setstate_cython, sizeof(__pyx_k_setstate_cython), 0, 0, 1, 1}, {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, {&__pyx_n_s_version, __pyx_k_version, sizeof(__pyx_k_version), 0, 0, 1, 1}, {0, 0, 0, 0, 0, 0, 0} }; -static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;} +static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) { + __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(0, 80, __pyx_L1_error) + __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(0, 141, __pyx_L1_error) return 0; __pyx_L1_error:; return -1; } -static int __Pyx_InitCachedConstants(void) { +static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); + + /* "(tree fragment)":2 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + */ + __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__2); + __Pyx_GIVEREF(__pyx_tuple__2); + + /* "(tree fragment)":4 + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + */ + __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__3); + __Pyx_GIVEREF(__pyx_tuple__3); + + /* "(tree fragment)":2 + * def __reduce_cython__(self): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + */ + __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__4); + __Pyx_GIVEREF(__pyx_tuple__4); + + /* "(tree fragment)":4 + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") + * def __setstate_cython__(self, __pyx_state): + * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< + */ + __pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__5); + __Pyx_GIVEREF(__pyx_tuple__5); + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; +} + +static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) { + if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error); + __pyx_int_18446744073709551616L = PyLong_FromString((char *)"18446744073709551616", 0, 0); if (unlikely(!__pyx_int_18446744073709551616L)) __PYX_ERR(0, 1, __pyx_L1_error) + return 0; + __pyx_L1_error:; + return -1; +} + +static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/ + +static int __Pyx_modinit_global_init_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0); + /*--- Global init code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_variable_export_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0); + /*--- Variable export code ---*/ __Pyx_RefNannyFinishContext(); return 0; } -static int __Pyx_InitGlobals(void) { - if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - __pyx_int_18446744073709551616L = PyLong_FromString((char *)"18446744073709551616", 0, 0); if (unlikely(!__pyx_int_18446744073709551616L)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} +static int __Pyx_modinit_function_export_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0); + /*--- Function export code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_type_init_code(void) { + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0); + /*--- Type init code ---*/ + if (PyType_Ready(&__pyx_type_9metrohash_MetroHash64) < 0) __PYX_ERR(0, 131, __pyx_L1_error) + #if PY_VERSION_HEX < 0x030800B1 + __pyx_type_9metrohash_MetroHash64.tp_print = 0; + #endif + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_9metrohash_MetroHash64.tp_dictoffset && __pyx_type_9metrohash_MetroHash64.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type_9metrohash_MetroHash64.tp_getattro = __Pyx_PyObject_GenericGetAttr; + } + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_MetroHash64, (PyObject *)&__pyx_type_9metrohash_MetroHash64) < 0) __PYX_ERR(0, 131, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_9metrohash_MetroHash64) < 0) __PYX_ERR(0, 131, __pyx_L1_error) + __pyx_ptype_9metrohash_MetroHash64 = &__pyx_type_9metrohash_MetroHash64; + if (PyType_Ready(&__pyx_type_9metrohash_MetroHash128) < 0) __PYX_ERR(0, 174, __pyx_L1_error) + #if PY_VERSION_HEX < 0x030800B1 + __pyx_type_9metrohash_MetroHash128.tp_print = 0; + #endif + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_9metrohash_MetroHash128.tp_dictoffset && __pyx_type_9metrohash_MetroHash128.tp_getattro == PyObject_GenericGetAttr)) { + __pyx_type_9metrohash_MetroHash128.tp_getattro = __Pyx_PyObject_GenericGetAttr; + } + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_MetroHash128, (PyObject *)&__pyx_type_9metrohash_MetroHash128) < 0) __PYX_ERR(0, 174, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_9metrohash_MetroHash128) < 0) __PYX_ERR(0, 174, __pyx_L1_error) + __pyx_ptype_9metrohash_MetroHash128 = &__pyx_type_9metrohash_MetroHash128; + __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); return -1; } +static int __Pyx_modinit_type_import_code(void) { + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0); + /*--- Type import code ---*/ + __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "type", + #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000 + sizeof(PyTypeObject), + #else + sizeof(PyHeapTypeObject), + #endif + __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_7cpython_4type_type) __PYX_ERR(2, 9, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_7cpython_4bool_bool) __PYX_ERR(3, 8, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), __Pyx_ImportType_CheckSize_Warn); + if (!__pyx_ptype_7cpython_7complex_complex) __PYX_ERR(4, 15, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_RefNannyFinishContext(); + return -1; +} + +static int __Pyx_modinit_variable_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0); + /*--- Variable import code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_function_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0); + /*--- Function import code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + + +#ifndef CYTHON_NO_PYINIT_EXPORT +#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC +#elif PY_MAJOR_VERSION < 3 +#ifdef __cplusplus +#define __Pyx_PyMODINIT_FUNC extern "C" void +#else +#define __Pyx_PyMODINIT_FUNC void +#endif +#else +#ifdef __cplusplus +#define __Pyx_PyMODINIT_FUNC extern "C" PyObject * +#else +#define __Pyx_PyMODINIT_FUNC PyObject * +#endif +#endif + + #if PY_MAJOR_VERSION < 3 -PyMODINIT_FUNC initmetrohash(void); /*proto*/ -PyMODINIT_FUNC initmetrohash(void) +__Pyx_PyMODINIT_FUNC initmetrohash(void) CYTHON_SMALL_CODE; /*proto*/ +__Pyx_PyMODINIT_FUNC initmetrohash(void) #else -PyMODINIT_FUNC PyInit_metrohash(void); /*proto*/ -PyMODINIT_FUNC PyInit_metrohash(void) +__Pyx_PyMODINIT_FUNC PyInit_metrohash(void) CYTHON_SMALL_CODE; /*proto*/ +__Pyx_PyMODINIT_FUNC PyInit_metrohash(void) +#if CYTHON_PEP489_MULTI_PHASE_INIT +{ + return PyModuleDef_Init(&__pyx_moduledef); +} +static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) { + #if PY_VERSION_HEX >= 0x030700A1 + static PY_INT64_T main_interpreter_id = -1; + PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp); + if (main_interpreter_id == -1) { + main_interpreter_id = current_id; + return (unlikely(current_id == -1)) ? -1 : 0; + } else if (unlikely(main_interpreter_id != current_id)) + #else + static PyInterpreterState *main_interpreter = NULL; + PyInterpreterState *current_interpreter = PyThreadState_Get()->interp; + if (!main_interpreter) { + main_interpreter = current_interpreter; + } else if (unlikely(main_interpreter != current_interpreter)) + #endif + { + PyErr_SetString( + PyExc_ImportError, + "Interpreter change detected - this module can only be loaded into one interpreter per process."); + return -1; + } + return 0; +} +static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name, int allow_none) { + PyObject *value = PyObject_GetAttrString(spec, from_name); + int result = 0; + if (likely(value)) { + if (allow_none || value != Py_None) { + result = PyDict_SetItemString(moddict, to_name, value); + } + Py_DECREF(value); + } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) { + PyErr_Clear(); + } else { + result = -1; + } + return result; +} +static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) { + PyObject *module = NULL, *moddict, *modname; + if (__Pyx_check_single_interpreter()) + return NULL; + if (__pyx_m) + return __Pyx_NewRef(__pyx_m); + modname = PyObject_GetAttrString(spec, "name"); + if (unlikely(!modname)) goto bad; + module = PyModule_NewObject(modname); + Py_DECREF(modname); + if (unlikely(!module)) goto bad; + moddict = PyModule_GetDict(module); + if (unlikely(!moddict)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad; + return module; +bad: + Py_XDECREF(module); + return NULL; +} + + +static CYTHON_SMALL_CODE int __pyx_pymod_exec_metrohash(PyObject *__pyx_pyinit_module) +#endif #endif { PyObject *__pyx_t_1 = NULL; @@ -3058,163 +4294,166 @@ PyMODINIT_FUNC PyInit_metrohash(void) const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannyDeclarations - #if CYTHON_REFNANNY - __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); - if (!__Pyx_RefNanny) { - PyErr_Clear(); - __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); - if (!__Pyx_RefNanny) - Py_FatalError("failed to import 'refnanny' module"); + #if CYTHON_PEP489_MULTI_PHASE_INIT + if (__pyx_m) { + if (__pyx_m == __pyx_pyinit_module) return 0; + PyErr_SetString(PyExc_RuntimeError, "Module 'metrohash' has already been imported. Re-initialisation is not supported."); + return -1; } + #elif PY_MAJOR_VERSION >= 3 + if (__pyx_m) return __Pyx_NewRef(__pyx_m); #endif - __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit_metrohash(void)", 0); - if (__Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + #if CYTHON_REFNANNY +__Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); +if (!__Pyx_RefNanny) { + PyErr_Clear(); + __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); + if (!__Pyx_RefNanny) + Py_FatalError("failed to import 'refnanny' module"); +} +#endif + __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_metrohash(void)", 0); + if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #ifdef __Pxy_PyFrame_Initialize_Offsets + __Pxy_PyFrame_Initialize_Offsets(); + #endif + __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error) #ifdef __Pyx_CyFunction_USED - if (__pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif #ifdef __Pyx_FusedFunction_USED - if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif #ifdef __Pyx_Coroutine_USED - if (__pyx_Coroutine_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif #ifdef __Pyx_Generator_USED - if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_AsyncGen_USED + if (__pyx_AsyncGen_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif #ifdef __Pyx_StopAsyncIteration_USED - if (__pyx_StopAsyncIteration_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif /*--- Library function declarations ---*/ /*--- Threads initialization code ---*/ - #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS - #ifdef WITH_THREAD /* Python build with threading support? */ + #if defined(WITH_THREAD) && PY_VERSION_HEX < 0x030700F0 && defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS PyEval_InitThreads(); #endif - #endif /*--- Module creation code ---*/ + #if CYTHON_PEP489_MULTI_PHASE_INIT + __pyx_m = __pyx_pyinit_module; + Py_INCREF(__pyx_m); + #else #if PY_MAJOR_VERSION < 3 __pyx_m = Py_InitModule4("metrohash", __pyx_methods, __pyx_k_A_Python_wrapper_for_MetroHash, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); #else __pyx_m = PyModule_Create(&__pyx_moduledef); #endif - if (unlikely(!__pyx_m)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error) Py_INCREF(__pyx_d); - __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #if CYTHON_COMPILING_IN_PYPY + __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error) Py_INCREF(__pyx_b); - #endif - if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) + Py_INCREF(__pyx_cython_runtime); + if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error); /*--- Initialize various global constants etc. ---*/ - if (__Pyx_InitGlobals() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) - if (__Pyx_init_sys_getdefaultencoding_params() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif if (__pyx_module_is_main_metrohash) { - if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name, __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error) } #if PY_MAJOR_VERSION >= 3 { - PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error) if (!PyDict_GetItemString(modules, "metrohash")) { - if (unlikely(PyDict_SetItemString(modules, "metrohash", __pyx_m) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(PyDict_SetItemString(modules, "metrohash", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error) } } #endif /*--- Builtin init code ---*/ - if (__Pyx_InitCachedBuiltins() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error) /*--- Constants init code ---*/ - if (__Pyx_InitCachedConstants() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /*--- Global init code ---*/ - /*--- Variable export code ---*/ - /*--- Function export code ---*/ - /*--- Type init code ---*/ - if (PyType_Ready(&__pyx_type_9metrohash_MetroHash64) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_type_9metrohash_MetroHash64.tp_print = 0; - if (PyObject_SetAttrString(__pyx_m, "MetroHash64", (PyObject *)&__pyx_type_9metrohash_MetroHash64) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_9metrohash_MetroHash64 = &__pyx_type_9metrohash_MetroHash64; - if (PyType_Ready(&__pyx_type_9metrohash_MetroHash128) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_type_9metrohash_MetroHash128.tp_print = 0; - if (PyObject_SetAttrString(__pyx_m, "MetroHash128", (PyObject *)&__pyx_type_9metrohash_MetroHash128) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_9metrohash_MetroHash128 = &__pyx_type_9metrohash_MetroHash128; - /*--- Type import code ---*/ - __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "type", - #if CYTHON_COMPILING_IN_PYPY - sizeof(PyTypeObject), - #else - sizeof(PyHeapTypeObject), - #endif - 0); if (unlikely(!__pyx_ptype_7cpython_4type_type)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), 0); if (unlikely(!__pyx_ptype_7cpython_4bool_bool)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), 0); if (unlikely(!__pyx_ptype_7cpython_7complex_complex)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /*--- Variable import code ---*/ - /*--- Function import code ---*/ + if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + /*--- Global type/function init code ---*/ + (void)__Pyx_modinit_global_init_code(); + (void)__Pyx_modinit_variable_export_code(); + (void)__Pyx_modinit_function_export_code(); + if (unlikely(__Pyx_modinit_type_init_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error) + if (unlikely(__Pyx_modinit_type_import_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error) + (void)__Pyx_modinit_variable_import_code(); + (void)__Pyx_modinit_function_import_code(); /*--- Execution code ---*/ #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) - if (__Pyx_patch_abc() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif - /* "metrohash.pyx":7 + /* "metrohash.pyx":9 * """ * * __author__ = "Eugene Scherba" # <<<<<<<<<<<<<< * __email__ = "escherba+metrohash@gmail.com" - * __version__ = "0.0.13" + * __version__ = "0.1.0" */ - if (PyDict_SetItem(__pyx_d, __pyx_n_s_author, __pyx_kp_s_Eugene_Scherba) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_d, __pyx_n_s_author, __pyx_kp_u_Eugene_Scherba) < 0) __PYX_ERR(0, 9, __pyx_L1_error) - /* "metrohash.pyx":8 + /* "metrohash.pyx":10 * * __author__ = "Eugene Scherba" * __email__ = "escherba+metrohash@gmail.com" # <<<<<<<<<<<<<< - * __version__ = "0.0.13" + * __version__ = "0.1.0" * __all__ = [ */ - if (PyDict_SetItem(__pyx_d, __pyx_n_s_email, __pyx_kp_s_escherba_metrohash_gmail_com) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_d, __pyx_n_s_email, __pyx_kp_u_escherba_metrohash_gmail_com) < 0) __PYX_ERR(0, 10, __pyx_L1_error) - /* "metrohash.pyx":9 + /* "metrohash.pyx":11 * __author__ = "Eugene Scherba" * __email__ = "escherba+metrohash@gmail.com" - * __version__ = "0.0.13" # <<<<<<<<<<<<<< + * __version__ = "0.1.0" # <<<<<<<<<<<<<< * __all__ = [ - * "metrohash64", "metrohash128", + * "metrohash64", */ - if (PyDict_SetItem(__pyx_d, __pyx_n_s_version, __pyx_kp_s_0_0_13) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_d, __pyx_n_s_version, __pyx_kp_u_0_1_0) < 0) __PYX_ERR(0, 11, __pyx_L1_error) - /* "metrohash.pyx":10 + /* "metrohash.pyx":12 * __email__ = "escherba+metrohash@gmail.com" - * __version__ = "0.0.13" + * __version__ = "0.1.0" * __all__ = [ # <<<<<<<<<<<<<< - * "metrohash64", "metrohash128", - * "MetroHash64", "MetroHash128", + * "metrohash64", + * "metrohash128", */ - __pyx_t_1 = PyList_New(4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyList_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_n_s_metrohash64); - __Pyx_GIVEREF(__pyx_n_s_metrohash64); - PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_metrohash64); - __Pyx_INCREF(__pyx_n_s_metrohash128); - __Pyx_GIVEREF(__pyx_n_s_metrohash128); - PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_metrohash128); - __Pyx_INCREF(__pyx_n_s_MetroHash64); - __Pyx_GIVEREF(__pyx_n_s_MetroHash64); - PyList_SET_ITEM(__pyx_t_1, 2, __pyx_n_s_MetroHash64); - __Pyx_INCREF(__pyx_n_s_MetroHash128); - __Pyx_GIVEREF(__pyx_n_s_MetroHash128); - PyList_SET_ITEM(__pyx_t_1, 3, __pyx_n_s_MetroHash128); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_n_u_metrohash64); + __Pyx_GIVEREF(__pyx_n_u_metrohash64); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_u_metrohash64); + __Pyx_INCREF(__pyx_n_u_metrohash128); + __Pyx_GIVEREF(__pyx_n_u_metrohash128); + PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_u_metrohash128); + __Pyx_INCREF(__pyx_n_u_MetroHash64); + __Pyx_GIVEREF(__pyx_n_u_MetroHash64); + PyList_SET_ITEM(__pyx_t_1, 2, __pyx_n_u_MetroHash64); + __Pyx_INCREF(__pyx_n_u_MetroHash128); + __Pyx_GIVEREF(__pyx_n_u_MetroHash128); + PyList_SET_ITEM(__pyx_t_1, 3, __pyx_n_u_MetroHash128); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_1) < 0) __PYX_ERR(0, 12, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "metrohash.pyx":1 * #cython: infer_types=True # <<<<<<<<<<<<<< - * - * """ + * #cython: language_level=3 + * #distutils: language=c++ */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /*--- Wrapped vars code ---*/ @@ -3226,27 +4465,30 @@ PyMODINIT_FUNC PyInit_metrohash(void) if (__pyx_d) { __Pyx_AddTraceback("init metrohash", __pyx_clineno, __pyx_lineno, __pyx_filename); } - Py_DECREF(__pyx_m); __pyx_m = 0; + Py_CLEAR(__pyx_m); } else if (!PyErr_Occurred()) { PyErr_SetString(PyExc_ImportError, "init metrohash"); } __pyx_L0:; __Pyx_RefNannyFinishContext(); - #if PY_MAJOR_VERSION < 3 - return; - #else + #if CYTHON_PEP489_MULTI_PHASE_INIT + return (__pyx_m != NULL) ? 0 : -1; + #elif PY_MAJOR_VERSION >= 3 return __pyx_m; + #else + return; #endif } /* --- Runtime support code --- */ +/* Refnanny */ #if CYTHON_REFNANNY static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { PyObject *m = NULL, *p = NULL; void *r = NULL; - m = PyImport_ImportModule((char *)modname); + m = PyImport_ImportModule(modname); if (!m) goto end; - p = PyObject_GetAttrString(m, (char *)"RefNannyAPI"); + p = PyObject_GetAttrString(m, "RefNannyAPI"); if (!p) goto end; r = PyLong_AsVoidPtr(p); end: @@ -3256,6 +4498,21 @@ static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { } #endif +/* PyObjectGetAttrStr */ +#if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) { + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_getattro)) + return tp->tp_getattro(obj, attr_name); +#if PY_MAJOR_VERSION < 3 + if (likely(tp->tp_getattr)) + return tp->tp_getattr(obj, PyString_AS_STRING(attr_name)); +#endif + return PyObject_GetAttr(obj, attr_name); +} +#endif + +/* GetBuiltinName */ static PyObject *__Pyx_GetBuiltinName(PyObject *name) { PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name); if (unlikely(!result)) { @@ -3269,10 +4526,241 @@ static PyObject *__Pyx_GetBuiltinName(PyObject *name) { return result; } +/* PyUnicode_Unicode */ +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_Unicode(PyObject *obj) { + if (unlikely(obj == Py_None)) + obj = __pyx_kp_u_None; + return __Pyx_NewRef(obj); +} + +/* PyObjectFormatAndDecref */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatSimpleAndDecref(PyObject* s, PyObject* f) { + if (unlikely(!s)) return NULL; + if (likely(PyUnicode_CheckExact(s))) return s; + #if PY_MAJOR_VERSION < 3 + if (likely(PyString_CheckExact(s))) { + PyObject *result = PyUnicode_FromEncodedObject(s, NULL, "strict"); + Py_DECREF(s); + return result; + } + #endif + return __Pyx_PyObject_FormatAndDecref(s, f); +} +static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatAndDecref(PyObject* s, PyObject* f) { + PyObject *result = PyObject_Format(s, f); + Py_DECREF(s); + return result; +} + +/* JoinPyUnicode */ +static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength, + CYTHON_UNUSED Py_UCS4 max_char) { +#if CYTHON_USE_UNICODE_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + PyObject *result_uval; + int result_ukind; + Py_ssize_t i, char_pos; + void *result_udata; +#if CYTHON_PEP393_ENABLED + result_uval = PyUnicode_New(result_ulength, max_char); + if (unlikely(!result_uval)) return NULL; + result_ukind = (max_char <= 255) ? PyUnicode_1BYTE_KIND : (max_char <= 65535) ? PyUnicode_2BYTE_KIND : PyUnicode_4BYTE_KIND; + result_udata = PyUnicode_DATA(result_uval); +#else + result_uval = PyUnicode_FromUnicode(NULL, result_ulength); + if (unlikely(!result_uval)) return NULL; + result_ukind = sizeof(Py_UNICODE); + result_udata = PyUnicode_AS_UNICODE(result_uval); +#endif + char_pos = 0; + for (i=0; i < value_count; i++) { + int ukind; + Py_ssize_t ulength; + void *udata; + PyObject *uval = PyTuple_GET_ITEM(value_tuple, i); + if (unlikely(__Pyx_PyUnicode_READY(uval))) + goto bad; + ulength = __Pyx_PyUnicode_GET_LENGTH(uval); + if (unlikely(!ulength)) + continue; + if (unlikely(char_pos + ulength < 0)) + goto overflow; + ukind = __Pyx_PyUnicode_KIND(uval); + udata = __Pyx_PyUnicode_DATA(uval); + if (!CYTHON_PEP393_ENABLED || ukind == result_ukind) { + memcpy((char *)result_udata + char_pos * result_ukind, udata, (size_t) (ulength * result_ukind)); + } else { + #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030300F0 || defined(_PyUnicode_FastCopyCharacters) + _PyUnicode_FastCopyCharacters(result_uval, char_pos, uval, 0, ulength); + #else + Py_ssize_t j; + for (j=0; j < ulength; j++) { + Py_UCS4 uchar = __Pyx_PyUnicode_READ(ukind, udata, j); + __Pyx_PyUnicode_WRITE(result_ukind, result_udata, char_pos+j, uchar); + } + #endif + } + char_pos += ulength; + } + return result_uval; +overflow: + PyErr_SetString(PyExc_OverflowError, "join() result is too long for a Python string"); +bad: + Py_DECREF(result_uval); + return NULL; +#else + result_ulength++; + value_count++; + return PyUnicode_Join(__pyx_empty_unicode, value_tuple); +#endif +} + +/* PyCFunctionFastCall */ +#if CYTHON_FAST_PYCCALL +static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) { + PyCFunctionObject *func = (PyCFunctionObject*)func_obj; + PyCFunction meth = PyCFunction_GET_FUNCTION(func); + PyObject *self = PyCFunction_GET_SELF(func); + int flags = PyCFunction_GET_FLAGS(func); + assert(PyCFunction_Check(func)); + assert(METH_FASTCALL == (flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS))); + assert(nargs >= 0); + assert(nargs == 0 || args != NULL); + /* _PyCFunction_FastCallDict() must not be called with an exception set, + because it may clear it (directly or indirectly) and so the + caller loses its exception */ + assert(!PyErr_Occurred()); + if ((PY_VERSION_HEX < 0x030700A0) || unlikely(flags & METH_KEYWORDS)) { + return (*((__Pyx_PyCFunctionFastWithKeywords)(void*)meth)) (self, args, nargs, NULL); + } else { + return (*((__Pyx_PyCFunctionFast)(void*)meth)) (self, args, nargs); + } +} +#endif + +/* PyFunctionFastCall */ +#if CYTHON_FAST_PYCALL +static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na, + PyObject *globals) { + PyFrameObject *f; + PyThreadState *tstate = __Pyx_PyThreadState_Current; + PyObject **fastlocals; + Py_ssize_t i; + PyObject *result; + assert(globals != NULL); + /* XXX Perhaps we should create a specialized + PyFrame_New() that doesn't take locals, but does + take builtins without sanity checking them. + */ + assert(tstate != NULL); + f = PyFrame_New(tstate, co, globals, NULL); + if (f == NULL) { + return NULL; + } + fastlocals = __Pyx_PyFrame_GetLocalsplus(f); + for (i = 0; i < na; i++) { + Py_INCREF(*args); + fastlocals[i] = *args++; + } + result = PyEval_EvalFrameEx(f,0); + ++tstate->recursion_depth; + Py_DECREF(f); + --tstate->recursion_depth; + return result; +} +#if 1 || PY_VERSION_HEX < 0x030600B1 +static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs) { + PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func); + PyObject *globals = PyFunction_GET_GLOBALS(func); + PyObject *argdefs = PyFunction_GET_DEFAULTS(func); + PyObject *closure; +#if PY_MAJOR_VERSION >= 3 + PyObject *kwdefs; +#endif + PyObject *kwtuple, **k; + PyObject **d; + Py_ssize_t nd; + Py_ssize_t nk; + PyObject *result; + assert(kwargs == NULL || PyDict_Check(kwargs)); + nk = kwargs ? PyDict_Size(kwargs) : 0; + if (Py_EnterRecursiveCall((char*)" while calling a Python object")) { + return NULL; + } + if ( +#if PY_MAJOR_VERSION >= 3 + co->co_kwonlyargcount == 0 && +#endif + likely(kwargs == NULL || nk == 0) && + co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) { + if (argdefs == NULL && co->co_argcount == nargs) { + result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals); + goto done; + } + else if (nargs == 0 && argdefs != NULL + && co->co_argcount == Py_SIZE(argdefs)) { + /* function called with no arguments, but all parameters have + a default value: use default values as arguments .*/ + args = &PyTuple_GET_ITEM(argdefs, 0); + result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals); + goto done; + } + } + if (kwargs != NULL) { + Py_ssize_t pos, i; + kwtuple = PyTuple_New(2 * nk); + if (kwtuple == NULL) { + result = NULL; + goto done; + } + k = &PyTuple_GET_ITEM(kwtuple, 0); + pos = i = 0; + while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) { + Py_INCREF(k[i]); + Py_INCREF(k[i+1]); + i += 2; + } + nk = i / 2; + } + else { + kwtuple = NULL; + k = NULL; + } + closure = PyFunction_GET_CLOSURE(func); +#if PY_MAJOR_VERSION >= 3 + kwdefs = PyFunction_GET_KW_DEFAULTS(func); +#endif + if (argdefs != NULL) { + d = &PyTuple_GET_ITEM(argdefs, 0); + nd = Py_SIZE(argdefs); + } + else { + d = NULL; + nd = 0; + } +#if PY_MAJOR_VERSION >= 3 + result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL, + args, (int)nargs, + k, (int)nk, + d, (int)nd, kwdefs, closure); +#else + result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL, + args, (int)nargs, + k, (int)nk, + d, (int)nd, closure); +#endif + Py_XDECREF(kwtuple); +done: + Py_LeaveRecursiveCall(); + return result; +} +#endif +#endif + +/* PyObjectCall */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) { PyObject *result; - ternaryfunc call = func->ob_type->tp_call; + ternaryfunc call = Py_TYPE(func)->tp_call; if (unlikely(!call)) return PyObject_Call(func, arg, kw); if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) @@ -3288,10 +4776,70 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg } #endif -static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) { +/* PyObjectCallMethO */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) { + PyObject *self, *result; + PyCFunction cfunc; + cfunc = PyCFunction_GET_FUNCTION(func); + self = PyCFunction_GET_SELF(func); + if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) + return NULL; + result = cfunc(self, arg); + Py_LeaveRecursiveCall(); + if (unlikely(!result) && unlikely(!PyErr_Occurred())) { + PyErr_SetString( + PyExc_SystemError, + "NULL result without error in PyObject_Call"); + } + return result; +} +#endif + +/* PyObjectCallOneArg */ #if CYTHON_COMPILING_IN_CPYTHON +static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) { + PyObject *result; + PyObject *args = PyTuple_New(1); + if (unlikely(!args)) return NULL; + Py_INCREF(arg); + PyTuple_SET_ITEM(args, 0, arg); + result = __Pyx_PyObject_Call(func, args, NULL); + Py_DECREF(args); + return result; +} +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) { +#if CYTHON_FAST_PYCALL + if (PyFunction_Check(func)) { + return __Pyx_PyFunction_FastCall(func, &arg, 1); + } +#endif + if (likely(PyCFunction_Check(func))) { + if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) { + return __Pyx_PyObject_CallMethO(func, arg); +#if CYTHON_FAST_PYCCALL + } else if (__Pyx_PyFastCFunction_Check(func)) { + return __Pyx_PyCFunction_FastCall(func, &arg, 1); +#endif + } + } + return __Pyx__PyObject_CallOneArg(func, arg); +} +#else +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) { + PyObject *result; + PyObject *args = PyTuple_Pack(1, arg); + if (unlikely(!args)) return NULL; + result = __Pyx_PyObject_Call(func, args, NULL); + Py_DECREF(args); + return result; +} +#endif + +/* PyErrFetchRestore */ +#if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { PyObject *tmp_type, *tmp_value, *tmp_tb; - PyThreadState *tstate = PyThreadState_GET(); tmp_type = tstate->curexc_type; tmp_value = tstate->curexc_value; tmp_tb = tstate->curexc_traceback; @@ -3301,27 +4849,22 @@ static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyOb Py_XDECREF(tmp_type); Py_XDECREF(tmp_value); Py_XDECREF(tmp_tb); -#else - PyErr_Restore(type, value, tb); -#endif } -static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) { -#if CYTHON_COMPILING_IN_CPYTHON - PyThreadState *tstate = PyThreadState_GET(); +static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { *type = tstate->curexc_type; *value = tstate->curexc_value; *tb = tstate->curexc_traceback; tstate->curexc_type = 0; tstate->curexc_value = 0; tstate->curexc_traceback = 0; -#else - PyErr_Fetch(type, value, tb); -#endif } +#endif +/* RaiseException */ #if PY_MAJOR_VERSION < 3 static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, CYTHON_UNUSED PyObject *cause) { + __Pyx_PyThreadState_declare Py_XINCREF(type); if (!value || value == Py_None) value = NULL; @@ -3360,6 +4903,7 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, goto raise_error; } } + __Pyx_PyThreadState_assign __Pyx_ErrRestore(type, value, tb); return; raise_error: @@ -3432,11 +4976,7 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject "raise: exception class must be a subclass of BaseException"); goto bad; } -#if PY_VERSION_HEX >= 0x03030000 if (cause) { -#else - if (cause && cause != Py_None) { -#endif PyObject *fixed_cause; if (cause == Py_None) { fixed_cause = NULL; @@ -3464,7 +5004,7 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject PyErr_Restore(tmp_type, tmp_value, tb); Py_XDECREF(tmp_tb); #else - PyThreadState *tstate = PyThreadState_GET(); + PyThreadState *tstate = __Pyx_PyThreadState_Current; PyObject* tmp_tb = tstate->curexc_traceback; if (tb != tmp_tb) { Py_INCREF(tb); @@ -3479,6 +5019,7 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject } #endif +/* RaiseDoubleKeywords */ static void __Pyx_RaiseDoubleKeywordsError( const char* func_name, PyObject* kw_name) @@ -3492,6 +5033,7 @@ static void __Pyx_RaiseDoubleKeywordsError( #endif } +/* ParseKeywords */ static int __Pyx_ParseOptionalKeywords( PyObject *kwds, PyObject **argnames[], @@ -3513,7 +5055,7 @@ static int __Pyx_ParseOptionalKeywords( } name = first_kw_arg; #if PY_MAJOR_VERSION < 3 - if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) { + if (likely(PyString_Check(key))) { while (*name) { if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key)) && _PyString_Eq(**name, key)) { @@ -3540,7 +5082,7 @@ static int __Pyx_ParseOptionalKeywords( while (*name) { int cmp = (**name == key) ? 0 : #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 - (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 : + (__Pyx_PyUnicode_GET_LENGTH(**name) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 : #endif PyUnicode_Compare(**name, key); if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; @@ -3556,7 +5098,7 @@ static int __Pyx_ParseOptionalKeywords( while (argname != first_kw_arg) { int cmp = (**argname == key) ? 0 : #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 - (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 : + (__Pyx_PyUnicode_GET_LENGTH(**argname) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 : #endif PyUnicode_Compare(**argname, key); if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; @@ -3572,52 +5114,364 @@ static int __Pyx_ParseOptionalKeywords( goto invalid_keyword; } } - return 0; -arg_passed_twice: - __Pyx_RaiseDoubleKeywordsError(function_name, key); - goto bad; -invalid_keyword_type: - PyErr_Format(PyExc_TypeError, - "%.200s() keywords must be strings", function_name); - goto bad; -invalid_keyword: - PyErr_Format(PyExc_TypeError, - #if PY_MAJOR_VERSION < 3 - "%.200s() got an unexpected keyword argument '%.200s'", - function_name, PyString_AsString(key)); - #else - "%s() got an unexpected keyword argument '%U'", - function_name, key); - #endif + return 0; +arg_passed_twice: + __Pyx_RaiseDoubleKeywordsError(function_name, key); + goto bad; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%.200s() keywords must be strings", function_name); + goto bad; +invalid_keyword: + PyErr_Format(PyExc_TypeError, + #if PY_MAJOR_VERSION < 3 + "%.200s() got an unexpected keyword argument '%.200s'", + function_name, PyString_AsString(key)); + #else + "%s() got an unexpected keyword argument '%U'", + function_name, key); + #endif +bad: + return -1; +} + +/* RaiseArgTupleInvalid */ +static void __Pyx_RaiseArgtupleInvalid( + const char* func_name, + int exact, + Py_ssize_t num_min, + Py_ssize_t num_max, + Py_ssize_t num_found) +{ + Py_ssize_t num_expected; + const char *more_or_less; + if (num_found < num_min) { + num_expected = num_min; + more_or_less = "at least"; + } else { + num_expected = num_max; + more_or_less = "at most"; + } + if (exact) { + more_or_less = "exactly"; + } + PyErr_Format(PyExc_TypeError, + "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)", + func_name, more_or_less, num_expected, + (num_expected == 1) ? "" : "s", num_found); +} + +/* PyObject_GenericGetAttrNoDict */ +#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +static PyObject *__Pyx_RaiseGenericGetAttributeError(PyTypeObject *tp, PyObject *attr_name) { + PyErr_Format(PyExc_AttributeError, +#if PY_MAJOR_VERSION >= 3 + "'%.50s' object has no attribute '%U'", + tp->tp_name, attr_name); +#else + "'%.50s' object has no attribute '%.400s'", + tp->tp_name, PyString_AS_STRING(attr_name)); +#endif + return NULL; +} +static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name) { + PyObject *descr; + PyTypeObject *tp = Py_TYPE(obj); + if (unlikely(!PyString_Check(attr_name))) { + return PyObject_GenericGetAttr(obj, attr_name); + } + assert(!tp->tp_dictoffset); + descr = _PyType_Lookup(tp, attr_name); + if (unlikely(!descr)) { + return __Pyx_RaiseGenericGetAttributeError(tp, attr_name); + } + Py_INCREF(descr); + #if PY_MAJOR_VERSION < 3 + if (likely(PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_HAVE_CLASS))) + #endif + { + descrgetfunc f = Py_TYPE(descr)->tp_descr_get; + if (unlikely(f)) { + PyObject *res = f(descr, obj, (PyObject *)tp); + Py_DECREF(descr); + return res; + } + } + return descr; +} +#endif + +/* PyObject_GenericGetAttr */ +#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name) { + if (unlikely(Py_TYPE(obj)->tp_dictoffset)) { + return PyObject_GenericGetAttr(obj, attr_name); + } + return __Pyx_PyObject_GenericGetAttrNoDict(obj, attr_name); +} +#endif + +/* PyErrExceptionMatches */ +#if CYTHON_FAST_THREAD_STATE +static int __Pyx_PyErr_ExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { + Py_ssize_t i, n; + n = PyTuple_GET_SIZE(tuple); +#if PY_MAJOR_VERSION >= 3 + for (i=0; icurexc_type; + if (exc_type == err) return 1; + if (unlikely(!exc_type)) return 0; + if (unlikely(PyTuple_Check(err))) + return __Pyx_PyErr_ExceptionMatchesTuple(exc_type, err); + return __Pyx_PyErr_GivenExceptionMatches(exc_type, err); +} +#endif + +/* PyObjectGetAttrStrNoError */ +static void __Pyx_PyObject_GetAttrStr_ClearAttributeError(void) { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))) + __Pyx_PyErr_Clear(); +} +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name) { + PyObject *result; +#if CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_TYPE_SLOTS && PY_VERSION_HEX >= 0x030700B1 + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_getattro == PyObject_GenericGetAttr)) { + return _PyObject_GenericGetAttrWithDict(obj, attr_name, NULL, 1); + } +#endif + result = __Pyx_PyObject_GetAttrStr(obj, attr_name); + if (unlikely(!result)) { + __Pyx_PyObject_GetAttrStr_ClearAttributeError(); + } + return result; +} + +/* SetupReduce */ +static int __Pyx_setup_reduce_is_named(PyObject* meth, PyObject* name) { + int ret; + PyObject *name_attr; + name_attr = __Pyx_PyObject_GetAttrStr(meth, __pyx_n_s_name); + if (likely(name_attr)) { + ret = PyObject_RichCompareBool(name_attr, name, Py_EQ); + } else { + ret = -1; + } + if (unlikely(ret < 0)) { + PyErr_Clear(); + ret = 0; + } + Py_XDECREF(name_attr); + return ret; +} +static int __Pyx_setup_reduce(PyObject* type_obj) { + int ret = 0; + PyObject *object_reduce = NULL; + PyObject *object_reduce_ex = NULL; + PyObject *reduce = NULL; + PyObject *reduce_ex = NULL; + PyObject *reduce_cython = NULL; + PyObject *setstate = NULL; + PyObject *setstate_cython = NULL; +#if CYTHON_USE_PYTYPE_LOOKUP + if (_PyType_Lookup((PyTypeObject*)type_obj, __pyx_n_s_getstate)) goto __PYX_GOOD; +#else + if (PyObject_HasAttr(type_obj, __pyx_n_s_getstate)) goto __PYX_GOOD; +#endif +#if CYTHON_USE_PYTYPE_LOOKUP + object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD; +#else + object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD; +#endif + reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_ex); if (unlikely(!reduce_ex)) goto __PYX_BAD; + if (reduce_ex == object_reduce_ex) { +#if CYTHON_USE_PYTYPE_LOOKUP + object_reduce = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD; +#else + object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD; +#endif + reduce = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce); if (unlikely(!reduce)) goto __PYX_BAD; + if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, __pyx_n_s_reduce_cython)) { + reduce_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_reduce_cython); + if (likely(reduce_cython)) { + ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce, reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + } else if (reduce == object_reduce || PyErr_Occurred()) { + goto __PYX_BAD; + } + setstate = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_setstate); + if (!setstate) PyErr_Clear(); + if (!setstate || __Pyx_setup_reduce_is_named(setstate, __pyx_n_s_setstate_cython)) { + setstate_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_setstate_cython); + if (likely(setstate_cython)) { + ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate, setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + } else if (!setstate || PyErr_Occurred()) { + goto __PYX_BAD; + } + } + PyType_Modified((PyTypeObject*)type_obj); + } + } + goto __PYX_GOOD; +__PYX_BAD: + if (!PyErr_Occurred()) + PyErr_Format(PyExc_RuntimeError, "Unable to initialize pickling for %s", ((PyTypeObject*)type_obj)->tp_name); + ret = -1; +__PYX_GOOD: +#if !CYTHON_USE_PYTYPE_LOOKUP + Py_XDECREF(object_reduce); + Py_XDECREF(object_reduce_ex); +#endif + Py_XDECREF(reduce); + Py_XDECREF(reduce_ex); + Py_XDECREF(reduce_cython); + Py_XDECREF(setstate); + Py_XDECREF(setstate_cython); + return ret; +} + +/* TypeImport */ +#ifndef __PYX_HAVE_RT_ImportType +#define __PYX_HAVE_RT_ImportType +static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, const char *class_name, + size_t size, enum __Pyx_ImportType_CheckSize check_size) +{ + PyObject *result = 0; + char warning[200]; + Py_ssize_t basicsize; +#ifdef Py_LIMITED_API + PyObject *py_basicsize; +#endif + result = PyObject_GetAttrString(module, class_name); + if (!result) + goto bad; + if (!PyType_Check(result)) { + PyErr_Format(PyExc_TypeError, + "%.200s.%.200s is not a type object", + module_name, class_name); + goto bad; + } +#ifndef Py_LIMITED_API + basicsize = ((PyTypeObject *)result)->tp_basicsize; +#else + py_basicsize = PyObject_GetAttrString(result, "__basicsize__"); + if (!py_basicsize) + goto bad; + basicsize = PyLong_AsSsize_t(py_basicsize); + Py_DECREF(py_basicsize); + py_basicsize = 0; + if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred()) + goto bad; +#endif + if ((size_t)basicsize < size) { + PyErr_Format(PyExc_ValueError, + "%.200s.%.200s size changed, may indicate binary incompatibility. " + "Expected %zd from C header, got %zd from PyObject", + module_name, class_name, size, basicsize); + goto bad; + } + if (check_size == __Pyx_ImportType_CheckSize_Error && (size_t)basicsize != size) { + PyErr_Format(PyExc_ValueError, + "%.200s.%.200s size changed, may indicate binary incompatibility. " + "Expected %zd from C header, got %zd from PyObject", + module_name, class_name, size, basicsize); + goto bad; + } + else if (check_size == __Pyx_ImportType_CheckSize_Warn && (size_t)basicsize > size) { + PyOS_snprintf(warning, sizeof(warning), + "%s.%s size changed, may indicate binary incompatibility. " + "Expected %zd from C header, got %zd from PyObject", + module_name, class_name, size, basicsize); + if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad; + } + return (PyTypeObject *)result; bad: - return -1; + Py_XDECREF(result); + return NULL; } +#endif -static void __Pyx_RaiseArgtupleInvalid( - const char* func_name, - int exact, - Py_ssize_t num_min, - Py_ssize_t num_max, - Py_ssize_t num_found) -{ - Py_ssize_t num_expected; - const char *more_or_less; - if (num_found < num_min) { - num_expected = num_min; - more_or_less = "at least"; - } else { - num_expected = num_max; - more_or_less = "at most"; +/* PyDictVersioning */ +#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) { + PyObject *dict = Py_TYPE(obj)->tp_dict; + return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0; +} +static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) { + PyObject **dictptr = NULL; + Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset; + if (offset) { +#if CYTHON_COMPILING_IN_CPYTHON + dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj); +#else + dictptr = _PyObject_GetDictPtr(obj); +#endif } - if (exact) { - more_or_less = "exactly"; + return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0; +} +static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) { + PyObject *dict = Py_TYPE(obj)->tp_dict; + if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict))) + return 0; + return obj_dict_version == __Pyx_get_object_dict_version(obj); +} +#endif + +/* CLineInTraceback */ +#ifndef CYTHON_CLINE_IN_TRACEBACK +static int __Pyx_CLineForTraceback(CYTHON_NCP_UNUSED PyThreadState *tstate, int c_line) { + PyObject *use_cline; + PyObject *ptype, *pvalue, *ptraceback; +#if CYTHON_COMPILING_IN_CPYTHON + PyObject **cython_runtime_dict; +#endif + if (unlikely(!__pyx_cython_runtime)) { + return c_line; } - PyErr_Format(PyExc_TypeError, - "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)", - func_name, more_or_less, num_expected, - (num_expected == 1) ? "" : "s", num_found); + __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback); +#if CYTHON_COMPILING_IN_CPYTHON + cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime); + if (likely(cython_runtime_dict)) { + __PYX_PY_DICT_LOOKUP_IF_MODIFIED( + use_cline, *cython_runtime_dict, + __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback)) + } else +#endif + { + PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback); + if (use_cline_obj) { + use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True; + Py_DECREF(use_cline_obj); + } else { + PyErr_Clear(); + use_cline = NULL; + } + } + if (!use_cline) { + c_line = 0; + (void) PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False); + } + else if (use_cline == Py_False || (use_cline != Py_True && PyObject_Not(use_cline) != 0)) { + c_line = 0; + } + __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback); + return c_line; } +#endif +/* CodeObjectCache */ static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { int start = 0, mid = 0, end = count - 1; if (end >= 0 && code_line > entries[end].code_line) { @@ -3681,7 +5535,7 @@ static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { if (__pyx_code_cache.count == __pyx_code_cache.max_count) { int new_max = __pyx_code_cache.max_count + 64; entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( - __pyx_code_cache.entries, (size_t)new_max*sizeof(__Pyx_CodeObjectCacheEntry)); + __pyx_code_cache.entries, ((size_t)new_max) * sizeof(__Pyx_CodeObjectCacheEntry)); if (unlikely(!entries)) { return; } @@ -3697,36 +5551,38 @@ static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { Py_INCREF(code_object); } +/* AddTraceback */ #include "compile.h" #include "frameobject.h" #include "traceback.h" static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( const char *funcname, int c_line, int py_line, const char *filename) { - PyCodeObject *py_code = 0; - PyObject *py_srcfile = 0; - PyObject *py_funcname = 0; + PyCodeObject *py_code = NULL; + PyObject *py_funcname = NULL; #if PY_MAJOR_VERSION < 3 + PyObject *py_srcfile = NULL; py_srcfile = PyString_FromString(filename); - #else - py_srcfile = PyUnicode_FromString(filename); - #endif if (!py_srcfile) goto bad; + #endif if (c_line) { #if PY_MAJOR_VERSION < 3 py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); + if (!py_funcname) goto bad; #else py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); + if (!py_funcname) goto bad; + funcname = PyUnicode_AsUTF8(py_funcname); + if (!funcname) goto bad; #endif } else { #if PY_MAJOR_VERSION < 3 py_funcname = PyString_FromString(funcname); - #else - py_funcname = PyUnicode_FromString(funcname); + if (!py_funcname) goto bad; #endif } - if (!py_funcname) goto bad; + #if PY_MAJOR_VERSION < 3 py_code = __Pyx_PyCode_New( 0, 0, @@ -3745,38 +5601,48 @@ static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( __pyx_empty_bytes /*PyObject *lnotab*/ ); Py_DECREF(py_srcfile); - Py_DECREF(py_funcname); + #else + py_code = PyCode_NewEmpty(filename, funcname, py_line); + #endif + Py_XDECREF(py_funcname); // XDECREF since it's only set on Py3 if cline return py_code; bad: - Py_XDECREF(py_srcfile); Py_XDECREF(py_funcname); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(py_srcfile); + #endif return NULL; } static void __Pyx_AddTraceback(const char *funcname, int c_line, int py_line, const char *filename) { PyCodeObject *py_code = 0; PyFrameObject *py_frame = 0; - py_code = __pyx_find_code_object(c_line ? c_line : py_line); + PyThreadState *tstate = __Pyx_PyThreadState_Current; + if (c_line) { + c_line = __Pyx_CLineForTraceback(tstate, c_line); + } + py_code = __pyx_find_code_object(c_line ? -c_line : py_line); if (!py_code) { py_code = __Pyx_CreateCodeObjectForTraceback( funcname, c_line, py_line, filename); if (!py_code) goto bad; - __pyx_insert_code_object(c_line ? c_line : py_line, py_code); + __pyx_insert_code_object(c_line ? -c_line : py_line, py_code); } py_frame = PyFrame_New( - PyThreadState_GET(), /*PyThreadState *tstate,*/ - py_code, /*PyCodeObject *code,*/ - __pyx_d, /*PyObject *globals,*/ - 0 /*PyObject *locals*/ + tstate, /*PyThreadState *tstate,*/ + py_code, /*PyCodeObject *code,*/ + __pyx_d, /*PyObject *globals,*/ + 0 /*PyObject *locals*/ ); if (!py_frame) goto bad; - py_frame->f_lineno = py_line; + __Pyx_PyFrame_SetLineNumber(py_frame, py_line); PyTraceBack_Here(py_frame); bad: Py_XDECREF(py_code); Py_XDECREF(py_frame); } +/* CIntFromPyVerify */ #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\ __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0) #define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\ @@ -3798,12 +5664,16 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, return (target_type) value;\ } -#if CYTHON_USE_PYLONG_INTERNALS - #include "longintrepr.h" -#endif - +/* CIntFromPy */ static CYTHON_INLINE uint64_t __Pyx_PyInt_As_uint64_t(PyObject *x) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif const uint64_t neg_one = (uint64_t) -1, const_zero = (uint64_t) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x))) { @@ -3869,15 +5739,17 @@ static CYTHON_INLINE uint64_t __Pyx_PyInt_As_uint64_t(PyObject *x) { #endif if (sizeof(uint64_t) <= sizeof(unsigned long)) { __PYX_VERIFY_RETURN_INT_EXC(uint64_t, unsigned long, PyLong_AsUnsignedLong(x)) +#ifdef HAVE_LONG_LONG } else if (sizeof(uint64_t) <= sizeof(unsigned PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(uint64_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) +#endif } } else { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (uint64_t) 0; - case -1: __PYX_VERIFY_RETURN_INT(uint64_t, sdigit, -(sdigit) digits[0]) + case -1: __PYX_VERIFY_RETURN_INT(uint64_t, sdigit, (sdigit) (-(sdigit)digits[0])) case 1: __PYX_VERIFY_RETURN_INT(uint64_t, digit, +digits[0]) case -2: if (8 * sizeof(uint64_t) - 1 > 1 * PyLong_SHIFT) { @@ -3937,8 +5809,10 @@ static CYTHON_INLINE uint64_t __Pyx_PyInt_As_uint64_t(PyObject *x) { #endif if (sizeof(uint64_t) <= sizeof(long)) { __PYX_VERIFY_RETURN_INT_EXC(uint64_t, long, PyLong_AsLong(x)) +#ifdef HAVE_LONG_LONG } else if (sizeof(uint64_t) <= sizeof(PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(uint64_t, PY_LONG_LONG, PyLong_AsLongLong(x)) +#endif } } { @@ -3947,7 +5821,7 @@ static CYTHON_INLINE uint64_t __Pyx_PyInt_As_uint64_t(PyObject *x) { "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); #else uint64_t val; - PyObject *v = __Pyx_PyNumber_Int(x); + PyObject *v = __Pyx_PyNumber_IntOrLong(x); #if PY_MAJOR_VERSION < 3 if (likely(v) && !PyLong_Check(v)) { PyObject *tmp = v; @@ -3970,7 +5844,7 @@ static CYTHON_INLINE uint64_t __Pyx_PyInt_As_uint64_t(PyObject *x) { } } else { uint64_t val; - PyObject *tmp = __Pyx_PyNumber_Int(x); + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); if (!tmp) return (uint64_t) -1; val = __Pyx_PyInt_As_uint64_t(tmp); Py_DECREF(tmp); @@ -3986,22 +5860,34 @@ static CYTHON_INLINE uint64_t __Pyx_PyInt_As_uint64_t(PyObject *x) { return (uint64_t) -1; } +/* CIntToPy */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint64_t(uint64_t value) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif const uint64_t neg_one = (uint64_t) -1, const_zero = (uint64_t) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif const int is_unsigned = neg_one > const_zero; if (is_unsigned) { if (sizeof(uint64_t) < sizeof(long)) { return PyInt_FromLong((long) value); } else if (sizeof(uint64_t) <= sizeof(unsigned long)) { return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG } else if (sizeof(uint64_t) <= sizeof(unsigned PY_LONG_LONG)) { return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif } } else { if (sizeof(uint64_t) <= sizeof(long)) { return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG } else if (sizeof(uint64_t) <= sizeof(PY_LONG_LONG)) { return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif } } { @@ -4012,22 +5898,34 @@ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint64_t(uint64_t value) { } } +/* CIntToPy */ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif const long neg_one = (long) -1, const_zero = (long) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif const int is_unsigned = neg_one > const_zero; if (is_unsigned) { if (sizeof(long) < sizeof(long)) { return PyInt_FromLong((long) value); } else if (sizeof(long) <= sizeof(unsigned long)) { return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif } } else { if (sizeof(long) <= sizeof(long)) { return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif } } { @@ -4038,8 +5936,16 @@ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { } } +/* CIntFromPy */ static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif const long neg_one = (long) -1, const_zero = (long) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x))) { @@ -4105,15 +6011,17 @@ static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { #endif if (sizeof(long) <= sizeof(unsigned long)) { __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x)) +#ifdef HAVE_LONG_LONG } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) +#endif } } else { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (long) 0; - case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, -(sdigit) digits[0]) + case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0])) case 1: __PYX_VERIFY_RETURN_INT(long, digit, +digits[0]) case -2: if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) { @@ -4173,8 +6081,10 @@ static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { #endif if (sizeof(long) <= sizeof(long)) { __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x)) +#ifdef HAVE_LONG_LONG } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x)) +#endif } } { @@ -4183,7 +6093,7 @@ static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); #else long val; - PyObject *v = __Pyx_PyNumber_Int(x); + PyObject *v = __Pyx_PyNumber_IntOrLong(x); #if PY_MAJOR_VERSION < 3 if (likely(v) && !PyLong_Check(v)) { PyObject *tmp = v; @@ -4206,7 +6116,7 @@ static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { } } else { long val; - PyObject *tmp = __Pyx_PyNumber_Int(x); + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); if (!tmp) return (long) -1; val = __Pyx_PyInt_As_long(tmp); Py_DECREF(tmp); @@ -4222,8 +6132,16 @@ static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { return (long) -1; } +/* CIntFromPy */ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif const int neg_one = (int) -1, const_zero = (int) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x))) { @@ -4289,15 +6207,17 @@ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { #endif if (sizeof(int) <= sizeof(unsigned long)) { __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x)) +#ifdef HAVE_LONG_LONG } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) +#endif } } else { #if CYTHON_USE_PYLONG_INTERNALS const digit* digits = ((PyLongObject*)x)->ob_digit; switch (Py_SIZE(x)) { case 0: return (int) 0; - case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, -(sdigit) digits[0]) + case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0])) case 1: __PYX_VERIFY_RETURN_INT(int, digit, +digits[0]) case -2: if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) { @@ -4357,8 +6277,10 @@ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { #endif if (sizeof(int) <= sizeof(long)) { __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x)) +#ifdef HAVE_LONG_LONG } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) { __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x)) +#endif } } { @@ -4367,7 +6289,7 @@ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); #else int val; - PyObject *v = __Pyx_PyNumber_Int(x); + PyObject *v = __Pyx_PyNumber_IntOrLong(x); #if PY_MAJOR_VERSION < 3 if (likely(v) && !PyLong_Check(v)) { PyObject *tmp = v; @@ -4390,7 +6312,7 @@ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { } } else { int val; - PyObject *tmp = __Pyx_PyNumber_Int(x); + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); if (!tmp) return (int) -1; val = __Pyx_PyInt_As_int(tmp); Py_DECREF(tmp); @@ -4406,6 +6328,107 @@ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { return (int) -1; } +/* FastTypeChecks */ +#if CYTHON_COMPILING_IN_CPYTHON +static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) { + while (a) { + a = a->tp_base; + if (a == b) + return 1; + } + return b == &PyBaseObject_Type; +} +static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) { + PyObject *mro; + if (a == b) return 1; + mro = a->tp_mro; + if (likely(mro)) { + Py_ssize_t i, n; + n = PyTuple_GET_SIZE(mro); + for (i = 0; i < n; i++) { + if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b) + return 1; + } + return 0; + } + return __Pyx_InBases(a, b); +} +#if PY_MAJOR_VERSION == 2 +static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) { + PyObject *exception, *value, *tb; + int res; + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ErrFetch(&exception, &value, &tb); + res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0; + if (unlikely(res == -1)) { + PyErr_WriteUnraisable(err); + res = 0; + } + if (!res) { + res = PyObject_IsSubclass(err, exc_type2); + if (unlikely(res == -1)) { + PyErr_WriteUnraisable(err); + res = 0; + } + } + __Pyx_ErrRestore(exception, value, tb); + return res; +} +#else +static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) { + int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0; + if (!res) { + res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2); + } + return res; +} +#endif +static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { + Py_ssize_t i, n; + assert(PyExceptionClass_Check(exc_type)); + n = PyTuple_GET_SIZE(tuple); +#if PY_MAJOR_VERSION >= 3 + for (i=0; itp_basicsize; -#else - py_basicsize = PyObject_GetAttrString(result, "__basicsize__"); - if (!py_basicsize) - goto bad; - basicsize = PyLong_AsSsize_t(py_basicsize); - Py_DECREF(py_basicsize); - py_basicsize = 0; - if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred()) - goto bad; -#endif - if (!strict && (size_t)basicsize > size) { - PyOS_snprintf(warning, sizeof(warning), - "%s.%s size changed, may indicate binary incompatibility", - module_name, class_name); - if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad; - } - else if ((size_t)basicsize != size) { - PyErr_Format(PyExc_ValueError, - "%.200s.%.200s has the wrong size, try recompiling", - module_name, class_name); - goto bad; - } - return (PyTypeObject *)result; -bad: - Py_XDECREF(py_module); - Py_XDECREF(result); - return NULL; -} -#endif - +/* InitStrings */ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { while (t->p) { #if PY_MAJOR_VERSION < 3 @@ -4527,6 +6470,8 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { #endif if (!*t->p) return -1; + if (PyObject_Hash(*t->p) == -1) + return -1; ++t; } return 0; @@ -4535,50 +6480,57 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) { return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str)); } -static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject* o) { +static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) { Py_ssize_t ignore; return __Pyx_PyObject_AsStringAndSize(o, &ignore); } -static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) { -#if CYTHON_COMPILING_IN_CPYTHON && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) - if ( -#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII - __Pyx_sys_getdefaultencoding_not_ascii && -#endif - PyUnicode_Check(o)) { -#if PY_VERSION_HEX < 0x03030000 - char* defenc_c; - PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL); - if (!defenc) return NULL; - defenc_c = PyBytes_AS_STRING(defenc); +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT +#if !CYTHON_PEP393_ENABLED +static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) { + char* defenc_c; + PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL); + if (!defenc) return NULL; + defenc_c = PyBytes_AS_STRING(defenc); #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII - { - char* end = defenc_c + PyBytes_GET_SIZE(defenc); - char* c; - for (c = defenc_c; c < end; c++) { - if ((unsigned char) (*c) >= 128) { - PyUnicode_AsASCIIString(o); - return NULL; - } + { + char* end = defenc_c + PyBytes_GET_SIZE(defenc); + char* c; + for (c = defenc_c; c < end; c++) { + if ((unsigned char) (*c) >= 128) { + PyUnicode_AsASCIIString(o); + return NULL; } } + } #endif - *length = PyBytes_GET_SIZE(defenc); - return defenc_c; + *length = PyBytes_GET_SIZE(defenc); + return defenc_c; +} #else - if (__Pyx_PyUnicode_READY(o) == -1) return NULL; +static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) { + if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL; #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII - if (PyUnicode_IS_ASCII(o)) { - *length = PyUnicode_GET_LENGTH(o); - return PyUnicode_AsUTF8(o); - } else { - PyUnicode_AsASCIIString(o); - return NULL; - } + if (likely(PyUnicode_IS_ASCII(o))) { + *length = PyUnicode_GET_LENGTH(o); + return PyUnicode_AsUTF8(o); + } else { + PyUnicode_AsASCIIString(o); + return NULL; + } #else - return PyUnicode_AsUTF8AndSize(o, length); + return PyUnicode_AsUTF8AndSize(o, length); +#endif +} +#endif #endif +static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) { +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT + if ( +#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + __Pyx_sys_getdefaultencoding_not_ascii && #endif + PyUnicode_Check(o)) { + return __Pyx_PyUnicode_AsStringAndSize(o, length); } else #endif #if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE)) @@ -4602,43 +6554,74 @@ static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { if (is_true | (x == Py_False) | (x == Py_None)) return is_true; else return PyObject_IsTrue(x); } -static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) { +static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) { + int retval; + if (unlikely(!x)) return -1; + retval = __Pyx_PyObject_IsTrue(x); + Py_DECREF(x); + return retval; +} +static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) { +#if PY_MAJOR_VERSION >= 3 + if (PyLong_Check(result)) { + if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, + "__int__ returned non-int (type %.200s). " + "The ability to return an instance of a strict subclass of int " + "is deprecated, and may be removed in a future version of Python.", + Py_TYPE(result)->tp_name)) { + Py_DECREF(result); + return NULL; + } + return result; + } +#endif + PyErr_Format(PyExc_TypeError, + "__%.4s__ returned non-%.4s (type %.200s)", + type_name, type_name, Py_TYPE(result)->tp_name); + Py_DECREF(result); + return NULL; +} +static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) { +#if CYTHON_USE_TYPE_SLOTS PyNumberMethods *m; +#endif const char *name = NULL; PyObject *res = NULL; #if PY_MAJOR_VERSION < 3 - if (PyInt_Check(x) || PyLong_Check(x)) + if (likely(PyInt_Check(x) || PyLong_Check(x))) #else - if (PyLong_Check(x)) + if (likely(PyLong_Check(x))) #endif return __Pyx_NewRef(x); +#if CYTHON_USE_TYPE_SLOTS m = Py_TYPE(x)->tp_as_number; -#if PY_MAJOR_VERSION < 3 + #if PY_MAJOR_VERSION < 3 if (m && m->nb_int) { name = "int"; - res = PyNumber_Int(x); + res = m->nb_int(x); } else if (m && m->nb_long) { name = "long"; - res = PyNumber_Long(x); + res = m->nb_long(x); } -#else - if (m && m->nb_int) { + #else + if (likely(m && m->nb_int)) { name = "int"; - res = PyNumber_Long(x); + res = m->nb_int(x); + } + #endif +#else + if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) { + res = PyNumber_Int(x); } #endif - if (res) { + if (likely(res)) { #if PY_MAJOR_VERSION < 3 - if (!PyInt_Check(res) && !PyLong_Check(res)) { + if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) { #else - if (!PyLong_Check(res)) { + if (unlikely(!PyLong_CheckExact(res))) { #endif - PyErr_Format(PyExc_TypeError, - "__%.4s__ returned non-%.4s (type %.200s)", - name, name, Py_TYPE(res)->tp_name); - Py_DECREF(res); - return NULL; + return __Pyx_PyNumber_IntOrLongWrongResultType(res, name); } } else if (!PyErr_Occurred()) { @@ -4655,7 +6638,7 @@ static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { if (sizeof(Py_ssize_t) >= sizeof(long)) return PyInt_AS_LONG(b); else - return PyInt_AsSsize_t(x); + return PyInt_AsSsize_t(b); } #endif if (likely(PyLong_CheckExact(b))) { @@ -4709,6 +6692,26 @@ static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { Py_DECREF(x); return ival; } +static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject* o) { + if (sizeof(Py_hash_t) == sizeof(Py_ssize_t)) { + return (Py_hash_t) __Pyx_PyIndex_AsSsize_t(o); +#if PY_MAJOR_VERSION < 3 + } else if (likely(PyInt_CheckExact(o))) { + return PyInt_AS_LONG(o); +#endif + } else { + Py_ssize_t ival; + PyObject *x; + x = PyNumber_Index(o); + if (!x) return -1; + ival = PyInt_AsLong(x); + Py_DECREF(x); + return ival; + } +} +static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) { + return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False); +} static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { return PyInt_FromSize_t(ival); } diff --git a/src/metrohash.pyx b/src/metrohash.pyx index dd0b3c0..8116aaf 100644 --- a/src/metrohash.pyx +++ b/src/metrohash.pyx @@ -1,4 +1,6 @@ #cython: infer_types=True +#cython: language_level=3 +#distutils: language=c++ """ A Python wrapper for MetroHash, a fast non-cryptographic hashing algorithm @@ -6,10 +8,12 @@ A Python wrapper for MetroHash, a fast non-cryptographic hashing algorithm __author__ = "Eugene Scherba" __email__ = "escherba+metrohash@gmail.com" -__version__ = "0.0.13" +__version__ = "0.1.0" __all__ = [ - "metrohash64", "metrohash128", - "MetroHash64", "MetroHash128", + "metrohash64", + "metrohash128", + "MetroHash64", + "MetroHash128", ] @@ -56,6 +60,8 @@ cdef extern from "metro.h" nogil: void Update(const uint8* buf, const uint64 length) void Finalize(uint8* const result) +from cpython.long cimport long + from cpython.buffer cimport PyObject_CheckBuffer from cpython.buffer cimport PyBUF_SIMPLE from cpython.buffer cimport Py_buffer @@ -64,9 +70,9 @@ from cpython.buffer cimport PyObject_GetBuffer from cpython.unicode cimport PyUnicode_Check from cpython.unicode cimport PyUnicode_AsUTF8String -from cpython.string cimport PyString_Check -from cpython.string cimport PyString_GET_SIZE -from cpython.string cimport PyString_AS_STRING +from cpython.bytes cimport PyBytes_Check +from cpython.bytes cimport PyBytes_GET_SIZE +from cpython.bytes cimport PyBytes_AS_STRING from cpython cimport Py_DECREF @@ -88,9 +94,9 @@ cpdef metrohash64(data, uint64 seed=0ULL): PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) result = c_metrohash64(buf.buf, buf.len, seed) Py_DECREF(obj) - elif PyString_Check(data): - result = c_metrohash64(PyString_AS_STRING(data), - PyString_GET_SIZE(data), seed) + elif PyBytes_Check(data): + result = c_metrohash64(PyBytes_AS_STRING(data), + PyBytes_GET_SIZE(data), seed) elif PyObject_CheckBuffer(data): PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) result = c_metrohash64(buf.buf, buf.len, seed) @@ -110,9 +116,9 @@ cpdef metrohash128(data, uint64 seed=0ULL): PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) result = c_metrohash128(buf.buf, buf.len, seed) Py_DECREF(obj) - elif PyString_Check(data): - result = c_metrohash128(PyString_AS_STRING(data), - PyString_GET_SIZE(data), seed) + elif PyBytes_Check(data): + result = c_metrohash128(PyBytes_AS_STRING(data), + PyBytes_GET_SIZE(data), seed) elif PyObject_CheckBuffer(data): PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) result = c_metrohash128(buf.buf, buf.len, seed) @@ -150,9 +156,9 @@ cdef class MetroHash64(object): PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) Py_DECREF(obj) self._m.Update(buf.buf, buf.len) - elif PyString_Check(data): - self._m.Update(PyString_AS_STRING(data), - PyString_GET_SIZE(data)) + elif PyBytes_Check(data): + self._m.Update(PyBytes_AS_STRING(data), + PyBytes_GET_SIZE(data)) elif PyObject_CheckBuffer(data): PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) self._m.Update(buf.buf, buf.len) @@ -193,9 +199,9 @@ cdef class MetroHash128(object): PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) Py_DECREF(obj) self._m.Update(buf.buf, buf.len) - elif PyString_Check(data): - self._m.Update(PyString_AS_STRING(data), - PyString_GET_SIZE(data)) + elif PyBytes_Check(data): + self._m.Update(PyBytes_AS_STRING(data), + PyBytes_GET_SIZE(data)) elif PyObject_CheckBuffer(data): PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) self._m.Update(buf.buf, buf.len) diff --git a/tests/test_metrohash.py b/tests/test_metrohash.py index 81eb236..021d506 100644 --- a/tests/test_metrohash.py +++ b/tests/test_metrohash.py @@ -1,67 +1,91 @@ +""" +Python-based tests for metrohash extension +""" import unittest import random import string -from metrohash import MetroHash64, MetroHash128, metrohash64, metrohash128 +import sys + +from metrohash import ( + MetroHash64, + MetroHash128, + metrohash64, + metrohash128 +) + + +EMPTY_STRING = "" +EMPTY_UNICODE = u"" # pylint: disable=redundant-u-string-prefix + + +if sys.version_info[0] >= 3: + long = int def random_string(n, alphabet=string.ascii_lowercase): + """generate a random string""" return ''.join(random.choice(alphabet) for _ in range(n)) -def random_splits(string, n, nsplits=2): +def random_splits(s, n, nsplits=2): + """split string in random places""" splits = sorted([random.randint(0, n) for _ in range(nsplits - 1)]) splits = [0] + splits + [n] - for a, b in zip(splits, splits[1:]): - yield string[a:b] + for begin, end in zip(splits, splits[1:]): + yield s[begin:end] class TestStandalone(unittest.TestCase): + """test single-line methods""" + def test_string_unicode_64(self): """Empty Python string has same hash value as empty Unicode string """ - self.assertEqual(metrohash64(""), metrohash64(u"")) + self.assertEqual(metrohash64(EMPTY_STRING), metrohash64(EMPTY_UNICODE)) def test_string_unicode_128(self): """Empty Python string has same hash value as empty Unicode string """ - self.assertEqual(metrohash128(""), metrohash128(u"")) + self.assertEqual(metrohash128(EMPTY_STRING), metrohash128(EMPTY_UNICODE)) def test_consistent_encoding_64(self): """ASCII-range Unicode strings have the same hash values as ASCII strings """ - text = u"abracadabra" + text = u"abracadabra" # pylint: disable=redundant-u-string-prefix self.assertEqual(metrohash64(text), metrohash64(text.encode("utf-8"))) def test_consistent_encoding_128(self): """ASCII-range Unicode strings have the same hash values as ASCII strings """ - text = u"abracadabra" + text = u"abracadabra" # pylint: disable=redundant-u-string-prefix self.assertEqual(metrohash128(text), metrohash128(text.encode("utf-8"))) def test_unicode_1_64(self): """Accepts Unicode input""" - test_case = u"abc" + test_case = u"abc" # pylint: disable=redundant-u-string-prefix self.assertTrue(isinstance(metrohash64(test_case), long)) def test_unicode_1_128(self): """Accepts Unicode input""" - test_case = u"abc" + test_case = u"abc" # pylint: disable=redundant-u-string-prefix self.assertTrue(isinstance(metrohash128(test_case), long)) def test_unicode_2_64(self): """Accepts Unicode input outside of ASCII range""" - test_case = u'\u2661' + test_case = u'\u2661' # pylint: disable=redundant-u-string-prefix self.assertTrue(isinstance(metrohash64(test_case), long)) def test_unicode_2_128(self): """Accepts Unicode input outside of ASCII range""" - test_case = u'\u2661' + test_case = u'\u2661' # pylint: disable=redundant-u-string-prefix self.assertTrue(isinstance(metrohash128(test_case), long)) class TestCombiners(unittest.TestCase): + """test combiners""" + def test_compose_64(self): """Test various ways to split a string """ @@ -71,16 +95,16 @@ def test_compose_64(self): hasher = MetroHash64 alphabet = string.ascii_uppercase + string.ascii_lowercase + string.digits - for _ in xrange(num_tests): + for _ in range(num_tests): data = random_string(nchars, alphabet=alphabet) - m1 = hasher() + hasher1 = hasher() pieces = list(random_splits(data, nchars, random.randint(*split_range))) for piece in pieces: - m1.update(piece) - incremental = m1.intdigest() - m2 = hasher() - m2.update(data) - whole = m2.intdigest() + hasher1.update(piece) + incremental = hasher1.intdigest() + hasher2 = hasher() + hasher2.update(data) + whole = hasher2.intdigest() msg = "\ndata: %s\nwhole: %s\nincremental: %s\n" % (pieces, whole, incremental) self.assertEqual(whole, incremental, msg) @@ -93,15 +117,15 @@ def test_compose_128(self): hasher = MetroHash128 alphabet = string.ascii_lowercase - for _ in xrange(num_tests): + for _ in range(num_tests): data = random_string(nchars, alphabet=alphabet) - m1 = hasher() + hasher1 = hasher() pieces = list(random_splits(data, nchars, random.randint(*split_range))) for piece in pieces: - m1.update(piece) - incremental = m1.intdigest() - m2 = hasher() - m2.update(data) - whole = m2.intdigest() + hasher1.update(piece) + incremental = hasher1.intdigest() + hasher2 = hasher() + hasher2.update(data) + whole = hasher2.intdigest() msg = "\ndata: %s\nwhole: %s\nincremental: %s\n" % (pieces, whole, incremental) self.assertEqual(whole, incremental, msg) From 991ad4b6c291ab68597403e9cda981c0942a6235 Mon Sep 17 00:00:00 2001 From: Eugene Scherba Date: Tue, 28 Dec 2021 12:55:50 -0800 Subject: [PATCH 2/7] fix C++ tests --- cpp.mk | 2 +- setup.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cpp.mk b/cpp.mk index b311eb0..5f41131 100644 --- a/cpp.mk +++ b/cpp.mk @@ -1,5 +1,5 @@ CXX := g++ -CXXFLAGS := -msse4.2 -O3 +CXXFLAGS := -std=c++11 -O3 -msse4.2 LDFLAGS := SRCEXT := cc INC := -I include diff --git a/setup.py b/setup.py index cf9853a..3f7227e 100644 --- a/setup.py +++ b/setup.py @@ -64,7 +64,7 @@ def is_pure(self): language="c++", extra_compile_args=CXXFLAGS, include_dirs=INCLUDE_DIRS) - ) + ) CMDCLASS['build_ext'] = build_ext else: EXT_MODULES.append( @@ -75,7 +75,7 @@ def is_pure(self): language="c++", extra_compile_args=CXXFLAGS, include_dirs=INCLUDE_DIRS) - ) + ) VERSION = '0.1.0' From 145820226bfd8e969876bc43feb72313645a255d Mon Sep 17 00:00:00 2001 From: Eugene Scherba Date: Tue, 28 Dec 2021 13:00:44 -0800 Subject: [PATCH 3/7] add new CircleCI config --- .circleci/config.yml | 93 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..c226fee --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,93 @@ +# Use the latest 2.1 version of CircleCI pipeline process engine. +# See: https://circleci.com/docs/2.0/configuration-reference +version: 2.1 + +# Orbs are reusable packages of CircleCI configuration that you may share across projects, enabling you to create encapsulated, parameterized commands, jobs, and executors that can be used across multiple projects. +# See: https://circleci.com/docs/2.0/orb-intro/ +orbs: + # The python orb contains a set of prepackaged CircleCI configuration you can use repeatedly in your configuration files + # Orb commands and jobs help you with common scripting around a language/tool, + # so you don't have to copy and paste it everywhere. + # See the orb documentation here: https://circleci.com/developer/orbs/orb/circleci/python + python: circleci/python@1.2 + +# Define a job to be invoked later in a workflow. +# See: https://circleci.com/docs/2.0/configuration-reference/#jobs +jobs: + build-and-test: # This is the name of the job, feel free to change it to better match what you're trying to do! + # These next lines defines a Docker executors: https://circleci.com/docs/2.0/executor-types/ + # You can specify an image from Dockerhub or use one of the convenience images from CircleCI's Developer Hub + # A list of available CircleCI Docker convenience images are available here: https://circleci.com/developer/images/image/cimg/python + # The executor is the environment in which the steps below will be executed - below will use a python 3.8 container + # Change the version below to your required version of python + docker: + - image: cimg/python:3.8 + environment: + SETUPTOOLS_USE_DISTUTILS: stdlib + # Checkout the code as the first step. This is a dedicated CircleCI step. + # The python orb's install-packages step will install the dependencies from a Pipfile via Pipenv by default. + # Here we're making sure we use just use the system-wide pip. By default, it uses the project root's requirements.txt. + # Then run your tests! + # CircleCI will report the results back to your VCS provider. + steps: + - checkout + - restore_cache: + keys: + # when lock file changes, use increasingly general patterns to restore cache + - pip-packages-v1-{{ .Branch }}-{{ checksum "pip-freeze.txt" }} + - pip-packages-v1-{{ .Branch }}- + - pip-packages-v1- + - python/install-packages: + pkg-manager: pip-dist + pip-dependency-file: requirements.txt + # app-dir: ~/project/package-directory/ # If you're requirements.txt isn't in the root directory. + - run: + name: Run tests + # This assumes pytest is installed via the install-package step above + command: | + make env + make test + - save_cache: + paths: + - env # this path depends on where pipenv creates a virtualenv + key: pip-packages-v1-{{ .Branch }}-{{ checksum "pip-freeze.txt" }} + build-and-publish: + docker: + - image: cimg/python:3.8 + environment: + SETUPTOOLS_USE_DISTUTILS: stdlib + steps: + - checkout + - restore_cache: + keys: + # when lock file changes, use increasingly general patterns to restore cache + - pip-packages-v1-{{ .Branch }}-{{ checksum "pip-freeze.txt" }} + - pip-packages-v1-{{ .Branch }}- + - pip-packages-v1- + - python/install-packages: + pkg-manager: pip-dist + pip-dependency-file: requirements.txt + - run: + name: Publish to PyPI + command: | + bash create_pypirc.sh + make test + make release + - save_cache: + paths: + - env # this path depends on where pipenv creates a virtualenv + key: pip-packages-v1-{{ .Branch }}-{{ checksum "pip-freeze.txt" }} + + +# Invoke jobs via workflows +# See: https://circleci.com/docs/2.0/configuration-reference/#workflows +workflows: + run-tests: + jobs: + - build-and-test + publish-to-pypi: + jobs: + - build-and-publish: + filters: + branches: + only: master From dc510c29023965895fa61ec19e3c40c6292fc514 Mon Sep 17 00:00:00 2001 From: Eugene Scherba Date: Tue, 28 Dec 2021 13:05:43 -0800 Subject: [PATCH 4/7] update readme --- README.rst | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/README.rst b/README.rst index 51e69d1..052565b 100644 --- a/README.rst +++ b/README.rst @@ -18,7 +18,7 @@ A Python wrapper around `MetroHash ` Getting Started --------------- -To use this package in your program, simply enter +To use this package in your program, simply type .. code-block:: bash @@ -31,10 +31,10 @@ Example Usage below). Example Usage ------------- -This package provides Python interfaces to 64- and 128-bit implementations -of MetroHash algorithm. For stateless hashing, it exports ``metrohash64`` and -``metrohash128`` functions. Both take a value to be hashed (either string or unicode) and -an optional ``seed`` parameter: +This package provides Python interfaces to 64- and 128-bit implementations of +MetroHash algorithm. For stateless hashing, it exports ``metrohash64`` and +``metrohash128`` functions. Both take a value to be hashed (either string or +unicode) and an optional ``seed`` parameter: .. code-block:: python @@ -47,9 +47,9 @@ an optional ``seed`` parameter: For incremental hashing, use ``MetroHash64`` and ``MetroHash128`` classes. -Incremental hashing is associative and guarantees that any combination of -input slices will result in the same final hash value. This is useful for -processing large inputs and stream data. Example with two slices: +Incremental hashing is associative and guarantees that any combination of input +slices will result in the same final hash value. This is useful for processing +large inputs and stream data. Example with two slices: .. code-block:: python @@ -72,27 +72,37 @@ Note that the resulting hash value above is the same as in: Development ----------- -If you want to contribute to this package by developing, the included Makefile -provides some useful commands to help with that task: +For those who want to contribute, here is a quick start using some makefile +commands: .. code-block:: bash git clone https://github.com/escherba/python-metrohash.git cd python-metrohash make env # creates a Python virtualenv - make test # builds and runs C++ and Python tests + make test # run Python tests + make cpp-test # run C++ tests +The Makefiles provided have self-documenting targets. To find out which targets +are available, type: + +.. code-block:: bash + + make help See Also -------- -For other fast non-cryptographic hashing implementations available as Python extensions, see `CityHash `__ and `xxh `__. +For other fast non-cryptographic hashing implementations available as Python +extensions, see `CityHash `__ and +`xxh `__. Authors ------- -The original MetroHash algorithm was designed by J. Andrew Rogers. The Python bindings in this package were written by Eugene Scherba. +The original MetroHash algorithm was designed by J. Andrew Rogers. The Python +bindings in this package were written by Eugene Scherba. License ------- This software is licensed under the `MIT License -`_. -See the included LICENSE file for more information. +`_. See the included LICENSE +file for more information. From f44727818a7218a25bc319215a4ff461f1ca7f4b Mon Sep 17 00:00:00 2001 From: Eugene Scherba Date: Tue, 28 Dec 2021 13:33:11 -0800 Subject: [PATCH 5/7] properly source requirements.txt during env set up --- Makefile | 7 +++++++ pip-freeze.txt | 16 ++++++++++++++-- python.mk | 12 ++++++------ requirements.txt | 3 --- setup.py | 1 + 5 files changed, 28 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index a111311..a9685f1 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,10 @@ +SHELL := /usr/bin/env bash -c + +MAKEFLAGS += --warn-undefined-variables +MAKEFLAGS += --no-builtin-rules +.DEFAULT_GOAL := help +.SUFFIXES: + include python.mk include cpp.mk diff --git a/pip-freeze.txt b/pip-freeze.txt index 85aad11..ab1541d 100644 --- a/pip-freeze.txt +++ b/pip-freeze.txt @@ -1,3 +1,15 @@ +attrs==21.3.0 Cython==0.29.26 -markerlib==0.6.0 --e git+https://github.com/escherba/python-metrohash@3c66ddae69762d7b7872f67ba9ca11d06371a433#egg=metrohash +distlib==0.3.4 +filelock==3.4.2 +iniconfig==1.1.1 +-e git+https://github.com/escherba/python-metrohash@dc510c29023965895fa61ec19e3c40c6292fc514#egg=metrohash +packaging==21.3 +platformdirs==2.4.1 +pluggy==1.0.0 +py==1.11.0 +pyparsing==3.0.6 +pytest==6.2.5 +six==1.16.0 +toml==0.10.2 +virtualenv==20.11.0 diff --git a/python.mk b/python.mk index 996fd0d..c2d16dd 100644 --- a/python.mk +++ b/python.mk @@ -37,9 +37,9 @@ release: env build_ext ## upload package to PyPI $(PYTHON) setup.py $(DISTRIBUTE) upload -r $(PYPI_URL) .PHONY: shell -shell: build_ext ## open IPython shell within the virtualenv +shell: build_ext ## open Python shell within the virtualenv @echo "Using $(PYVERSION)" - $(PYENV) $(ENV_EXTRA) ipython + $(PYENV) $(ENV_EXTRA) python .PHONY: build_ext build_ext: $(EXTENSION) ## build C extension(s) @@ -75,14 +75,14 @@ install: build_ext ## install package -pip uninstall --yes $(PYMODULE) pip install -e . +.PRECIOUS: env/bin/activate .PHONY: env env: env/bin/activate ## set up a virtual environment -env/bin/activate: setup.py +env/bin/activate: setup.py requirements.txt test -f $@ || virtualenv $(VENV_OPTS) env export SETUPTOOLS_USE_DISTUTILS=stdlib; $(PYENV) curl https://bootstrap.pypa.io/ez_setup.py | $(INTERPRETER) $(PIP) install -U pip - $(PIP) install -U markerlib - $(PIP) install -U wheel - $(PIP) install -U cython + export SETUPTOOLS_USE_DISTUTILS=stdlib; $(PIP) install -r requirements.txt $(PIP) install -e . $(PIP) freeze > pip-freeze.txt + touch $@ diff --git a/requirements.txt b/requirements.txt index 5a03a86..bd3b0ec 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,4 @@ cython -distribute -ipdb -ipython pytest setuptools virtualenv diff --git a/setup.py b/setup.py index 3f7227e..0934c56 100644 --- a/setup.py +++ b/setup.py @@ -132,5 +132,6 @@ def get_long_description(): 'Topic :: Utilities' ], long_description=get_long_description(), + tests_require=['pytest'], distclass=BinaryDistribution, ) From 33f42830b2598eab7a06844f58e5ddbad0cf0343 Mon Sep 17 00:00:00 2001 From: Eugene Scherba Date: Tue, 28 Dec 2021 17:49:11 -0800 Subject: [PATCH 6/7] lint cython code --- pip-freeze.txt | 2 +- python.mk | 4 +- setup.cfg | 2 +- src/metrohash.cpp | 661 ++++++++++++++++++++++++---------------- src/metrohash.pyx | 30 +- tests/test_metrohash.py | 11 + 6 files changed, 432 insertions(+), 278 deletions(-) diff --git a/pip-freeze.txt b/pip-freeze.txt index ab1541d..6ecb9ca 100644 --- a/pip-freeze.txt +++ b/pip-freeze.txt @@ -3,7 +3,7 @@ Cython==0.29.26 distlib==0.3.4 filelock==3.4.2 iniconfig==1.1.1 --e git+https://github.com/escherba/python-metrohash@dc510c29023965895fa61ec19e3c40c6292fc514#egg=metrohash +-e git+https://github.com/escherba/python-metrohash@f44727818a7218a25bc319215a4ff461f1ca7f4b#egg=metrohash packaging==21.3 platformdirs==2.4.1 pluggy==1.0.0 diff --git a/python.mk b/python.mk index c2d16dd..5cdfaa9 100644 --- a/python.mk +++ b/python.mk @@ -39,7 +39,7 @@ release: env build_ext ## upload package to PyPI .PHONY: shell shell: build_ext ## open Python shell within the virtualenv @echo "Using $(PYVERSION)" - $(PYENV) $(ENV_EXTRA) python + $(PYENV) python .PHONY: build_ext build_ext: $(EXTENSION) ## build C extension(s) @@ -82,7 +82,7 @@ env/bin/activate: setup.py requirements.txt test -f $@ || virtualenv $(VENV_OPTS) env export SETUPTOOLS_USE_DISTUTILS=stdlib; $(PYENV) curl https://bootstrap.pypa.io/ez_setup.py | $(INTERPRETER) $(PIP) install -U pip - export SETUPTOOLS_USE_DISTUTILS=stdlib; $(PIP) install -r requirements.txt + $(PIP) install -r requirements.txt $(PIP) install -e . $(PIP) freeze > pip-freeze.txt touch $@ diff --git a/setup.cfg b/setup.cfg index 43b4615..1814ac4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -4,7 +4,7 @@ package_dir = [metadata] version = attr:cityhash.__version__ -description-file = README.rst +description_file = README.rst [tool:pytest] addopts = --doctest-modules diff --git a/src/metrohash.cpp b/src/metrohash.cpp index 8bfe4d5..2971c8a 100644 --- a/src/metrohash.cpp +++ b/src/metrohash.cpp @@ -929,7 +929,7 @@ struct __pyx_opt_args_9metrohash_metrohash64 { uint64 seed; }; -/* "metrohash.pyx":108 +/* "metrohash.pyx":109 * * * cpdef metrohash128(data, uint64 seed=0ULL): # <<<<<<<<<<<<<< @@ -941,7 +941,7 @@ struct __pyx_opt_args_9metrohash_metrohash128 { uint64 seed; }; -/* "metrohash.pyx":131 +/* "metrohash.pyx":133 * * * cdef class MetroHash64(object): # <<<<<<<<<<<<<< @@ -954,7 +954,7 @@ struct __pyx_obj_9metrohash_MetroHash64 { }; -/* "metrohash.pyx":174 +/* "metrohash.pyx":177 * * * cdef class MetroHash128(object): # <<<<<<<<<<<<<< @@ -1041,9 +1041,6 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject /* GetBuiltinName.proto */ static PyObject *__Pyx_GetBuiltinName(PyObject *name); -/* PyUnicode_Unicode.proto */ -static CYTHON_INLINE PyObject* __Pyx_PyUnicode_Unicode(PyObject *obj); - /* PyObjectFormatAndDecref.proto */ static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatSimpleAndDecref(PyObject* s, PyObject* f); static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatAndDecref(PyObject* s, PyObject* f); @@ -1192,6 +1189,12 @@ enum __Pyx_ImportType_CheckSize { static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size); #endif +/* Import.proto */ +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level); + +/* ImportFrom.proto */ +static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name); + /* PyDictVersioning.proto */ #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS #define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1) @@ -1284,22 +1287,18 @@ static int __Pyx_check_binary_version(void); static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); -/* Module declarations from 'cpython.long' */ +/* Module declarations from 'cpython.version' */ -/* Module declarations from 'cpython.buffer' */ +/* Module declarations from '__builtin__' */ -/* Module declarations from 'cpython.unicode' */ +/* Module declarations from 'cpython.type' */ +static PyTypeObject *__pyx_ptype_7cpython_4type_type = 0; /* Module declarations from 'libc.string' */ /* Module declarations from 'libc.stdio' */ -/* Module declarations from '__builtin__' */ - -/* Module declarations from 'cpython.type' */ -static PyTypeObject *__pyx_ptype_7cpython_4type_type = 0; - -/* Module declarations from 'cpython.version' */ +/* Module declarations from 'cpython.object' */ /* Module declarations from 'cpython.ref' */ @@ -1328,6 +1327,8 @@ static PyTypeObject *__pyx_ptype_7cpython_4type_type = 0; /* Module declarations from 'cpython.bool' */ static PyTypeObject *__pyx_ptype_7cpython_4bool_bool = 0; +/* Module declarations from 'cpython.long' */ + /* Module declarations from 'cpython.float' */ /* Module declarations from '__builtin__' */ @@ -1337,6 +1338,8 @@ static PyTypeObject *__pyx_ptype_7cpython_7complex_complex = 0; /* Module declarations from 'cpython.string' */ +/* Module declarations from 'cpython.unicode' */ + /* Module declarations from 'cpython.dict' */ /* Module declarations from 'cpython.instance' */ @@ -1359,13 +1362,13 @@ static PyTypeObject *__pyx_ptype_7cpython_7complex_complex = 0; /* Module declarations from 'cpython.set' */ -/* Module declarations from 'cpython.pycapsule' */ +/* Module declarations from 'cpython.buffer' */ -/* Module declarations from 'cpython' */ +/* Module declarations from 'cpython.bytes' */ -/* Module declarations from 'cpython.object' */ +/* Module declarations from 'cpython.pycapsule' */ -/* Module declarations from 'cpython.bytes' */ +/* Module declarations from 'cpython' */ /* Module declarations from 'metrohash' */ static PyTypeObject *__pyx_ptype_9metrohash_MetroHash64 = 0; @@ -1383,7 +1386,6 @@ static PyObject *__pyx_builtin_MemoryError; static const char __pyx_k_[] = ")"; static const char __pyx_k_all[] = "__all__"; static const char __pyx_k_got[] = ", got "; -static const char __pyx_k_None[] = "None"; static const char __pyx_k_data[] = "data"; static const char __pyx_k_main[] = "__main__"; static const char __pyx_k_name[] = "__name__"; @@ -1393,6 +1395,8 @@ static const char __pyx_k_0_1_0[] = "0.1.0"; static const char __pyx_k_email[] = "__email__"; static const char __pyx_k_author[] = "__author__"; static const char __pyx_k_buffer[] = "buffer"; +static const char __pyx_k_cython[] = "cython"; +static const char __pyx_k_import[] = "__import__"; static const char __pyx_k_reduce[] = "__reduce__"; static const char __pyx_k_version[] = "__version__"; static const char __pyx_k_Argument[] = "Argument '"; @@ -1412,7 +1416,7 @@ static const char __pyx_k_setstate_cython[] = "__setstate_cython__"; static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; static const char __pyx_k_has_incorrect_type_expected[] = "' has incorrect type (expected "; static const char __pyx_k_escherba_metrohash_gmail_com[] = "escherba+metrohash@gmail.com"; -static const char __pyx_k_A_Python_wrapper_for_MetroHash[] = "\nA Python wrapper for MetroHash, a fast non-cryptographic hashing algorithm\n"; +static const char __pyx_k_Python_wrapper_for_MetroHash_a[] = "\nPython wrapper for MetroHash, a fast non-cryptographic hashing algorithm\n"; static const char __pyx_k_no_default___reduce___due_to_non[] = "no default __reduce__ due to non-trivial __cinit__"; static PyObject *__pyx_kp_u_; static PyObject *__pyx_kp_u_0_1_0; @@ -1423,13 +1427,14 @@ static PyObject *__pyx_n_s_MetroHash128; static PyObject *__pyx_n_u_MetroHash128; static PyObject *__pyx_n_s_MetroHash64; static PyObject *__pyx_n_u_MetroHash64; -static PyObject *__pyx_kp_u_None; static PyObject *__pyx_n_s_TypeError; static PyObject *__pyx_n_s_all; static PyObject *__pyx_n_s_author; +static PyObject *__pyx_n_s_basestring; static PyObject *__pyx_n_u_basestring; static PyObject *__pyx_n_u_buffer; static PyObject *__pyx_n_s_cline_in_traceback; +static PyObject *__pyx_n_s_cython; static PyObject *__pyx_n_s_data; static PyObject *__pyx_n_u_data; static PyObject *__pyx_n_s_email; @@ -1437,6 +1442,7 @@ static PyObject *__pyx_kp_u_escherba_metrohash_gmail_com; static PyObject *__pyx_n_s_getstate; static PyObject *__pyx_kp_u_got; static PyObject *__pyx_kp_u_has_incorrect_type_expected; +static PyObject *__pyx_n_s_import; static PyObject *__pyx_n_s_main; static PyObject *__pyx_n_u_metrohash128; static PyObject *__pyx_n_u_metrohash64; @@ -1478,7 +1484,7 @@ static PyObject *__pyx_tuple__5; /* "metrohash.pyx":79 * * - * cdef object _type_error(str argname, expected, value): # <<<<<<<<<<<<<< + * cdef object _type_error(argname: basestring, expected: object, value: object): # <<<<<<<<<<<<<< * return TypeError( * "Argument '%s' has incorrect type (expected %s, got %s)" % */ @@ -1497,7 +1503,7 @@ static PyObject *__pyx_f_9metrohash__type_error(PyObject *__pyx_v_argname, PyObj /* "metrohash.pyx":80 * - * cdef object _type_error(str argname, expected, value): + * cdef object _type_error(argname: basestring, expected: object, value: object): * return TypeError( # <<<<<<<<<<<<<< * "Argument '%s' has incorrect type (expected %s, got %s)" % * (argname, expected, type(value)) @@ -1505,7 +1511,7 @@ static PyObject *__pyx_f_9metrohash__type_error(PyObject *__pyx_v_argname, PyObj __Pyx_XDECREF(__pyx_r); /* "metrohash.pyx":81 - * cdef object _type_error(str argname, expected, value): + * cdef object _type_error(argname: basestring, expected: object, value: object): * return TypeError( * "Argument '%s' has incorrect type (expected %s, got %s)" % # <<<<<<<<<<<<<< * (argname, expected, type(value)) @@ -1527,7 +1533,7 @@ static PyObject *__pyx_f_9metrohash__type_error(PyObject *__pyx_v_argname, PyObj * ) * */ - __pyx_t_4 = __Pyx_PyUnicode_Unicode(__pyx_v_argname); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 82, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_argname), __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 82, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_3) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_3; __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4); @@ -1562,7 +1568,7 @@ static PyObject *__pyx_f_9metrohash__type_error(PyObject *__pyx_v_argname, PyObj PyTuple_SET_ITEM(__pyx_t_1, 6, __pyx_kp_u_); /* "metrohash.pyx":81 - * cdef object _type_error(str argname, expected, value): + * cdef object _type_error(argname: basestring, expected: object, value: object): * return TypeError( * "Argument '%s' has incorrect type (expected %s, got %s)" % # <<<<<<<<<<<<<< * (argname, expected, type(value)) @@ -1574,7 +1580,7 @@ static PyObject *__pyx_f_9metrohash__type_error(PyObject *__pyx_v_argname, PyObj /* "metrohash.pyx":80 * - * cdef object _type_error(str argname, expected, value): + * cdef object _type_error(argname: basestring, expected: object, value: object): * return TypeError( # <<<<<<<<<<<<<< * "Argument '%s' has incorrect type (expected %s, got %s)" % * (argname, expected, type(value)) @@ -1589,7 +1595,7 @@ static PyObject *__pyx_f_9metrohash__type_error(PyObject *__pyx_v_argname, PyObj /* "metrohash.pyx":79 * * - * cdef object _type_error(str argname, expected, value): # <<<<<<<<<<<<<< + * cdef object _type_error(argname: basestring, expected: object, value: object): # <<<<<<<<<<<<<< * return TypeError( * "Argument '%s' has incorrect type (expected %s, got %s)" % */ @@ -1637,7 +1643,7 @@ static PyObject *__pyx_f_9metrohash_metrohash64(PyObject *__pyx_v_data, CYTHON_U } /* "metrohash.pyx":92 - * cdef object obj + * cdef bytes obj * cdef uint64 result * if PyUnicode_Check(data): # <<<<<<<<<<<<<< * obj = PyUnicode_AsUTF8String(data) @@ -1655,7 +1661,7 @@ static PyObject *__pyx_f_9metrohash_metrohash64(PyObject *__pyx_v_data, CYTHON_U */ __pyx_t_2 = PyUnicode_AsUTF8String(__pyx_v_data); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 93, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_v_obj = __pyx_t_2; + __pyx_v_obj = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; /* "metrohash.pyx":94 @@ -1663,7 +1669,7 @@ static PyObject *__pyx_f_9metrohash_metrohash64(PyObject *__pyx_v_data, CYTHON_U * obj = PyUnicode_AsUTF8String(data) * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) # <<<<<<<<<<<<<< * result = c_metrohash64(buf.buf, buf.len, seed) - * Py_DECREF(obj) + * PyBuffer_Release(&buf) */ __pyx_t_3 = PyObject_GetBuffer(__pyx_v_obj, (&__pyx_v_buf), PyBUF_SIMPLE); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 94, __pyx_L1_error) @@ -1671,7 +1677,7 @@ static PyObject *__pyx_f_9metrohash_metrohash64(PyObject *__pyx_v_data, CYTHON_U * obj = PyUnicode_AsUTF8String(data) * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) * result = c_metrohash64(buf.buf, buf.len, seed) # <<<<<<<<<<<<<< - * Py_DECREF(obj) + * PyBuffer_Release(&buf) * elif PyBytes_Check(data): */ __pyx_v_result = metrohash64(((uint8 const *)__pyx_v_buf.buf), __pyx_v_buf.len, __pyx_v_seed); @@ -1679,14 +1685,14 @@ static PyObject *__pyx_f_9metrohash_metrohash64(PyObject *__pyx_v_data, CYTHON_U /* "metrohash.pyx":96 * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) * result = c_metrohash64(buf.buf, buf.len, seed) - * Py_DECREF(obj) # <<<<<<<<<<<<<< + * PyBuffer_Release(&buf) # <<<<<<<<<<<<<< * elif PyBytes_Check(data): * result = c_metrohash64(PyBytes_AS_STRING(data), */ - Py_DECREF(__pyx_v_obj); + PyBuffer_Release((&__pyx_v_buf)); /* "metrohash.pyx":92 - * cdef object obj + * cdef bytes obj * cdef uint64 result * if PyUnicode_Check(data): # <<<<<<<<<<<<<< * obj = PyUnicode_AsUTF8String(data) @@ -1697,7 +1703,7 @@ static PyObject *__pyx_f_9metrohash_metrohash64(PyObject *__pyx_v_data, CYTHON_U /* "metrohash.pyx":97 * result = c_metrohash64(buf.buf, buf.len, seed) - * Py_DECREF(obj) + * PyBuffer_Release(&buf) * elif PyBytes_Check(data): # <<<<<<<<<<<<<< * result = c_metrohash64(PyBytes_AS_STRING(data), * PyBytes_GET_SIZE(data), seed) @@ -1706,7 +1712,7 @@ static PyObject *__pyx_f_9metrohash_metrohash64(PyObject *__pyx_v_data, CYTHON_U if (__pyx_t_1) { /* "metrohash.pyx":98 - * Py_DECREF(obj) + * PyBuffer_Release(&buf) * elif PyBytes_Check(data): * result = c_metrohash64(PyBytes_AS_STRING(data), # <<<<<<<<<<<<<< * PyBytes_GET_SIZE(data), seed) @@ -1716,7 +1722,7 @@ static PyObject *__pyx_f_9metrohash_metrohash64(PyObject *__pyx_v_data, CYTHON_U /* "metrohash.pyx":97 * result = c_metrohash64(buf.buf, buf.len, seed) - * Py_DECREF(obj) + * PyBuffer_Release(&buf) * elif PyBytes_Check(data): # <<<<<<<<<<<<<< * result = c_metrohash64(PyBytes_AS_STRING(data), * PyBytes_GET_SIZE(data), seed) @@ -1739,7 +1745,7 @@ static PyObject *__pyx_f_9metrohash_metrohash64(PyObject *__pyx_v_data, CYTHON_U * elif PyObject_CheckBuffer(data): * PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) # <<<<<<<<<<<<<< * result = c_metrohash64(buf.buf, buf.len, seed) - * else: + * PyBuffer_Release(&buf) */ __pyx_t_3 = PyObject_GetBuffer(__pyx_v_data, (&__pyx_v_buf), PyBUF_SIMPLE); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 101, __pyx_L1_error) @@ -1747,11 +1753,20 @@ static PyObject *__pyx_f_9metrohash_metrohash64(PyObject *__pyx_v_data, CYTHON_U * elif PyObject_CheckBuffer(data): * PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) * result = c_metrohash64(buf.buf, buf.len, seed) # <<<<<<<<<<<<<< + * PyBuffer_Release(&buf) * else: - * raise _type_error("data", ["basestring", "buffer"], data) */ __pyx_v_result = metrohash64(((uint8 const *)__pyx_v_buf.buf), __pyx_v_buf.len, __pyx_v_seed); + /* "metrohash.pyx":103 + * PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) + * result = c_metrohash64(buf.buf, buf.len, seed) + * PyBuffer_Release(&buf) # <<<<<<<<<<<<<< + * else: + * raise _type_error("data", ["basestring", "buffer"], data) + */ + PyBuffer_Release((&__pyx_v_buf)); + /* "metrohash.pyx":100 * result = c_metrohash64(PyBytes_AS_STRING(data), * PyBytes_GET_SIZE(data), seed) @@ -1762,15 +1777,15 @@ static PyObject *__pyx_f_9metrohash_metrohash64(PyObject *__pyx_v_data, CYTHON_U goto __pyx_L3; } - /* "metrohash.pyx":104 - * result = c_metrohash64(buf.buf, buf.len, seed) + /* "metrohash.pyx":105 + * PyBuffer_Release(&buf) * else: * raise _type_error("data", ["basestring", "buffer"], data) # <<<<<<<<<<<<<< * return result * */ /*else*/ { - __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 104, __pyx_L1_error) + __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 105, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_u_basestring); __Pyx_GIVEREF(__pyx_n_u_basestring); @@ -1778,16 +1793,16 @@ static PyObject *__pyx_f_9metrohash_metrohash64(PyObject *__pyx_v_data, CYTHON_U __Pyx_INCREF(__pyx_n_u_buffer); __Pyx_GIVEREF(__pyx_n_u_buffer); PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_u_buffer); - __pyx_t_4 = __pyx_f_9metrohash__type_error(__pyx_n_u_data, __pyx_t_2, __pyx_v_data); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 104, __pyx_L1_error) + __pyx_t_4 = __pyx_f_9metrohash__type_error(__pyx_n_u_data, __pyx_t_2, __pyx_v_data); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 105, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 104, __pyx_L1_error) + __PYX_ERR(0, 105, __pyx_L1_error) } __pyx_L3:; - /* "metrohash.pyx":105 + /* "metrohash.pyx":106 * else: * raise _type_error("data", ["basestring", "buffer"], data) * return result # <<<<<<<<<<<<<< @@ -1795,7 +1810,7 @@ static PyObject *__pyx_f_9metrohash_metrohash64(PyObject *__pyx_v_data, CYTHON_U * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_PyInt_From_uint64_t(__pyx_v_result); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 105, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyInt_From_uint64_t(__pyx_v_result); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 106, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; @@ -1923,7 +1938,7 @@ static PyObject *__pyx_pf_9metrohash_metrohash64(CYTHON_UNUSED PyObject *__pyx_s return __pyx_r; } -/* "metrohash.pyx":108 +/* "metrohash.pyx":109 * * * cpdef metrohash128(data, uint64 seed=0ULL): # <<<<<<<<<<<<<< @@ -1955,8 +1970,8 @@ static PyObject *__pyx_f_9metrohash_metrohash128(PyObject *__pyx_v_data, CYTHON_ } } - /* "metrohash.pyx":114 - * cdef object obj + /* "metrohash.pyx":115 + * cdef bytes obj * cdef pair[uint64, uint64] result * if PyUnicode_Check(data): # <<<<<<<<<<<<<< * obj = PyUnicode_AsUTF8String(data) @@ -1965,47 +1980,47 @@ static PyObject *__pyx_f_9metrohash_metrohash128(PyObject *__pyx_v_data, CYTHON_ __pyx_t_1 = (PyUnicode_Check(__pyx_v_data) != 0); if (__pyx_t_1) { - /* "metrohash.pyx":115 + /* "metrohash.pyx":116 * cdef pair[uint64, uint64] result * if PyUnicode_Check(data): * obj = PyUnicode_AsUTF8String(data) # <<<<<<<<<<<<<< * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) * result = c_metrohash128(buf.buf, buf.len, seed) */ - __pyx_t_2 = PyUnicode_AsUTF8String(__pyx_v_data); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 115, __pyx_L1_error) + __pyx_t_2 = PyUnicode_AsUTF8String(__pyx_v_data); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 116, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_v_obj = __pyx_t_2; + __pyx_v_obj = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; - /* "metrohash.pyx":116 + /* "metrohash.pyx":117 * if PyUnicode_Check(data): * obj = PyUnicode_AsUTF8String(data) * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) # <<<<<<<<<<<<<< * result = c_metrohash128(buf.buf, buf.len, seed) - * Py_DECREF(obj) + * PyBuffer_Release(&buf) */ - __pyx_t_3 = PyObject_GetBuffer(__pyx_v_obj, (&__pyx_v_buf), PyBUF_SIMPLE); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 116, __pyx_L1_error) + __pyx_t_3 = PyObject_GetBuffer(__pyx_v_obj, (&__pyx_v_buf), PyBUF_SIMPLE); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 117, __pyx_L1_error) - /* "metrohash.pyx":117 + /* "metrohash.pyx":118 * obj = PyUnicode_AsUTF8String(data) * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) * result = c_metrohash128(buf.buf, buf.len, seed) # <<<<<<<<<<<<<< - * Py_DECREF(obj) + * PyBuffer_Release(&buf) * elif PyBytes_Check(data): */ __pyx_v_result = metrohash128(((uint8 const *)__pyx_v_buf.buf), __pyx_v_buf.len, __pyx_v_seed); - /* "metrohash.pyx":118 + /* "metrohash.pyx":119 * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) * result = c_metrohash128(buf.buf, buf.len, seed) - * Py_DECREF(obj) # <<<<<<<<<<<<<< + * PyBuffer_Release(&buf) # <<<<<<<<<<<<<< * elif PyBytes_Check(data): * result = c_metrohash128(PyBytes_AS_STRING(data), */ - Py_DECREF(__pyx_v_obj); + PyBuffer_Release((&__pyx_v_buf)); - /* "metrohash.pyx":114 - * cdef object obj + /* "metrohash.pyx":115 + * cdef bytes obj * cdef pair[uint64, uint64] result * if PyUnicode_Check(data): # <<<<<<<<<<<<<< * obj = PyUnicode_AsUTF8String(data) @@ -2014,9 +2029,9 @@ static PyObject *__pyx_f_9metrohash_metrohash128(PyObject *__pyx_v_data, CYTHON_ goto __pyx_L3; } - /* "metrohash.pyx":119 + /* "metrohash.pyx":120 * result = c_metrohash128(buf.buf, buf.len, seed) - * Py_DECREF(obj) + * PyBuffer_Release(&buf) * elif PyBytes_Check(data): # <<<<<<<<<<<<<< * result = c_metrohash128(PyBytes_AS_STRING(data), * PyBytes_GET_SIZE(data), seed) @@ -2024,8 +2039,8 @@ static PyObject *__pyx_f_9metrohash_metrohash128(PyObject *__pyx_v_data, CYTHON_ __pyx_t_1 = (PyBytes_Check(__pyx_v_data) != 0); if (__pyx_t_1) { - /* "metrohash.pyx":120 - * Py_DECREF(obj) + /* "metrohash.pyx":121 + * PyBuffer_Release(&buf) * elif PyBytes_Check(data): * result = c_metrohash128(PyBytes_AS_STRING(data), # <<<<<<<<<<<<<< * PyBytes_GET_SIZE(data), seed) @@ -2033,9 +2048,9 @@ static PyObject *__pyx_f_9metrohash_metrohash128(PyObject *__pyx_v_data, CYTHON_ */ __pyx_v_result = metrohash128(((uint8 const *)PyBytes_AS_STRING(__pyx_v_data)), PyBytes_GET_SIZE(__pyx_v_data), __pyx_v_seed); - /* "metrohash.pyx":119 + /* "metrohash.pyx":120 * result = c_metrohash128(buf.buf, buf.len, seed) - * Py_DECREF(obj) + * PyBuffer_Release(&buf) * elif PyBytes_Check(data): # <<<<<<<<<<<<<< * result = c_metrohash128(PyBytes_AS_STRING(data), * PyBytes_GET_SIZE(data), seed) @@ -2043,7 +2058,7 @@ static PyObject *__pyx_f_9metrohash_metrohash128(PyObject *__pyx_v_data, CYTHON_ goto __pyx_L3; } - /* "metrohash.pyx":122 + /* "metrohash.pyx":123 * result = c_metrohash128(PyBytes_AS_STRING(data), * PyBytes_GET_SIZE(data), seed) * elif PyObject_CheckBuffer(data): # <<<<<<<<<<<<<< @@ -2053,25 +2068,34 @@ static PyObject *__pyx_f_9metrohash_metrohash128(PyObject *__pyx_v_data, CYTHON_ __pyx_t_1 = (PyObject_CheckBuffer(__pyx_v_data) != 0); if (likely(__pyx_t_1)) { - /* "metrohash.pyx":123 + /* "metrohash.pyx":124 * PyBytes_GET_SIZE(data), seed) * elif PyObject_CheckBuffer(data): * PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) # <<<<<<<<<<<<<< * result = c_metrohash128(buf.buf, buf.len, seed) - * else: + * PyBuffer_Release(&buf) */ - __pyx_t_3 = PyObject_GetBuffer(__pyx_v_data, (&__pyx_v_buf), PyBUF_SIMPLE); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 123, __pyx_L1_error) + __pyx_t_3 = PyObject_GetBuffer(__pyx_v_data, (&__pyx_v_buf), PyBUF_SIMPLE); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 124, __pyx_L1_error) - /* "metrohash.pyx":124 + /* "metrohash.pyx":125 * elif PyObject_CheckBuffer(data): * PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) * result = c_metrohash128(buf.buf, buf.len, seed) # <<<<<<<<<<<<<< + * PyBuffer_Release(&buf) * else: - * raise _type_error("data", ["basestring", "buffer"], data) */ __pyx_v_result = metrohash128(((uint8 const *)__pyx_v_buf.buf), __pyx_v_buf.len, __pyx_v_seed); - /* "metrohash.pyx":122 + /* "metrohash.pyx":126 + * PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) + * result = c_metrohash128(buf.buf, buf.len, seed) + * PyBuffer_Release(&buf) # <<<<<<<<<<<<<< + * else: + * raise _type_error("data", ["basestring", "buffer"], data) + */ + PyBuffer_Release((&__pyx_v_buf)); + + /* "metrohash.pyx":123 * result = c_metrohash128(PyBytes_AS_STRING(data), * PyBytes_GET_SIZE(data), seed) * elif PyObject_CheckBuffer(data): # <<<<<<<<<<<<<< @@ -2081,15 +2105,15 @@ static PyObject *__pyx_f_9metrohash_metrohash128(PyObject *__pyx_v_data, CYTHON_ goto __pyx_L3; } - /* "metrohash.pyx":126 - * result = c_metrohash128(buf.buf, buf.len, seed) + /* "metrohash.pyx":128 + * PyBuffer_Release(&buf) * else: * raise _type_error("data", ["basestring", "buffer"], data) # <<<<<<<<<<<<<< * final = 0x10000000000000000L * long(result.first) + long(result.second) * return final */ /*else*/ { - __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 126, __pyx_L1_error) + __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 128, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_u_basestring); __Pyx_GIVEREF(__pyx_n_u_basestring); @@ -2097,44 +2121,44 @@ static PyObject *__pyx_f_9metrohash_metrohash128(PyObject *__pyx_v_data, CYTHON_ __Pyx_INCREF(__pyx_n_u_buffer); __Pyx_GIVEREF(__pyx_n_u_buffer); PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_u_buffer); - __pyx_t_4 = __pyx_f_9metrohash__type_error(__pyx_n_u_data, __pyx_t_2, __pyx_v_data); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 126, __pyx_L1_error) + __pyx_t_4 = __pyx_f_9metrohash__type_error(__pyx_n_u_data, __pyx_t_2, __pyx_v_data); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 128, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 126, __pyx_L1_error) + __PYX_ERR(0, 128, __pyx_L1_error) } __pyx_L3:; - /* "metrohash.pyx":127 + /* "metrohash.pyx":129 * else: * raise _type_error("data", ["basestring", "buffer"], data) * final = 0x10000000000000000L * long(result.first) + long(result.second) # <<<<<<<<<<<<<< * return final * */ - __pyx_t_4 = __Pyx_PyInt_From_uint64_t(__pyx_v_result.first); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 127, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyInt_From_uint64_t(__pyx_v_result.first); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 129, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyLong_Type)), __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 127, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyLong_Type)), __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 129, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyNumber_Multiply(__pyx_int_18446744073709551616L, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 127, __pyx_L1_error) + __pyx_t_4 = PyNumber_Multiply(__pyx_int_18446744073709551616L, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 129, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyInt_From_uint64_t(__pyx_v_result.second); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 127, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_uint64_t(__pyx_v_result.second); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 129, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyLong_Type)), __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 127, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyLong_Type)), __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 129, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyNumber_Add(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 127, __pyx_L1_error) + __pyx_t_2 = PyNumber_Add(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 129, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - if (!(likely(PyLong_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "long", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 127, __pyx_L1_error) + if (!(likely(PyLong_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "long", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 129, __pyx_L1_error) __pyx_v_final = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; - /* "metrohash.pyx":128 + /* "metrohash.pyx":130 * raise _type_error("data", ["basestring", "buffer"], data) * final = 0x10000000000000000L * long(result.first) + long(result.second) * return final # <<<<<<<<<<<<<< @@ -2146,7 +2170,7 @@ static PyObject *__pyx_f_9metrohash_metrohash128(PyObject *__pyx_v_data, CYTHON_ __pyx_r = __pyx_v_final; goto __pyx_L0; - /* "metrohash.pyx":108 + /* "metrohash.pyx":109 * * * cpdef metrohash128(data, uint64 seed=0ULL): # <<<<<<<<<<<<<< @@ -2208,7 +2232,7 @@ static PyObject *__pyx_pw_9metrohash_3metrohash128(PyObject *__pyx_self, PyObjec } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "metrohash128") < 0)) __PYX_ERR(0, 108, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "metrohash128") < 0)) __PYX_ERR(0, 109, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -2221,14 +2245,14 @@ static PyObject *__pyx_pw_9metrohash_3metrohash128(PyObject *__pyx_self, PyObjec } __pyx_v_data = values[0]; if (values[1]) { - __pyx_v_seed = __Pyx_PyInt_As_uint64_t(values[1]); if (unlikely((__pyx_v_seed == ((uint64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 108, __pyx_L3_error) + __pyx_v_seed = __Pyx_PyInt_As_uint64_t(values[1]); if (unlikely((__pyx_v_seed == ((uint64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 109, __pyx_L3_error) } else { __pyx_v_seed = ((uint64)0ULL); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("metrohash128", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 108, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("metrohash128", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 109, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("metrohash.metrohash128", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -2253,7 +2277,7 @@ static PyObject *__pyx_pf_9metrohash_2metrohash128(CYTHON_UNUSED PyObject *__pyx __Pyx_XDECREF(__pyx_r); __pyx_t_2.__pyx_n = 1; __pyx_t_2.seed = __pyx_v_seed; - __pyx_t_1 = __pyx_f_9metrohash_metrohash128(__pyx_v_data, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 108, __pyx_L1_error) + __pyx_t_1 = __pyx_f_9metrohash_metrohash128(__pyx_v_data, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 109, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -2270,7 +2294,7 @@ static PyObject *__pyx_pf_9metrohash_2metrohash128(CYTHON_UNUSED PyObject *__pyx return __pyx_r; } -/* "metrohash.pyx":138 +/* "metrohash.pyx":140 * cdef CCMetroHash64* _m * * def __cinit__(self, uint64 seed=0ULL): # <<<<<<<<<<<<<< @@ -2309,7 +2333,7 @@ static int __pyx_pw_9metrohash_11MetroHash64_1__cinit__(PyObject *__pyx_v_self, } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(0, 138, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(0, 140, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -2320,14 +2344,14 @@ static int __pyx_pw_9metrohash_11MetroHash64_1__cinit__(PyObject *__pyx_v_self, } } if (values[0]) { - __pyx_v_seed = __Pyx_PyInt_As_uint64_t(values[0]); if (unlikely((__pyx_v_seed == ((uint64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 138, __pyx_L3_error) + __pyx_v_seed = __Pyx_PyInt_As_uint64_t(values[0]); if (unlikely((__pyx_v_seed == ((uint64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 140, __pyx_L3_error) } else { __pyx_v_seed = ((uint64)0ULL); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 138, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 140, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("metrohash.MetroHash64.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -2349,7 +2373,7 @@ static int __pyx_pf_9metrohash_11MetroHash64___cinit__(struct __pyx_obj_9metroha int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__cinit__", 0); - /* "metrohash.pyx":139 + /* "metrohash.pyx":141 * * def __cinit__(self, uint64 seed=0ULL): * self._m = new CCMetroHash64(seed) # <<<<<<<<<<<<<< @@ -2358,7 +2382,7 @@ static int __pyx_pf_9metrohash_11MetroHash64___cinit__(struct __pyx_obj_9metroha */ __pyx_v_self->_m = new MetroHash64(__pyx_v_seed); - /* "metrohash.pyx":140 + /* "metrohash.pyx":142 * def __cinit__(self, uint64 seed=0ULL): * self._m = new CCMetroHash64(seed) * if self._m is NULL: # <<<<<<<<<<<<<< @@ -2368,16 +2392,16 @@ static int __pyx_pf_9metrohash_11MetroHash64___cinit__(struct __pyx_obj_9metroha __pyx_t_1 = ((__pyx_v_self->_m == NULL) != 0); if (unlikely(__pyx_t_1)) { - /* "metrohash.pyx":141 + /* "metrohash.pyx":143 * self._m = new CCMetroHash64(seed) * if self._m is NULL: * raise MemoryError() # <<<<<<<<<<<<<< * * def __dealloc__(self): */ - PyErr_NoMemory(); __PYX_ERR(0, 141, __pyx_L1_error) + PyErr_NoMemory(); __PYX_ERR(0, 143, __pyx_L1_error) - /* "metrohash.pyx":140 + /* "metrohash.pyx":142 * def __cinit__(self, uint64 seed=0ULL): * self._m = new CCMetroHash64(seed) * if self._m is NULL: # <<<<<<<<<<<<<< @@ -2386,7 +2410,7 @@ static int __pyx_pf_9metrohash_11MetroHash64___cinit__(struct __pyx_obj_9metroha */ } - /* "metrohash.pyx":138 + /* "metrohash.pyx":140 * cdef CCMetroHash64* _m * * def __cinit__(self, uint64 seed=0ULL): # <<<<<<<<<<<<<< @@ -2405,7 +2429,7 @@ static int __pyx_pf_9metrohash_11MetroHash64___cinit__(struct __pyx_obj_9metroha return __pyx_r; } -/* "metrohash.pyx":143 +/* "metrohash.pyx":145 * raise MemoryError() * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -2429,7 +2453,7 @@ static void __pyx_pf_9metrohash_11MetroHash64_2__dealloc__(struct __pyx_obj_9met int __pyx_t_1; __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "metrohash.pyx":144 + /* "metrohash.pyx":146 * * def __dealloc__(self): * if not self._m is NULL: # <<<<<<<<<<<<<< @@ -2439,7 +2463,7 @@ static void __pyx_pf_9metrohash_11MetroHash64_2__dealloc__(struct __pyx_obj_9met __pyx_t_1 = ((__pyx_v_self->_m != NULL) != 0); if (__pyx_t_1) { - /* "metrohash.pyx":145 + /* "metrohash.pyx":147 * def __dealloc__(self): * if not self._m is NULL: * del self._m # <<<<<<<<<<<<<< @@ -2448,7 +2472,7 @@ static void __pyx_pf_9metrohash_11MetroHash64_2__dealloc__(struct __pyx_obj_9met */ delete __pyx_v_self->_m; - /* "metrohash.pyx":146 + /* "metrohash.pyx":148 * if not self._m is NULL: * del self._m * self._m = NULL # <<<<<<<<<<<<<< @@ -2457,7 +2481,7 @@ static void __pyx_pf_9metrohash_11MetroHash64_2__dealloc__(struct __pyx_obj_9met */ __pyx_v_self->_m = NULL; - /* "metrohash.pyx":144 + /* "metrohash.pyx":146 * * def __dealloc__(self): * if not self._m is NULL: # <<<<<<<<<<<<<< @@ -2466,7 +2490,7 @@ static void __pyx_pf_9metrohash_11MetroHash64_2__dealloc__(struct __pyx_obj_9met */ } - /* "metrohash.pyx":143 + /* "metrohash.pyx":145 * raise MemoryError() * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -2478,7 +2502,7 @@ static void __pyx_pf_9metrohash_11MetroHash64_2__dealloc__(struct __pyx_obj_9met __Pyx_RefNannyFinishContext(); } -/* "metrohash.pyx":148 +/* "metrohash.pyx":150 * self._m = NULL * * def initialize(self, uint64 seed=0ULL): # <<<<<<<<<<<<<< @@ -2517,7 +2541,7 @@ static PyObject *__pyx_pw_9metrohash_11MetroHash64_5initialize(PyObject *__pyx_v } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "initialize") < 0)) __PYX_ERR(0, 148, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "initialize") < 0)) __PYX_ERR(0, 150, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -2528,14 +2552,14 @@ static PyObject *__pyx_pw_9metrohash_11MetroHash64_5initialize(PyObject *__pyx_v } } if (values[0]) { - __pyx_v_seed = __Pyx_PyInt_As_uint64_t(values[0]); if (unlikely((__pyx_v_seed == ((uint64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 148, __pyx_L3_error) + __pyx_v_seed = __Pyx_PyInt_As_uint64_t(values[0]); if (unlikely((__pyx_v_seed == ((uint64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 150, __pyx_L3_error) } else { __pyx_v_seed = ((uint64)0ULL); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("initialize", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 148, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("initialize", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 150, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("metrohash.MetroHash64.initialize", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -2553,7 +2577,7 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_4initialize(struct __pyx_obj_ __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("initialize", 0); - /* "metrohash.pyx":149 + /* "metrohash.pyx":151 * * def initialize(self, uint64 seed=0ULL): * self._m.Initialize(seed) # <<<<<<<<<<<<<< @@ -2562,7 +2586,7 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_4initialize(struct __pyx_obj_ */ __pyx_v_self->_m->Initialize(__pyx_v_seed); - /* "metrohash.pyx":148 + /* "metrohash.pyx":150 * self._m = NULL * * def initialize(self, uint64 seed=0ULL): # <<<<<<<<<<<<<< @@ -2577,12 +2601,12 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_4initialize(struct __pyx_obj_ return __pyx_r; } -/* "metrohash.pyx":151 +/* "metrohash.pyx":153 * self._m.Initialize(seed) * * def update(self, data): # <<<<<<<<<<<<<< * cdef Py_buffer buf - * cdef object obj + * cdef bytes obj */ /* Python wrapper */ @@ -2612,9 +2636,9 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_6update(struct __pyx_obj_9met int __pyx_clineno = 0; __Pyx_RefNannySetupContext("update", 0); - /* "metrohash.pyx":154 + /* "metrohash.pyx":156 * cdef Py_buffer buf - * cdef object obj + * cdef bytes obj * if PyUnicode_Check(data): # <<<<<<<<<<<<<< * obj = PyUnicode_AsUTF8String(data) * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) @@ -2622,48 +2646,48 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_6update(struct __pyx_obj_9met __pyx_t_1 = (PyUnicode_Check(__pyx_v_data) != 0); if (__pyx_t_1) { - /* "metrohash.pyx":155 - * cdef object obj + /* "metrohash.pyx":157 + * cdef bytes obj * if PyUnicode_Check(data): * obj = PyUnicode_AsUTF8String(data) # <<<<<<<<<<<<<< * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) - * Py_DECREF(obj) + * self._m.Update(buf.buf, buf.len) */ - __pyx_t_2 = PyUnicode_AsUTF8String(__pyx_v_data); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 155, __pyx_L1_error) + __pyx_t_2 = PyUnicode_AsUTF8String(__pyx_v_data); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 157, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_v_obj = __pyx_t_2; + __pyx_v_obj = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; - /* "metrohash.pyx":156 + /* "metrohash.pyx":158 * if PyUnicode_Check(data): * obj = PyUnicode_AsUTF8String(data) * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) # <<<<<<<<<<<<<< - * Py_DECREF(obj) * self._m.Update(buf.buf, buf.len) + * PyBuffer_Release(&buf) */ - __pyx_t_3 = PyObject_GetBuffer(__pyx_v_obj, (&__pyx_v_buf), PyBUF_SIMPLE); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 156, __pyx_L1_error) + __pyx_t_3 = PyObject_GetBuffer(__pyx_v_obj, (&__pyx_v_buf), PyBUF_SIMPLE); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 158, __pyx_L1_error) - /* "metrohash.pyx":157 + /* "metrohash.pyx":159 * obj = PyUnicode_AsUTF8String(data) * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) - * Py_DECREF(obj) # <<<<<<<<<<<<<< - * self._m.Update(buf.buf, buf.len) + * self._m.Update(buf.buf, buf.len) # <<<<<<<<<<<<<< + * PyBuffer_Release(&buf) * elif PyBytes_Check(data): */ - Py_DECREF(__pyx_v_obj); + __pyx_v_self->_m->Update(((uint8 const *)__pyx_v_buf.buf), __pyx_v_buf.len); - /* "metrohash.pyx":158 + /* "metrohash.pyx":160 * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) - * Py_DECREF(obj) - * self._m.Update(buf.buf, buf.len) # <<<<<<<<<<<<<< + * self._m.Update(buf.buf, buf.len) + * PyBuffer_Release(&buf) # <<<<<<<<<<<<<< * elif PyBytes_Check(data): * self._m.Update(PyBytes_AS_STRING(data), */ - __pyx_v_self->_m->Update(((uint8 const *)__pyx_v_buf.buf), __pyx_v_buf.len); + PyBuffer_Release((&__pyx_v_buf)); - /* "metrohash.pyx":154 + /* "metrohash.pyx":156 * cdef Py_buffer buf - * cdef object obj + * cdef bytes obj * if PyUnicode_Check(data): # <<<<<<<<<<<<<< * obj = PyUnicode_AsUTF8String(data) * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) @@ -2671,9 +2695,9 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_6update(struct __pyx_obj_9met goto __pyx_L3; } - /* "metrohash.pyx":159 - * Py_DECREF(obj) + /* "metrohash.pyx":161 * self._m.Update(buf.buf, buf.len) + * PyBuffer_Release(&buf) * elif PyBytes_Check(data): # <<<<<<<<<<<<<< * self._m.Update(PyBytes_AS_STRING(data), * PyBytes_GET_SIZE(data)) @@ -2681,8 +2705,8 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_6update(struct __pyx_obj_9met __pyx_t_1 = (PyBytes_Check(__pyx_v_data) != 0); if (__pyx_t_1) { - /* "metrohash.pyx":160 - * self._m.Update(buf.buf, buf.len) + /* "metrohash.pyx":162 + * PyBuffer_Release(&buf) * elif PyBytes_Check(data): * self._m.Update(PyBytes_AS_STRING(data), # <<<<<<<<<<<<<< * PyBytes_GET_SIZE(data)) @@ -2690,9 +2714,9 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_6update(struct __pyx_obj_9met */ __pyx_v_self->_m->Update(((uint8 const *)PyBytes_AS_STRING(__pyx_v_data)), PyBytes_GET_SIZE(__pyx_v_data)); - /* "metrohash.pyx":159 - * Py_DECREF(obj) + /* "metrohash.pyx":161 * self._m.Update(buf.buf, buf.len) + * PyBuffer_Release(&buf) * elif PyBytes_Check(data): # <<<<<<<<<<<<<< * self._m.Update(PyBytes_AS_STRING(data), * PyBytes_GET_SIZE(data)) @@ -2700,7 +2724,7 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_6update(struct __pyx_obj_9met goto __pyx_L3; } - /* "metrohash.pyx":162 + /* "metrohash.pyx":164 * self._m.Update(PyBytes_AS_STRING(data), * PyBytes_GET_SIZE(data)) * elif PyObject_CheckBuffer(data): # <<<<<<<<<<<<<< @@ -2710,25 +2734,34 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_6update(struct __pyx_obj_9met __pyx_t_1 = (PyObject_CheckBuffer(__pyx_v_data) != 0); if (likely(__pyx_t_1)) { - /* "metrohash.pyx":163 + /* "metrohash.pyx":165 * PyBytes_GET_SIZE(data)) * elif PyObject_CheckBuffer(data): * PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) # <<<<<<<<<<<<<< * self._m.Update(buf.buf, buf.len) - * else: + * PyBuffer_Release(&buf) */ - __pyx_t_3 = PyObject_GetBuffer(__pyx_v_data, (&__pyx_v_buf), PyBUF_SIMPLE); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 163, __pyx_L1_error) + __pyx_t_3 = PyObject_GetBuffer(__pyx_v_data, (&__pyx_v_buf), PyBUF_SIMPLE); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 165, __pyx_L1_error) - /* "metrohash.pyx":164 + /* "metrohash.pyx":166 * elif PyObject_CheckBuffer(data): * PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) * self._m.Update(buf.buf, buf.len) # <<<<<<<<<<<<<< + * PyBuffer_Release(&buf) * else: - * raise _type_error("data", ["basestring", "buffer"], data) */ __pyx_v_self->_m->Update(((uint8 const *)__pyx_v_buf.buf), __pyx_v_buf.len); - /* "metrohash.pyx":162 + /* "metrohash.pyx":167 + * PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) + * self._m.Update(buf.buf, buf.len) + * PyBuffer_Release(&buf) # <<<<<<<<<<<<<< + * else: + * raise _type_error("data", ["basestring", "buffer"], data) + */ + PyBuffer_Release((&__pyx_v_buf)); + + /* "metrohash.pyx":164 * self._m.Update(PyBytes_AS_STRING(data), * PyBytes_GET_SIZE(data)) * elif PyObject_CheckBuffer(data): # <<<<<<<<<<<<<< @@ -2738,15 +2771,15 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_6update(struct __pyx_obj_9met goto __pyx_L3; } - /* "metrohash.pyx":166 - * self._m.Update(buf.buf, buf.len) + /* "metrohash.pyx":169 + * PyBuffer_Release(&buf) * else: * raise _type_error("data", ["basestring", "buffer"], data) # <<<<<<<<<<<<<< * * def intdigest(self): */ /*else*/ { - __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 166, __pyx_L1_error) + __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 169, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_u_basestring); __Pyx_GIVEREF(__pyx_n_u_basestring); @@ -2754,21 +2787,21 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_6update(struct __pyx_obj_9met __Pyx_INCREF(__pyx_n_u_buffer); __Pyx_GIVEREF(__pyx_n_u_buffer); PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_u_buffer); - __pyx_t_4 = __pyx_f_9metrohash__type_error(__pyx_n_u_data, __pyx_t_2, __pyx_v_data); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 166, __pyx_L1_error) + __pyx_t_4 = __pyx_f_9metrohash__type_error(__pyx_n_u_data, __pyx_t_2, __pyx_v_data); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 169, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 166, __pyx_L1_error) + __PYX_ERR(0, 169, __pyx_L1_error) } __pyx_L3:; - /* "metrohash.pyx":151 + /* "metrohash.pyx":153 * self._m.Initialize(seed) * * def update(self, data): # <<<<<<<<<<<<<< * cdef Py_buffer buf - * cdef object obj + * cdef bytes obj */ /* function exit code */ @@ -2786,7 +2819,7 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_6update(struct __pyx_obj_9met return __pyx_r; } -/* "metrohash.pyx":168 +/* "metrohash.pyx":171 * raise _type_error("data", ["basestring", "buffer"], data) * * def intdigest(self): # <<<<<<<<<<<<<< @@ -2817,7 +2850,7 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_8intdigest(struct __pyx_obj_9 int __pyx_clineno = 0; __Pyx_RefNannySetupContext("intdigest", 0); - /* "metrohash.pyx":170 + /* "metrohash.pyx":173 * def intdigest(self): * cdef uint8 buf[8] * self._m.Finalize(buf) # <<<<<<<<<<<<<< @@ -2826,7 +2859,7 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_8intdigest(struct __pyx_obj_9 */ __pyx_v_self->_m->Finalize(__pyx_v_buf); - /* "metrohash.pyx":171 + /* "metrohash.pyx":174 * cdef uint8 buf[8] * self._m.Finalize(buf) * return c_bytes2int64(buf) # <<<<<<<<<<<<<< @@ -2834,13 +2867,13 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_8intdigest(struct __pyx_obj_9 * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_uint64_t(bytes2int64(__pyx_v_buf)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 171, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_uint64_t(bytes2int64(__pyx_v_buf)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 174, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "metrohash.pyx":168 + /* "metrohash.pyx":171 * raise _type_error("data", ["basestring", "buffer"], data) * * def intdigest(self): # <<<<<<<<<<<<<< @@ -2972,7 +3005,7 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_12__setstate_cython__(CYTHON_ return __pyx_r; } -/* "metrohash.pyx":181 +/* "metrohash.pyx":184 * cdef CCMetroHash128* _m * * def __cinit__(self, uint64 seed=0ULL): # <<<<<<<<<<<<<< @@ -3011,7 +3044,7 @@ static int __pyx_pw_9metrohash_12MetroHash128_1__cinit__(PyObject *__pyx_v_self, } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(0, 181, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(0, 184, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -3022,14 +3055,14 @@ static int __pyx_pw_9metrohash_12MetroHash128_1__cinit__(PyObject *__pyx_v_self, } } if (values[0]) { - __pyx_v_seed = __Pyx_PyInt_As_uint64_t(values[0]); if (unlikely((__pyx_v_seed == ((uint64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 181, __pyx_L3_error) + __pyx_v_seed = __Pyx_PyInt_As_uint64_t(values[0]); if (unlikely((__pyx_v_seed == ((uint64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 184, __pyx_L3_error) } else { __pyx_v_seed = ((uint64)0ULL); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 181, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 184, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("metrohash.MetroHash128.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -3051,7 +3084,7 @@ static int __pyx_pf_9metrohash_12MetroHash128___cinit__(struct __pyx_obj_9metroh int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__cinit__", 0); - /* "metrohash.pyx":182 + /* "metrohash.pyx":185 * * def __cinit__(self, uint64 seed=0ULL): * self._m = new CCMetroHash128(seed) # <<<<<<<<<<<<<< @@ -3060,7 +3093,7 @@ static int __pyx_pf_9metrohash_12MetroHash128___cinit__(struct __pyx_obj_9metroh */ __pyx_v_self->_m = new MetroHash128(__pyx_v_seed); - /* "metrohash.pyx":183 + /* "metrohash.pyx":186 * def __cinit__(self, uint64 seed=0ULL): * self._m = new CCMetroHash128(seed) * if self._m is NULL: # <<<<<<<<<<<<<< @@ -3070,16 +3103,16 @@ static int __pyx_pf_9metrohash_12MetroHash128___cinit__(struct __pyx_obj_9metroh __pyx_t_1 = ((__pyx_v_self->_m == NULL) != 0); if (unlikely(__pyx_t_1)) { - /* "metrohash.pyx":184 + /* "metrohash.pyx":187 * self._m = new CCMetroHash128(seed) * if self._m is NULL: * raise MemoryError() # <<<<<<<<<<<<<< * * def __dealloc__(self): */ - PyErr_NoMemory(); __PYX_ERR(0, 184, __pyx_L1_error) + PyErr_NoMemory(); __PYX_ERR(0, 187, __pyx_L1_error) - /* "metrohash.pyx":183 + /* "metrohash.pyx":186 * def __cinit__(self, uint64 seed=0ULL): * self._m = new CCMetroHash128(seed) * if self._m is NULL: # <<<<<<<<<<<<<< @@ -3088,7 +3121,7 @@ static int __pyx_pf_9metrohash_12MetroHash128___cinit__(struct __pyx_obj_9metroh */ } - /* "metrohash.pyx":181 + /* "metrohash.pyx":184 * cdef CCMetroHash128* _m * * def __cinit__(self, uint64 seed=0ULL): # <<<<<<<<<<<<<< @@ -3107,7 +3140,7 @@ static int __pyx_pf_9metrohash_12MetroHash128___cinit__(struct __pyx_obj_9metroh return __pyx_r; } -/* "metrohash.pyx":186 +/* "metrohash.pyx":189 * raise MemoryError() * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -3131,7 +3164,7 @@ static void __pyx_pf_9metrohash_12MetroHash128_2__dealloc__(struct __pyx_obj_9me int __pyx_t_1; __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "metrohash.pyx":187 + /* "metrohash.pyx":190 * * def __dealloc__(self): * if not self._m is NULL: # <<<<<<<<<<<<<< @@ -3141,7 +3174,7 @@ static void __pyx_pf_9metrohash_12MetroHash128_2__dealloc__(struct __pyx_obj_9me __pyx_t_1 = ((__pyx_v_self->_m != NULL) != 0); if (__pyx_t_1) { - /* "metrohash.pyx":188 + /* "metrohash.pyx":191 * def __dealloc__(self): * if not self._m is NULL: * del self._m # <<<<<<<<<<<<<< @@ -3150,7 +3183,7 @@ static void __pyx_pf_9metrohash_12MetroHash128_2__dealloc__(struct __pyx_obj_9me */ delete __pyx_v_self->_m; - /* "metrohash.pyx":189 + /* "metrohash.pyx":192 * if not self._m is NULL: * del self._m * self._m = NULL # <<<<<<<<<<<<<< @@ -3159,7 +3192,7 @@ static void __pyx_pf_9metrohash_12MetroHash128_2__dealloc__(struct __pyx_obj_9me */ __pyx_v_self->_m = NULL; - /* "metrohash.pyx":187 + /* "metrohash.pyx":190 * * def __dealloc__(self): * if not self._m is NULL: # <<<<<<<<<<<<<< @@ -3168,7 +3201,7 @@ static void __pyx_pf_9metrohash_12MetroHash128_2__dealloc__(struct __pyx_obj_9me */ } - /* "metrohash.pyx":186 + /* "metrohash.pyx":189 * raise MemoryError() * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -3180,7 +3213,7 @@ static void __pyx_pf_9metrohash_12MetroHash128_2__dealloc__(struct __pyx_obj_9me __Pyx_RefNannyFinishContext(); } -/* "metrohash.pyx":191 +/* "metrohash.pyx":194 * self._m = NULL * * def initialize(self, uint64 seed=0ULL): # <<<<<<<<<<<<<< @@ -3219,7 +3252,7 @@ static PyObject *__pyx_pw_9metrohash_12MetroHash128_5initialize(PyObject *__pyx_ } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "initialize") < 0)) __PYX_ERR(0, 191, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "initialize") < 0)) __PYX_ERR(0, 194, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -3230,14 +3263,14 @@ static PyObject *__pyx_pw_9metrohash_12MetroHash128_5initialize(PyObject *__pyx_ } } if (values[0]) { - __pyx_v_seed = __Pyx_PyInt_As_uint64_t(values[0]); if (unlikely((__pyx_v_seed == ((uint64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 191, __pyx_L3_error) + __pyx_v_seed = __Pyx_PyInt_As_uint64_t(values[0]); if (unlikely((__pyx_v_seed == ((uint64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 194, __pyx_L3_error) } else { __pyx_v_seed = ((uint64)0ULL); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("initialize", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 191, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("initialize", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 194, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("metrohash.MetroHash128.initialize", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -3255,7 +3288,7 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_4initialize(struct __pyx_obj __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("initialize", 0); - /* "metrohash.pyx":192 + /* "metrohash.pyx":195 * * def initialize(self, uint64 seed=0ULL): * self._m.Initialize(seed) # <<<<<<<<<<<<<< @@ -3264,7 +3297,7 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_4initialize(struct __pyx_obj */ __pyx_v_self->_m->Initialize(__pyx_v_seed); - /* "metrohash.pyx":191 + /* "metrohash.pyx":194 * self._m = NULL * * def initialize(self, uint64 seed=0ULL): # <<<<<<<<<<<<<< @@ -3279,12 +3312,12 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_4initialize(struct __pyx_obj return __pyx_r; } -/* "metrohash.pyx":194 +/* "metrohash.pyx":197 * self._m.Initialize(seed) * * def update(self, data): # <<<<<<<<<<<<<< * cdef Py_buffer buf - * cdef object obj + * cdef bytes obj */ /* Python wrapper */ @@ -3314,9 +3347,9 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_6update(struct __pyx_obj_9me int __pyx_clineno = 0; __Pyx_RefNannySetupContext("update", 0); - /* "metrohash.pyx":197 + /* "metrohash.pyx":200 * cdef Py_buffer buf - * cdef object obj + * cdef bytes obj * if PyUnicode_Check(data): # <<<<<<<<<<<<<< * obj = PyUnicode_AsUTF8String(data) * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) @@ -3324,48 +3357,48 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_6update(struct __pyx_obj_9me __pyx_t_1 = (PyUnicode_Check(__pyx_v_data) != 0); if (__pyx_t_1) { - /* "metrohash.pyx":198 - * cdef object obj + /* "metrohash.pyx":201 + * cdef bytes obj * if PyUnicode_Check(data): * obj = PyUnicode_AsUTF8String(data) # <<<<<<<<<<<<<< * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) - * Py_DECREF(obj) + * self._m.Update(buf.buf, buf.len) */ - __pyx_t_2 = PyUnicode_AsUTF8String(__pyx_v_data); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 198, __pyx_L1_error) + __pyx_t_2 = PyUnicode_AsUTF8String(__pyx_v_data); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 201, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_v_obj = __pyx_t_2; + __pyx_v_obj = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; - /* "metrohash.pyx":199 + /* "metrohash.pyx":202 * if PyUnicode_Check(data): * obj = PyUnicode_AsUTF8String(data) * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) # <<<<<<<<<<<<<< - * Py_DECREF(obj) * self._m.Update(buf.buf, buf.len) + * PyBuffer_Release(&buf) */ - __pyx_t_3 = PyObject_GetBuffer(__pyx_v_obj, (&__pyx_v_buf), PyBUF_SIMPLE); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 199, __pyx_L1_error) + __pyx_t_3 = PyObject_GetBuffer(__pyx_v_obj, (&__pyx_v_buf), PyBUF_SIMPLE); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 202, __pyx_L1_error) - /* "metrohash.pyx":200 + /* "metrohash.pyx":203 * obj = PyUnicode_AsUTF8String(data) * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) - * Py_DECREF(obj) # <<<<<<<<<<<<<< - * self._m.Update(buf.buf, buf.len) + * self._m.Update(buf.buf, buf.len) # <<<<<<<<<<<<<< + * PyBuffer_Release(&buf) * elif PyBytes_Check(data): */ - Py_DECREF(__pyx_v_obj); + __pyx_v_self->_m->Update(((uint8 const *)__pyx_v_buf.buf), __pyx_v_buf.len); - /* "metrohash.pyx":201 + /* "metrohash.pyx":204 * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) - * Py_DECREF(obj) - * self._m.Update(buf.buf, buf.len) # <<<<<<<<<<<<<< + * self._m.Update(buf.buf, buf.len) + * PyBuffer_Release(&buf) # <<<<<<<<<<<<<< * elif PyBytes_Check(data): * self._m.Update(PyBytes_AS_STRING(data), */ - __pyx_v_self->_m->Update(((uint8 const *)__pyx_v_buf.buf), __pyx_v_buf.len); + PyBuffer_Release((&__pyx_v_buf)); - /* "metrohash.pyx":197 + /* "metrohash.pyx":200 * cdef Py_buffer buf - * cdef object obj + * cdef bytes obj * if PyUnicode_Check(data): # <<<<<<<<<<<<<< * obj = PyUnicode_AsUTF8String(data) * PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) @@ -3373,9 +3406,9 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_6update(struct __pyx_obj_9me goto __pyx_L3; } - /* "metrohash.pyx":202 - * Py_DECREF(obj) + /* "metrohash.pyx":205 * self._m.Update(buf.buf, buf.len) + * PyBuffer_Release(&buf) * elif PyBytes_Check(data): # <<<<<<<<<<<<<< * self._m.Update(PyBytes_AS_STRING(data), * PyBytes_GET_SIZE(data)) @@ -3383,8 +3416,8 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_6update(struct __pyx_obj_9me __pyx_t_1 = (PyBytes_Check(__pyx_v_data) != 0); if (__pyx_t_1) { - /* "metrohash.pyx":203 - * self._m.Update(buf.buf, buf.len) + /* "metrohash.pyx":206 + * PyBuffer_Release(&buf) * elif PyBytes_Check(data): * self._m.Update(PyBytes_AS_STRING(data), # <<<<<<<<<<<<<< * PyBytes_GET_SIZE(data)) @@ -3392,9 +3425,9 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_6update(struct __pyx_obj_9me */ __pyx_v_self->_m->Update(((uint8 const *)PyBytes_AS_STRING(__pyx_v_data)), PyBytes_GET_SIZE(__pyx_v_data)); - /* "metrohash.pyx":202 - * Py_DECREF(obj) + /* "metrohash.pyx":205 * self._m.Update(buf.buf, buf.len) + * PyBuffer_Release(&buf) * elif PyBytes_Check(data): # <<<<<<<<<<<<<< * self._m.Update(PyBytes_AS_STRING(data), * PyBytes_GET_SIZE(data)) @@ -3402,7 +3435,7 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_6update(struct __pyx_obj_9me goto __pyx_L3; } - /* "metrohash.pyx":205 + /* "metrohash.pyx":208 * self._m.Update(PyBytes_AS_STRING(data), * PyBytes_GET_SIZE(data)) * elif PyObject_CheckBuffer(data): # <<<<<<<<<<<<<< @@ -3412,25 +3445,34 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_6update(struct __pyx_obj_9me __pyx_t_1 = (PyObject_CheckBuffer(__pyx_v_data) != 0); if (likely(__pyx_t_1)) { - /* "metrohash.pyx":206 + /* "metrohash.pyx":209 * PyBytes_GET_SIZE(data)) * elif PyObject_CheckBuffer(data): * PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) # <<<<<<<<<<<<<< * self._m.Update(buf.buf, buf.len) - * else: + * PyBuffer_Release(&buf) */ - __pyx_t_3 = PyObject_GetBuffer(__pyx_v_data, (&__pyx_v_buf), PyBUF_SIMPLE); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 206, __pyx_L1_error) + __pyx_t_3 = PyObject_GetBuffer(__pyx_v_data, (&__pyx_v_buf), PyBUF_SIMPLE); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 209, __pyx_L1_error) - /* "metrohash.pyx":207 + /* "metrohash.pyx":210 * elif PyObject_CheckBuffer(data): * PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) * self._m.Update(buf.buf, buf.len) # <<<<<<<<<<<<<< + * PyBuffer_Release(&buf) * else: - * raise _type_error("data", ["basestring", "buffer"], data) */ __pyx_v_self->_m->Update(((uint8 const *)__pyx_v_buf.buf), __pyx_v_buf.len); - /* "metrohash.pyx":205 + /* "metrohash.pyx":211 + * PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) + * self._m.Update(buf.buf, buf.len) + * PyBuffer_Release(&buf) # <<<<<<<<<<<<<< + * else: + * raise _type_error("data", ["basestring", "buffer"], data) + */ + PyBuffer_Release((&__pyx_v_buf)); + + /* "metrohash.pyx":208 * self._m.Update(PyBytes_AS_STRING(data), * PyBytes_GET_SIZE(data)) * elif PyObject_CheckBuffer(data): # <<<<<<<<<<<<<< @@ -3440,15 +3482,15 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_6update(struct __pyx_obj_9me goto __pyx_L3; } - /* "metrohash.pyx":209 - * self._m.Update(buf.buf, buf.len) + /* "metrohash.pyx":213 + * PyBuffer_Release(&buf) * else: * raise _type_error("data", ["basestring", "buffer"], data) # <<<<<<<<<<<<<< * * def intdigest(self): */ /*else*/ { - __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 209, __pyx_L1_error) + __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 213, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_u_basestring); __Pyx_GIVEREF(__pyx_n_u_basestring); @@ -3456,21 +3498,21 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_6update(struct __pyx_obj_9me __Pyx_INCREF(__pyx_n_u_buffer); __Pyx_GIVEREF(__pyx_n_u_buffer); PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_u_buffer); - __pyx_t_4 = __pyx_f_9metrohash__type_error(__pyx_n_u_data, __pyx_t_2, __pyx_v_data); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 209, __pyx_L1_error) + __pyx_t_4 = __pyx_f_9metrohash__type_error(__pyx_n_u_data, __pyx_t_2, __pyx_v_data); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 213, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 209, __pyx_L1_error) + __PYX_ERR(0, 213, __pyx_L1_error) } __pyx_L3:; - /* "metrohash.pyx":194 + /* "metrohash.pyx":197 * self._m.Initialize(seed) * * def update(self, data): # <<<<<<<<<<<<<< * cdef Py_buffer buf - * cdef object obj + * cdef bytes obj */ /* function exit code */ @@ -3488,7 +3530,7 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_6update(struct __pyx_obj_9me return __pyx_r; } -/* "metrohash.pyx":211 +/* "metrohash.pyx":215 * raise _type_error("data", ["basestring", "buffer"], data) * * def intdigest(self): # <<<<<<<<<<<<<< @@ -3522,7 +3564,7 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_8intdigest(struct __pyx_obj_ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("intdigest", 0); - /* "metrohash.pyx":213 + /* "metrohash.pyx":217 * def intdigest(self): * cdef uint8 buf[16] * self._m.Finalize(buf) # <<<<<<<<<<<<<< @@ -3531,7 +3573,7 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_8intdigest(struct __pyx_obj_ */ __pyx_v_self->_m->Finalize(__pyx_v_buf); - /* "metrohash.pyx":214 + /* "metrohash.pyx":218 * cdef uint8 buf[16] * self._m.Finalize(buf) * cdef pair[uint64, uint64] result = c_bytes2int128(buf) # <<<<<<<<<<<<<< @@ -3539,26 +3581,26 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_8intdigest(struct __pyx_obj_ */ __pyx_v_result = bytes2int128(__pyx_v_buf); - /* "metrohash.pyx":215 + /* "metrohash.pyx":219 * self._m.Finalize(buf) * cdef pair[uint64, uint64] result = c_bytes2int128(buf) * return 0x10000000000000000L * long(result.first) + long(result.second) # <<<<<<<<<<<<<< */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyInt_From_uint64_t(__pyx_v_result.first); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 215, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_uint64_t(__pyx_v_result.first); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 219, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyLong_Type)), __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 215, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyLong_Type)), __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 219, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyNumber_Multiply(__pyx_int_18446744073709551616L, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 215, __pyx_L1_error) + __pyx_t_1 = PyNumber_Multiply(__pyx_int_18446744073709551616L, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 219, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyInt_From_uint64_t(__pyx_v_result.second); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 215, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_uint64_t(__pyx_v_result.second); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 219, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyLong_Type)), __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 215, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyLong_Type)), __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 219, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 215, __pyx_L1_error) + __pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 219, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; @@ -3566,7 +3608,7 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_8intdigest(struct __pyx_obj_ __pyx_t_2 = 0; goto __pyx_L0; - /* "metrohash.pyx":211 + /* "metrohash.pyx":215 * raise _type_error("data", ["basestring", "buffer"], data) * * def intdigest(self): # <<<<<<<<<<<<<< @@ -3946,7 +3988,7 @@ static PyModuleDef_Slot __pyx_moduledef_slots[] = { static struct PyModuleDef __pyx_moduledef = { PyModuleDef_HEAD_INIT, "metrohash", - __pyx_k_A_Python_wrapper_for_MetroHash, /* m_doc */ + __pyx_k_Python_wrapper_for_MetroHash_a, /* m_doc */ #if CYTHON_PEP489_MULTI_PHASE_INIT 0, /* m_size */ #else @@ -3983,13 +4025,14 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_u_MetroHash128, __pyx_k_MetroHash128, sizeof(__pyx_k_MetroHash128), 0, 1, 0, 1}, {&__pyx_n_s_MetroHash64, __pyx_k_MetroHash64, sizeof(__pyx_k_MetroHash64), 0, 0, 1, 1}, {&__pyx_n_u_MetroHash64, __pyx_k_MetroHash64, sizeof(__pyx_k_MetroHash64), 0, 1, 0, 1}, - {&__pyx_kp_u_None, __pyx_k_None, sizeof(__pyx_k_None), 0, 1, 0, 0}, {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1}, {&__pyx_n_s_all, __pyx_k_all, sizeof(__pyx_k_all), 0, 0, 1, 1}, {&__pyx_n_s_author, __pyx_k_author, sizeof(__pyx_k_author), 0, 0, 1, 1}, + {&__pyx_n_s_basestring, __pyx_k_basestring, sizeof(__pyx_k_basestring), 0, 0, 1, 1}, {&__pyx_n_u_basestring, __pyx_k_basestring, sizeof(__pyx_k_basestring), 0, 1, 0, 1}, {&__pyx_n_u_buffer, __pyx_k_buffer, sizeof(__pyx_k_buffer), 0, 1, 0, 1}, {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1}, + {&__pyx_n_s_cython, __pyx_k_cython, sizeof(__pyx_k_cython), 0, 0, 1, 1}, {&__pyx_n_s_data, __pyx_k_data, sizeof(__pyx_k_data), 0, 0, 1, 1}, {&__pyx_n_u_data, __pyx_k_data, sizeof(__pyx_k_data), 0, 1, 0, 1}, {&__pyx_n_s_email, __pyx_k_email, sizeof(__pyx_k_email), 0, 0, 1, 1}, @@ -3997,6 +4040,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_getstate, __pyx_k_getstate, sizeof(__pyx_k_getstate), 0, 0, 1, 1}, {&__pyx_kp_u_got, __pyx_k_got, sizeof(__pyx_k_got), 0, 1, 0, 0}, {&__pyx_kp_u_has_incorrect_type_expected, __pyx_k_has_incorrect_type_expected, sizeof(__pyx_k_has_incorrect_type_expected), 0, 1, 0, 0}, + {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, {&__pyx_n_u_metrohash128, __pyx_k_metrohash128, sizeof(__pyx_k_metrohash128), 0, 1, 0, 1}, {&__pyx_n_u_metrohash64, __pyx_k_metrohash64, sizeof(__pyx_k_metrohash64), 0, 1, 0, 1}, @@ -4014,7 +4058,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { }; static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) { __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(0, 80, __pyx_L1_error) - __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(0, 141, __pyx_L1_error) + __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(0, 143, __pyx_L1_error) return 0; __pyx_L1_error:; return -1; @@ -4115,25 +4159,25 @@ static int __Pyx_modinit_type_init_code(void) { int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0); /*--- Type init code ---*/ - if (PyType_Ready(&__pyx_type_9metrohash_MetroHash64) < 0) __PYX_ERR(0, 131, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_9metrohash_MetroHash64) < 0) __PYX_ERR(0, 133, __pyx_L1_error) #if PY_VERSION_HEX < 0x030800B1 __pyx_type_9metrohash_MetroHash64.tp_print = 0; #endif if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_9metrohash_MetroHash64.tp_dictoffset && __pyx_type_9metrohash_MetroHash64.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_9metrohash_MetroHash64.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (PyObject_SetAttr(__pyx_m, __pyx_n_s_MetroHash64, (PyObject *)&__pyx_type_9metrohash_MetroHash64) < 0) __PYX_ERR(0, 131, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_9metrohash_MetroHash64) < 0) __PYX_ERR(0, 131, __pyx_L1_error) + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_MetroHash64, (PyObject *)&__pyx_type_9metrohash_MetroHash64) < 0) __PYX_ERR(0, 133, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_9metrohash_MetroHash64) < 0) __PYX_ERR(0, 133, __pyx_L1_error) __pyx_ptype_9metrohash_MetroHash64 = &__pyx_type_9metrohash_MetroHash64; - if (PyType_Ready(&__pyx_type_9metrohash_MetroHash128) < 0) __PYX_ERR(0, 174, __pyx_L1_error) + if (PyType_Ready(&__pyx_type_9metrohash_MetroHash128) < 0) __PYX_ERR(0, 177, __pyx_L1_error) #if PY_VERSION_HEX < 0x030800B1 __pyx_type_9metrohash_MetroHash128.tp_print = 0; #endif if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_9metrohash_MetroHash128.tp_dictoffset && __pyx_type_9metrohash_MetroHash128.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_9metrohash_MetroHash128.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (PyObject_SetAttr(__pyx_m, __pyx_n_s_MetroHash128, (PyObject *)&__pyx_type_9metrohash_MetroHash128) < 0) __PYX_ERR(0, 174, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_9metrohash_MetroHash128) < 0) __PYX_ERR(0, 174, __pyx_L1_error) + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_MetroHash128, (PyObject *)&__pyx_type_9metrohash_MetroHash128) < 0) __PYX_ERR(0, 177, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_9metrohash_MetroHash128) < 0) __PYX_ERR(0, 177, __pyx_L1_error) __pyx_ptype_9metrohash_MetroHash128 = &__pyx_type_9metrohash_MetroHash128; __Pyx_RefNannyFinishContext(); return 0; @@ -4290,6 +4334,7 @@ static CYTHON_SMALL_CODE int __pyx_pymod_exec_metrohash(PyObject *__pyx_pyinit_m #endif { PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; @@ -4349,7 +4394,7 @@ if (!__Pyx_RefNanny) { Py_INCREF(__pyx_m); #else #if PY_MAJOR_VERSION < 3 - __pyx_m = Py_InitModule4("metrohash", __pyx_methods, __pyx_k_A_Python_wrapper_for_MetroHash, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); + __pyx_m = Py_InitModule4("metrohash", __pyx_methods, __pyx_k_Python_wrapper_for_MetroHash_a, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); #else __pyx_m = PyModule_Create(&__pyx_moduledef); #endif @@ -4446,21 +4491,43 @@ if (!__Pyx_RefNanny) { if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_1) < 0) __PYX_ERR(0, 12, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + /* "metrohash.pyx":64 + * + * from cpython cimport long + * from cython import basestring # <<<<<<<<<<<<<< + * + * from cpython.buffer cimport PyObject_CheckBuffer + */ + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 64, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_n_s_basestring); + __Pyx_GIVEREF(__pyx_n_s_basestring); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_basestring); + __pyx_t_2 = __Pyx_Import(__pyx_n_s_cython, __pyx_t_1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 64, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_basestring); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 64, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_basestring, __pyx_t_1) < 0) __PYX_ERR(0, 64, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + /* "metrohash.pyx":1 * #cython: infer_types=True # <<<<<<<<<<<<<< * #cython: language_level=3 * #distutils: language=c++ */ - __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /*--- Wrapped vars code ---*/ goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); if (__pyx_m) { if (__pyx_d) { __Pyx_AddTraceback("init metrohash", __pyx_clineno, __pyx_lineno, __pyx_filename); @@ -4526,13 +4593,6 @@ static PyObject *__Pyx_GetBuiltinName(PyObject *name) { return result; } -/* PyUnicode_Unicode */ -static CYTHON_INLINE PyObject* __Pyx_PyUnicode_Unicode(PyObject *obj) { - if (unlikely(obj == Py_None)) - obj = __pyx_kp_u_None; - return __Pyx_NewRef(obj); -} - /* PyObjectFormatAndDecref */ static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatSimpleAndDecref(PyObject* s, PyObject* f) { if (unlikely(!s)) return NULL; @@ -5403,6 +5463,85 @@ static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, } #endif +/* Import */ +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) { + PyObject *empty_list = 0; + PyObject *module = 0; + PyObject *global_dict = 0; + PyObject *empty_dict = 0; + PyObject *list; + #if PY_MAJOR_VERSION < 3 + PyObject *py_import; + py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import); + if (!py_import) + goto bad; + #endif + if (from_list) + list = from_list; + else { + empty_list = PyList_New(0); + if (!empty_list) + goto bad; + list = empty_list; + } + global_dict = PyModule_GetDict(__pyx_m); + if (!global_dict) + goto bad; + empty_dict = PyDict_New(); + if (!empty_dict) + goto bad; + { + #if PY_MAJOR_VERSION >= 3 + if (level == -1) { + if ((1) && (strchr(__Pyx_MODULE_NAME, '.'))) { + module = PyImport_ImportModuleLevelObject( + name, global_dict, empty_dict, list, 1); + if (!module) { + if (!PyErr_ExceptionMatches(PyExc_ImportError)) + goto bad; + PyErr_Clear(); + } + } + level = 0; + } + #endif + if (!module) { + #if PY_MAJOR_VERSION < 3 + PyObject *py_level = PyInt_FromLong(level); + if (!py_level) + goto bad; + module = PyObject_CallFunctionObjArgs(py_import, + name, global_dict, empty_dict, list, py_level, (PyObject *)NULL); + Py_DECREF(py_level); + #else + module = PyImport_ImportModuleLevelObject( + name, global_dict, empty_dict, list, level); + #endif + } + } +bad: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(py_import); + #endif + Py_XDECREF(empty_list); + Py_XDECREF(empty_dict); + return module; +} + +/* ImportFrom */ +static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) { + PyObject* value = __Pyx_PyObject_GetAttrStr(module, name); + if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) { + PyErr_Format(PyExc_ImportError, + #if PY_MAJOR_VERSION < 3 + "cannot import name %.230s", PyString_AS_STRING(name)); + #else + "cannot import name %S", name); + #endif + } + return value; +} + /* PyDictVersioning */ #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) { diff --git a/src/metrohash.pyx b/src/metrohash.pyx index 8116aaf..a0b607e 100644 --- a/src/metrohash.pyx +++ b/src/metrohash.pyx @@ -3,7 +3,7 @@ #distutils: language=c++ """ -A Python wrapper for MetroHash, a fast non-cryptographic hashing algorithm +Python wrapper for MetroHash, a fast non-cryptographic hashing algorithm """ __author__ = "Eugene Scherba" @@ -60,12 +60,13 @@ cdef extern from "metro.h" nogil: void Update(const uint8* buf, const uint64 length) void Finalize(uint8* const result) -from cpython.long cimport long +from cpython cimport long +from cython import basestring from cpython.buffer cimport PyObject_CheckBuffer from cpython.buffer cimport PyBUF_SIMPLE -from cpython.buffer cimport Py_buffer from cpython.buffer cimport PyObject_GetBuffer +from cpython.buffer cimport PyBuffer_Release from cpython.unicode cimport PyUnicode_Check from cpython.unicode cimport PyUnicode_AsUTF8String @@ -73,10 +74,9 @@ from cpython.unicode cimport PyUnicode_AsUTF8String from cpython.bytes cimport PyBytes_Check from cpython.bytes cimport PyBytes_GET_SIZE from cpython.bytes cimport PyBytes_AS_STRING -from cpython cimport Py_DECREF -cdef object _type_error(str argname, expected, value): +cdef object _type_error(argname: basestring, expected: object, value: object): return TypeError( "Argument '%s' has incorrect type (expected %s, got %s)" % (argname, expected, type(value)) @@ -87,19 +87,20 @@ cpdef metrohash64(data, uint64 seed=0ULL): """64-bit hash function for a basestring or buffer type """ cdef Py_buffer buf - cdef object obj + cdef bytes obj cdef uint64 result if PyUnicode_Check(data): obj = PyUnicode_AsUTF8String(data) PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) result = c_metrohash64(buf.buf, buf.len, seed) - Py_DECREF(obj) + PyBuffer_Release(&buf) elif PyBytes_Check(data): result = c_metrohash64(PyBytes_AS_STRING(data), PyBytes_GET_SIZE(data), seed) elif PyObject_CheckBuffer(data): PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) result = c_metrohash64(buf.buf, buf.len, seed) + PyBuffer_Release(&buf) else: raise _type_error("data", ["basestring", "buffer"], data) return result @@ -109,19 +110,20 @@ cpdef metrohash128(data, uint64 seed=0ULL): """128-bit hash function for a basestring or buffer type """ cdef Py_buffer buf - cdef object obj + cdef bytes obj cdef pair[uint64, uint64] result if PyUnicode_Check(data): obj = PyUnicode_AsUTF8String(data) PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) result = c_metrohash128(buf.buf, buf.len, seed) - Py_DECREF(obj) + PyBuffer_Release(&buf) elif PyBytes_Check(data): result = c_metrohash128(PyBytes_AS_STRING(data), PyBytes_GET_SIZE(data), seed) elif PyObject_CheckBuffer(data): PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) result = c_metrohash128(buf.buf, buf.len, seed) + PyBuffer_Release(&buf) else: raise _type_error("data", ["basestring", "buffer"], data) final = 0x10000000000000000L * long(result.first) + long(result.second) @@ -150,18 +152,19 @@ cdef class MetroHash64(object): def update(self, data): cdef Py_buffer buf - cdef object obj + cdef bytes obj if PyUnicode_Check(data): obj = PyUnicode_AsUTF8String(data) PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) - Py_DECREF(obj) self._m.Update(buf.buf, buf.len) + PyBuffer_Release(&buf) elif PyBytes_Check(data): self._m.Update(PyBytes_AS_STRING(data), PyBytes_GET_SIZE(data)) elif PyObject_CheckBuffer(data): PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) self._m.Update(buf.buf, buf.len) + PyBuffer_Release(&buf) else: raise _type_error("data", ["basestring", "buffer"], data) @@ -193,18 +196,19 @@ cdef class MetroHash128(object): def update(self, data): cdef Py_buffer buf - cdef object obj + cdef bytes obj if PyUnicode_Check(data): obj = PyUnicode_AsUTF8String(data) PyObject_GetBuffer(obj, &buf, PyBUF_SIMPLE) - Py_DECREF(obj) self._m.Update(buf.buf, buf.len) + PyBuffer_Release(&buf) elif PyBytes_Check(data): self._m.Update(PyBytes_AS_STRING(data), PyBytes_GET_SIZE(data)) elif PyObject_CheckBuffer(data): PyObject_GetBuffer(data, &buf, PyBUF_SIMPLE) self._m.Update(buf.buf, buf.len) + PyBuffer_Release(&buf) else: raise _type_error("data", ["basestring", "buffer"], data) diff --git a/tests/test_metrohash.py b/tests/test_metrohash.py index 021d506..d773d6c 100644 --- a/tests/test_metrohash.py +++ b/tests/test_metrohash.py @@ -81,6 +81,17 @@ def test_unicode_2_128(self): test_case = u'\u2661' # pylint: disable=redundant-u-string-prefix self.assertTrue(isinstance(metrohash128(test_case), long)) + def test_refcounts(self): + """Doesn't leak references to its argument""" + funcs = [metrohash64, metrohash128] + args = ['abc', b'abc', bytearray(b'def'), memoryview(b'ghi')] + for func in funcs: + for arg in args: + old_refcount = sys.getrefcount(arg) + func(arg) + self.assertEqual(sys.getrefcount(arg), old_refcount) + + class TestCombiners(unittest.TestCase): From 3c0fcd6720f2677e5580f8a2dc3b62738e81f4bc Mon Sep 17 00:00:00 2001 From: Eugene Scherba Date: Tue, 28 Dec 2021 17:54:39 -0800 Subject: [PATCH 7/7] rename argument in declaration --- src/metrohash.pyx | 4 ++-- tests/test_metrohash.py | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/metrohash.pyx b/src/metrohash.pyx index a0b607e..7658623 100644 --- a/src/metrohash.pyx +++ b/src/metrohash.pyx @@ -45,10 +45,10 @@ cdef extern from "metro.h" nogil: ctypedef pair uint128 cdef uint64 c_Uint128Low64 "Uint128Low64" (uint128& x) cdef uint64 c_Uint128High64 "Uint128High64" (uint128& x) - cdef uint64 c_metrohash64 "metrohash64" (const uint8* buf, uint64 len, uint64 seed) + cdef uint64 c_metrohash64 "metrohash64" (const uint8* buf, uint64 length, uint64 seed) cdef uint64 c_bytes2int64 "bytes2int64" (uint8* const array) cdef uint128[uint64,uint64] c_bytes2int128 "bytes2int128" (uint8* const array) - cdef uint128[uint64,uint64] c_metrohash128 "metrohash128" (const uint8* buf, uint64 len, uint64 seed) + cdef uint128[uint64,uint64] c_metrohash128 "metrohash128" (const uint8* buf, uint64 length, uint64 seed) cdef cppclass CCMetroHash64 "MetroHash64": CCMetroHash64(const uint64 seed) void Initialize(const uint64 seed) diff --git a/tests/test_metrohash.py b/tests/test_metrohash.py index d773d6c..5ca1789 100644 --- a/tests/test_metrohash.py +++ b/tests/test_metrohash.py @@ -92,7 +92,6 @@ def test_refcounts(self): self.assertEqual(sys.getrefcount(arg), old_refcount) - class TestCombiners(unittest.TestCase): """test combiners"""