On Sat, Jan 07, 2012 at 08:45:08PM +0100, Waldek Hebisch wrote:
> Serge D. Mechveliani wrote:
> >
> > > [..]
> > > OTOH it seems that code which simply writes and reads lines
> > > does not work due to bug in sbcl (in version used for release,
> > > seems to be fixed in newer versions).
> > >
> > [..]
>
> [..]
>
> Look at:
>
> http://www.math.uni.wroc.pl/~hebisch/fricas/fifoToAxiom.c
>
> and
>
> http://www.math.uni.wroc.pl/~hebisch/fricas/fifoToC.input
>
> When using clisp based FriCAS they "almost" work (there
> is message at the end:
>
> >> Error detected within library code:
> End of file
>
> but otherwise it seem be what you expect.
>
But I managed to break this IO on
http://www.math.uni.wroc.pl/~hebisch/fricas/fifoToAxiom.c,
fifoToC.input.
Remove from there all the intermediate print-outs,
remove also parsing-evaluation,
so that fifoToAxiom and fifoToC.input only push each line to and
from.
Then, for n = 1000, is runs correct,
and n = 2000 leads to Segmentation fault
(FriCAS-1.1.5 made from source with GNU CLisp, Linux Debian).
I do not know, where is an error here: in the C code or in FriCAS.
The files are:
** fifoToC.input *****************************************************
toA: TextFile := open("toA", "input")
fromA: TextFile := open("fromA", "output")
repeat
iStr := readLine! toA
if iStr = "failed" then (output ""; output "input -> failed"; break)
resStr := iStr
writeLine!(fromA, resStr)
flush(fromA)
** fifoToAxiom.c *****************************************************
#include <stdio.h>
#include <string.h>
#define LBND 64
static const int lineBound = LBND;
FILE *toA, *fromA;
char *cAxiom(char *line, char *res)
// the pipes are called "toA", "fromA",
// their pointers are called toA, fromA.
{
toA = fopen("toA", "w");
if (fputs(line, toA) == EOF) {
perror("fputs(line, toA) failed: "); return(NULL);
}
if (fflush(toA) == EOF) {
perror("ffush(toA) failed: "); return(NULL);
}
// input the first non-trivial string
for (;;)
{
if (fgets(res, lineBound, fromA) == NULL)
{
perror("fgets(res, _, fromA) failed: "); return(NULL);
}
if ((*res != '\n') && (*res != ' ')) {break;}
};
return(res);
}
static char arr0[50] = "((2*x + y + x^2*z^3) ^ 2) + ";
static char arr[50];
static char res [LBND];
void repeatAxiom(int n)
{
// It builds n different inputs for a polynomials of kind f + i,
// f = (2*x + y + x^2*z^3)^2, i = 0 .. n-1,
// and applies cAxiom to the corresponding string.
char *q; int i;
for (i = 0; i < n; i++)
{
sprintf(arr, "%s%d\n", arr0, i); // append `<i>"', returns length
q = cAxiom(arr, res); // returns res
if (q == NULL) {
fprintf(stderr, "cAxiom(arr, res) failed.\n");
printf("i = %d\n", i);
break;
}
}
printf("%s\n", "done");
return;
}
int main(void)
{
int n = 2000; // edit it
toA = fopen("toA", "w");
if (toA == NULL) {perror("fopen(toA, w) failed: "); return 1;}
fromA = fopen("fromA", "r");
if (fromA == NULL) {perror("fopen(fromA, r) filed: "); return 1;}
printf("n = %d\n", n);
repeatAxiom(n);
fclose(toA); fclose(fromA); return 0;
}
*********************************************************************
For the case of C <-> C I managed to arrange this loop by using a lower
level functions read, write, open, close, so that `open' and `close'
are out of the loop, and the program runs correct for large n too,
like n = 1000000.
Now, I shall try to replace the second end with FriCAS.
Regards,
------
Sergei
[email protected]
--
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/fricas-devel?hl=en.