Author: Armin Rigo <[email protected]>
Branch: rpython-hash
Changeset: r89831:dcfe8dc6240f
Date: 2017-01-30 11:25 +0100
http://bitbucket.org/pypy/pypy/changeset/dcfe8dc6240f/
Log: make --hash a PyPy-specific option, fixes
diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py
--- a/pypy/config/pypyoption.py
+++ b/pypy/config/pypyoption.py
@@ -196,6 +196,13 @@
default=False,
requires=[("objspace.usemodules.cpyext", False)]),
+ ChoiceOption("hash",
+ "The hash function to use for strings: fnv from CPython 2.7"
+ " or siphash24 from CPython >= 3.4",
+ ["fnv", "siphash24"],
+ default="fnv",
+ cmdline="--hash"),
+
OptionDescription("std", "Standard Object Space Options", [
BoolOption("withtproxy", "support transparent proxies",
default=True),
diff --git a/pypy/goal/targetpypystandalone.py
b/pypy/goal/targetpypystandalone.py
--- a/pypy/goal/targetpypystandalone.py
+++ b/pypy/goal/targetpypystandalone.py
@@ -35,6 +35,7 @@
w_run_toplevel = space.getitem(w_dict, space.wrap('run_toplevel'))
w_initstdio = space.getitem(w_dict, space.wrap('initstdio'))
withjit = space.config.objspace.usemodules.pypyjit
+ hashfunc = space.config.objspace.hash
else:
w_initstdio = space.appexec([], """():
return lambda unbuffered: None
@@ -45,6 +46,10 @@
from rpython.jit.backend.hlinfo import highleveljitinfo
highleveljitinfo.sys_executable = argv[0]
+ if hashfunc == "siphash24":
+ from rpython.rlib import rsiphash
+ rsiphash.enable_siphash24()
+
#debug("entry point starting")
#for arg in argv:
# debug(" argv -> " + arg)
diff --git a/rpython/config/translationoption.py
b/rpython/config/translationoption.py
--- a/rpython/config/translationoption.py
+++ b/rpython/config/translationoption.py
@@ -201,10 +201,6 @@
StrOption("icon", "Path to the (Windows) icon to use for the executable"),
StrOption("libname",
"Windows: name and possibly location of the lib file to create"),
- ChoiceOption("hash",
- "The hash to use for strings",
- ["rpython", "siphash24"],
- default="rpython", cmdline="--hash"),
OptionDescription("backendopt", "Backend Optimization Options", [
# control inlining
@@ -394,12 +390,6 @@
if sys.platform == "darwin" or sys.platform =="win32":
raise ConfigError("'asmgcc' not supported on this platform")
-def apply_extra_settings(config):
- # make the setting of config.hash definitive
- from rpython.rlib.objectmodel import set_hash_algorithm
- config.translation.hash = config.translation.hash
- set_hash_algorithm(config.translation.hash)
-
# ----------------------------------------------------------------
def set_platform(config):
diff --git a/rpython/rlib/objectmodel.py b/rpython/rlib/objectmodel.py
--- a/rpython/rlib/objectmodel.py
+++ b/rpython/rlib/objectmodel.py
@@ -521,6 +521,12 @@
def _hash_string(s):
"""The default algorithm behind compute_hash() for a string or a unicode.
+ This is a modified Fowler-Noll-Vo (FNV) hash. According to Wikipedia,
+ FNV needs carefully-computed constants called FNV primes and FNV offset
+ basis, which are absent from the present algorithm. Nevertheless,
+ this matches CPython 2.7 without -R, which has proven a good hash in
+ practice (even if not crypographical nor randomizable).
+
There is a mechanism to use another one in programs after translation.
See rsiphash.py, which implements the algorithm of CPython >= 3.4.
"""
diff --git a/rpython/translator/goal/translate.py
b/rpython/translator/goal/translate.py
--- a/rpython/translator/goal/translate.py
+++ b/rpython/translator/goal/translate.py
@@ -11,8 +11,7 @@
from rpython.config.config import (to_optparse, OptionDescription, BoolOption,
ArbitraryOption, StrOption, IntOption, Config, ChoiceOption,
OptHelpFormatter)
from rpython.config.translationoption import (get_combined_translation_config,
- set_opt_level, OPT_LEVELS, DEFAULT_OPT_LEVEL, set_platform, CACHE_DIR,
- apply_extra_settings)
+ set_opt_level, OPT_LEVELS, DEFAULT_OPT_LEVEL, set_platform, CACHE_DIR)
# clean up early rpython/_cache
try:
@@ -178,9 +177,6 @@
if 'handle_config' in targetspec_dic:
targetspec_dic['handle_config'](config, translateconfig)
- # apply extra settings
- apply_extra_settings(config)
-
return targetspec_dic, translateconfig, config, args
def show_help(translateconfig, opt_parser, targetspec_dic, config):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit