Mercurial > cpython-lru_cache-weakref
comparison Python/sysmodule.c @ 61873:0bc8ffe6ba9a
Issue #8188: Introduce a new scheme for computing hashes of numbers
(instances of int, float, complex, decimal.Decimal and
fractions.Fraction) that makes it easy to maintain the invariant that
hash(x) == hash(y) whenever x and y have equal value.
| author | Mark Dickinson <dickinsm@gmail.com> |
|---|---|
| date | Sun, 23 May 2010 13:33:13 +0000 |
| parents | 795762b5e0d6 |
| children | 600c23127207 |
comparison
equal
deleted
inserted
replaced
| 61872:b0dee32a1c6b | 61873:0bc8ffe6ba9a |
|---|---|
| 567 } | 567 } |
| 568 Py_SetRecursionLimit(new_limit); | 568 Py_SetRecursionLimit(new_limit); |
| 569 Py_INCREF(Py_None); | 569 Py_INCREF(Py_None); |
| 570 return Py_None; | 570 return Py_None; |
| 571 } | 571 } |
| 572 | |
| 573 static PyTypeObject Hash_InfoType; | |
| 574 | |
| 575 PyDoc_STRVAR(hash_info_doc, | |
| 576 "hash_info\n\ | |
| 577 \n\ | |
| 578 A struct sequence providing parameters used for computing\n\ | |
| 579 numeric hashes. The attributes are read only."); | |
| 580 | |
| 581 static PyStructSequence_Field hash_info_fields[] = { | |
| 582 {"width", "width of the type used for hashing, in bits"}, | |
| 583 {"modulus", "prime number giving the modulus on which the hash " | |
| 584 "function is based"}, | |
| 585 {"inf", "value to be used for hash of a positive infinity"}, | |
| 586 {"nan", "value to be used for hash of a nan"}, | |
| 587 {"imag", "multiplier used for the imaginary part of a complex number"}, | |
| 588 {NULL, NULL} | |
| 589 }; | |
| 590 | |
| 591 static PyStructSequence_Desc hash_info_desc = { | |
| 592 "sys.hash_info", | |
| 593 hash_info_doc, | |
| 594 hash_info_fields, | |
| 595 5, | |
| 596 }; | |
| 597 | |
| 598 PyObject * | |
| 599 get_hash_info(void) | |
| 600 { | |
| 601 PyObject *hash_info; | |
| 602 int field = 0; | |
| 603 hash_info = PyStructSequence_New(&Hash_InfoType); | |
| 604 if (hash_info == NULL) | |
| 605 return NULL; | |
| 606 PyStructSequence_SET_ITEM(hash_info, field++, | |
| 607 PyLong_FromLong(8*sizeof(long))); | |
| 608 PyStructSequence_SET_ITEM(hash_info, field++, | |
| 609 PyLong_FromLong(_PyHASH_MODULUS)); | |
| 610 PyStructSequence_SET_ITEM(hash_info, field++, | |
| 611 PyLong_FromLong(_PyHASH_INF)); | |
| 612 PyStructSequence_SET_ITEM(hash_info, field++, | |
| 613 PyLong_FromLong(_PyHASH_NAN)); | |
| 614 PyStructSequence_SET_ITEM(hash_info, field++, | |
| 615 PyLong_FromLong(_PyHASH_IMAG)); | |
| 616 if (PyErr_Occurred()) { | |
| 617 Py_CLEAR(hash_info); | |
| 618 return NULL; | |
| 619 } | |
| 620 return hash_info; | |
| 621 } | |
| 622 | |
| 572 | 623 |
| 573 PyDoc_STRVAR(setrecursionlimit_doc, | 624 PyDoc_STRVAR(setrecursionlimit_doc, |
| 574 "setrecursionlimit(n)\n\ | 625 "setrecursionlimit(n)\n\ |
| 575 \n\ | 626 \n\ |
| 576 Set the maximum depth of the Python interpreter stack to n. This\n\ | 627 Set the maximum depth of the Python interpreter stack to n. This\n\ |
| 1480 PyLong_FromSsize_t(PY_SSIZE_T_MAX)); | 1531 PyLong_FromSsize_t(PY_SSIZE_T_MAX)); |
| 1481 SET_SYS_FROM_STRING("float_info", | 1532 SET_SYS_FROM_STRING("float_info", |
| 1482 PyFloat_GetInfo()); | 1533 PyFloat_GetInfo()); |
| 1483 SET_SYS_FROM_STRING("int_info", | 1534 SET_SYS_FROM_STRING("int_info", |
| 1484 PyLong_GetInfo()); | 1535 PyLong_GetInfo()); |
| 1536 /* initialize hash_info */ | |
| 1537 if (Hash_InfoType.tp_name == 0) | |
| 1538 PyStructSequence_InitType(&Hash_InfoType, &hash_info_desc); | |
| 1539 SET_SYS_FROM_STRING("hash_info", | |
| 1540 get_hash_info()); | |
| 1485 SET_SYS_FROM_STRING("maxunicode", | 1541 SET_SYS_FROM_STRING("maxunicode", |
| 1486 PyLong_FromLong(PyUnicode_GetMax())); | 1542 PyLong_FromLong(PyUnicode_GetMax())); |
| 1487 SET_SYS_FROM_STRING("builtin_module_names", | 1543 SET_SYS_FROM_STRING("builtin_module_names", |
| 1488 list_builtin_module_names()); | 1544 list_builtin_module_names()); |
| 1489 { | 1545 { |
