{"id":143,"date":"2014-07-06T20:08:00","date_gmt":"2014-07-06T20:08:00","guid":{"rendered":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/?p=143"},"modified":"2017-12-17T15:51:00","modified_gmt":"2017-12-17T15:51:00","slug":"the-ovm_extern_t-type","status":"publish","type":"post","link":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/?p=143","title":{"rendered":"The ovm_extern_t type"},"content":{"rendered":"<p>The <code>ovm_extern_t<\/code> type is a catch-all OrchIDS type, for all foreign data structures.<!--more--><\/p>\n<p>It is defined this way in <tt>src\/lang.h<\/tt>:<\/p>\n<pre>struct ovm_extern_s\r\n{\r\n  gc_header_t gc;\r\n  void     *ptr;\r\n  char\t   *desc;\r\n  void *(*copy)(gc_t *gc_ctx, void *ptr);\r\n  void (*free)(void *ptr);\r\n};<\/pre>\n<p>The <code>ptr<\/code> field points to the piece of foreign data. The only thing OrchIDS needs to know about it is how to copy it, and how to deallocate it. \u00a0You must provide a function\u00a0<code>copy<\/code>, and a function <code>free<\/code> that do those tasks. The <code>desc<\/code> field points to an optional string descriptor. This should be a global static constant, typically. It won&#8217;t be deallocated or touched in any way by the garbage collector.<\/p>\n<p>The type <code>ovm_extern_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_extern_t<\/code>, the following function is provided:<\/p>\n<pre>ovm_var_t *ovm_extern_new(gc_t* gc_ctx, void *ptr, char *desc,\r\n                          void *(*copy)(gc_t *gc_ctx, void *ptr),\r\n<span style=\"font-size: 0.857142857rem; line-height: 1.714285714;\">                          void (*free) (gc_t *gc_ctx, void *ptr));<\/span><\/pre>\n<p>This creates a new <code>ovm_extern_t<\/code> object, pointing to <code>ptr<\/code>, with descriptor <code>desc<\/code>, copying\u00a0function\u00a0<code>copy<\/code>, and deallocating function <code>free<\/code>. Calling <code>res<\/code> the result, one always has <code>TYPE(res)==T_EXTERN<\/code>. One can access the <code>ptr<\/code>, <code>desc,\u00a0<code>copy<\/code><\/code>\u00a0and <code>free<\/code> fields using <code>EXTPTR(res)<\/code>, <code>EXTDESC(res)<\/code>, <code>EXTCOPY(res)<\/code>, and <code>EXTFREE(res)<\/code> respectively, all to write into or to read from.<\/p>\n<p>The return type of <code>ovm_extern_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_extern_t<\/code>, for practical reasons.<\/p>\n<p>The result of <code>ovm_extern_new()<\/code> 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_extern_t type is a catch-all OrchIDS type, for all foreign data structures.<\/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-143","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\/143","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=143"}],"version-history":[{"count":4,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=\/wp\/v2\/posts\/143\/revisions"}],"predecessor-version":[{"id":303,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=\/wp\/v2\/posts\/143\/revisions\/303"}],"wp:attachment":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=143"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=143"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=143"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}