Re: Possible to register a foreign function dynamically?
- From: Jan Wielemaker <jan@xxxxxxxxxxxxxxxxxxx>
- Date: 31 May 2007 14:41:04 GMT
On 2007-05-31, yuce <yucetekol@xxxxxxxxx> wrote:
def atom_checksum(a0, arity, context):
s = c_char_p("\x00"*MAXSTR)
if PL_get_atom_chars(a0, addressof(s)):
Hmmm. PL_get_atom_chars stores a pointer to a string over the
second argument. The "\x00"*MAXSTR looks a bit odd to me.
I thought I have to get the memory for s, but looking at the C-source,
it seems PL_get_atom_chars allocates it; if you could confirm that,
PL_get_atom_chars() provides a pointer to the actual string that is
part of the Prolog atom. Don't change! It remains valid inside a
predicate definition due to the fact that it is an argument to an
active call and thus protected from the atom garbage collector. If
you want to keep it longer you must either use PL_register_atom() to
lock the atom from atom-gc or copy the string. In this example there
is of course no need to keep it longer.
Cheers --- Jan
I'll replace that line with `s = c_char_p()`.
[In python, "\x00"*MAXSTR creates a string of length MAXSTR having
"\x00" as each character. I used it just to create some space for the
string]
Thanks :)
Yuce
- References:
- [SWI-Prolog] Possible to register a foreign function dynamically?
- From: yuce
- Re: [SWI-Prolog] Possible to register a foreign function dynamically?
- From: Jan Wielemaker
- Re: Possible to register a foreign function dynamically?
- From: yuce
- Re: Possible to register a foreign function dynamically?
- From: Jan Wielemaker
- Re: Possible to register a foreign function dynamically?
- From: yuce
- Re: Possible to register a foreign function dynamically?
- From: Jan Wielemaker
- Re: Possible to register a foreign function dynamically?
- From: yuce
- [SWI-Prolog] Possible to register a foreign function dynamically?
- Prev by Date: Re: Possible to register a foreign function dynamically?
- Next by Date: Re: Business Rules in Prolog
- Previous by thread: Re: Possible to register a foreign function dynamically?
- Next by thread: Arithmetic and lists.
- Index(es):
Relevant Pages
|
|