The ovm_bstr_t type

The ovm_bstr_t type is the OrchIDS type of binary strings: fixed-size arrays of bytes.

It is defined this way in src/lang.h:

typedef struct ovm_bstr_s ovm_bstr_t;
struct ovm_bstr_s
  gc_header_t gc;
  size_t    len;
  uint8_t   str[STR_PAD_LEN];

The str field is defined with a dummy length of STR_PAD_LEN; its actual length is given by the len field.

The type ovm_bstr_t is a type of garbage-collectable data. To allocate a new object of type ovm_bstr_t, use the function:

ovm_var_t *ovm_bstr_new (gc_t *gc_ctx, size_t size);

This creates a new ovm_bstr_t object containing size bytes. Calling res the result, one always has TYPE(res)==T_BSTR. The actual array of bytes is left uninitialized. One can access it using BSTR(res), and its length (size) is BSTRLEN(res).

The return type of ovm_bstr_new() is the universal type ovm_var_t instead of ovm_bstr_t, for practical reasons.

The result is created white, and much be gc_touch()ed before storing it into a garbage-collectable object.

The returned ovm_bstr_t object res is modifiable.

There is also a type of virtual binary strings ovm_vbstr_t.