-
Notifications
You must be signed in to change notification settings - Fork 161
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
manipulate output streams (esp. errout) in libgap #2874
Comments
Have you tried using the variable introduced in #2824? |
I don't really know how. Suppose I call I tried, and only say that Am I supposed to manipulate |
I tried printing OK, I'm getting there, sorry for noise; I'm doing something like
|
Here is something that appears to work.
int main(int argc, char ** argv)
{
Int a = 42;
Obj b, str, out;
char *buf;
printf("# Initializing GAP...\n");
GAP_Initialize(argc, argv, environ, 0L, &err_callback);
b = INTOBJ_INT(a);
b = INV(b);
GAP_EvalString("libgap_errout := \"\"; ERROR_OUTPUT := OutputTextString(libgap_errout, false);");
str = NEW_STRING(0);
out = CALL_2ARGS(
GAP_ValueGlobalVariable("OutputTextString"), str, True);
CALL_2ARGS(GAP_ValueGlobalVariable("PrintTo"), out, b);
CALL_1ARGS(GAP_ValueGlobalVariable("CloseStream"), out);
buf = CSTR_STRING(str);
printf("\n its C part: %s\n", buf);
printf("# error processing\n");
GAP_EvalString("_rich_repr_;"); /* or whatever */
GAP_EvalString("1/0;");
printf("# done\n");
return 0;
}
void err_callback(void) {
Obj r;
int len;
printf(" err_callback!\n");
r = GAP_ValueGlobalVariable("libgap_errout");
len = GET_LEN_STRING(r);
printf(" got: %.*s\n", len, CSTR_STRING(r));
GAP_EvalString("CloseStream(ERROR_OUTPUT);");
GAP_EvalString("libgap_errout := \"\"; ERROR_OUTPUT := OutputTextString(libgap_errout, false);");
return;
} PS. Would it be a good idea to add this to my PR with tests for libgap? |
Per my comments here it would be much easier from a third-party integration perspective if it were possible to prevent error messages from being printed to I/O streams at all, as doing so results in a lot of overhead (e.g. unnecessary copying) and other complications. Likewise, going into Not relying strictly on I/O (even in-memory I/O streams) would also help avoid problems like #3028 |
And now, as I wrote about here, the GAP kernel state already has an effectively unused "ThrownObject" member that, with some relatively minor patching, could be made useful again by using it to store error messages and other error information. |
@embray Atm there is no code to get the string of e.g. an expression directly. Ofc there is the kernel function |
I think I've brought this up elsewhere, but something like #2858 is very necessary--there are far too many objects in GAP whose string representation is made available only by printing (and thus having to capture output), which is exactly backwards :) |
Are there cases of error messages (e.g. as passed to |
Note that I'm not speaking on behalf of the actual GAP devs:
Improving this with the kernel may be possible but doing that for the whole library and all packages at once doesn't sound realistic to me. IIRC there have been attempts to do something like that with the
Expression are printed when printing the traceback. I don't know much about the actual error messages like "No method found".
Do you mean in this repository or in the version you use for sage? |
I'm working on a possible solution to this, and possibly #2822 at least from the libgap API perspective. |
At the moment, asking libgap to compute something like 1/0 results in an error message printed:
It is often necessary to be able to capture this output for further processing
(something what current libGAP in Sage does by changing source code in GAP kernel)
Thus it would be great to able to have more control over it in libgap.
Perhaps #2824 is relevant here, I don't know.
The text was updated successfully, but these errors were encountered: