Debian Codegraph @

pypy/module/sys/system.py

raw symbols SCIP
1 """Information about the current system."""
2 import sys
3 import os
4
5 from pypy.objspace.std.complexobject import HASH_IMAG
6 from pypy.objspace.std.floatobject import HASH_INF, HASH_NAN
7 from pypy.objspace.std.intobject import HASH_MODULUS
8 from pypy.interpreter import gateway
9 from rpython.rlib import rbigint, rfloat
10 from rpython.rtyper.lltypesystem import lltype, rffi
11
12 PLATFORM = 'linux' if sys.platform.startswith('linux') else sys.platform
13
14 DEFAULT_MAX_STR_DIGITS = 4300
15 MAX_STR_DIGITS_THRESHOLD = 640
16
17 if DEFAULT_MAX_STR_DIGITS != 0 and DEFAULT_MAX_STR_DIGITS < MAX_STR_DIGITS_THRESHOLD:
18 raise RuntimeError("DEFAULT_MAX_STR_DIGITS is smaller than MAX_STR_DIGITS_THRESHOLD")
19
20 app = gateway.applevel("""
21 "NOT_RPYTHON"
22 from _structseq import structseqtype, structseqfield
23 class float_info(metaclass=structseqtype):
24
25 max = structseqfield(0)
26 max_exp = structseqfield(1)
27 max_10_exp = structseqfield(2)
28 min = structseqfield(3)
29 min_exp = structseqfield(4)
30 min_10_exp = structseqfield(5)
31 dig = structseqfield(6)
32 mant_dig = structseqfield(7)
33 epsilon = structseqfield(8)
34 radix = structseqfield(9)
35 rounds = structseqfield(10)
36
37 class int_info(metaclass=structseqtype):
38 bits_per_digit = structseqfield(0)
39 sizeof_digit = structseqfield(1)
40 default_max_str_digits = structseqfield(2)
41 str_digits_check_threshold = structseqfield(3)
42
43 class hash_info(metaclass=structseqtype):
44 __module__ = 'sys'
45 name = 'sys.hash_info'
46 width = structseqfield(0)
47 modulus = structseqfield(1)
48 inf = structseqfield(2)
49 nan = structseqfield(3)
50 imag = structseqfield(4)
51 algorithm = structseqfield(5)
52 hash_bits = structseqfield(6)
53 seed_bits = structseqfield(7)
54 cutoff = structseqfield(8)
55
56 class thread_info(metaclass=structseqtype):
57 name = structseqfield(0)
58 lock = structseqfield(1)
59 version = structseqfield(2)
60 """)
61
62
63 def get_float_info(space):
64 info_w = [
65 space.newfloat(rfloat.DBL_MAX),
66 space.newint(rfloat.DBL_MAX_EXP),
67 space.newint(rfloat.DBL_MAX_10_EXP),
68 space.newfloat(rfloat.DBL_MIN),
69 space.newint(rfloat.DBL_MIN_EXP),
70 space.newint(rfloat.DBL_MIN_10_EXP),
71 space.newint(rfloat.DBL_DIG),
72 space.newint(rfloat.DBL_MANT_DIG),
73 space.newfloat(rfloat.DBL_EPSILON),
74 space.newint(rfloat.FLT_RADIX),
75 space.newint(rfloat.FLT_ROUNDS),
76 ]
77 w_float_info = app.wget(space, "float_info")
78 return space.call_function(w_float_info, space.newtuple(info_w))
79
80 def get_int_info(space):
81 bits_per_digit = rbigint.SHIFT
82 sizeof_digit = rffi.sizeof(rbigint.STORE_TYPE)
83 info_w = [
84 space.newint(bits_per_digit),
85 space.newint(sizeof_digit),
86 space.newint(DEFAULT_MAX_STR_DIGITS),
87 space.newint(MAX_STR_DIGITS_THRESHOLD),
88 ]
89 w_int_info = app.wget(space, "int_info")
90 return space.call_function(w_int_info, space.newtuple(info_w))
91
92 def get_hash_info(space):
93 HASH_ALGORITHM = space.config.objspace.hash
94 if space.config.objspace.hash == "fnv":
95 HASH_HASH_BITS = 8 * rffi.sizeof(lltype.Signed)
96 HASH_SEED_BITS = 0
97 # CPython has ^ > 0 here, but the seed of "fnv" is of limited
98 # use, so we don't implement it
99 elif space.config.objspace.hash == "siphash24":
100 HASH_HASH_BITS = 64
101 HASH_SEED_BITS = 128
102 else:
103 assert 0, "please add the parameters for this different hash function"
104
105 HASH_WIDTH = 8 * rffi.sizeof(lltype.Signed)
106 HASH_CUTOFF = 0
107 info_w = [
108 space.newint(HASH_WIDTH),
109 space.newint(HASH_MODULUS),
110 space.newint(HASH_INF),
111 space.newint(HASH_NAN),
112 space.newint(HASH_IMAG),
113 space.newtext(HASH_ALGORITHM),
114 space.newint(HASH_HASH_BITS),
115 space.newint(HASH_SEED_BITS),
116 space.newint(HASH_CUTOFF),
117 ]
118 w_hash_info = app.wget(space, "hash_info")
119 return space.call_function(w_hash_info, space.newtuple(info_w))
120
121 def get_float_repr_style(space):
122 return space.newtext("short")
123
124 def get_thread_info(space):
125 if not space.config.objspace.usemodules.thread:
126 return None
127 from rpython.rlib import rthread
128 w_version = space.w_None
129 if rthread.RPYTHREAD_NAME == "pthread":
130 w_lock = space.newtext("semaphore" if rthread.USE_SEMAPHORES
131 else "mutex+cond")
132 if rthread.CS_GNU_LIBPTHREAD_VERSION is not None:
133 try:
134 name = os.confstr(rthread.CS_GNU_LIBPTHREAD_VERSION)
135 except OSError:
136 pass
137 else:
138 w_version = space.newtext(name)
139 else:
140 w_lock = space.w_None
141 info_w = [
142 space.newtext(rthread.RPYTHREAD_NAME),
143 w_lock, w_version,
144 ]
145 w_thread_info = app.wget(space, "thread_info")
146 return space.call_function(w_thread_info, space.newtuple(info_w))
147
148 def getdlopenflags(space):
149 return space.newint(space.sys.dlopenflags)
150
151 def setdlopenflags(space, w_flags):
152 space.sys.dlopenflags = space.int_w(w_flags)