Skip to content

Commit 4906174

Browse files
authored
Merge pull request #1665 from clasp-developers/quit-other-thread
Quit other thread
2 parents a072f7c + 75a35bc commit 4906174

File tree

8 files changed

+42
-89
lines changed

8 files changed

+42
-89
lines changed

RELEASE_NOTES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77

88
## Fixed
99
* Weak pointers and weak hash tables survive snapshot save/load.
10+
* `ext:quit` can be used from any thread, not just the initial thread.
11+
12+
## Removed
13+
* `-z`/`--snapshot-symbols-save` command line option, occasionally used
14+
for snapshot debugging. You can call `core:mangled-symbol-names` if the
15+
effect is still needed.
1016

1117
# Version 2.7.0 (LLVM15-19) 2025-01-21
1218

include/clasp/core/commandLineOptions.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ struct CommandLineOptions {
6666
std::string _DescribeFile;
6767
long _RandomNumberSeed;
6868
bool _ExportedSymbolsCheck;
69-
bool _ExportedSymbolsSave;
70-
std::string _ExportedSymbolsFilename;
7169
bool _NoInform;
7270
bool _NoPrint;
7371
bool _DebuggerDisabled;

include/clasp/core/exceptions.h

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -198,32 +198,8 @@ namespace core {
198198

199199
class DebugStream;
200200

201-
/*! To exit the program throw this exception
202-
*/
203-
class ExitProgramException : public std::exception {
204-
private:
205-
int _ExitResult;
206-
207-
public:
208-
ExitProgramException(int result) : _ExitResult(result){};
209-
int getExitResult() { return this->_ExitResult; };
210-
};
211-
212-
/*! To exit the program throw this exception
213-
*/
214-
class TerminateProgramIfBatch {
215-
private:
216-
int _ExitResult;
217-
string _Message;
218-
219-
public:
220-
TerminateProgramIfBatch(int result, string const& message) : _ExitResult(result), _Message(message){};
221-
string message() const { return this->_Message; };
222-
int getExitResult() { return this->_ExitResult; };
223-
};
224-
225201
#pragma GCC visibility push(default)
226-
class ATTR_WEAK CatchThrow {
202+
class ATTR_WEAK CatchThrow : public std::exception {
227203
virtual void keyFunctionForVtable() ATTR_WEAK;
228204

229205
private:
@@ -232,19 +208,22 @@ class ATTR_WEAK CatchThrow {
232208
public:
233209
CatchThrow(T_sp tag) : _Tag(tag){};
234210
T_sp getTag() { return this->_Tag; };
211+
const char* what() const noexcept override { return "Lisp Throw exception"; }
235212
};
236213

237-
class ATTR_WEAK Unwind {
214+
class ATTR_WEAK Unwind : public std::exception {
238215
virtual void keyFunctionForVtable() ATTR_WEAK;
239216

240217
private:
241218
void* _Frame; // NOT GC'd use FIXNUM tagged_ptr
242219
size_t _Index;
243220

244221
public:
245-
ATTR_WEAK Unwind(void* frame, size_t index) : _Frame(frame), _Index(index){};
222+
ATTR_WEAK Unwind(void* frame, size_t index)
223+
: _Frame(frame), _Index(index){};
246224
void* getFrame() const { return this->_Frame; };
247225
size_t index() const { return this->_Index; };
226+
const char* what() const noexcept override { return "Lisp Unwind exception"; }
248227
};
249228

250229
#pragma GCC visibility pop

include/clasp/core/lisp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,4 +874,6 @@ extern bool global_Started;
874874
void dumpDebuggingLayouts();
875875
T_mv cl__intern(String_sp symbol_name, T_sp package_desig);
876876

877+
[[noreturn]] void core__exit(int);
878+
877879
}; // namespace core

src/core/commandLineOptions.cc

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,6 @@ const char* help = R"dx(Usage: clasp <options>
8888
Check symbols while starting up and verify that snapshot save will
8989
work. The symbols can be recovered at runtime calling by
9090
(core:mangled-symbol-names <stream>).
91-
-z, --snapshot-symbols-save <file>
92-
Accumulate symbols while starting up and verify that snapshot save will
93-
work. The symbols can be recovered at runtime calling by
94-
(core:mangled-symbol-names <stream>). They are written out to the <file>
95-
on exit.
9691
-f, --feature <feature>
9792
Add the feature to *features*
9893
-e, --eval <form>
@@ -334,10 +329,6 @@ void process_clasp_arguments(CommandLineOptions* options) {
334329
options->_PauseForDebugger = true;
335330
} else if (*arg == "-y" || *arg == "--snapshot-symbols") {
336331
options->_ExportedSymbolsCheck = true;
337-
} else if (*arg == "-z" || *arg == "--snapshot-symbols-save") {
338-
options->_ExportedSymbolsCheck = true;
339-
options->_ExportedSymbolsSave = true;
340-
options->_ExportedSymbolsFilename = *++arg;
341332
} else if (*arg == "-m" || *arg == "--disable-mpi") {
342333
options->_DisableMpi = true;
343334
} else if (*arg == "-v" || *arg == "--version") {
@@ -440,7 +431,7 @@ void process_clasp_arguments(CommandLineOptions* options) {
440431
CommandLineOptions::CommandLineOptions(int argc, const char* argv[])
441432
: _ProcessArguments(process_clasp_arguments), _DisableMpi(false), _AddressesP(false), _StartupType(DEFAULT_STARTUP_TYPE),
442433
_FreezeStartupType(false), _HasDescribeFile(false), _StartupFile(""), _ExportedSymbolsCheck(false),
443-
_ExportedSymbolsSave(false), _RandomNumberSeed(0), _NoInform(false), _NoPrint(false), _DebuggerDisabled(false),
434+
_RandomNumberSeed(0), _NoInform(false), _NoPrint(false), _DebuggerDisabled(false),
444435
_Interactive(true), _Version(false), _SilentStartup(true), _GenerateTrampolines(false),
445436
_RCFileName(std::string(getenv("HOME")) + "/.clasprc"), _NoRc(false), _PauseForDebugger(false) {
446437
if (argc == 0) {

src/core/debugger2.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ T_mv early_debug_inner(DebuggerFrame_sp bot, bool can_continue) {
155155
line = myReadLine(sprompt.str(), end_of_transmission);
156156
if (end_of_transmission) {
157157
printf("%s:%d Exiting debugger\n", __FILE__, __LINE__);
158-
throw ExitProgramException(0);
158+
core__exit(0);
159159
}
160160
char cmd;
161161
string eline;

src/core/lisp.cc

Lines changed: 26 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,7 +1401,7 @@ CL_LAMBDA(&optional (exit-value 0));
14011401
CL_DECLARE();
14021402
CL_DOCSTRING(R"dx(exit)dx");
14031403
DOCGROUP(clasp);
1404-
CL_DEFUN void core__exit(int exitValue) {
1404+
[[noreturn]] CL_DEFUN void core__exit(int exitValue) {
14051405
#ifdef CLASP_APPLE_SILICON
14061406
exit(exitValue);
14071407
#else
@@ -1416,7 +1416,7 @@ CL_DEFUN void core__exit(int exitValue) {
14161416
}
14171417
VirtualMachine& vm = my_thread->_VM;
14181418
vm.shutdown();
1419-
throw(ExitProgramException(exitValue));
1419+
exit(exitValue);
14201420
#endif
14211421
};
14221422

@@ -2211,24 +2211,23 @@ void Lisp::dump_apropos(const char* part) const {
22112211

22122212
bool Lisp::load(int& exitCode) {
22132213
MultipleValues& mvn = core::lisp_multipleValues();
2214-
try {
2215-
switch (global_options->_StartupType) {
2216-
case cloInitLisp: {
2217-
Pathname_sp initPathname = cl__pathname(SimpleBaseString_O::make(globals_->_InitFileName));
2218-
if (!global_options->_SilentStartup) {
2219-
printf("Loading image %s\n", _rep_(initPathname).c_str());
2220-
}
2221-
T_mv result = core__load_no_package_set(initPathname);
2222-
if (result.nilp()) {
2223-
T_sp err = mvn.second(result.number_of_values());
2224-
printf("Could not load %s error: %s\n", _rep_(initPathname).c_str(), _rep_(err).c_str());
2225-
exitCode = 1;
2226-
return false;
2227-
}
2228-
} break;
2229-
case cloBaseImage:
2230-
case cloExtensionImage:
2231-
case cloImageFile:
2214+
switch (global_options->_StartupType) {
2215+
case cloInitLisp: {
2216+
Pathname_sp initPathname = cl__pathname(SimpleBaseString_O::make(globals_->_InitFileName));
2217+
if (!global_options->_SilentStartup) {
2218+
printf("Loading image %s\n", _rep_(initPathname).c_str());
2219+
}
2220+
T_mv result = core__load_no_package_set(initPathname);
2221+
if (result.nilp()) {
2222+
T_sp err = mvn.second(result.number_of_values());
2223+
printf("Could not load %s error: %s\n", _rep_(initPathname).c_str(), _rep_(err).c_str());
2224+
exitCode = 1;
2225+
return false;
2226+
}
2227+
} break;
2228+
case cloBaseImage:
2229+
case cloExtensionImage:
2230+
case cloImageFile:
22322231
if (startup_functions_are_waiting()) {
22332232
startup_functions_invoke(NULL);
22342233
} else {
@@ -2251,36 +2250,21 @@ bool Lisp::load(int& exitCode) {
22512250
}
22522251
}
22532252
break;
2254-
default:
2253+
default:
22552254
break;
2256-
}
2257-
} catch (core::ExitProgramException& ee) {
2258-
exitCode = ee.getExitResult();
2259-
return false;
22602255
}
22612256
return true;
22622257
};
22632258

22642259
int Lisp::run() {
2265-
int exitCode;
2266-
try {
2267-
if (ext::_sym_STARtoplevel_hookSTAR->symbolValue().notnilp()) {
2268-
core::T_sp fn = ext::_sym_STARtoplevel_hookSTAR->symbolValue();
2269-
core::eval::funcall(fn);
2270-
} else if (global_options->_Interactive) {
2271-
this->readEvalPrintInteractive();
2272-
}
2273-
exitCode = 0;
2274-
} catch (core::ExitProgramException& ee) {
2275-
exitCode = ee.getExitResult();
2276-
}
2277-
if (global_options->_ExportedSymbolsSave) {
2278-
T_sp stream = core::cl__open(core::SimpleBaseString_O::make(global_options->_ExportedSymbolsFilename), StreamDirection::output);
2279-
core::core__mangledSymbols(stream);
2280-
cl__close(stream);
2260+
if (ext::_sym_STARtoplevel_hookSTAR->symbolValue().notnilp()) {
2261+
core::T_sp fn = ext::_sym_STARtoplevel_hookSTAR->symbolValue();
2262+
core::eval::funcall(fn);
2263+
} else if (global_options->_Interactive) {
2264+
this->readEvalPrintInteractive();
22812265
}
22822266

2283-
return exitCode;
2267+
return 0;
22842268
};
22852269

22862270
FileScope_mv Lisp::getOrRegisterFileScope(const string& fileName) {

src/gctools/startRunStop.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,6 @@ int handleFatalCondition() {
105105
int exitCode = 0;
106106
try {
107107
throw;
108-
} catch (core::ExitProgramException& ee) {
109-
// Do nothing
110-
// printf("Caught ExitProgram in %s:%d\n", __FILE__, __LINE__);
111-
exitCode = ee.getExitResult();
112-
} catch (core::TerminateProgramIfBatch& ee) {
113-
// Do nothing
114-
printf("Caught TerminateProgramIfBatch in %s:%d\n", __FILE__, __LINE__);
115108
} catch (core::CatchThrow& ee) {
116109
core::clasp_write_string(fmt::format("{}:{} Uncaught THROW tag[{}] - this should NEVER happen - the stack should never be "
117110
"unwound unless there is a CATCH clause that matches the THROW",

0 commit comments

Comments
 (0)