Replies: 3 comments · 3 replies
-
| UPD: it says registers are ok in ruby, but RB_GC_GUARD is still needed in some cases |
Beta Was this translation helpful? Give feedback.
All reactions
-
| I see. I'll try to figure out if it is possible to automatically generate bindings for C macros. |
Beta Was this translation helpful? Give feedback.
All reactions
-
| You may want to look how it's done in |
Beta Was this translation helpful? Give feedback.
All reactions
-
👀 1
-
| Stumbled upon Python's cffi, it uses pycparser - common approach is to preprocess headers with Also, I have a question about compatibility, where will it fail if a signature of a function is changed or it's removed completely? For example, Rust |
Beta Was this translation helpful? Give feedback.
All reactions
-
👀 1
-
| @uvlad7 Sorry for the late reply.
https://github.com/jasonroelofs/rbgccxml uses https://github.com/CastXML/CastXML internally. Therefore, I tried using CastXML directly, but it seemed that the macro function information could not be expanded. e.g. # sum.h #define SUM(a, b) ((a) + (b))$ castxml -Wno-unused-command-line-argument --castxml-cc-gnu-c /usr/bin/clang --castxml-gccxml sum.h -o sum.h.xmlBody of sum.h.xml<?xml version="1.0"?> <GCC_XML version="0.9.0" cvs_revision="1.145"> <Namespace id="_1" name="::" members="_2 _3 _4 _5 _6 _7 _8 _9 _10 _11 _12 _13 _14 _15 _16 _17 _18 _19 _20 _21 _22 _23 _24 _25 _26 _27 _28 _29 _30 _31 _32 _33 _34 _35 _36 _37 _38 _39 _40 _41 _42 _43 _44 _45 _46 _47 _48 _49 _50 _51 _52 _53 _54 _55 _56 _57 _58 _59 _60 _61 _62 _63"/> <Typedef id="_2" name="__int128_t" type="_64" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_3" name="__uint128_t" type="_65" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_4" name="__NSConstantString" type="_66" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_5" name="__SVInt8_t" type="_67" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_6" name="__SVInt16_t" type="_68" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_7" name="__SVInt32_t" type="_69" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_8" name="__SVInt64_t" type="_70" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_9" name="__SVUint8_t" type="_71" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_10" name="__SVUint16_t" type="_72" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_11" name="__SVUint32_t" type="_73" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_12" name="__SVUint64_t" type="_74" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_13" name="__SVFloat16_t" type="_75" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_14" name="__SVFloat32_t" type="_76" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_15" name="__SVFloat64_t" type="_77" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_16" name="__SVBfloat16_t" type="_78" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_17" name="__SVMfloat8_t" type="_79" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_18" name="__clang_svint8x2_t" type="_80" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_19" name="__clang_svint16x2_t" type="_81" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_20" name="__clang_svint32x2_t" type="_82" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_21" name="__clang_svint64x2_t" type="_83" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_22" name="__clang_svuint8x2_t" type="_84" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_23" name="__clang_svuint16x2_t" type="_85" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_24" name="__clang_svuint32x2_t" type="_86" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_25" name="__clang_svuint64x2_t" type="_87" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_26" name="__clang_svfloat16x2_t" type="_88" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_27" name="__clang_svfloat32x2_t" type="_89" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_28" name="__clang_svfloat64x2_t" type="_90" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_29" name="__clang_svbfloat16x2_t" type="_91" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_30" name="__clang_svmfloat8x2_t" type="_92" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_31" name="__clang_svint8x3_t" type="_93" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_32" name="__clang_svint16x3_t" type="_94" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_33" name="__clang_svint32x3_t" type="_95" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_34" name="__clang_svint64x3_t" type="_96" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_35" name="__clang_svuint8x3_t" type="_97" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_36" name="__clang_svuint16x3_t" type="_98" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_37" name="__clang_svuint32x3_t" type="_99" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_38" name="__clang_svuint64x3_t" type="_100" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_39" name="__clang_svfloat16x3_t" type="_101" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_40" name="__clang_svfloat32x3_t" type="_102" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_41" name="__clang_svfloat64x3_t" type="_103" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_42" name="__clang_svbfloat16x3_t" type="_104" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_43" name="__clang_svmfloat8x3_t" type="_105" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_44" name="__clang_svint8x4_t" type="_106" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_45" name="__clang_svint16x4_t" type="_107" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_46" name="__clang_svint32x4_t" type="_108" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_47" name="__clang_svint64x4_t" type="_109" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_48" name="__clang_svuint8x4_t" type="_110" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_49" name="__clang_svuint16x4_t" type="_111" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_50" name="__clang_svuint32x4_t" type="_112" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_51" name="__clang_svuint64x4_t" type="_113" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_52" name="__clang_svfloat16x4_t" type="_114" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_53" name="__clang_svfloat32x4_t" type="_115" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_54" name="__clang_svfloat64x4_t" type="_116" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_55" name="__clang_svbfloat16x4_t" type="_117" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_56" name="__clang_svmfloat8x4_t" type="_118" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_57" name="__SVBool_t" type="_119" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_58" name="__clang_svboolx2_t" type="_120" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_59" name="__clang_svboolx4_t" type="_121" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_60" name="__SVCount_t" type="_122" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_61" name="__mfp8" type="_123" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_62" name="__builtin_ms_va_list" type="_124" context="_1" location="f0:0" file="f0" line="0"/> <Typedef id="_63" name="__builtin_va_list" type="_124" context="_1" location="f0:0" file="f0" line="0"/> <FundamentalType id="_64" name="__int128" size="128" align="128"/> <FundamentalType id="_65" name="unsigned __int128" size="128" align="128"/> <Struct id="_66" name="__NSConstantString_tag" context="_1" location="f0:0" file="f0" line="0" members="_125 _126 _127 _128" size="256" align="64"/> <FundamentalType id="_67" name="__SVInt8_t" size="0" align="128"/> <FundamentalType id="_68" name="__SVInt16_t" size="0" align="128"/> <FundamentalType id="_69" name="__SVInt32_t" size="0" align="128"/> <FundamentalType id="_70" name="__SVInt64_t" size="0" align="128"/> <FundamentalType id="_71" name="__SVUint8_t" size="0" align="128"/> <FundamentalType id="_72" name="__SVUint16_t" size="0" align="128"/> <FundamentalType id="_73" name="__SVUint32_t" size="0" align="128"/> <FundamentalType id="_74" name="__SVUint64_t" size="0" align="128"/> <FundamentalType id="_75" name="__SVFloat16_t" size="0" align="128"/> <FundamentalType id="_76" name="__SVFloat32_t" size="0" align="128"/> <FundamentalType id="_77" name="__SVFloat64_t" size="0" align="128"/> <FundamentalType id="_78" name="__SVBfloat16_t" size="0" align="128"/> <FundamentalType id="_79" name="__SVMfloat8_t" size="0" align="128"/> <FundamentalType id="_80" name="__clang_svint8x2_t" size="0" align="128"/> <FundamentalType id="_81" name="__clang_svint16x2_t" size="0" align="128"/> <FundamentalType id="_82" name="__clang_svint32x2_t" size="0" align="128"/> <FundamentalType id="_83" name="__clang_svint64x2_t" size="0" align="128"/> <FundamentalType id="_84" name="__clang_svuint8x2_t" size="0" align="128"/> <FundamentalType id="_85" name="__clang_svuint16x2_t" size="0" align="128"/> <FundamentalType id="_86" name="__clang_svuint32x2_t" size="0" align="128"/> <FundamentalType id="_87" name="__clang_svuint64x2_t" size="0" align="128"/> <FundamentalType id="_88" name="__clang_svfloat16x2_t" size="0" align="128"/> <FundamentalType id="_89" name="__clang_svfloat32x2_t" size="0" align="128"/> <FundamentalType id="_90" name="__clang_svfloat64x2_t" size="0" align="128"/> <FundamentalType id="_91" name="__clang_svbfloat16x2_t" size="0" align="128"/> <FundamentalType id="_92" name="__clang_svmfloat8x2_t" size="0" align="128"/> <FundamentalType id="_93" name="__clang_svint8x3_t" size="0" align="128"/> <FundamentalType id="_94" name="__clang_svint16x3_t" size="0" align="128"/> <FundamentalType id="_95" name="__clang_svint32x3_t" size="0" align="128"/> <FundamentalType id="_96" name="__clang_svint64x3_t" size="0" align="128"/> <FundamentalType id="_97" name="__clang_svuint8x3_t" size="0" align="128"/> <FundamentalType id="_98" name="__clang_svuint16x3_t" size="0" align="128"/> <FundamentalType id="_99" name="__clang_svuint32x3_t" size="0" align="128"/> <FundamentalType id="_100" name="__clang_svuint64x3_t" size="0" align="128"/> <FundamentalType id="_101" name="__clang_svfloat16x3_t" size="0" align="128"/> <FundamentalType id="_102" name="__clang_svfloat32x3_t" size="0" align="128"/> <FundamentalType id="_103" name="__clang_svfloat64x3_t" size="0" align="128"/> <FundamentalType id="_104" name="__clang_svbfloat16x3_t" size="0" align="128"/> <FundamentalType id="_105" name="__clang_svmfloat8x3_t" size="0" align="128"/> <FundamentalType id="_106" name="__clang_svint8x4_t" size="0" align="128"/> <FundamentalType id="_107" name="__clang_svint16x4_t" size="0" align="128"/> <FundamentalType id="_108" name="__clang_svint32x4_t" size="0" align="128"/> <FundamentalType id="_109" name="__clang_svint64x4_t" size="0" align="128"/> <FundamentalType id="_110" name="__clang_svuint8x4_t" size="0" align="128"/> <FundamentalType id="_111" name="__clang_svuint16x4_t" size="0" align="128"/> <FundamentalType id="_112" name="__clang_svuint32x4_t" size="0" align="128"/> <FundamentalType id="_113" name="__clang_svuint64x4_t" size="0" align="128"/> <FundamentalType id="_114" name="__clang_svfloat16x4_t" size="0" align="128"/> <FundamentalType id="_115" name="__clang_svfloat32x4_t" size="0" align="128"/> <FundamentalType id="_116" name="__clang_svfloat64x4_t" size="0" align="128"/> <FundamentalType id="_117" name="__clang_svbfloat16x4_t" size="0" align="128"/> <FundamentalType id="_118" name="__clang_svmfloat8x4_t" size="0" align="128"/> <FundamentalType id="_119" name="__SVBool_t" size="0" align="16"/> <FundamentalType id="_120" name="__clang_svboolx2_t" size="0" align="16"/> <FundamentalType id="_121" name="__clang_svboolx4_t" size="0" align="16"/> <FundamentalType id="_122" name="__SVCount_t" size="0" align="16"/> <FundamentalType id="_123" name="__mfp8" size="8" align="8"/> <PointerType id="_124" type="_129" size="64" align="64"/> <Field id="_125" name="isa" type="_130" context="_66" access="public" offset="0"/> <Field id="_126" name="flags" type="_131" context="_66" access="public" offset="64"/> <Field id="_127" name="str" type="_132" context="_66" access="public" offset="128"/> <Field id="_128" name="length" type="_133" context="_66" access="public" offset="192"/> <PointerType id="_130" type="_131c" size="64" align="64"/> <FundamentalType id="_131" name="int" size="32" align="32"/> <CvQualifiedType id="_131c" type="_131" const="1"/> <PointerType id="_132" type="_129c" size="64" align="64"/> <CvQualifiedType id="_129c" type="_129" const="1"/> <FundamentalType id="_133" name="long int" size="64" align="64"/> <FundamentalType id="_129" name="char" size="8" align="8"/> <File id="f0" name="<builtin>"/> </GCC_XML>
I checked out https://github.com/eliben/pycparser . However, it was found that the AST of macro functions cannot be obtained in pycparser. e.g. # sum.c #define SUM(a, b) ((a) + (b)) int foo() {} int main() { foo(); return 0; }$ python examples/using_gcc_E_libc.py /path/to/sum.c FileAST: FuncDef: Decl: foo, [], [], [], [] FuncDecl: TypeDecl: foo, [], None IdentifierType: ['int'] Compound: FuncDef: Decl: main, [], [], [], [] FuncDecl: TypeDecl: main, [], None IdentifierType: ['int'] Compound: FuncCall: ID: foo Return: Constant: int, 0
An error occurs during build. However, Ruby doesn't add or remove features within the same minor version. Therefore, go-gem-wrapper uses different bindings for each minor version of Ruby. e.g.
See also https://speakerdeck.com/sue445/road-to-go-gem-number-rubykaigi?slide=95 |
Beta Was this translation helpful? Give feedback.
All reactions
-
| I implemented In addition, I have provided comments automatic generation of macro functions at #324. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
This macro is used to protect
VALUEs from being GC-ed while they are still in use indirectly (or even directly, as otherwise it may be placed in a register, not on the stack). If for some reason it's not possible to useRB_GC_GUARDfrommemory.h, another solutions probably exist, as it's a common problem when interacting with conservative GCs. And I believe it should be mentioned in the readme.Beta Was this translation helpful? Give feedback.
All reactions