* t/pmc/complex.t:
[parrot.git] / src / pmc / managedstruct.pmc
blobe579ca0b0533ac98073cd7db2ba0b3ef1f5785a1
1 /*
2 Copyright (C) 2001-2007, The Perl Foundation.
3 $Id$
5 =head1 DESCRIPTION
7 src/pmc/managedstruct.pmc - Memory-managed C struct
9 =head1 DESCRIPTION
11 C<ManagedStruct> extends C<UnManagedStruct> to provide a class to hold C
12 C<struct> values that Parrot is responsible for disposing of.
14 =head2 Methods
16 =over 4
18 =cut
22 #include "parrot/parrot.h"
25 pmclass ManagedStruct extends UnManagedStruct need_ext {
29 =item C<void init()>
31 Initializes an empty struct.
33 =cut
37     VTABLE void init() {
38         PObj_active_destroy_SET(SELF);
39         PMC_pmc_val(SELF) = NULL;
40         PMC_int_val(SELF) = 0;
41     }
45 =item C<void init_pmc(PMC *value)>
47 Initializes the struct with C<*value>.
49 =cut
53     VTABLE void init_pmc(PMC *value) {
54         SELF.init();
55         SUPER(value);
56     }
60 =item C<void destroy()>
62 Destroys the struct, freeing the allocated memory.
64 =cut
68     VTABLE void destroy() {
69         if (PMC_data(SELF))
70             mem_sys_free(PMC_data(SELF));
71     }
75 =item C<void set_integer_native(INTVAL value)>
77 (Re)allocates C<value> bytes for the struct.
79 =cut
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;
88         }
89         else if (value && !PMC_data(SELF)) {
90             PMC_data(SELF)    = mem_sys_allocate_zeroed(value);
91             PMC_int_val(SELF) = value;
92         }
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;
97             }
98         }
100         return;
101     }
107 =back
109 =head1 HISTORY
111 Initial revision by sean 2002/08/04.
113 =cut
118  * Local variables:
119  *   c-file-style: "parrot"
120  * End:
121  * vim: expandtab shiftwidth=4:
122  */