How the Nasal GC works: Difference between revisions

Jump to navigation Jump to search
m
Line 187: Line 187:
void* naRealloc(void* b, int n) { return realloc(b, n); }
void* naRealloc(void* b, int n) { return realloc(b, n); }
void naBZero(void* m, int n) { memset(m, 0, n); }
void naBZero(void* m, int n) { memset(m, 0, n); }
</syntaxhighlight>
= Allocating Nasal types =
Nasal types (scalars, vectors, hashes, funcs, ghosts) are allocated via wrappers in [https://gitorious.org/fg/simgear/blobs/next/simgear/nasal/misc.c misc.c].
These wrappers are:
* naNewString(): https://gitorious.org/fg/simgear/blobs/next/simgear/nasal/misc.c#line77
* naNewVector(): https://gitorious.org/fg/simgear/blobs/next/simgear/nasal/misc.c#line87
* naNewHash(): https://gitorious.org/fg/simgear/blobs/next/simgear/nasal/misc.c#line94
* naNewCode(): https://gitorious.org/fg/simgear/blobs/next/simgear/nasal/misc.c#line101
* naNewCCode(): https://gitorious.org/fg/simgear/blobs/next/simgear/nasal/misc.c#line106
* naNewFunc(): https://gitorious.org/fg/simgear/blobs/next/simgear/nasal/misc.c#line113
* naNewGhost(): https://gitorious.org/fg/simgear/blobs/next/simgear/nasal/misc.c#line122
* naNewGhost2(): https://gitorious.org/fg/simgear/blobs/next/simgear/nasal/misc.c#line135
All of these wrappers are really just helpers on top of naNew(), they just set up type-specific information and initialize each Nasal type properly.
For instance, first naNew() is called for the given context, along with the type info (to set up the size properly)- and then each type is initialized:
<syntaxhighlight lang="C">
naRef naNewString(struct Context* c)
{
    naRef s = naNew(c, T_STR);
    PTR(s).str->emblen = 0;
    PTR(s).str->data.ref.len = 0;
    PTR(s).str->data.ref.ptr = 0;
    PTR(s).str->hashcode = 0;
    return s;
}
</syntaxhighlight>
</syntaxhighlight>


Navigation menu