{"id":294115,"date":"2019-09-01T15:00:12","date_gmt":"2019-09-01T15:00:12","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=294115"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=294115","title":{"rendered":"FFI: \u043f\u0438\u0448\u0435\u043c \u043d\u0430 Rust \u0432 PHP-\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\n<p>\u0412 PHP 7.4 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f FFI, \u0442.\u0435. \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 C (\u0438\u043b\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, Rust) \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u0446\u0435\u043b\u044b\u0439 extension \u0438 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u0435\u0433\u043e \u043c\u043d\u043e\u0433\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u043d\u044e\u0430\u043d\u0441\u0430\u0445. <\/p>\n<p>  <\/p>\n<blockquote><p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434 \u043d\u0430 <strong>Rust<\/strong>, \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0435\u0433\u043e <strong>PHP<\/strong>-\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435<\/p><\/blockquote>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u0418\u0434\u0435\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 FFI \u0432 PHP 7.4 \u0431\u044b\u043b\u0430 \u0432\u0437\u044f\u0442\u0430 \u0438\u0437 LuaJIT \u0438 Python, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e: \u0432 \u044f\u0437\u044b\u043a \u0432\u0441\u0442\u0440\u043e\u0435\u043d \u043f\u0430\u0440\u0441\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442 \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0446\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0438 \u0442.\u0434. \u044f\u0437\u044b\u043a\u0430 \u0421\u0438. \u041f\u043e \u0444\u0430\u043a\u0442\u0443 \u0442\u0443\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u0441\u0443\u043d\u0443\u0442\u044c \u0432\u0441\u0451 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0438 \u0441\u0440\u0430\u0437\u0443 \u043d\u0430\u0447\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440: <\/p>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php \/\/ \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0446\u0438\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 printf \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 \u0421\u0438 $ffi = FFI::cdef(     \"int printf(const char *format, ...);\", \/\/ \u044d\u0442\u043e \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u044f\u0437\u044b\u043a\u0430 \u0421\u0438     \"libc.so.6\"); \/\/  \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \/\/ \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c printf $ffi-&gt;printf(\"Hello %s!\\n\", \"world\");<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0447\u044c\u0438-\u0442\u043e \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u043b\u0438\u0431\u044b \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0438 \u0432\u0435\u0441\u0435\u043b\u043e, \u043d\u043e \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0438 \u0447\u0442\u043e-\u0442\u043e \u0441\u0432\u043e\u0451 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0440\u0430\u0441\u043f\u0430\u0440\u0441\u0438\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0444\u0430\u0439\u043b, \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0437 php.<\/p>\n<p>  <\/p>\n<p>\u0418\u0437 \u0442\u0440\u0435\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u043e\u0432 (C, C++, Rust) \u043b\u0438\u0447\u043d\u043e \u044f \u0432\u044b\u0431\u0438\u0440\u0430\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439. \u041f\u0440\u0438\u0447\u0438\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u0430: \u0443 \u043c\u0435\u043d\u044f \u043d\u0435 \u0445\u0432\u0430\u0442\u0438\u0442 \u043a\u043e\u043c\u043f\u0435\u0442\u0435\u043d\u0446\u0438\u0439, \u0447\u0442\u043e\u0431\u044b \u0441\u0445\u043e\u0434\u0443 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u0443\u044e \u043f\u043e \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043d\u0430 C \u0438\u043b\u0438 \u0421++. Rust \u0441\u043b\u043e\u0436\u043d\u043e\u0432\u0430\u0442, \u043d\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043c\u044b\u0441\u043b\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0430\u0434\u0451\u0436\u043d\u0435\u0435. \u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0441\u0440\u0430\u0437\u0443 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0442\u0435\u0431\u0435, \u0433\u0434\u0435 \u0442\u044b \u043d\u0435\u043f\u0440\u0430\u0432. \u041f\u043e\u0447\u0442\u0438 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f Undefined Behavior.<\/p>\n<p>  <\/p>\n<p>Disclaimer: \u044f \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0441\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043d\u0430 \u0441\u0432\u043e\u0439 \u0441\u0442\u0440\u0430\u0445 \u0438 \u0440\u0438\u0441\u043a.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0447\u0442\u043e-\u0442\u043e \u0441\u043e\u0432\u0441\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0435, \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u043d\u0438\u044f \u0447\u0438\u0441\u0435\u043b. \u041f\u0440\u043e\u0441\u0442\u043e \u0434\u043b\u044f \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043a\u0438. \u0410 \u043f\u043e\u0442\u043e\u043c \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435.<\/p>\n<p>  <\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442 \u043a\u0430\u043a \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <\/p>\n<p>  <\/p>\n<p><code>cargo new hellofromrust --lib<\/code><\/p>\n<p>  <\/p>\n<p>\u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0432 cargo.toml, \u0447\u0442\u043e \u044d\u0442\u043e \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 (dylib) <\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\"> \u2026. [lib] name=\"hellofromrust\" crate-type = [\"dylib\"]  \u2026.<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u0430\u043c\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043d\u0430 \u0420\u0430\u0441\u0442\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[no_mangle] pub extern \"C\" fn addNumbers(x: i32, y: i32) -&gt; i32 { x + y }<\/code><\/pre>\n<p>  <\/p>\n<p>\u043d\u0443 \u0442.\u0435. \u043e\u0431\u044b\u0447\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0442\u043e\u043b\u044c\u043a\u043e \u043a \u043d\u0435\u0439 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043e \u043f\u0430\u0440\u0430 \u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0441\u043b\u043e\u0432 no_mangle \u0438 extern &#171;C&#187;<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435, \u0434\u0435\u043b\u0430\u0435\u043c cargo build, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c so-\u0444\u0430\u0439\u043b (\u043f\u043e\u0434 \u041b\u0438\u043d\u0443\u043a\u0441\u043e\u043c)<\/p>\n<p>  <\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0437 php:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php $ffi = FFI::cdef(\"int addNumbers(int x, int y);\", '.\/libhellofromrust.so'); print \"1+2=\" . $ffi-&gt;addNumbers(1, 2) . \"\\n\"; \/\/ 1+2=3<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0447\u0438\u0441\u043b\u0430 \u043f\u0440\u043e\u0441\u0442\u043e. \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0446\u0435\u043b\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e, \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u043e\u0432\u043e\u0435 \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e.<\/p>\n<p>  <\/p>\n<p>\u0410 \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438? \u0410 \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0434\u0435\u0440\u0435\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432? \u0410 \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0420\u0430\u0441\u0442\u0430 \u0432 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0439?<\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u0438 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043c\u0435\u043d\u044f \u0437\u0430\u043c\u0443\u0447\u0438\u043b\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u043f\u0430\u0440\u0441\u0435\u0440 \u0430\u0440\u0438\u0444\u043c\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u043d\u0430 \u0420\u0430\u0441\u0442\u0435. \u0418 \u0440\u0435\u0448\u0438\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0438\u0437 PHP \u0434\u043b\u044f \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u043d\u044e\u0430\u043d\u0441\u043e\u0432.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0437\u0434\u0435\u0441\u044c: <a href=\"https:\/\/github.com\/anton-okolelov\/simple-rust-ariphmetic-parser\">simple-rust-ariphmetic-parser<\/a>. \u041a\u0441\u0442\u0430\u0442\u0438, \u0442\u0443\u0434\u0430 \u0436\u0435 \u044f \u043f\u043e\u043b\u043e\u0436\u0438\u043b docker \u043e\u0431\u0440\u0430\u0437, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0435\u0441\u0442\u044c PHP (\u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441 FFI), Rust, Cbindgen \u0438 \u0442.\u0434. \u0412\u0441\u0451, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430.<\/p>\n<p>  <\/p>\n<p>\u041f\u0430\u0440\u0441\u0435\u0440, \u0435\u0441\u043b\u0438 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0447\u0438\u0441\u0442\u044b\u0439 \u044f\u0437\u044b\u043a \u0420\u0430\u0441\u0442, \u0434\u0435\u043b\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<p>  <\/p>\n<p>\u0431\u0435\u0440\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u0432\u0438\u0434\u0430 &#171;100500<em>(2+35)-2<\/em>5&#8243; \u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0435\u0442 \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435-\u0434\u0435\u0440\u0435\u0432\u043e <a href=\"https:\/\/github.com\/anton-okolelov\/simple-rust-ariphmetic-parser\/blob\/master\/src\/expression.rs\">expression.rs<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">pub enum Expression {     Add(Box&lt;Expression&gt;, Box&lt;Expression&gt;),     Subtract(Box&lt;Expression&gt;, Box&lt;Expression&gt;),     Multiply(Box&lt;Expression&gt;, Box&lt;Expression&gt;),     Divide(Box&lt;Expression&gt;, Box&lt;Expression&gt;),     UnaryMinus(Box&lt;Expression&gt;),     Value(i64), }<\/code><\/pre>\n<p>  <\/p>\n<p>\u044d\u0442\u043e \u0420\u0430\u0441\u0442\u043e\u0432\u044b\u0439 enum, \u0430 \u0432 \u0420\u0430\u0441\u0442\u0435, \u043a\u0430\u043a \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, enum \u2014 \u044d\u0442\u043e \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u0431\u043e\u0440 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442, \u043d\u043e \u043a \u043d\u0438\u043c \u043c\u043e\u0436\u043d\u043e \u0435\u0449\u0435 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0417\u0434\u0435\u0441\u044c \u0435\u0441\u043b\u0438 \u0442\u0438\u043f \u0443\u0437\u043b\u0430 Expression::Value, \u0442\u043e \u043a \u043d\u0435\u043c\u0443 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 100500. \u0414\u043b\u044f \u0443\u0437\u043b\u0430 \u0442\u0438\u043f\u0430 Add \u0431\u0443\u0434\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0442\u0430\u043a\u0436\u0435 \u0434\u0432\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 (Box) \u043d\u0430 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f-\u043e\u043f\u0435\u0440\u0430\u043d\u0434\u044b \u044d\u0442\u043e\u0433\u043e \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u044f.  <\/p>\n<p>\u041f\u0430\u0440\u0441\u0435\u0440 \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e, \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u043d\u0438\u0435 Rust, \u0430 \u0432\u043e\u0442 \u0441 FFI \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043f\u043e\u043c\u0443\u0447\u0438\u0442\u044c\u0441\u044f. \u0415\u0441\u043b\u0438 \u0432 C \u0441\u0442\u0440\u043e\u043a\u0438 \u2014 \u044d\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0442\u0438\u043f char *, \u0442.\u0435. \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u043d\u0430 \\0, \u0442\u043e \u0432 \u0420\u0430\u0441\u0442\u0435 \u044d\u0442\u043e \u0441\u043e\u0432\u0441\u0435\u043c \u0434\u0440\u0443\u0433\u043e\u0439 \u0442\u0438\u043f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0445\u043e\u0434\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u0432 \u0442\u0438\u043f &amp;str \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c: <\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">CStr::from_ptr(s).to_str()<\/code><\/pre>\n<p>  <\/p>\n<p><a href=\"https:\/\/doc.rust-lang.org\/std\/ffi\/struct.CStr.html\">\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e CStr<\/a><\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0432\u0441\u0451 \u043f\u043e\u043b\u0431\u0435\u0434\u044b. \u041d\u0430\u0441\u0442\u043e\u044f\u0449\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043d\u0438 \u0420\u0430\u0441\u0442\u043e\u0432\u044b\u0445 \u0435\u043d\u0443\u043c\u043e\u0432, \u043d\u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0445 \u0441\u0441\u044b\u043b\u043e\u043a \u0442\u0438\u043f\u0430 Box \u0432 \u044f\u0437\u044b\u043a\u0435 C \u043d\u0435\u0442. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 ExpressionFfi \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0435\u0440\u0435\u0432\u0430 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0432 C-\u0441\u0442\u0438\u043b\u0435, \u0442.\u0435. \u0447\u0435\u0440\u0435\u0437 struct, union \u0438 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 (<a href=\"https:\/\/github.com\/anton-okolelov\/simple-rust-ariphmetic-parser\/blob\/master\/src\/ffi.rs\">ffi.rs<\/a>).<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[repr(C)] pub struct ExpressionFfi {     expression_type: ExpressionType,     data: ExpressionData, }  #[repr(u8)] pub enum ExpressionType {     Add = 0,     Subtract = 1,     Multiply = 2,     Divide = 3,     UnaryMinus = 4,     Value = 5, }  #[repr(C)] pub union ExpressionData {     pair_operands: PairOperands,     single_operand: *mut ExpressionFfi,     value: i64, }  #[derive(Copy, Clone)] #[repr(C)] pub struct PairOperands {     left: *mut ExpressionFfi,     right: *mut ExpressionFfi, }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0443 \u0438 \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u043d\u0435\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">impl Expression {     fn convert_to_c(&amp;self) -&gt; *mut ExpressionFfi {         let expression_data = match self {             Value(value) =&gt; ExpressionData { value: *value },             Add(left, right)             | Subtract(left, right)             | Multiply(left, right)             | Divide(left, right) =&gt; ExpressionData {                 pair_operands: PairOperands {                     left: left.convert_to_c(),                     right: right.convert_to_c(),                 },             },             UnaryMinus(operand) =&gt; ExpressionData {                 single_operand: operand.convert_to_c(),             },         };          let expression_ffi = match self {             Add(_, _) =&gt; ExpressionFfi {                 expression_type: ExpressionType::Add,                 data: expression_data,             },             Subtract(_, _) =&gt; ExpressionFfi {                 expression_type: ExpressionType::Subtract,                 data: expression_data,             },             Multiply(_, _) =&gt; ExpressionFfi {                 expression_type: ExpressionType::Multiply,                 data: expression_data,             },             Divide(_, _) =&gt; ExpressionFfi {                 expression_type: ExpressionType::Multiply,                 data: expression_data,             },             UnaryMinus(_) =&gt; ExpressionFfi {                 expression_type: ExpressionType::UnaryMinus,                 data: expression_data,             },             Value(_) =&gt; ExpressionFfi {                 expression_type: ExpressionType::Value,                 data: expression_data,             },         };         Box::into_raw(Box::new(expression_ffi))     } }<\/code><\/pre>\n<p>  <\/p>\n<p><code>Box::into_raw<\/code> \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u0438\u043f <code>Box<\/code> \u0432 \u0441\u044b\u0440\u043e\u0439 &#171;\u0441\u0438\u0448\u043d\u044b\u0439&#187; \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c<\/p>\n<p>  <\/p>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 PHP, \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[no_mangle] pub extern \"C\" fn parse_arithmetic(s: *const c_char) -&gt; *mut ExpressionFfi {     unsafe {         \/\/ todo: error handling         let rust_string = CStr::from_ptr(s).to_str().unwrap();         parse(rust_string).unwrap().convert_to_c()     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u043a\u0443\u0447\u0430 unwrap(), \u0447\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 &#171;\u043f\u0430\u043d\u0438\u043a\u0443\u0439 \u043f\u0440\u0438 \u043b\u044e\u0431\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0435&#187;. \u0412 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d \u043a\u043e\u0434\u0435 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 \u0421-\u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p>  <\/p>\n<p>\u041d\u0443 \u0438 \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u0437\u0434\u0435\u0441\u044c \u0432\u044b\u043d\u0443\u0436\u0434\u0435\u043d\u043d\u044b\u0439 \u0431\u043b\u043e\u043a unsafe, \u0431\u0435\u0437 \u043d\u0435\u0433\u043e \u0431\u044b \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043b\u043e\u0441\u044c. \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0432 \u044d\u0442\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 Rust \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u0437\u0430 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u0438. \u042d\u0442\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0438 \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e. \u041d\u0430 \u0441\u0442\u044b\u043a\u0435 Rust \u0438 C \u0442\u0430\u043a\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u0441\u0435\u0433\u0434\u0430. \u041e\u0434\u043d\u0430\u043a\u043e \u0432\u043e \u0432\u0441\u0435\u0445 \u0434\u0440\u0443\u0433\u0438\u0445 \u043c\u0435\u0441\u0442\u0430\u0445 \u0432\u0441\u0451 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u0435\u043c\u043e \u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e.<\/p>\n<p>  <\/p>\n<p>\u0424\u0443\u0444, \u043d\u0443 \u0432\u0440\u043e\u0434\u0435 \u0432\u0441\u0451, \u043c\u043e\u0436\u043d\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u041d\u043e \u0432\u043e\u043e\u0431\u0449\u0435-\u0442\u043e \u0435\u0441\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u043d\u044e\u0430\u043d\u0441: \u043d\u0430\u0434\u043e \u0435\u0449\u0435 \u043d\u0430\u0434\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u044b\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438, \u0447\u0442\u043e\u0431\u044b PHP \u043f\u043e\u043d\u0438\u043c\u0430\u043b \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438 \u0442\u0438\u043f\u043e\u0432.<\/p>\n<p>  <\/p>\n<p>\u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0432 \u0420\u0430\u0441\u0442 \u0435\u0441\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u0430\u044f \u0442\u0443\u043b\u0437\u0430 cbindgen. \u041e\u043d\u0430 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u0449\u0435\u0442 \u0432 \u043a\u043e\u0434\u0435 \u043d\u0430 \u0420\u0430\u0441\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u044b extern &#171;C&#187;, repr(\u0421) \u0438 \u0442.\u0434. \u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u044b\u0439 \u0444\u0430\u0439\u043b\u044b<\/p>\n<p>  <\/p>\n<p>\u041c\u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u043c\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0441 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u043c\u0438 cbindgen, \u043e\u043d\u0438 \u0443 \u043c\u0435\u043d\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438\u0441\u044c \u0442\u0430\u043a\u0438\u0435 (<a href=\"https:\/\/github.com\/anton-okolelov\/simple-rust-ariphmetic-parser\/blob\/master\/cbindgen.toml\">cbindgen.toml<\/a>):<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">language = \"C\" no_includes = true style=\"tag\"  [parse] parse_deps = true<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0435 \u0443\u0432\u0435\u0440\u0435\u043d, \u0447\u0442\u043e \u044f \u0447\u0435\u0442\u043a\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u044e \u0432\u0441\u0435 \u043d\u044e\u0430\u043d\u0441\u044b, \u043d\u043e \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 )<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u043f\u0443\u0441\u043a\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">cbindgen . -o target\/testffi.h<\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a\u043e\u0439:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">enum ExpressionType {   Add = 0,   Subtract = 1,   Multiply = 2,   Divide = 3,   UnaryMinus = 4,   Value = 5, }; typedef uint8_t ExpressionType;  struct PairOperands {   struct ExpressionFfi *left;   struct ExpressionFfi *right; };  union ExpressionData {   struct PairOperands pair_operands;   struct ExpressionFfi *single_operand;   int64_t value; };  struct ExpressionFfi {   ExpressionType expression_type;   union ExpressionData data; };  struct ExpressionFfi *parse_arithmetic(const char *s);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u00a0\u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0438 h-\u0444\u0430\u0439\u043b, \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <code>cargo build<\/code> \u0438 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430\u0448 php \u043a\u043e\u0434. \u041a\u043e\u0434 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 printExpression \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u0442\u043e, \u0447\u0442\u043e \u0440\u0430\u0441\u043f\u0430\u0440\u0448\u0435\u043d\u043e \u043d\u0430\u0448\u0435\u0439 Rust-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">&lt;?php  $cdef = \\FFI::cdef(file_get_contents(\"target\/testffi.h\"), \"target\/debug\/libexpr_parser.so\"); $expression = $cdef-&gt;parse_arithmetic(\"-6-(4+5)+(5+5)*(4-4)\");  printExpression($expression);  class ExpressionKind {     const Add = 0;     const Subtract = 1;     const Multiply = 2;     const Divide = 3;     const UnaryMinus = 4;     const Value = 5; }  function printExpression($expression) {     switch ($expression-&gt;expression_type) {         case ExpressionKind::Add:         case ExpressionKind::Subtract:         case ExpressionKind::Multiply:         case ExpressionKind::Divide:             $operations = [\"+\", \"-\", \"*\", \"\/\"];             print \"(\";             printExpression($expression-&gt;data-&gt;pair_operands-&gt;left);             print $operations[$expression-&gt;expression_type];             printExpression($expression-&gt;data-&gt;pair_operands-&gt;right);             print \")\";             break;         case ExpressionKind::UnaryMinus:             print \"-\";             printExpression($expression-&gt;data-&gt;single_operand);             break;         case ExpressionKind::Value:             print $expression-&gt;data-&gt;value;             break;     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0443 \u0432\u043e\u0442 \u0438 \u0432\u0441\u0451, \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435.<\/p>\n<p>  <\/p>\n<p>\u0425\u0440\u0435\u043d \u0442\u0430\u043c \u0431\u044b\u043b &#171;\u0432\u0441\u0451&#187;. \u041f\u0430\u043c\u044f\u0442\u044c \u043d\u0430\u0434\u043e \u0435\u0449\u0435 \u043e\u0447\u0438\u0441\u0442\u0438\u0442\u044c. \u0420\u0430\u0441\u0442 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0441\u0432\u043e\u044e \u043c\u0430\u0433\u0438\u044e \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u043c\u0438 \u0420\u0430\u0441\u0442-\u043a\u043e\u0434\u0430.<\/p>\n<p>  <\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u0449\u0435 \u043e\u0434\u043d\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e destroy<\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">#[no_mangle] pub extern \"C\" fn destroy(expression: *mut ExpressionFfi) {     unsafe {         match (*expression).expression_type {             ExpressionType::Add             | ExpressionType::Subtract             | ExpressionType::Multiply             | ExpressionType::Divide =&gt; {                 destroy((*expression).data.pair_operands.right);                 destroy((*expression).data.pair_operands.left);                 Box::from_raw(expression);             }             ExpressionType::UnaryMinus =&gt; {                 destroy((*expression).data.single_operand);                 Box::from_raw(expression);             }             ExpressionType::Value =&gt; {                 Box::from_raw(expression);             }         };     } }<\/code><\/pre>\n<p>  <\/p>\n<p><code>Box::from_raw(expression);<\/code> \u2014 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0435\u0442 \u0441\u044b\u0440\u043e\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0432 \u0442\u0438\u043f Box, \u0430 \u0442\u0430\u043a \u043a\u0430\u043a \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0438\u043a\u0435\u043c \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u0440\u0438 \u0432\u044b\u0445\u043e\u0434\u0435 \u0438\u0437 \u0441\u043a\u043e\u0443\u043f\u0430.<\/p>\n<p>  <\/p>\n<p>\u041d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u0441\u0431\u0438\u043b\u0434\u0438\u0442\u044c \u0438 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0442\u044c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u044b\u0439 \u0444\u0430\u0439\u043b.<\/p>\n<p>  <\/p>\n<p>\u0438 \u0432 php \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432\u044b\u0437\u043e\u0432 \u043d\u0430\u0448\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$cdef-&gt;destroy($expression);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u0442\u0435\u043f\u0435\u0440\u044c \u0442\u043e\u0447\u043d\u043e \u0432\u0441\u0451. \u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0438\u043b\u0438 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u044f \u0433\u0434\u0435-\u0442\u043e \u0431\u044b\u043b \u043d\u0435 \u043f\u0440\u0430\u0432, please feel free to comment.<\/p>\n<p>  <\/p>\n<p>\u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0441 \u043f\u043e\u043b\u043d\u044b\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435: [<a href=\"https:\/\/github.com\/anton-okolelov\/simple-rust-ariphmetic-parser\">https:\/\/github.com\/anton-okolelov\/simple-rust-ariphmetic-parser<\/a>]<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\"># build docker-compose build docker-compose run php74 cargo build  docker-compose run php74 cbindgen . -o target\/testffi.h  #run php docker-compose run php74 php testffi.php <\/code><\/pre>\n<p>  <\/p>\n<p>P.S. \u041c\u044b \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u044d\u0442\u043e \u043e\u0431\u0441\u0443\u0434\u0438\u043c \u0432 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u043c \u0432\u044b\u043f\u0443\u0441\u043a\u0435 \u043f\u043e\u0434\u043a\u0430\u0441\u0442\u0430 <a href=\"https:\/\/soundcloud.com\/znprod\/\">&#171;\u0426\u0438\u043d\u043a\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0434&#187;<\/a>, \u0442\u0430\u043a \u0447\u0442\u043e \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043f\u043e\u0434\u043a\u0430\u0441\u0442.<\/p>\n<\/div>\n<p>               <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/455614\/\"> https:\/\/habr.com\/ru\/post\/455614\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\n<p>\u0412 PHP 7.4 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f FFI, \u0442.\u0435. \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 C (\u0438\u043b\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, Rust) \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u0446\u0435\u043b\u044b\u0439 extension \u0438 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u0435\u0433\u043e \u043c\u043d\u043e\u0433\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u043d\u044e\u0430\u043d\u0441\u0430\u0445. <\/p>\n<p>  <\/p>\n<blockquote><p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434 \u043d\u0430 <strong>Rust<\/strong>, \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0435\u0433\u043e <strong>PHP<\/strong>-\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435<\/p><\/blockquote>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-294115","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/294115","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=294115"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/294115\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=294115"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=294115"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=294115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}