Gawk/Constructor-Functions
Next: Registration Functions, Previous: Memory Allocation Functions, Up: Extension API Description [Contents][Index]
17.4.4 Constructor Functions
The API provides a number of constructor functions for creating string and numeric values, as well as a number of convenience macros. This subsection presents them all as function prototypes, in the way that extension code would use them:
static inline awk_value_t *
make_const_string(const char *string, size_t length, awk_value_t *result);
- This function creates a string value in the
awk_value_t
variable pointed to byresult
. It expectsstring
to be a C string constant (or other string data), and automatically creates a copy of the data for storage inresult
. It returnsresult
. static inline awk_value_t *
make_malloced_string(const char *string, size_t length, awk_value_t *result);
- This function creates a string value in the
awk_value_t
variable pointed to byresult
. It expectsstring
to be a ‘char *
’ value pointing to data previously obtained fromgawk_malloc()
,gawk_calloc()
, orgawk_realloc()
. The idea here is that the data is passed directly togawk
, which assumes responsibility for it. It returnsresult
. static inline awk_value_t *
make_null_string(awk_value_t *result);
- This specialized function creates a null string (the “undefined” value) in the
awk_value_t
variable pointed to byresult
. It returnsresult
. static inline awk_value_t *
make_number(double num, awk_value_t *result);
- This function simply creates a numeric value in the
awk_value_t
variable pointed to byresult
. static inline awk_value_t *
make_number_mpz(void *mpz, awk_value_t *result);
- This function creates a GMP number value in
result
. Thempz
must be from a call toget_mpz_ptr()
(and thus be of real underlying typempz_ptr
).gawk
takes ownership of this memory. static inline awk_value_t *
make_number_mpfr(void *mpfr, awk_value_t *result);
- This function creates an MPFR number value in
result
. Thempfr
must be from a call toget_mpfr_ptr()
. (and thus be of real underlying typempfr_ptr
)gawk
takes ownership of this memory. static inline awk_value_t *
make_const_user_input(const char *string, size_t length, awk_value_t *result);
- This function is identical to
make_const_string()
, but the string is flagged as user input that should be treated as a strnum value if the contents of the string are numeric. static inline awk_value_t *
make_malloced_user_input(const char *string, size_t length, awk_value_t *result);
- This function is identical to
make_malloced_string()
, but the string is flagged as user input that should be treated as a strnum value if the contents of the string are numeric. static inline awk_value_t *
make_const_regex(const char *string, size_t length, awk_value_t *result);
- This function creates a strongly typed regexp value by allocating a copy of the string.
string
is the regular expression of lengthlen
. static inline awk_value_t *
make_malloced_regex(const char *string, size_t length, awk_value_t *result);
- This function creates a strongly typed regexp value.
string
is the regular expression of lengthlen
. It expectsstring
to be a ‘char *
’ value pointing to data previously obtained fromgawk_malloc()
,gawk_calloc()
, orgawk_realloc()
.
Next: Registration Functions, Previous: Memory Allocation Functions, Up: Extension API Description [Contents][Index]