2 Copyright (C) 2001-2007, The Perl Foundation.
7 src/pmc/managedstruct.pmc - Memory-managed C struct
11 C<ManagedStruct> extends C<UnManagedStruct> to provide a class to hold C
12 C<struct> values that Parrot is responsible for disposing of.
22 #include "parrot/parrot.h"
25 pmclass ManagedStruct extends UnManagedStruct need_ext {
31 Initializes an empty struct.
38 PObj_active_destroy_SET(SELF);
39 PMC_pmc_val(SELF) = NULL;
40 PMC_int_val(SELF) = 0;
45 =item C<void init_pmc(PMC *value)>
47 Initializes the struct with C<*value>.
53 VTABLE void init_pmc(PMC *value) {
60 =item C<void destroy()>
62 Destroys the struct, freeing the allocated memory.
68 VTABLE void destroy() {
70 mem_sys_free(PMC_data(SELF));
75 =item C<void set_integer_native(INTVAL value)>
77 (Re)allocates C<value> bytes for the struct.
83 VTABLE void set_integer_native(INTVAL value) {
84 if (PMC_data(SELF) && !value) {
85 mem_sys_free(PMC_data(SELF));
86 PMC_data(SELF) = NULL;
87 PMC_int_val(SELF) = 0;
89 else if (value && !PMC_data(SELF)) {
90 PMC_data(SELF) = mem_sys_allocate_zeroed(value);
91 PMC_int_val(SELF) = value;
93 else if (value && PMC_data(SELF)) {
94 if (PMC_int_val(SELF) != value) {
95 PMC_data(SELF) = mem_sys_realloc(PMC_data(SELF), value);
96 PMC_int_val(SELF) = value;
111 Initial revision by sean 2002/08/04.
119 * c-file-style: "parrot"
121 * vim: expandtab shiftwidth=4: