-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for writing to ERROR_OUTPUT from kernel code #3043
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,13 +33,49 @@ | |
|
||
|
||
static Obj ErrorInner; | ||
static Obj ERROR_OUTPUT = NULL; | ||
|
||
|
||
/**************************************************************************** | ||
** | ||
*F * * * * * * * * * * * * * * error functions * * * * * * * * * * * * * * * | ||
*/ | ||
|
||
/**************************************************************************** | ||
** | ||
*F OpenErrorOutput() . . . . . . . open the file or stream assigned to the | ||
** ERROR_OUTPUT global variable defined in | ||
** error.g, or "*errout*" otherwise | ||
*/ | ||
UInt OpenErrorOutput( void ) | ||
{ | ||
/* Try to print the output to stream. Use *errout* as a fallback. */ | ||
UInt ret = 0; | ||
|
||
if (ERROR_OUTPUT != NULL) { | ||
if (IsStringConv(ERROR_OUTPUT)) { | ||
ret = OpenOutput(CONST_CSTR_STRING(ERROR_OUTPUT)); | ||
} | ||
else { | ||
ret = OpenOutputStream(ERROR_OUTPUT); | ||
} | ||
} | ||
|
||
if (!ret) { | ||
/* It may be we already tried and failed to open *errout* above but | ||
* but this is an extreme case so it can't hurt to try again | ||
* anyways */ | ||
if ((ret = OpenOutput("*errout*"))) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't assign inside the |
||
Pr("failed to open error stream\n", 0, 0); | ||
} | ||
else { | ||
Panic("failed to open *errout*"); | ||
} | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
|
||
/**************************************************************************** | ||
** | ||
|
@@ -581,6 +617,7 @@ static Int InitKernel(StructInitInfo * module) | |
InitHdlrFuncsFromTable(GVarFuncs); | ||
|
||
ImportFuncFromLibrary("ErrorInner", &ErrorInner); | ||
ImportGVarFromLibrary("ERROR_OUTPUT", &ERROR_OUTPUT); | ||
|
||
// return success | ||
return 0; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We started to add more validation, and here, one could verify that ERROR_OUTPUT actually is a stream; see e.g.
PRINT_OR_APPEND_TO_FILE_OR_STREAM
.On that note, perhaps it would be "better" to put this new function into
streams.c
orio.c
...; but I have no strong conviction in either direction, and in any case, it's not hard to move a function to another file later on, should we feel the need for it :-).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to check that it was actually a stream, but I couldn't quickly find the "right" way to check that. Is there a TNUM for stream objects? I'll look at those functions you mentioned.
I agree this function might make more sense in a
io.c
. I put it inerror.c
because that was already loading another global variable fromerror.g
. I don't know if that entirely matters though: The connection between the C-based modules and the GAP language library modules is one that I haven't deeply explored yet and is unclear to me.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, TNUMs only cover a very small, hard-wired list of types with special representations in the GAP kernel (things like integers, booleans, permutations). For things like streams, you want to use the more general
IsOutputStream
. As Max mentioned, you can see how to get this GAP level variable, and copy a reference to it into C, in PRINT_OR_APPEND_TO_FILE_OR_STREAMThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, clearly I did not even test my last commit. I'm just going to delete it.