Can I store a term permanently? (SWI-prolog, C interface)

From: seguso (look_at_in.signature)
Date: 12/12/03

  • Next message: Rob Myers: "Re: Substring Substitution"
    Date: Fri, 12 Dec 2003 11:32:54 GMT
    
    

    Hello,

    I noticed that I cannot permanently store a term_t passed to a C predicate.

    term_t g_term; // I need to store a term here.

    foreign_t listBoxAddItem(
                // must be an atom:
                term_t aListBoxPrologName,
                // this is not necessarily an atom:
                term_t aItemData)
    {
           g_term = aItemData;
           PL_succeed; // g_term and aItemData become invalid here
    }

    Apparently, when PL_succeed is called, the term is
    destroyed and all references to it become invalid (both aItemData and
    g_term).

    So I tried to copy the term, but nothing changes:

      g_term = PL_copy_term_ref(aItemData);

    Unfortunately, I need to store a term in order permanently, in order to
    give it back to the prolog program when it asks:

    foreign_t listBoxGetItem(
                // must be an atom:
                term_t aListBoxPrologName,
                // this must be unified with the data contained in that item
                term_t outputItemData)
    {
            //... I should unify outputItemData with g_term, but I can't
    }

    I think there should be a way to tell the garbage collector not to destroy
    the term, but the manual doesn't talk about it... it only mentions
    destructions of ATOMS (why? >:-( )

    Is there any easy way to do what I need (other than writing my own CTerm
    class in C++ and supplying conversion structures from Term to term_t and
    viceversa)?

    Thank you very much.

    -- 
    Best Regards,
    Maurizio Colucci
    Please remove the uppercase letters "S,P,A,M":
    seSgPuAsMo.forever@tin.it
    

  • Next message: Rob Myers: "Re: Substring Substitution"