summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
Diffstat (limited to 'Python')
-rw-r--r--Python/sysmodule.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 77b120f..4c87d54 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -570,6 +570,57 @@ sys_setrecursionlimit(PyObject *self, PyObject *args)
return Py_None;
}
+static PyTypeObject Hash_InfoType;
+
+PyDoc_STRVAR(hash_info_doc,
+"hash_info\n\
+\n\
+A struct sequence providing parameters used for computing\n\
+numeric hashes. The attributes are read only.");
+
+static PyStructSequence_Field hash_info_fields[] = {
+ {"width", "width of the type used for hashing, in bits"},
+ {"modulus", "prime number giving the modulus on which the hash "
+ "function is based"},
+ {"inf", "value to be used for hash of a positive infinity"},
+ {"nan", "value to be used for hash of a nan"},
+ {"imag", "multiplier used for the imaginary part of a complex number"},
+ {NULL, NULL}
+};
+
+static PyStructSequence_Desc hash_info_desc = {
+ "sys.hash_info",
+ hash_info_doc,
+ hash_info_fields,
+ 5,
+};
+
+PyObject *
+get_hash_info(void)
+{
+ PyObject *hash_info;
+ int field = 0;
+ hash_info = PyStructSequence_New(&Hash_InfoType);
+ if (hash_info == NULL)
+ return NULL;
+ PyStructSequence_SET_ITEM(hash_info, field++,
+ PyLong_FromLong(8*sizeof(long)));
+ PyStructSequence_SET_ITEM(hash_info, field++,
+ PyLong_FromLong(_PyHASH_MODULUS));
+ PyStructSequence_SET_ITEM(hash_info, field++,
+ PyLong_FromLong(_PyHASH_INF));
+ PyStructSequence_SET_ITEM(hash_info, field++,
+ PyLong_FromLong(_PyHASH_NAN));
+ PyStructSequence_SET_ITEM(hash_info, field++,
+ PyLong_FromLong(_PyHASH_IMAG));
+ if (PyErr_Occurred()) {
+ Py_CLEAR(hash_info);
+ return NULL;
+ }
+ return hash_info;
+}
+
+
PyDoc_STRVAR(setrecursionlimit_doc,
"setrecursionlimit(n)\n\
\n\
@@ -1482,6 +1533,11 @@ _PySys_Init(void)
PyFloat_GetInfo());
SET_SYS_FROM_STRING("int_info",
PyLong_GetInfo());
+ /* initialize hash_info */
+ if (Hash_InfoType.tp_name == 0)
+ PyStructSequence_InitType(&Hash_InfoType, &hash_info_desc);
+ SET_SYS_FROM_STRING("hash_info",
+ get_hash_info());
SET_SYS_FROM_STRING("maxunicode",
PyLong_FromLong(PyUnicode_GetMax()));
SET_SYS_FROM_STRING("builtin_module_names",