Re: Possible to register a foreign function dynamically?



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

.



Relevant Pages

  • Re: Is this str_rev() ok?
    ... Very odd stuff indeed. ... ....since you don't modify the input string and the function is safe ... unsuccessful and returned a null pointer. ... allocated memory, which is in itself undefined behavior. ...
    (comp.lang.c)
  • Re: "Mastering C Pointers"....
    ... A pointer is a kind of variable that can "point to" some object. ... has a type (pointer to int), and a value of some kind. ... You may know that you can access these integers by using array notation ... The function will take one argument, a string, and will return the length ...
    (comp.lang.c)
  • Re: pesky Pointers !!
    ... > and the function takes it as a reference instead of a copy. ... function may access the string passed directly, ... > *px dereferences the pointer to get the value ... If pTest is a pointer-to-string, *pTest is the string it points to ...
    (alt.comp.lang.learn.c-cpp)
  • Re: strtok ( ) help
    ... > splitCommandssomehow modifying the pointer, but I HAVE to call that ... Here's an idea of how to use the strtok() function. ... don't mind trashing the contents of a string s, ... will give you a loop that extracts the tokens one at a time from s. ...
    (comp.lang.c)
  • Re: Increasing efficiency in C
    ... > You don't know where the pointer will end pointing to. ... > representation of a C string. ... Wow Dan, ... My whole point is that data structure development should ...
    (comp.lang.c)