NAME ^

src/pmc/unmanagedstruct.pmc - C struct with unmanaged memory

DESCRIPTION ^

PMC class to hold C structs that parrot's not responsible for disposing of.

Buffer can be accessed using keyed assignments to PMC. Out of bounds access will very likely segfault.

Functions ^

static char *char_offset_int(PARROT_INTERP, PMC *pmc, INTVAL ix, int *type)

Returns the pointer for the element at index ix, and sets the element type in *type.

static INTVAL key_2_idx(PARROT_INTERP, PMC *pmc, PMC *key)

Returns the index for the element associated with key *key. Raises an exception if the key doesn't exist.

static char *char_offset_key(PARROT_INTERP, PMC *pmc, PMC *key, int *type)

Returns the pointer for the element associated with key *key, and sets the element type in *type.

static INTVAL ret_int(PARROT_INTERP, const char *p, int type)

Returns the element of type type starting at *p as an INTVAL.

If, for example, char or c<short> type size doesn't match, this will fail we need some more configure support for type sizes.

static FLOATVAL ret_float(PARROT_INTERP, const char *p, int type)

Returns the element of type type starting at *p as a FLOATVAL.

static STRING *ret_string(PARROT_INTERP, char *p, int type)

Returns the element of type type starting at *p as a Parrot string.

static PMC *ret_pmc(PARROT_INTERP, PMC *pmc, char *p, int type, INTVAL idx)

Returns the element of type type starting at *p as a PMC.

static void set_int(PARROT_INTERP, char *p, int type, INTVAL value)

static void set_float(PARROT_INTERP, char *p, int type, FLOATVAL value)

Sets the value of the element of type type starting at *p to value.

static void set_string(PARROT_INTERP, char *p, int type, STRING *value)

Sets the value of the element of type type starting at *p to *value.

static int calc_align(PARROT_INTERP, PMC *pmc, PMC *type_pmc, int type, int offs)

Alignment of contained structures is the alignment of the biggest item in that struct.

i386: long long or double is aligned on 4.

This is recursive as structure definitions.

static size_t calc_offsets(PARROT_INTERP, PMC *pmc, PMC *value, size_t toff)

Calculates the offsets for the struct. See init_pmc() for a description of *value.

Methods ^

void init()

Initializes the struct with a default value of NULL.

void init_pmc(PMC *value)

Initialize the struct with some data.

*value should be an array of triples of:

0

The datatype. See the enum in include/parrot/datatypes.h.

1

The count.

2

The offset.

void set_pmc(PMC *value)

Sets *value (see init_pmc() and calculates the offsets.

void mark()

Marks the struct as live.

INTVAL is_equal(PMC *value)

Returns whether the two structs are equivalent.

INTVAL defined()

Returns whether the struct is defined.

INTVAL get_integer()

Returns the size of the struct.

void set_integer_native(INTVAL size)

Sets the size of the struct.

INTVAL get_integer_keyed_int(INTVAL ix)

Returns the integer value at index ix.

INTVAL get_integer_keyed(PMC *key)

Returns the integer value associated with *key.

FLOATVAL get_number_keyed_int(INTVAL key)

Returns the floating-point value at index ix.

FLOATVAL get_number_keyed(PMC *key)

Returns the floating-point value associated with *key.

STRING *get_string_keyed_int(INTVAL key)

Returns the Parrot string value at index ix.

STRING *get_string_keyed(PMC *key)

Returns the Parrot string value associated with *key.

PMC *get_pmc_keyed_int(INTVAL key)

Returns the PMC value at index ix.

PMC *get_pmc_keyed(PMC *key)

Returns the PMC value associated with *key.

void *get_pointer()

Returns the pointer to the actual C struct.

void set_pointer(void *value)

Set the pointer to the actual C struct.

void set_integer_keyed_int(INTVAL ix, INTVAL value)

Sets the value of the element at index ix to value.

void set_integer_keyed(PMC *key, INTVAL value)

Sets the value of the element associated with key *key to value.

May cause segfaults if value is out of bounds.

void set_number_keyed_int(INTVAL key, FLOATVAL value)

Sets the value of the element at index ix to value.

void set_number_keyed(PMC *key, FLOATVAL value)

Sets the value of the element associated with key *key to value.

void set_string_keyed_int(INTVAL key, STRING *value)

Sets the value of the element at index key to *value.

void set_string_keyed(PMC *key, STRING *value)

Sets the value of the element associated with key *key to *value.

HISTORY ^

Initial revision by sean 2002/08/04

SEE ALSO ^

docs/pmc/struct.pod


parrot