fix string_concat/2
This commit is contained in:
48
C/atomic.c
48
C/atomic.c
@@ -808,6 +808,53 @@ p_atom_concat2( USES_REGS1 )
|
||||
cut_fail();
|
||||
}
|
||||
|
||||
static Int
|
||||
p_string_concat2( USES_REGS1 )
|
||||
{
|
||||
Term t1;
|
||||
Term *tailp;
|
||||
Int n;
|
||||
restart_aux:
|
||||
t1 = Deref(ARG1);
|
||||
n = Yap_SkipList(&t1, &tailp);
|
||||
if (*tailp != TermNil) {
|
||||
LOCAL_Error_TYPE = TYPE_ERROR_LIST;
|
||||
} else {
|
||||
seq_tv_t *inpv = (seq_tv_t *)malloc(n*sizeof(seq_tv_t)), out;
|
||||
int i = 0;
|
||||
|
||||
if (!inpv) {
|
||||
LOCAL_Error_TYPE = OUT_OF_HEAP_ERROR;
|
||||
free(inpv);
|
||||
goto error;
|
||||
}
|
||||
|
||||
while (t1 != TermNil) {
|
||||
inpv[i].type = YAP_STRING_STRING;
|
||||
inpv[i].val.t = HeadOfTerm(t1);
|
||||
i++;
|
||||
t1 = TailOfTerm(t1);
|
||||
}
|
||||
out.type = YAP_STRING_STRING;
|
||||
if (!Yap_Concat_Text(n, inpv, &out PASS_REGS)) {
|
||||
free(inpv);
|
||||
goto error;
|
||||
}
|
||||
free(inpv);
|
||||
if (out.val.t) return Yap_unify(ARG2, out.val.t);
|
||||
}
|
||||
error:
|
||||
/* Error handling */
|
||||
if (LOCAL_Error_TYPE) {
|
||||
if (Yap_HandleError( "string_code/3" )) {
|
||||
goto restart_aux;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
cut_fail();
|
||||
}
|
||||
|
||||
|
||||
static Int
|
||||
p_atomic_concat2( USES_REGS1 )
|
||||
@@ -1929,6 +1976,7 @@ Yap_InitAtomPreds(void)
|
||||
Yap_InitCPred("atom_number", 2, p_atom_number, 0);
|
||||
Yap_InitCPred("string_number", 2, p_string_number, 0);
|
||||
Yap_InitCPred("$atom_concat", 2, p_atom_concat2, 0);
|
||||
Yap_InitCPred("$string_concat", 2, p_string_concat2, 0);
|
||||
Yap_InitCPred("atomic_concat", 2, p_atomic_concat2, 0);
|
||||
Yap_InitCPred("atomic_concat", 3, p_atomic_concat3, 0);
|
||||
Yap_InitCPred("atomics_to_string", 2, p_atomics_to_string2, 0);
|
||||
|
@@ -4589,7 +4589,8 @@ remove_dirty_clauses_from_index(yamop *header)
|
||||
curp->opc = startopc;
|
||||
if (curp->opc == endop)
|
||||
return;
|
||||
if (!header->u.Illss.e)
|
||||
// don't try to follow the chain if there is no chain.
|
||||
if (header->u.Illss.e <= 1)
|
||||
return;
|
||||
previouscurp = curp;
|
||||
curp = curp->u.OtaLl.n;
|
||||
|
15
C/sysbits.c
15
C/sysbits.c
@@ -2086,21 +2086,28 @@ Run an external command and wait for its completion.
|
||||
char *shell;
|
||||
register int bourne = FALSE;
|
||||
Term t1 = Deref (ARG1);
|
||||
const char *cmd;
|
||||
|
||||
shell = (char *) getenv ("SHELL");
|
||||
if (!strcmp (shell, "/bin/sh"))
|
||||
bourne = TRUE;
|
||||
if (shell == NIL)
|
||||
bourne = TRUE;
|
||||
if (IsAtomTerm(t1))
|
||||
cmd = RepAtom(AtomOfTerm(t1))->StrOfAE;
|
||||
else if (IsStringTerm(t1))
|
||||
cmd = StringOfTerm(t1);
|
||||
else
|
||||
return FALSE;
|
||||
/* Yap_CloseStreams(TRUE); */
|
||||
if (bourne)
|
||||
return system(RepAtom(AtomOfTerm(t1))->StrOfAE) == 0;
|
||||
return system( cmd ) == 0;
|
||||
else {
|
||||
int status = -1;
|
||||
int child = fork ();
|
||||
|
||||
if (child == 0) { /* let the children go */
|
||||
if (!execl (shell, shell, "-c", RepAtom(AtomOfTerm(t1))->StrOfAE , NULL)) {
|
||||
if (!execl (shell, shell, "-c", cmd , NULL)) {
|
||||
exit(-1);
|
||||
}
|
||||
exit(TRUE);
|
||||
@@ -2182,13 +2189,15 @@ Run an external command and wait for its completion.
|
||||
return FALSE;
|
||||
#elif HAVE_SYSTEM
|
||||
Term t1 = Deref (ARG1);
|
||||
char *s;
|
||||
const char *s;
|
||||
|
||||
if (IsVarTerm(t1)) {
|
||||
Yap_Error(INSTANTIATION_ERROR,t1,"argument to system/1 unbound");
|
||||
return FALSE;
|
||||
} else if (IsAtomTerm(t1)) {
|
||||
s = RepAtom(AtomOfTerm(t1))->StrOfAE;
|
||||
} else if (IsStringTerm(t1)) {
|
||||
s = StringOfTerm(t1);
|
||||
} else {
|
||||
if (!Yap_GetName (LOCAL_FileNameBuf, YAP_FILENAME_MAX, t1)) {
|
||||
Yap_Error(TYPE_ERROR_ATOM,t1,"argument to system/1");
|
||||
|
Reference in New Issue
Block a user