regina 7.3.0__cp310-cp310-macosx_11_0_arm64.whl → 7.3.1.1__cp310-cp310-macosx_11_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 regina might be problematic. Click here for more details.

@@ -1,229 +0,0 @@
1
-
2
- /**************************************************************************
3
- * *
4
- * Regina - A Normal Surface Theory Calculator *
5
- * Python Interface *
6
- * *
7
- * Copyright (c) 1999-2023, Ben Burton *
8
- * For further details contact Ben Burton (bab@debian.org). *
9
- * *
10
- * This program is free software; you can redistribute it and/or *
11
- * modify it under the terms of the GNU General Public License as *
12
- * published by the Free Software Foundation; either version 2 of the *
13
- * License, or (at your option) any later version. *
14
- * *
15
- * As an exception, when this program is distributed through (i) the *
16
- * App Store by Apple Inc.; (ii) the Mac App Store by Apple Inc.; or *
17
- * (iii) Google Play by Google Inc., then that store may impose any *
18
- * digital rights management, device limits and/or redistribution *
19
- * restrictions that are required by its terms of service. *
20
- * *
21
- * This program is distributed in the hope that it will be useful, but *
22
- * WITHOUT ANY WARRANTY; without even the implied warranty of *
23
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
24
- * General Public License for more details. *
25
- * *
26
- * You should have received a copy of the GNU General Public *
27
- * License along with this program; if not, write to the Free *
28
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
29
- * MA 02110-1301, USA. *
30
- * *
31
- **************************************************************************/
32
-
33
- #include "../gui/pythoninterpreter.h"
34
- #include "../gui/pythonoutputstream.h"
35
- #include <fstream>
36
- #include <iostream>
37
- #include <condition_variable>
38
- #include <thread>
39
-
40
- /**
41
- * This is a very basic Python interpreter, designed to test scenarios
42
- * where Python is embedded in a C++ program. It processes input commands
43
- * one line at a time (so even if a script is passed via the command line,
44
- * it behaves as though the input were interactive).
45
- *
46
- * If -t <seconds> is passed, the interpreter runs under a strict time limit:
47
- * it will exit with non-zero error status if the given time limit is exceeded.
48
- * This is so that deadlock scenarios can be detected and reported effectively.
49
- *
50
- * The main reason for having this basic interpreter is so we can more easily
51
- * test for problems that might occur in the Qt GUI (e.g., problems related to
52
- * multithreading, or subinterpreters, or the global interpreter lock).
53
- *
54
- * This interpreter is designed to be run directly out of the source tree.
55
- * It does not set LD_LIBRARY_PATH, PYTHONHOME or PYTHONPATH at all; it is
56
- * up to whoever calls this interpreter to set these paths appropriately.
57
- */
58
-
59
- long timeout = 0; // measured in seconds
60
- bool mainThread = true;
61
-
62
- std::condition_variable cond; // used with timeout mechanism
63
- bool finished = false;
64
- std::mutex mutex; // guards finished and cond
65
-
66
- class NativeOutputStream : public regina::python::PythonOutputStream {
67
- private:
68
- std::ostream& stream_;
69
-
70
- public:
71
- NativeOutputStream(std::ostream& stream) : stream_(stream) {}
72
-
73
- protected:
74
- virtual void processOutput(const std::string& data) override {
75
- stream_ << data;
76
- stream_.flush();
77
- }
78
- };
79
-
80
- void usage(const char* progName, const std::string& error = std::string()) {
81
- if (! error.empty())
82
- std::cerr << error << "\n\n";
83
-
84
- std::cerr << "Usage:\n";
85
- std::cerr << " " << progName << " [ -m ] [ -t <seconds> ] [ <commands> ]\n";
86
- std::cerr << " " << progName << " -v\n";
87
- std::cerr << std::endl;
88
- std::cerr << " -m : Execute commands in a different thread\n";
89
- std::cerr << " -t : Timeout after the given number of seconds\n";
90
- std::cerr << " -v : Output the Python version being used\n";
91
- std::cerr << std::endl;
92
- std::cerr << " <script> : Read commands line-by-line from the "
93
- "given file (otherwise\n";
94
- std::cerr << " uses standard input)\n";
95
- exit(1);
96
- }
97
-
98
- void watcher() {
99
- std::unique_lock<std::mutex> lock(mutex);
100
-
101
- // At this point, either finished is true, or else the main thread
102
- // will not be able to notify the condition variable until *after*
103
- // we wait (thus ensuring we will be properly woken up).
104
-
105
- if (finished)
106
- return;
107
-
108
- if (cond.wait_for(lock, std::chrono::seconds(timeout)) ==
109
- std::cv_status::timeout) {
110
- std::cerr << "ERROR: Timed out after " << timeout << "s." << std::endl;
111
-
112
- // We assume the python code is deadlocked; we will not be able to
113
- // clean up Python properly.
114
- exit(3);
115
- }
116
- }
117
-
118
- void run(regina::python::PythonInterpreter& py, std::istream& input) {
119
- std::string line;
120
- while (input) {
121
- std::getline(input, line);
122
- if (mainThread) {
123
- py.executeLine(line);
124
- } else {
125
- std::thread([&]() {
126
- py.executeLine(line);
127
- }).join();
128
- }
129
- }
130
- }
131
-
132
- int main(int argc, char* argv[]) {
133
- std::string input;
134
-
135
- for (int i = 1; i < argc; ++i) {
136
- if (*argv[i] == '-') {
137
- if (! (argv[i][1] && ! argv[i][2]))
138
- usage(argv[0], "Unknown option.");
139
- switch (argv[i][1]) {
140
- case 'v':
141
- if (argc == 2) {
142
- std::cout << PY_MAJOR_VERSION << '.'
143
- << PY_MINOR_VERSION << '.'
144
- << PY_MICRO_VERSION << std::endl;
145
- return 0;
146
- } else
147
- usage(argv[0],
148
- "Argument -v cannot be used with other options.");
149
- case 'm':
150
- mainThread = false;
151
- break;
152
- case 't':
153
- if (i == argc - 1)
154
- usage(argv[0], "Missing timeout argument.");
155
- ++i;
156
- {
157
- char* err = nullptr;
158
- timeout = strtol(argv[i], &err, 10);
159
- if (*err)
160
- usage(argv[0], "Timeout should be an integer.");
161
- else if (timeout <= 0)
162
- usage(argv[0],
163
- "Timeout should be strictly positive.");
164
- }
165
- break;
166
- default:
167
- usage(argv[0], "Unknown option.");
168
- }
169
- } else {
170
- if (i != argc - 1)
171
- usage(argv[0], "The <commands> argument must come last.");
172
- input = argv[i];
173
- }
174
- }
175
-
176
- NativeOutputStream out(std::cout);
177
- NativeOutputStream err(std::cerr);
178
- // In the new python interpreter, do not adjust the Python path to reflect
179
- // Regina's installation location, since this tool is designed to be
180
- // run directly out of the source tree.
181
- regina::python::PythonInterpreter py(out, err, false);
182
- if (! py.importRegina(false)) {
183
- std::cerr << "ERROR: Could not import regina" << std::endl;
184
- exit(2);
185
- }
186
-
187
- py.executeLine("from regina import *");
188
- std::string exec = argv[0];
189
- py.executeLine("regina.GlobalDirs.deduceDirs('" + exec + "');");
190
-
191
- if (input.empty()) {
192
- if (timeout) {
193
- std::thread w(watcher);
194
- run(py, std::cin);
195
- {
196
- std::unique_lock<std::mutex> lock(mutex);
197
- finished = true;
198
- }
199
- cond.notify_one();
200
-
201
- w.join();
202
- } else {
203
- run(py, std::cin);
204
- }
205
- } else {
206
- std::ifstream in(input);
207
- if (! in) {
208
- std::cerr << "ERROR: Could not open input file: " << input
209
- << std::endl;
210
- return 1;
211
- }
212
- if (timeout) {
213
- std::thread w(watcher);
214
- run(py, in);
215
- {
216
- std::unique_lock<std::mutex> lock(mutex);
217
- finished = true;
218
- }
219
- cond.notify_one();
220
-
221
- w.join();
222
- } else {
223
- run(py, in);
224
- }
225
- }
226
-
227
- return 0;
228
- }
229
-