Open vadorovsky opened 1 week ago
src/llvm/types/mod.rs
line 7 at r2 (raw file):
why is it unsafe?
The most of pointer types coming from LLVM-C API (through llvm-sys) are more vague than the C++ ones.
There is LLVMValueRef
which can be pretty much anything - Value
, Instruction
, GlobalVariable
or any of dozens of classes inheriting from Value
. Therefore constructing a wrapper corresponding to a C++ type (e.g. Instruction
) from LLVMValueRef
is unsafe, unless you perform a direct check.
But good that you asked. I didn't think about it before, but there are functions like IsAMDNode
or IsAInstruction
for performing such checks. Let me check if they cover all the types. If yes, I could make it method safe and just make sure we have checks everywhere. If no, I would either insist on keeping this unsafe or provide a separate method/trait for types for which the check functions exist.
Instead of keeping raw pointer fields (of types like
LLVMValueRef
,LLVMMetadataRef
) public and defining constructors with different names, provide theLLVMTypeWrapper
trait withfrom_ptr()
as_ptr()
method for all of them.This will allow to convert all safe wrappers from and to raw pointers with one method, which is going to be helpful for building macros for them.
Depends on #222
This change is