fix stream_property

This commit is contained in:
Vítor Santos Costa 2016-03-05 00:08:04 +00:00
parent 27b7e32036
commit 5a95c6bbc7
2 changed files with 19 additions and 18 deletions

View File

@ -336,7 +336,7 @@ FetchAlias (int sno)
} }
aliasp++; aliasp++;
} }
return(AtomFoundVar); return NULL;
} }
/* check if arg is an alias */ /* check if arg is an alias */

View File

@ -345,7 +345,7 @@ found_eof(int sno,
return Yap_unify(t2, MkAtomTerm(AtomPast)); return Yap_unify(t2, MkAtomTerm(AtomPast));
if (flags & Eof_Stream_f) if (flags & Eof_Stream_f)
return Yap_unify(t2, MkAtomTerm(AtomAt)); return Yap_unify(t2, MkAtomTerm(AtomAt));
return Yap_unify(t2, MkAtomTerm(AtomNot)); return Yap_unify(t2, MkAtomTerm(AtomAltNot));
} }
static bool static bool
@ -503,8 +503,11 @@ static bool do_stream_property(int sno,
if (args[i].used) { if (args[i].used) {
switch (i) { switch (i) {
case STREAM_PROPERTY_ALIAS: case STREAM_PROPERTY_ALIAS:
{
Term ta = args[STREAM_PROPERTY_ALIAS].tvalue;
rc = rc & Yap_FetchStreamAlias( rc = rc & Yap_FetchStreamAlias(
sno, args[STREAM_PROPERTY_ALIAS].tvalue PASS_REGS); sno, ta PASS_REGS);
}
break; break;
case STREAM_PROPERTY_BOM: case STREAM_PROPERTY_BOM:
rc = rc && has_bom(sno, args[STREAM_PROPERTY_BOM].tvalue PASS_REGS); rc = rc && has_bom(sno, args[STREAM_PROPERTY_BOM].tvalue PASS_REGS);
@ -588,9 +591,8 @@ static xarg *generate_property(int sno, Term t2,
if (p == STREAM_PROPERTY_INPUT) Yap_unify(t2, MkAtomTerm(AtomInput)); if (p == STREAM_PROPERTY_INPUT) Yap_unify(t2, MkAtomTerm(AtomInput));
else if (p == STREAM_PROPERTY_OUTPUT) Yap_unify(t2, MkAtomTerm(AtomOutput)); else if (p == STREAM_PROPERTY_OUTPUT) Yap_unify(t2, MkAtomTerm(AtomOutput));
else { else {
Term t0 = MkVarTerm();
Functor f = Yap_MkFunctor(Yap_LookupAtom(stream_property_defs[p].name), 1); Functor f = Yap_MkFunctor(Yap_LookupAtom(stream_property_defs[p].name), 1);
Yap_unify( t2, Yap_MkApplTerm(f, 1, &t0)); Yap_unify( t2, Yap_MkNewApplTerm(f, 1));
} }
return Yap_ArgListToVector(t2, stream_property_defs, return Yap_ArgListToVector(t2, stream_property_defs,
STREAM_PROPERTY_END); STREAM_PROPERTY_END);
@ -626,18 +628,15 @@ static Int cont_stream_property(USES_REGS1) { /* current_stream */
cut_fail(); cut_fail();
} }
LOCK(GLOBAL_Stream[i].streamlock); LOCK(GLOBAL_Stream[i].streamlock);
if (args[STREAM_PROPERTY_ALIAS].tvalue && if (IsAtomTerm(args[STREAM_PROPERTY_ALIAS].tvalue)) {
IsAtomTerm(args[STREAM_PROPERTY_ALIAS].tvalue)) { // one solution only
// one solution only i = Yap_CheckAlias(AtomOfTerm(args[STREAM_PROPERTY_ALIAS].tvalue));
LOCK(GLOBAL_Stream[i].streamlock); UNLOCK(GLOBAL_Stream[i].streamlock);
UNLOCK(GLOBAL_Stream[i].streamlock); if (i < 0 ||!Yap_unify(ARG1, Yap_MkStream(i) ) ) {
i = Yap_CheckAlias(AtomOfTerm(args[STREAM_PROPERTY_ALIAS].tvalue));
UNLOCK(GLOBAL_Stream[i].streamlock);
if (i < 0 ||!Yap_unify(ARG1, Yap_MkStream(i) ) ) {
cut_fail(); cut_fail();
} }
cut_succeed(); cut_succeed();
} }
LOCK(GLOBAL_Stream[i].streamlock); LOCK(GLOBAL_Stream[i].streamlock);
rc = do_stream_property(i, args PASS_REGS); rc = do_stream_property(i, args PASS_REGS);
UNLOCK(GLOBAL_Stream[i].streamlock); UNLOCK(GLOBAL_Stream[i].streamlock);
@ -691,12 +690,14 @@ static Int stream_property(USES_REGS1) { /* Init current_stream */
i = Yap_CheckStream(t1, Input_Stream_f | Output_Stream_f | Append_Stream_f, i = Yap_CheckStream(t1, Input_Stream_f | Output_Stream_f | Append_Stream_f,
"current_stream/3"); "current_stream/3");
if (i < 0) { if (i < 0) {
UNLOCK(GLOBAL_Stream[i].streamlock); UNLOCK(GLOBAL_Stream[i].streamlock);
return false; // error... return false; // error...
} }
if (IsVarTerm(t2)) EXTRA_CBACK_ARG(2, 1) = MkIntTerm(i);
if (IsVarTerm(t2)) {
return cont_stream_property(PASS_REGS1); return cont_stream_property(PASS_REGS1);
}
args = Yap_ArgListToVector(Deref(ARG2), stream_property_defs, args = Yap_ArgListToVector(Deref(ARG2), stream_property_defs,
STREAM_PROPERTY_END); STREAM_PROPERTY_END);
if (args == NULL) { if (args == NULL) {