Previous section To contents Next section

17.2.2 struct svalue

An svalue is the most central data structure in the Pike interpreter. It is used to hold values on the stack, local variables, items in arrays and mappings and a lot more. Any of the data types described in
chapter 4 "Data types" can be stored in an svalue.

A struct svalue has three members:

short type;
This says what type of value is actually stored in the svalue. Valid values are T_INT, T_FLOAT, T_STRING, T_ARRAY, T_MAPPING, T_MULTISET, T_FUNCTION, T_PROGRAM, T_OBJECT. In certain situations, other values are used in the type field, but those are reserved for internal Pike use only.
short subtype;
union anything u
This union contains the data. Depending on what the type member is, you can access one of the following union members:
type is:member to use:notes:
T_INTINT_TYPE integer
T_FLOATFLOAT_TYPE float_number
T_STRINGstruct pike_string *string
T_ARRAYstruct array *array
T_MAPPINGstruct mapping *mapping
T_MULTISETstruct multiset *multiset
T_OBJECTstruct object *object
T_PROGRAMstruct program *program
T_FUNCTIONstruct callable *efunIf subtype == FUNCTION_BUILTIN
T_FUNCTIONstruct object *objectIf subtype != FUNCTION_BUILTIN

Of course there are a whole bunch of functions for operating on svalues:

FUNCTION
free_svalue - free the contents of an svalue

SYNTAX
void free_svalue(struct svalue *s);

DESCRIPTION
This function is actually a macro, it will the contents of s. It does not however free s itself. After calling free_svalue, the contents of s is undefined, and you should not be surprised if your computer blows up if you try to access the it's contents. Also note that this doesn't nessecarily free whatever the svalue is pointing to, it only frees one reference. If that reference is the last one, the object/array/mapping/whatever will indeed be freed.

NOTE
This function will *not* call Pike code or error().

FUNCTION
free_svalues - free many svalues

SYNTAX
void free_svalues(struct svalue *s, INT32 howmany, TYPE_FIELD type_hint);

DESCRIPTION
This function does the same as free_svalue but operates on several svalues. The type_hint is used for optimization and should be set to BIT_MIXED if you don't know exactly what types are beeing freed.

NOTE
This function will *not* call Pike code or error().

SEE ALSO
free_svalue and TYPE_FIELD

FUNCTION
assign_svalue - copy an svalue to another svalue

SYNTAX
void assign_svalue(struct svalue *to, sstruct svalue *from);

DESCRIPTION
This function frees the contents of to and then copies the contents of from into to. If the value in from uses refcounts, they will be increased to reflect this copy.

NOTE
This function will *not* call Pike code or error().

SEE ALSO
free_svalue and assign_svalue_no_free

FUNCTION
assign_svalue_no_free - copy an svalue to another svalue

SYNTAX
void assign_svalue_no_free(struct svalue *to, sstruct svalue *from);

DESCRIPTION
This function does the same as assign_svalue() but does not free the contents of to before overwriting it. This should be used when to has not been initialized yet. If this funcion is incorrectly, memory leaks will occur. On the other hand, if you call assign_svalue on an uninitialized svalue, a core dump or bus error will most likely occur.

NOTE
This function will *not* call Pike code or error().

SEE ALSO
assign_svalue and free_svalue

FUNCTION
IS_ZERO - check if an svalue is true or false

SYNTAX
int IS_ZERO(struct svalue *s);

DESCRIPTION
This macro returns 1 if s is false and 0 if s is true.

NOTE
This macro will evaluate s several times.
This macro may call Pike code and/or error().

SEE ALSO
is_eq

FUNCTION
is_eq - check if two svalues contains the same value

SYNTAX
int is_eq(struct svalue *a, struct svalue *b);

DESCRIPTION
This function returns 1 if a and b contain the same value. This is the same as the `== operator in pike.

NOTE
This function may call Pike code and/or error().

SEE ALSO
IS_ZERO, is_lt, is_gt, is_le, is_ge and is_equal

FUNCTION
is_equal - check if two svalues are equal

SYNTAX
int is_equal(struct svalue *a, struct svalue *b);

DESCRIPTION
This function returns 1 if a and b contains equal values. This is the same as the function equal in pike.

NOTE
This function may call Pike code and/or error().

SEE ALSO
equal and is_eq

FUNCTION
is_lt - compare the contents of two svalues

SYNTAX
int is_lt(struct svalue *a, struct svalue *b);
int is_le(struct svalue *a, struct svalue *b);
int is_gt(struct svalue *a, struct svalue *b);
int is_ge(struct svalue *a, struct svalue *b);

DESCRIPTION
These functions are equal to the pike operators `<, `<=, `>, `>= respectively. For instance is_lt will return 1 if the contents of a is lesser than the contents of b.

NOTE
This function may call Pike code and/or error(). For instance, it will call error() if you try to compare values which cannot be compared such as comparing an integer to an array.

SEE ALSO
IS_ZERO and is_eq


Previous section To contents Next section