passagemath-objects 10.6.41__cp314-cp314t-macosx_13_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of passagemath-objects might be problematic. Click here for more details.
- passagemath_objects/.dylibs/libgmp.10.dylib +0 -0
- passagemath_objects/__init__.py +3 -0
- passagemath_objects-10.6.41.dist-info/METADATA +115 -0
- passagemath_objects-10.6.41.dist-info/RECORD +280 -0
- passagemath_objects-10.6.41.dist-info/WHEEL +6 -0
- passagemath_objects-10.6.41.dist-info/top_level.txt +3 -0
- sage/all__sagemath_objects.py +37 -0
- sage/arith/all__sagemath_objects.py +5 -0
- sage/arith/long.pxd +411 -0
- sage/arith/numerical_approx.cpython-314t-darwin.so +0 -0
- sage/arith/numerical_approx.pxd +35 -0
- sage/arith/numerical_approx.pyx +75 -0
- sage/arith/power.cpython-314t-darwin.so +0 -0
- sage/arith/power.pxd +31 -0
- sage/arith/power.pyx +127 -0
- sage/categories/action.cpython-314t-darwin.so +0 -0
- sage/categories/action.pxd +29 -0
- sage/categories/action.pyx +641 -0
- sage/categories/algebra_functor.py +745 -0
- sage/categories/all__sagemath_objects.py +33 -0
- sage/categories/basic.py +62 -0
- sage/categories/cartesian_product.py +295 -0
- sage/categories/category.py +3401 -0
- sage/categories/category_cy_helper.cpython-314t-darwin.so +0 -0
- sage/categories/category_cy_helper.pxd +8 -0
- sage/categories/category_cy_helper.pyx +322 -0
- sage/categories/category_singleton.cpython-314t-darwin.so +0 -0
- sage/categories/category_singleton.pxd +3 -0
- sage/categories/category_singleton.pyx +342 -0
- sage/categories/category_types.py +637 -0
- sage/categories/category_with_axiom.py +2876 -0
- sage/categories/covariant_functorial_construction.py +703 -0
- sage/categories/facade_sets.py +228 -0
- sage/categories/functor.cpython-314t-darwin.so +0 -0
- sage/categories/functor.pxd +7 -0
- sage/categories/functor.pyx +691 -0
- sage/categories/homset.py +1338 -0
- sage/categories/homsets.py +364 -0
- sage/categories/isomorphic_objects.py +73 -0
- sage/categories/map.cpython-314t-darwin.so +0 -0
- sage/categories/map.pxd +34 -0
- sage/categories/map.pyx +2112 -0
- sage/categories/morphism.cpython-314t-darwin.so +0 -0
- sage/categories/morphism.pxd +14 -0
- sage/categories/morphism.pyx +895 -0
- sage/categories/objects.py +167 -0
- sage/categories/primer.py +1696 -0
- sage/categories/pushout.py +4834 -0
- sage/categories/quotients.py +64 -0
- sage/categories/realizations.py +200 -0
- sage/categories/sets_cat.py +3228 -0
- sage/categories/sets_with_partial_maps.py +52 -0
- sage/categories/subobjects.py +64 -0
- sage/categories/subquotients.py +21 -0
- sage/categories/with_realizations.py +311 -0
- sage/cpython/__init__.py +19 -0
- sage/cpython/_py2_random.py +619 -0
- sage/cpython/all.py +3 -0
- sage/cpython/atexit.cpython-314t-darwin.so +0 -0
- sage/cpython/atexit.pyx +269 -0
- sage/cpython/builtin_types.cpython-314t-darwin.so +0 -0
- sage/cpython/builtin_types.pyx +7 -0
- sage/cpython/cython_metaclass.cpython-314t-darwin.so +0 -0
- sage/cpython/cython_metaclass.h +117 -0
- sage/cpython/cython_metaclass.pxd +3 -0
- sage/cpython/cython_metaclass.pyx +130 -0
- sage/cpython/debug.cpython-314t-darwin.so +0 -0
- sage/cpython/debug.pyx +302 -0
- sage/cpython/dict_del_by_value.cpython-314t-darwin.so +0 -0
- sage/cpython/dict_del_by_value.pxd +9 -0
- sage/cpython/dict_del_by_value.pyx +191 -0
- sage/cpython/dict_internal.h +245 -0
- sage/cpython/getattr.cpython-314t-darwin.so +0 -0
- sage/cpython/getattr.pxd +9 -0
- sage/cpython/getattr.pyx +439 -0
- sage/cpython/pycore_long.h +97 -0
- sage/cpython/pycore_long.pxd +10 -0
- sage/cpython/python_debug.h +44 -0
- sage/cpython/python_debug.pxd +47 -0
- sage/cpython/pyx_visit.h +13 -0
- sage/cpython/string.cpython-314t-darwin.so +0 -0
- sage/cpython/string.pxd +76 -0
- sage/cpython/string.pyx +34 -0
- sage/cpython/string_impl.h +60 -0
- sage/cpython/type.cpython-314t-darwin.so +0 -0
- sage/cpython/type.pxd +2 -0
- sage/cpython/type.pyx +40 -0
- sage/cpython/wrapperdescr.pxd +67 -0
- sage/ext/all__sagemath_objects.py +3 -0
- sage/ext/ccobject.h +64 -0
- sage/ext/cplusplus.pxd +17 -0
- sage/ext/mod_int.h +30 -0
- sage/ext/mod_int.pxd +24 -0
- sage/ext/stdsage.pxd +39 -0
- sage/groups/all__sagemath_objects.py +1 -0
- sage/groups/group.cpython-314t-darwin.so +0 -0
- sage/groups/group.pxd +14 -0
- sage/groups/group.pyx +322 -0
- sage/groups/old.cpython-314t-darwin.so +0 -0
- sage/groups/old.pxd +14 -0
- sage/groups/old.pyx +219 -0
- sage/libs/all__sagemath_objects.py +3 -0
- sage/libs/gmp/__init__.py +1 -0
- sage/libs/gmp/all.pxd +6 -0
- sage/libs/gmp/binop.pxd +23 -0
- sage/libs/gmp/misc.pxd +8 -0
- sage/libs/gmp/mpf.pxd +88 -0
- sage/libs/gmp/mpn.pxd +57 -0
- sage/libs/gmp/mpq.pxd +57 -0
- sage/libs/gmp/mpz.pxd +202 -0
- sage/libs/gmp/pylong.cpython-314t-darwin.so +0 -0
- sage/libs/gmp/pylong.pxd +12 -0
- sage/libs/gmp/pylong.pyx +150 -0
- sage/libs/gmp/random.pxd +25 -0
- sage/libs/gmp/randomize.pxd +59 -0
- sage/libs/gmp/types.pxd +53 -0
- sage/libs/gmpxx.pxd +19 -0
- sage/misc/abstract_method.py +276 -0
- sage/misc/all__sagemath_objects.py +43 -0
- sage/misc/bindable_class.py +253 -0
- sage/misc/c3_controlled.cpython-314t-darwin.so +0 -0
- sage/misc/c3_controlled.pxd +2 -0
- sage/misc/c3_controlled.pyx +1402 -0
- sage/misc/cachefunc.cpython-314t-darwin.so +0 -0
- sage/misc/cachefunc.pxd +43 -0
- sage/misc/cachefunc.pyx +3781 -0
- sage/misc/call.py +188 -0
- sage/misc/classcall_metaclass.cpython-314t-darwin.so +0 -0
- sage/misc/classcall_metaclass.pxd +14 -0
- sage/misc/classcall_metaclass.pyx +599 -0
- sage/misc/constant_function.cpython-314t-darwin.so +0 -0
- sage/misc/constant_function.pyx +130 -0
- sage/misc/decorators.py +747 -0
- sage/misc/fast_methods.cpython-314t-darwin.so +0 -0
- sage/misc/fast_methods.pxd +20 -0
- sage/misc/fast_methods.pyx +351 -0
- sage/misc/flatten.py +90 -0
- sage/misc/fpickle.cpython-314t-darwin.so +0 -0
- sage/misc/fpickle.pyx +177 -0
- sage/misc/function_mangling.cpython-314t-darwin.so +0 -0
- sage/misc/function_mangling.pxd +11 -0
- sage/misc/function_mangling.pyx +308 -0
- sage/misc/inherit_comparison.cpython-314t-darwin.so +0 -0
- sage/misc/inherit_comparison.pxd +5 -0
- sage/misc/inherit_comparison.pyx +105 -0
- sage/misc/instancedoc.cpython-314t-darwin.so +0 -0
- sage/misc/instancedoc.pyx +331 -0
- sage/misc/lazy_attribute.cpython-314t-darwin.so +0 -0
- sage/misc/lazy_attribute.pyx +607 -0
- sage/misc/lazy_format.py +135 -0
- sage/misc/lazy_import.cpython-314t-darwin.so +0 -0
- sage/misc/lazy_import.pyx +1299 -0
- sage/misc/lazy_import_cache.py +36 -0
- sage/misc/lazy_list.cpython-314t-darwin.so +0 -0
- sage/misc/lazy_list.pxd +19 -0
- sage/misc/lazy_list.pyx +1187 -0
- sage/misc/lazy_string.cpython-314t-darwin.so +0 -0
- sage/misc/lazy_string.pxd +7 -0
- sage/misc/lazy_string.pyx +546 -0
- sage/misc/misc.py +1066 -0
- sage/misc/misc_c.cpython-314t-darwin.so +0 -0
- sage/misc/misc_c.pxd +3 -0
- sage/misc/misc_c.pyx +766 -0
- sage/misc/namespace_package.py +37 -0
- sage/misc/nested_class.cpython-314t-darwin.so +0 -0
- sage/misc/nested_class.pxd +3 -0
- sage/misc/nested_class.pyx +394 -0
- sage/misc/persist.cpython-314t-darwin.so +0 -0
- sage/misc/persist.pyx +1251 -0
- sage/misc/prandom.py +418 -0
- sage/misc/randstate.cpython-314t-darwin.so +0 -0
- sage/misc/randstate.pxd +30 -0
- sage/misc/randstate.pyx +1059 -0
- sage/misc/repr.py +203 -0
- sage/misc/reset.cpython-314t-darwin.so +0 -0
- sage/misc/reset.pyx +196 -0
- sage/misc/sage_ostools.cpython-314t-darwin.so +0 -0
- sage/misc/sage_ostools.pyx +323 -0
- sage/misc/sage_timeit.py +276 -0
- sage/misc/sage_timeit_class.cpython-314t-darwin.so +0 -0
- sage/misc/sage_timeit_class.pyx +120 -0
- sage/misc/sage_unittest.py +637 -0
- sage/misc/sageinspect.py +2768 -0
- sage/misc/session.cpython-314t-darwin.so +0 -0
- sage/misc/session.pyx +392 -0
- sage/misc/superseded.py +557 -0
- sage/misc/test_nested_class.py +228 -0
- sage/misc/timing.py +264 -0
- sage/misc/unknown.py +222 -0
- sage/misc/verbose.py +253 -0
- sage/misc/weak_dict.cpython-314t-darwin.so +0 -0
- sage/misc/weak_dict.pxd +15 -0
- sage/misc/weak_dict.pyx +1231 -0
- sage/modules/all__sagemath_objects.py +1 -0
- sage/modules/module.cpython-314t-darwin.so +0 -0
- sage/modules/module.pxd +5 -0
- sage/modules/module.pyx +329 -0
- sage/rings/all__sagemath_objects.py +3 -0
- sage/rings/integer_fake.h +22 -0
- sage/rings/integer_fake.pxd +55 -0
- sage/sets/all__sagemath_objects.py +3 -0
- sage/sets/pythonclass.cpython-314t-darwin.so +0 -0
- sage/sets/pythonclass.pxd +9 -0
- sage/sets/pythonclass.pyx +247 -0
- sage/structure/__init__.py +4 -0
- sage/structure/all.py +30 -0
- sage/structure/category_object.cpython-314t-darwin.so +0 -0
- sage/structure/category_object.pxd +28 -0
- sage/structure/category_object.pyx +1087 -0
- sage/structure/coerce.cpython-314t-darwin.so +0 -0
- sage/structure/coerce.pxd +44 -0
- sage/structure/coerce.pyx +2107 -0
- sage/structure/coerce_actions.cpython-314t-darwin.so +0 -0
- sage/structure/coerce_actions.pxd +27 -0
- sage/structure/coerce_actions.pyx +988 -0
- sage/structure/coerce_dict.cpython-314t-darwin.so +0 -0
- sage/structure/coerce_dict.pxd +51 -0
- sage/structure/coerce_dict.pyx +1557 -0
- sage/structure/coerce_exceptions.py +23 -0
- sage/structure/coerce_maps.cpython-314t-darwin.so +0 -0
- sage/structure/coerce_maps.pxd +28 -0
- sage/structure/coerce_maps.pyx +718 -0
- sage/structure/debug_options.cpython-314t-darwin.so +0 -0
- sage/structure/debug_options.pxd +6 -0
- sage/structure/debug_options.pyx +54 -0
- sage/structure/dynamic_class.py +541 -0
- sage/structure/element.cpython-314t-darwin.so +0 -0
- sage/structure/element.pxd +272 -0
- sage/structure/element.pyx +4772 -0
- sage/structure/element_wrapper.cpython-314t-darwin.so +0 -0
- sage/structure/element_wrapper.pxd +12 -0
- sage/structure/element_wrapper.pyx +582 -0
- sage/structure/factorization.py +1422 -0
- sage/structure/factorization_integer.py +105 -0
- sage/structure/factory.cpython-314t-darwin.so +0 -0
- sage/structure/factory.pyx +786 -0
- sage/structure/formal_sum.py +489 -0
- sage/structure/gens_py.py +73 -0
- sage/structure/global_options.py +1743 -0
- sage/structure/indexed_generators.py +863 -0
- sage/structure/list_clone.cpython-314t-darwin.so +0 -0
- sage/structure/list_clone.pxd +65 -0
- sage/structure/list_clone.pyx +1867 -0
- sage/structure/list_clone_demo.cpython-314t-darwin.so +0 -0
- sage/structure/list_clone_demo.pyx +248 -0
- sage/structure/list_clone_timings.py +179 -0
- sage/structure/list_clone_timings_cy.cpython-314t-darwin.so +0 -0
- sage/structure/list_clone_timings_cy.pyx +86 -0
- sage/structure/mutability.cpython-314t-darwin.so +0 -0
- sage/structure/mutability.pxd +21 -0
- sage/structure/mutability.pyx +348 -0
- sage/structure/nonexact.py +69 -0
- sage/structure/parent.cpython-314t-darwin.so +0 -0
- sage/structure/parent.pxd +112 -0
- sage/structure/parent.pyx +3093 -0
- sage/structure/parent_base.cpython-314t-darwin.so +0 -0
- sage/structure/parent_base.pxd +13 -0
- sage/structure/parent_base.pyx +44 -0
- sage/structure/parent_gens.cpython-314t-darwin.so +0 -0
- sage/structure/parent_gens.pxd +22 -0
- sage/structure/parent_gens.pyx +377 -0
- sage/structure/parent_old.cpython-314t-darwin.so +0 -0
- sage/structure/parent_old.pxd +25 -0
- sage/structure/parent_old.pyx +294 -0
- sage/structure/proof/__init__.py +1 -0
- sage/structure/proof/all.py +243 -0
- sage/structure/proof/proof.py +300 -0
- sage/structure/richcmp.cpython-314t-darwin.so +0 -0
- sage/structure/richcmp.pxd +213 -0
- sage/structure/richcmp.pyx +495 -0
- sage/structure/sage_object.cpython-314t-darwin.so +0 -0
- sage/structure/sage_object.pxd +3 -0
- sage/structure/sage_object.pyx +988 -0
- sage/structure/sage_object_test.py +19 -0
- sage/structure/sequence.py +937 -0
- sage/structure/set_factories.py +1178 -0
- sage/structure/set_factories_example.py +527 -0
- sage/structure/support_view.py +179 -0
- sage/structure/test_factory.py +56 -0
- sage/structure/unique_representation.py +1359 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/* sage_setup: distribution = sagemath-objects
|
|
2
|
+
*/
|
|
3
|
+
#include "Python.h"
|
|
4
|
+
#include <stdbool.h>
|
|
5
|
+
|
|
6
|
+
#if PY_VERSION_HEX >= 0x030C00A5
|
|
7
|
+
// For Python 3.12 compatibility
|
|
8
|
+
#define ob_digit(o) (((PyLongObject*)o)->long_value.ob_digit)
|
|
9
|
+
#else
|
|
10
|
+
#define ob_digit(o) (((PyLongObject*)o)->ob_digit)
|
|
11
|
+
#endif
|
|
12
|
+
|
|
13
|
+
#if PY_VERSION_HEX >= 0x030C00A7
|
|
14
|
+
// For Python 3.12 compatibility
|
|
15
|
+
// taken from cpython:Include/internal/pycore_long.h @ 3.12
|
|
16
|
+
|
|
17
|
+
/* Long value tag bits:
|
|
18
|
+
* 0-1: Sign bits value = (1-sign), ie. negative=2, positive=0, zero=1.
|
|
19
|
+
* 2: Reserved for immortality bit
|
|
20
|
+
* 3+ Unsigned digit count
|
|
21
|
+
*/
|
|
22
|
+
#define SIGN_MASK 3
|
|
23
|
+
#define SIGN_ZERO 1
|
|
24
|
+
#define SIGN_NEGATIVE 2
|
|
25
|
+
#define NON_SIZE_BITS 3
|
|
26
|
+
|
|
27
|
+
static inline bool
|
|
28
|
+
_PyLong_IsZero(const PyLongObject *op)
|
|
29
|
+
{
|
|
30
|
+
return (op->long_value.lv_tag & SIGN_MASK) == SIGN_ZERO;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static inline bool
|
|
34
|
+
_PyLong_IsNegative(const PyLongObject *op)
|
|
35
|
+
{
|
|
36
|
+
return (op->long_value.lv_tag & SIGN_MASK) == SIGN_NEGATIVE;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static inline bool
|
|
40
|
+
_PyLong_IsPositive(const PyLongObject *op)
|
|
41
|
+
{
|
|
42
|
+
return (op->long_value.lv_tag & SIGN_MASK) == 0;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static inline Py_ssize_t
|
|
46
|
+
_PyLong_DigitCount(const PyLongObject *op)
|
|
47
|
+
{
|
|
48
|
+
assert(PyLong_Check(op));
|
|
49
|
+
return op->long_value.lv_tag >> NON_SIZE_BITS;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
#define TAG_FROM_SIGN_AND_SIZE(sign, size) ((1 - (sign)) | ((size) << NON_SIZE_BITS))
|
|
53
|
+
|
|
54
|
+
static inline void
|
|
55
|
+
_PyLong_SetSignAndDigitCount(PyLongObject *op, int sign, Py_ssize_t size)
|
|
56
|
+
{
|
|
57
|
+
assert(size >= 0);
|
|
58
|
+
assert(-1 <= sign && sign <= 1);
|
|
59
|
+
assert(sign != 0 || size == 0);
|
|
60
|
+
op->long_value.lv_tag = TAG_FROM_SIGN_AND_SIZE(sign, (size_t)size);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
#else
|
|
64
|
+
// fallback for < 3.12
|
|
65
|
+
|
|
66
|
+
static inline bool
|
|
67
|
+
_PyLong_IsZero(const PyLongObject *op)
|
|
68
|
+
{
|
|
69
|
+
return Py_SIZE(op) == 0;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static inline bool
|
|
73
|
+
_PyLong_IsNegative(const PyLongObject *op)
|
|
74
|
+
{
|
|
75
|
+
return Py_SIZE(op) < 0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
static inline bool
|
|
79
|
+
_PyLong_IsPositive(const PyLongObject *op)
|
|
80
|
+
{
|
|
81
|
+
return Py_SIZE(op) > 0;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
static inline Py_ssize_t
|
|
85
|
+
_PyLong_DigitCount(const PyLongObject *op)
|
|
86
|
+
{
|
|
87
|
+
Py_ssize_t size = Py_SIZE(op);
|
|
88
|
+
return size < 0 ? -size : size;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
static inline void
|
|
92
|
+
_PyLong_SetSignAndDigitCount(PyLongObject *op, int sign, Py_ssize_t size)
|
|
93
|
+
{
|
|
94
|
+
Py_SET_SIZE(op, sign < 0 ? -size : size);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
#endif
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-objects
|
|
2
|
+
from cpython.longintrepr cimport py_long, digit
|
|
3
|
+
|
|
4
|
+
cdef extern from "pycore_long.h":
|
|
5
|
+
digit* ob_digit(py_long o)
|
|
6
|
+
bint _PyLong_IsZero(py_long o)
|
|
7
|
+
bint _PyLong_IsNegative(py_long o)
|
|
8
|
+
bint _PyLong_IsPositive(py_long o)
|
|
9
|
+
Py_ssize_t _PyLong_DigitCount(py_long o)
|
|
10
|
+
void _PyLong_SetSignAndDigitCount(py_long o, int sign, Py_ssize_t size)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/* sage_setup: distribution = sagemath-objects
|
|
2
|
+
*/
|
|
3
|
+
/*
|
|
4
|
+
* Workaround to handle Python preprocessor macros: Translate defined /
|
|
5
|
+
* undefined into true / false
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
#include <Python.h>
|
|
10
|
+
|
|
11
|
+
#ifdef Py_DEBUG
|
|
12
|
+
#define SAGE_Py_DEBUG Py_DEBUG
|
|
13
|
+
#else
|
|
14
|
+
#define SAGE_Py_DEBUG 0
|
|
15
|
+
#endif
|
|
16
|
+
|
|
17
|
+
#ifdef Py_REF_DEBUG
|
|
18
|
+
#define SAGE_Py_REF_DEBUG Py_REF_DEBUG
|
|
19
|
+
#else
|
|
20
|
+
#define SAGE_Py_REF_DEBUG 0
|
|
21
|
+
#endif
|
|
22
|
+
|
|
23
|
+
#ifdef Py_TRACE_REFS
|
|
24
|
+
#define SAGE_Py_TRACE_REFS Py_TRACE_REFS
|
|
25
|
+
#define if_Py_TRACE_REFS_then_PyObject_INIT(obj, type) PyObject_INIT(obj, type)
|
|
26
|
+
#else
|
|
27
|
+
#define SAGE_Py_TRACE_REFS 0
|
|
28
|
+
#define if_Py_TRACE_REFS_then_PyObject_INIT(obj, type)
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
#ifdef PYMALLOC_DEBUG
|
|
32
|
+
#define SAGE_PYMALLOC_DEBUG PYMALLOC_DEBUG
|
|
33
|
+
#else
|
|
34
|
+
#define SAGE_PYMALLOC_DEBUG 0
|
|
35
|
+
#endif
|
|
36
|
+
|
|
37
|
+
#ifdef WITH_PYMALLOC
|
|
38
|
+
#define SAGE_WITH_PYMALLOC PYMALLOC_DEBUG
|
|
39
|
+
#else
|
|
40
|
+
#define SAGE_WITH_PYMALLOC 0
|
|
41
|
+
#endif
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-objects
|
|
2
|
+
# Python can be built with extensive debugging support. This file lets
|
|
3
|
+
# Sage know about which debugging options are enabled.
|
|
4
|
+
#
|
|
5
|
+
# To enable debugging, build Sage with the SAGE_DEBUG environment
|
|
6
|
+
# variable set to "yes":
|
|
7
|
+
#
|
|
8
|
+
# [user@localhost:~/sage-x.y.z] export SAGE_DEBUG=yes && make
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
from cpython.ref cimport PyObject, PyTypeObject
|
|
12
|
+
|
|
13
|
+
cdef extern from "python_debug.h":
|
|
14
|
+
|
|
15
|
+
# This is what is generally meant by "a debug build" of Python.
|
|
16
|
+
# Implies Py_REF_DEBUG, Py_TRACE_REFS, and PYMALLOC_DEBUG (if
|
|
17
|
+
# WITH_PYMALLOC is enabled). In addition, C assert()s are enabled.
|
|
18
|
+
cdef bint Py_DEBUG "SAGE_Py_DEBUG"
|
|
19
|
+
|
|
20
|
+
# Turn on aggregate reference counting. This arranges that extern
|
|
21
|
+
# _Py_RefTotal hold a count of all references, the sum of
|
|
22
|
+
# ob_refcnt across all objects. Also checks after every decref to
|
|
23
|
+
# verify that the refcount hasn't gone negative, and causes an
|
|
24
|
+
# immediate fatal error if it has.
|
|
25
|
+
cdef bint Py_REF_DEBUG "SAGE_Py_REF_DEBUG"
|
|
26
|
+
|
|
27
|
+
# Heavy reference debugging. Every PyObject grows two more
|
|
28
|
+
# pointers, to maintain a doubly-linked list of all live
|
|
29
|
+
# heap-allocated objects. Implies Py_REF_DEBUG.
|
|
30
|
+
cdef bint Py_TRACE_REFS "SAGE_Py_TRACE_REFS"
|
|
31
|
+
|
|
32
|
+
# Conditionally call PyObject_INIT() if Py_TRACE_REFS is
|
|
33
|
+
# enabled. This is necessary to initialize the aforementioned
|
|
34
|
+
# double-linked list.
|
|
35
|
+
void if_Py_TRACE_REFS_then_PyObject_INIT(PyObject *, PyTypeObject *)
|
|
36
|
+
|
|
37
|
+
# When this is enabled, calls to the PyObject_ memory routines are
|
|
38
|
+
# handled by Python's own small-object allocator, while calls to
|
|
39
|
+
# the PyMem_ memory routines are directed to the system malloc/
|
|
40
|
+
# realloc/free.
|
|
41
|
+
cdef bint WITH_PYMALLOC "SAGE_WITH_PYMALLOC"
|
|
42
|
+
|
|
43
|
+
# If this is also defined in addition to WITH_PYMALLOC, calls to
|
|
44
|
+
# both PyObject_ and PyMem_ memory routines are directed to a
|
|
45
|
+
# special debugging mode of Python's small-object
|
|
46
|
+
# allocator. Requires WITH_PYMALLOC.
|
|
47
|
+
cdef bint PYMALLOC_DEBUG "SAGE_PYMALLOC_DEBUG"
|
sage/cpython/pyx_visit.h
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* sage_setup: distribution = sagemath-objects
|
|
2
|
+
*/
|
|
3
|
+
/* 3-argument version of Py_VISIT, easier to use from Cython */
|
|
4
|
+
|
|
5
|
+
#define Py_VISIT3(op, visit, arg) \
|
|
6
|
+
do { \
|
|
7
|
+
if (op) { \
|
|
8
|
+
int vret = visit((PyObject *)(op), arg); \
|
|
9
|
+
if (vret) \
|
|
10
|
+
return vret; \
|
|
11
|
+
} \
|
|
12
|
+
} while (0)
|
|
13
|
+
|
|
Binary file
|
sage/cpython/string.pxd
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-objects
|
|
2
|
+
# ****************************************************************************
|
|
3
|
+
# Copyright (C) 2017 Erik M. Bray <erik.bray@lri.fr>
|
|
4
|
+
#
|
|
5
|
+
# This program is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 2 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
# https://www.gnu.org/licenses/
|
|
10
|
+
# ****************************************************************************
|
|
11
|
+
|
|
12
|
+
cdef extern from "string_impl.h":
|
|
13
|
+
str _cstr_to_str(const char* c, encoding, errors)
|
|
14
|
+
bytes _str_to_bytes(s, encoding, errors)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
cdef inline str char_to_str(const char* c, encoding=None, errors=None):
|
|
18
|
+
r"""
|
|
19
|
+
Convert a C string to a Python ``str``.
|
|
20
|
+
"""
|
|
21
|
+
# Implemented in C to avoid relying on PY_MAJOR_VERSION
|
|
22
|
+
# compile-time variable. We keep the Cython wrapper to deal with
|
|
23
|
+
# the default arguments.
|
|
24
|
+
return _cstr_to_str(c, encoding, errors)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
cpdef inline str bytes_to_str(b, encoding=None, errors=None):
|
|
28
|
+
r"""
|
|
29
|
+
Convert ``bytes`` to ``str``.
|
|
30
|
+
|
|
31
|
+
This decodes the given ``bytes`` to a Python 3 unicode ``str`` using
|
|
32
|
+
the specified encoding. It is a no-op on ``str`` input.
|
|
33
|
+
|
|
34
|
+
EXAMPLES::
|
|
35
|
+
|
|
36
|
+
sage: from sage.cpython.string import bytes_to_str
|
|
37
|
+
sage: s = bytes_to_str(b'\xcf\x80')
|
|
38
|
+
sage: s == u'π'
|
|
39
|
+
True
|
|
40
|
+
sage: bytes_to_str([])
|
|
41
|
+
Traceback (most recent call last):
|
|
42
|
+
...
|
|
43
|
+
TypeError: expected bytes, list found
|
|
44
|
+
"""
|
|
45
|
+
if isinstance(b, str):
|
|
46
|
+
return b
|
|
47
|
+
if type(b) is not bytes:
|
|
48
|
+
raise TypeError(f"expected bytes, {type(b).__name__} found")
|
|
49
|
+
|
|
50
|
+
return _cstr_to_str(<bytes>b, encoding, errors)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
cpdef inline bytes str_to_bytes(s, encoding=None, errors=None):
|
|
54
|
+
r"""
|
|
55
|
+
Convert ``str`` or ``unicode`` to ``bytes``.
|
|
56
|
+
|
|
57
|
+
It encodes the given ``str`` to a Python 3 ``bytes``
|
|
58
|
+
using the specified encoding. It is a no-op on ``bytes`` input.
|
|
59
|
+
|
|
60
|
+
EXAMPLES::
|
|
61
|
+
|
|
62
|
+
sage: from sage.cpython.string import str_to_bytes
|
|
63
|
+
sage: bs = [str_to_bytes(u'π')]
|
|
64
|
+
sage: all(b == b'\xcf\x80' for b in bs)
|
|
65
|
+
True
|
|
66
|
+
sage: str_to_bytes([])
|
|
67
|
+
Traceback (most recent call last):
|
|
68
|
+
...
|
|
69
|
+
TypeError: expected str... list found
|
|
70
|
+
"""
|
|
71
|
+
# Implemented in C to avoid relying on PY_MAJOR_VERSION
|
|
72
|
+
# compile-time variable. We keep the Cython wrapper to deal with
|
|
73
|
+
# the default arguments.
|
|
74
|
+
if isinstance(s, bytes):
|
|
75
|
+
return s
|
|
76
|
+
return _str_to_bytes(s, encoding, errors)
|
sage/cpython/string.pyx
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-objects
|
|
2
|
+
"""
|
|
3
|
+
String <-> bytes encoding/decoding
|
|
4
|
+
|
|
5
|
+
TESTS:
|
|
6
|
+
|
|
7
|
+
Check that this can be used outside of Sage (see :issue:`25549`)::
|
|
8
|
+
|
|
9
|
+
sage: cython( # needs sage.misc.cython
|
|
10
|
+
....: '''
|
|
11
|
+
....: from sage.cpython.string cimport char_to_str
|
|
12
|
+
....: print(char_to_str("hello world!"))
|
|
13
|
+
....: ''')
|
|
14
|
+
hello world!
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
# ****************************************************************************
|
|
18
|
+
# Copyright (C) 2017 Erik M. Bray <erik.bray@lri.fr>
|
|
19
|
+
#
|
|
20
|
+
# This program is free software: you can redistribute it and/or modify
|
|
21
|
+
# it under the terms of the GNU General Public License as published by
|
|
22
|
+
# the Free Software Foundation, either version 2 of the License, or
|
|
23
|
+
# (at your option) any later version.
|
|
24
|
+
# https://www.gnu.org/licenses/
|
|
25
|
+
# ****************************************************************************
|
|
26
|
+
|
|
27
|
+
import sys
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# Provide this as a shortcut to calling sys.getfilesystemencoding(), which
|
|
31
|
+
# after interpreter initialization is constant.
|
|
32
|
+
FS_ENCODING = sys.getfilesystemencoding()
|
|
33
|
+
|
|
34
|
+
# Functions in this module are implemented in the .pxd file for inlining.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/* sage_setup: distribution = sagemath-objects
|
|
2
|
+
*/
|
|
3
|
+
/*****************************************************************************
|
|
4
|
+
# Copyright (C) 2017 Erik M. Bray <erik.bray@lri.fr>
|
|
5
|
+
# Copyright (C) 2018 Jeroen Demeyer <J.Demeyer@UGent.be>
|
|
6
|
+
#
|
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
|
8
|
+
# it under the terms of the GNU General Public License as published by
|
|
9
|
+
# the Free Software Foundation, either version 2 of the License, or
|
|
10
|
+
# (at your option) any later version.
|
|
11
|
+
# https://www.gnu.org/licenses/
|
|
12
|
+
*****************************************************************************/
|
|
13
|
+
|
|
14
|
+
#include <Python.h>
|
|
15
|
+
#include <string.h>
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
static inline PyObject* _cstr_to_str(const char* c, PyObject* encoding, PyObject* errors)
|
|
19
|
+
{
|
|
20
|
+
const char* err = NULL; // Default: strict
|
|
21
|
+
const char* enc = NULL; // Default: utf-8
|
|
22
|
+
|
|
23
|
+
if (errors != Py_None) {
|
|
24
|
+
err = PyUnicode_AsUTF8(errors);
|
|
25
|
+
if (!err) return NULL;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (encoding != Py_None) {
|
|
29
|
+
enc = PyUnicode_AsUTF8(encoding);
|
|
30
|
+
if (!enc) return NULL;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return PyUnicode_Decode(c, strlen(c), enc, err);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
static inline PyObject* _str_to_bytes(PyObject* s, PyObject* encoding, PyObject* errors)
|
|
38
|
+
{
|
|
39
|
+
if (!PyUnicode_Check(s)) {
|
|
40
|
+
PyErr_Format(PyExc_TypeError,
|
|
41
|
+
"expected str, %s found",
|
|
42
|
+
Py_TYPE(s)->tp_name);
|
|
43
|
+
return NULL;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const char* err = NULL; // Default: strict
|
|
47
|
+
const char* enc = NULL; // Default: utf-8
|
|
48
|
+
|
|
49
|
+
if (errors != Py_None) {
|
|
50
|
+
err = PyUnicode_AsUTF8(errors);
|
|
51
|
+
if (!err) return NULL;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (encoding != Py_None) {
|
|
55
|
+
enc = PyUnicode_AsUTF8(encoding);
|
|
56
|
+
if (!enc) return NULL;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return PyUnicode_AsEncodedString(s, enc, err);
|
|
60
|
+
}
|
|
Binary file
|
sage/cpython/type.pxd
ADDED
sage/cpython/type.pyx
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-objects
|
|
2
|
+
"""
|
|
3
|
+
Type internals
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from cpython.object cimport Py_TYPE, PyTypeObject, Py_TPFLAGS_HEAPTYPE
|
|
7
|
+
|
|
8
|
+
cdef PyTypeObject* PyInstance_Type = NULL
|
|
9
|
+
try:
|
|
10
|
+
from types import InstanceType
|
|
11
|
+
PyInstance_Type = <PyTypeObject*>InstanceType
|
|
12
|
+
except ImportError:
|
|
13
|
+
pass
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
cpdef bint can_assign_class(obj) noexcept:
|
|
17
|
+
"""
|
|
18
|
+
Can we assign ``obj.__class__``?
|
|
19
|
+
|
|
20
|
+
Note that Python 3.5 has experimented with allowing assigning
|
|
21
|
+
``__class__`` in more cases but this was mostly reverted. In this
|
|
22
|
+
function, we apply the Python 2.7 semantics.
|
|
23
|
+
|
|
24
|
+
EXAMPLES::
|
|
25
|
+
|
|
26
|
+
sage: class X: pass
|
|
27
|
+
sage: from sage.cpython.type import can_assign_class
|
|
28
|
+
sage: can_assign_class(X())
|
|
29
|
+
True
|
|
30
|
+
sage: class Y(int): pass
|
|
31
|
+
sage: from sage.cpython.type import can_assign_class
|
|
32
|
+
sage: can_assign_class(Y())
|
|
33
|
+
True
|
|
34
|
+
sage: can_assign_class(1)
|
|
35
|
+
False
|
|
36
|
+
"""
|
|
37
|
+
cdef PyTypeObject* tp = Py_TYPE(obj)
|
|
38
|
+
if tp is PyInstance_Type:
|
|
39
|
+
return True
|
|
40
|
+
return (tp.tp_flags & Py_TPFLAGS_HEAPTYPE) != 0
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-objects
|
|
2
|
+
from cpython.object cimport PyObject, PyTypeObject
|
|
3
|
+
|
|
4
|
+
cdef extern from *:
|
|
5
|
+
ctypedef object (*wrapperfunc)(self, args, void* wrapped)
|
|
6
|
+
ctypedef object (*wrapperfunc_kwds)(self, args, void* wrapped, kwds)
|
|
7
|
+
|
|
8
|
+
struct wrapperbase:
|
|
9
|
+
char* name
|
|
10
|
+
int offset
|
|
11
|
+
void* function
|
|
12
|
+
wrapperfunc wrapper
|
|
13
|
+
char* doc
|
|
14
|
+
int flags
|
|
15
|
+
PyObject* name_strobj
|
|
16
|
+
|
|
17
|
+
int PyWrapperFlag_KEYWORDS
|
|
18
|
+
|
|
19
|
+
ctypedef class sage.cpython.builtin_types.wrapper_descriptor [object PyWrapperDescrObject]:
|
|
20
|
+
cdef type d_type
|
|
21
|
+
cdef d_name
|
|
22
|
+
cdef wrapperbase* d_base
|
|
23
|
+
cdef void* d_wrapped
|
|
24
|
+
|
|
25
|
+
PyDescr_NewWrapper(PyTypeObject* cls, wrapperbase* wrapper, void* wrapped)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
cdef wrapperdescr_fastcall(wrapper_descriptor slotwrapper, self, args, kwds)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
cdef inline wrapperbase* get_slotdef(wrapper_descriptor slotwrapper) except NULL:
|
|
32
|
+
"""
|
|
33
|
+
Given a slot wrapper, return the corresponding ``slotdef``.
|
|
34
|
+
|
|
35
|
+
A ``slotdef`` is associated to a specific slot like ``__eq__``
|
|
36
|
+
and does not depend at all on the type. In other words, calling
|
|
37
|
+
``get_slotdef(t.__eq__)`` will return the same ``slotdef``
|
|
38
|
+
independent of the type ``t`` (provided that the type implements
|
|
39
|
+
rich comparison in C).
|
|
40
|
+
|
|
41
|
+
TESTS::
|
|
42
|
+
|
|
43
|
+
sage: # needs sage.misc.cython
|
|
44
|
+
sage: cython(
|
|
45
|
+
....: '''
|
|
46
|
+
....: from sage.cpython.wrapperdescr cimport get_slotdef
|
|
47
|
+
....: from cpython.long cimport PyLong_FromVoidPtr
|
|
48
|
+
....: def py_get_slotdef(slotwrapper):
|
|
49
|
+
....: return PyLong_FromVoidPtr(get_slotdef(slotwrapper))
|
|
50
|
+
....: ''')
|
|
51
|
+
sage: py_get_slotdef(object.__init__) # random
|
|
52
|
+
140016903442416
|
|
53
|
+
sage: py_get_slotdef(bytes.__lt__) # random
|
|
54
|
+
140016903441800
|
|
55
|
+
sage: py_get_slotdef(bytes.__lt__) == py_get_slotdef(Integer.__lt__)
|
|
56
|
+
True
|
|
57
|
+
sage: py_get_slotdef(bytes.__lt__) == py_get_slotdef(bytes.__gt__)
|
|
58
|
+
False
|
|
59
|
+
sage: class X():
|
|
60
|
+
....: def __eq__(self, other):
|
|
61
|
+
....: return False
|
|
62
|
+
sage: py_get_slotdef(X.__eq__)
|
|
63
|
+
Traceback (most recent call last):
|
|
64
|
+
...
|
|
65
|
+
TypeError: Cannot convert ... to wrapper_descriptor
|
|
66
|
+
"""
|
|
67
|
+
return slotwrapper.d_base
|
sage/ext/ccobject.h
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/* sage_setup: distribution = sagemath-objects
|
|
2
|
+
*/
|
|
3
|
+
#ifndef __SAGE_CCOBJECT_H__
|
|
4
|
+
#define __SAGE_CCOBJECT_H__
|
|
5
|
+
|
|
6
|
+
#ifdef __cplusplus
|
|
7
|
+
|
|
8
|
+
#include <iostream>
|
|
9
|
+
#include <sstream>
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
template <class T>
|
|
13
|
+
static CYTHON_INLINE int ccreadstr(T& x, PyObject* b)
|
|
14
|
+
{
|
|
15
|
+
PyObject* converted = NULL;
|
|
16
|
+
|
|
17
|
+
// Accept "str" input
|
|
18
|
+
if (PyUnicode_Check(b))
|
|
19
|
+
{
|
|
20
|
+
converted = PyUnicode_EncodeFSDefault(b);
|
|
21
|
+
if (!converted) {return -1;}
|
|
22
|
+
b = converted;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
char* buffer;
|
|
26
|
+
Py_ssize_t length;
|
|
27
|
+
|
|
28
|
+
if (PyBytes_AsStringAndSize(b, &buffer, &length) == -1)
|
|
29
|
+
{Py_XDECREF(converted); return -1;}
|
|
30
|
+
std::istringstream input(std::string(buffer, length));
|
|
31
|
+
Py_XDECREF(converted);
|
|
32
|
+
|
|
33
|
+
input >> x;
|
|
34
|
+
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
template <class T>
|
|
40
|
+
static CYTHON_INLINE PyObject* ccrepr(const T& x)
|
|
41
|
+
{
|
|
42
|
+
std::ostringstream instore;
|
|
43
|
+
instore << x;
|
|
44
|
+
std::string instr = instore.str();
|
|
45
|
+
return PyUnicode_DecodeFSDefaultAndSize(instr.c_str(), instr.size());
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
/* Arrays */
|
|
50
|
+
template <class T>
|
|
51
|
+
static inline T* Allocate_array(size_t n)
|
|
52
|
+
{
|
|
53
|
+
return new T[n];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
template <class T>
|
|
57
|
+
static inline void Delete_array(T* v)
|
|
58
|
+
{
|
|
59
|
+
delete[] v;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
#endif
|
|
63
|
+
|
|
64
|
+
#endif /* ifndef __SAGE_CCOBJECT_H__ */
|
sage/ext/cplusplus.pxd
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-objects
|
|
2
|
+
# ***************************************************************************
|
|
3
|
+
# Copyright (C) 2017 Jeroen Demeyer <J.Demeyer@UGent.be>
|
|
4
|
+
#
|
|
5
|
+
# This program is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 2 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
# https://www.gnu.org/licenses/
|
|
10
|
+
# ***************************************************************************
|
|
11
|
+
|
|
12
|
+
cdef extern from "ccobject.h":
|
|
13
|
+
# Print representation of any C++ object
|
|
14
|
+
str ccrepr[T](const T& x)
|
|
15
|
+
|
|
16
|
+
# Read a Python bytes/str into a C++ object
|
|
17
|
+
int ccreadstr[T](T x, object b) except -1
|
sage/ext/mod_int.h
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* sage_setup: distribution = sagemath-objects
|
|
2
|
+
*/
|
|
3
|
+
/* See mod_int.pxd if you want to use these declarations in Cython */
|
|
4
|
+
|
|
5
|
+
/* CPython using signed long as the data type for plain integers, which is
|
|
6
|
+
* - 8 bytes on 64-bit Linux and OSX
|
|
7
|
+
* - 4 bytes on 64-bit Windows and all 32-bit supported platforms.
|
|
8
|
+
* If you want to convert mod_int quickly to Python, then it must fit
|
|
9
|
+
* into such an integer. Otherwise you'll end up with Python's
|
|
10
|
+
* arbitrary-size integers instead of machine ints.
|
|
11
|
+
*
|
|
12
|
+
* However, 4 bytes is rather small and one can quickly run out of
|
|
13
|
+
* primes, especially if the problem has many bad primes. See Trac
|
|
14
|
+
* #10281 for details.
|
|
15
|
+
*
|
|
16
|
+
* Hence, we use signed 64-bit ints. This gives us fast conversion
|
|
17
|
+
* to/from Python on 64-bit Linux and OSX, and a large number of
|
|
18
|
+
* available (but not quite as fast) primes on 64-bit Windows and all
|
|
19
|
+
* 32-bit platforms (see Issue #10281)
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
typedef int64_t mod_int;
|
|
23
|
+
|
|
24
|
+
/* The largest value we can do arithmetic on without risking overflowing.
|
|
25
|
+
* That is, you can multiply two MOD_INT_MAX in a mod_int.
|
|
26
|
+
*/
|
|
27
|
+
#define MOD_INT_OVERFLOW_UNSIGNED ((((uint64_t)1) << (sizeof(mod_int)*8 - 1)) - 1)
|
|
28
|
+
#define MOD_INT_OVERFLOW ((mod_int)MOD_INT_OVERFLOW_UNSIGNED)
|
|
29
|
+
#define MOD_INT_MAX ((mod_int)sqrt(MOD_INT_OVERFLOW_UNSIGNED) - 1)
|
|
30
|
+
|
sage/ext/mod_int.pxd
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-objects
|
|
2
|
+
"""
|
|
3
|
+
The `mod_int` Data Type
|
|
4
|
+
|
|
5
|
+
* In C/C++ headers, you can `#include "mod_int.h"`
|
|
6
|
+
* In Cython files, use `from sage.ext.mod_int cimport *`
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
# ***************************************************************************
|
|
10
|
+
# Copyright (C) 2013 Volker Braun <vbraun.name@gmail.com>
|
|
11
|
+
# Copyright (C) 2013 William Stein <wstein@gmail.com>
|
|
12
|
+
#
|
|
13
|
+
# This program is free software: you can redistribute it and/or modify
|
|
14
|
+
# it under the terms of the GNU General Public License as published by
|
|
15
|
+
# the Free Software Foundation, either version 2 of the License, or
|
|
16
|
+
# (at your option) any later version.
|
|
17
|
+
# https://www.gnu.org/licenses/
|
|
18
|
+
# ***************************************************************************
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
cdef extern from "mod_int.h":
|
|
22
|
+
ctypedef long mod_int
|
|
23
|
+
mod_int MOD_INT_MAX
|
|
24
|
+
mod_int MOD_INT_OVERFLOW
|
sage/ext/stdsage.pxd
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-objects
|
|
2
|
+
"""
|
|
3
|
+
Standard C helper code for Cython modules
|
|
4
|
+
"""
|
|
5
|
+
# ***************************************************************************
|
|
6
|
+
# Copyright (C) 2015 Jeroen Demeyer <jdemeyer@cage.ugent.be>
|
|
7
|
+
#
|
|
8
|
+
# Distributed under the terms of the GNU General Public License (GPL)
|
|
9
|
+
# as published by the Free Software Foundation; either version 2 of
|
|
10
|
+
# the License, or (at your option) any later version.
|
|
11
|
+
# https://www.gnu.org/licenses/
|
|
12
|
+
# ***************************************************************************
|
|
13
|
+
|
|
14
|
+
from cpython.object cimport Py_TYPE, PyTypeObject, PyObject
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
cdef inline PY_NEW(type t):
|
|
18
|
+
"""
|
|
19
|
+
Return ``t.__new__(t)``. This works even for types like
|
|
20
|
+
:class:`Integer` where we change ``tp_new`` at runtime (Cython
|
|
21
|
+
optimizations assume that ``tp_new`` doesn't change).
|
|
22
|
+
"""
|
|
23
|
+
return (<PyTypeObject*>t).tp_new(t, <PyObject*>NULL, <PyObject*>NULL)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
cdef inline void PY_SET_TP_NEW(type dst, type src) noexcept:
|
|
27
|
+
"""
|
|
28
|
+
Manually set ``dst.__new__`` to ``src.__new__``. This is used to
|
|
29
|
+
speed up Cython's boilerplate object construction code by skipping
|
|
30
|
+
irrelevant base class ``tp_new`` methods.
|
|
31
|
+
"""
|
|
32
|
+
(<PyTypeObject*>dst).tp_new = (<PyTypeObject*>src).tp_new
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
cdef inline bint HAS_DICTIONARY(obj) noexcept:
|
|
36
|
+
"""
|
|
37
|
+
Test whether the given object has a Python dictionary.
|
|
38
|
+
"""
|
|
39
|
+
return Py_TYPE(obj).tp_dictoffset != 0
|