bug-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Variables can be modified through the foreign C interface


From: Vésy Jordan
Subject: Variables can be modified through the foreign C interface
Date: Sun, 22 May 2022 16:59:06 +0000

Hello,

on GNU Prolog 1.5.0 tested on Arch Linux with kernel 5.17.8,

with
---------- bugged.pl ----------
:- foreign(magic(term)).
go(X) :-
    X = value(0),
    magic(X).
-------------------------------

and
---------- bugged.c ----------
#include "gprolog.h"
PlBool magic(PlTerm term) {
    int functor, arity;
    PlTerm *args = Pl_Rd_Compound_Check(term, &functor, &arity);
    args[0] = Pl_Mk_Number(1);
    return PL_TRUE;
}
------------------------------


The value of the X variable is modified like this:
-----------------------------
​| ?- go(X).

X = value(1)
-----------------------------

Shouldn't it either fail or leave X at "value(0)" instead of modifying its value ?

Thanks,

Jordan Vésy

reply via email to

[Prev in Thread] Current Thread [Next in Thread]