try to fix -l and -L from scripts

saved states should always interpret getting read() == 0 as EOF.


git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1662 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2006-06-02 15:21:35 +00:00
parent 9a941730f7
commit 0a96eab20d
3 changed files with 33 additions and 43 deletions

View File

@ -184,7 +184,7 @@ myread(int fd, char *buff, Int len)
{
while (len > 0) {
int nchars = read(fd, buff, len);
if (nchars < 0) {
if (nchars <= 0) {
return do_system_error(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM, "bad read on saved state");
}
len -= nchars;
@ -617,11 +617,13 @@ check_header(CELL *info, CELL *ATrail, CELL *AStack, CELL *AHeap)
char pp[80];
char msg[256];
CELL hp_size, gb_size, lc_size, tr_size, mode;
int n;
/* make sure we always check if there are enough bytes */
/* skip the first line */
pp[0] = '\0';
do {
if (read(splfild, pp, 1) < 0) {
if ((n = read(splfild, pp, 1)) <= 0) {
do_system_error(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM,"failed to scan first line from saved state");
return FAIL_RESTORE;
}
@ -631,7 +633,7 @@ check_header(CELL *info, CELL *ATrail, CELL *AStack, CELL *AHeap)
{
int count = 0, n, to_read = Unsigned(strlen(msg) + 1);
while (count < to_read) {
if ((n = read(splfild, pp, to_read-count)) < 0) {
if ((n = read(splfild, pp, to_read-count)) <= 0) {
do_system_error(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM,"failed to scan version info from saved state");
return FAIL_RESTORE;
}
@ -909,7 +911,7 @@ CopyCode(void)
/* skip the local and global data structures */
CELL j = get_cell();
if (Yap_ErrorMessage)
return -1;
return -1;
if (j != Unsigned(&GLOBAL) - Unsigned(Yap_HeapBase)) {
Yap_ErrorMessage = "code space size does not match saved state";
return -1;

View File

@ -16,6 +16,8 @@
<h2>Yap-5.1.2:</h2>
<ul>
<li> FIXED: -l and -L options (again?).</li>
<li> FIXED: if we cannot read more chars in saved state we're dead.</li>
<li> FIXED: termination info for failed and detached threads (obs Paulo Moura).</li>
<li> FIXED: check_callable should check for modules (obs Paulo Moura).</li>
<li> NEW: add thread_sleep/1, mostly works like system:sleep/1 (request from Paulo Moura).</li>

View File

@ -433,47 +433,33 @@ parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
break;
#endif
case 'L':
p++;
iap->HaltAfterConsult = TRUE;
if (*p != '\0') {
iap->YapPrologRCFile = p;
break;
} else {
if (--argc == 0) {
fprintf(stderr,
" [ YAP unrecoverable error: missing file name with option 'L' ]\n");
exit(1);
}
p = *++argv;
if (p[0] == '-' && p[1] == '-' && p[2] == '\0') {
if (--argc == 0) {
fprintf(stderr,
" [ YAP unrecoverable error: missing filename with option 'L' ]\n");
exit(1);
}
p = *++argv;
iap->YapPrologRCFile = p;
argc = 1;
} else {
iap->YapPrologRCFile = p;
}
}
break;
case 'l':
if ((*argv)[0] == '\0')
iap->YapPrologRCFile = *argv;
else {
argc--;
if (argc == 0) {
fprintf(stderr," [ YAP unrecoverable error: missing file name with option 'l' ]\n");
exit(EXIT_FAILURE);
}
argv++;
iap->YapPrologRCFile = *argv;
}
break;
/* run goal before top-level */
p++;
if (!*++argv) {
fprintf(stderr,
"%% YAP unrecoverable error: missing boot file name\n");
exit(1);
} else {
iap->YapPrologRCFile = *argv;
argc--;
}
if (*p) {
/* we have something, usually, of the form:
-L --
FileName
ExtraArgs
*/
/* being called from a script */
while (*p && (*p == ' ' || *p == '\t'))
p++;
if (p[0] == '-' && p[1] == '-') {
/* ignore what is next */
argc = 1;
}
}
break;
/* run goal before top-level */
case 'g':
if ((*argv)[0] == '\0')
iap->YapPrologGoal = *argv;