[PATCH][llvm-c] expose sys::getProcessTriple
Filip Pizlo
fpizlo at apple.com
Fri Jun 28 14:15:09 PDT 2013
Ping!
-F
On Jun 27, 2013, at 8:05 PM, Filip Pizlo <fpizlo at apple.com> wrote:
> The fact that this isn't already exposed makes using some other C APIs, like the disassembler API, really awkward in a JIT context - you don't want to have to describe to LLVM what the target name is for the process you're in, when LLVM already has this information.
>
> The challenge here is that sys::getProcessTriple() returns a std::string that it allocates itself. So we can't just have a "LLVMGetProcessTarget()" that returns a char*, unless we then require the user to free() that char*. I considered that but I feared that it would have been confusing to users: for example LLVMGetTarget() returns a char* that doesn't require deallocation. So, to make the ownership rules more explicit, I made the API take an already allocated char* and a size.
>
> I wanted to allow for this idiom for people who don't want to guess the right string size:
>
> size_t targetSize = LLVMGetProcessTarget(0, 0);
> char *target = malloc(targetSize);
> LLVMGetProcessTarget(target, targetSize);
>
> This means that I couldn't just call snprintf(). I actually ended up getting the buffer allocation wrong on the first try, so I include some test coverage to make sure that it really isn't messed up.
>
> -Filip
>
> <GetProcessTarget.patch>
More information about the llvm-commits
mailing list