{"id":53,"date":"2014-07-03T08:58:23","date_gmt":"2014-07-03T08:58:23","guid":{"rendered":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/?p=53"},"modified":"2014-07-08T08:30:55","modified_gmt":"2014-07-08T08:30:55","slug":"the-ovm_vstr_t-type","status":"publish","type":"post","link":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/?p=53","title":{"rendered":"The ovm_vstr_t type"},"content":{"rendered":"<p>The <code>ovm_vstr_t<\/code> type is the OrchIDS type of <strong>virtual<\/strong> character strings. Strings are fixed-size arrays of chars, and are implemented as the <a title=\"The ovm_str_t type\" href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/?p=50\"><code>ovm_str_t<\/code><\/a> type. On the opposite, virtual character strings are merely pointers to a subinterval of an actual character string.<!--more--><\/p>\n<p>It is defined this way in <tt>src\/lang.h<\/tt>:<\/p>\n<pre>typedef struct ovm_vstr_s ovm_vstr_t;\r\nstruct ovm_vstr_s\r\n{\r\n  gc_header_t gc;\r\n  ovm_var_t *delegate;\r\n  size_t    len;\r\n  char     *str;\r\n};<\/pre>\n<p>Typically, the <code>delegate<\/code> field will be a non-<code>NULL<\/code> object of type <code>ovm_str_t<\/code>, holding a character string; the <code>str<\/code> field points into the latter string, and the <code>len<\/code> field is meant to tell how many bytes we wish to actually consider for a substring.\u00a0 In general, if\u00a0the <code>delegate<\/code> field is non-<code>NULL<\/code>, it should be an object that should be marked by the garbage collector if we wish the <code>str<\/code> field to keep pointing to some valid string.\u00a0 For example, in <code>issdl_vstr_from_regex<\/code>, the <code>delegate<\/code> field is made to point to an object of type <code>ovm_regex_t<\/code>, and the <code>str<\/code> field points into its <code>regex_str<\/code> string.<\/p>\n<p>If the <code>delegate<\/code> field is <code>NULL<\/code>, then the <code>str<\/code> field must point into some global, constant array of chars. Don&#8217;t make it point to any other kind of data: if you deallocate the latter (either manually, or if you let the garbage collector do it), <code>str<\/code> will be left as a dangling pointer.<\/p>\n<p>The type <code>ovm_vstr_t<\/code> is a type of <a title=\"Garbage collection\" href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/?p=18\">garbage-collectable<\/a> data. To allocate a new object of type <code>ovm_vstr_t<\/code>, use the function:<\/p>\n<pre>ovm_var_t *ovm_vstr_new(gc_t *gc_ctx, ovm_var_t *delegate);<\/pre>\n<p>This creates a new <code>ovm_vstr_t<\/code> objecvt, with the given <code>delegate<\/code>. Calling <code>res<\/code> the result, one always has <code>TYPE(res)==T_VSTR<\/code>. The actual <code>len<\/code> and <code>str<\/code> fields are left uninitialized. One can access them using <code>VSTRLEN(res)<\/code> and <code>VSTR(res)<\/code>, respectively, both to write into or to read from.<\/p>\n<p>The return type of <code>ovm_vstr_new()<\/code> is the universal type <a title=\"The ovm_var_t universal type\" href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/?page_id=121\"><code>ovm_var_t<\/code><\/a> instead of <code>ovm_vstr_t<\/code>, for practical reasons.<\/p>\n<p>The result is created white, and much be <code>gc_touch()<\/code>ed before storing it into a garbage-collectable object.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The ovm_vstr_t type is the OrchIDS type of virtual character strings. Strings are fixed-size arrays of chars, and are implemented as the ovm_str_t type. On the opposite, virtual character strings are merely pointers to a subinterval of an actual character string.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4],"tags":[],"class_list":["post-53","post","type-post","status-publish","format-standard","hentry","category-data-types","category-virtual-machine"],"_links":{"self":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=\/wp\/v2\/posts\/53","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=53"}],"version-history":[{"count":6,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=\/wp\/v2\/posts\/53\/revisions"}],"predecessor-version":[{"id":147,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=\/wp\/v2\/posts\/53\/revisions\/147"}],"wp:attachment":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=53"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=53"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=53"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}