{"id":352,"date":"2022-08-30T14:59:55","date_gmt":"2022-08-30T14:59:55","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/06\/problem-about-ruby-ffi-collection-of-common-programming-errors\/"},"modified":"2022-08-30T14:59:55","modified_gmt":"2022-08-30T14:59:55","slug":"problem-about-ruby-ffi-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/problem-about-ruby-ffi-collection-of-common-programming-errors\/","title":{"rendered":"problem about ruby-ffi-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/d8d02cae31d044862e6cb39dcaa5e006?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nGeorgieF<br \/>\nc++ singleton shared-libraries ffi ruby-ffi<br \/>\nI am a real C++ noob, so please be patient with me. First lets set the stage.I have a C++ source in binary.cpp that compiles to a binary which looks like:# include &#8220;lotsofheaders.h&#8221;int main(int argc, char* argv[]) {int errorcode = FOOBAR_GLOBAL_UNKNOWN;\/\/ foobar instanciationFoobar foobar();\/\/ multiple calls to :send_auth passing in foobar instanceerrorcode = send_auth(getX(), getY(), foobar);errorcode = send_auth(getX(), getY(), foobar);errorcode = send_auth(getX(), getY(), foobar);return errorcode == FOOBAR_OK ? EXIT_SUCCESS : EXIT_FAILURE; }The send_auth method is loaded from another object code file and it gets passed an instance of foobar. The reason is, Foobar comes from an API object that I do not have the source of and which MUST NOT be instantiated more than once.Since main is called only once, everything works as expected: There is only one instance of Foobar and send_auth can be called multiple times.The binary is not of any use for me, I need a shared object library that does the same. It creates only one instance of Foobar and exposes an external interface method send_with_auth that can be called multiple times after my shared object lib was loaded.My library code in library.cpp looks some like this:# include &#8220;lotsof<\/li>\n<\/ul>\n<p id=\"rop\"><small>Originally posted 2013-11-06 03:13:51. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>GeorgieF c++ singleton shared-libraries ffi ruby-ffi I am a real C++ noob, so please be patient with me. First lets set the stage.I have a C++ source in binary.cpp that compiles to a binary which looks like:# include &#8220;lotsofheaders.h&#8221;int main(int argc, char* argv[]) {int errorcode = FOOBAR_GLOBAL_UNKNOWN;\/\/ foobar instanciationFoobar foobar();\/\/ multiple calls to :send_auth passing [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-352","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/352","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=352"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/352\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=352"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}