[PATCH] D10725: Improve testing for the C API
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 21 14:05:35 PST 2016
dblaikie added a subscriber: dblaikie.
================
Comment at: tools/llvm-c-test/echo.cpp:82
@@ +81,3 @@
+ LLVMGetParamTypes(Src, Params);
+ for (unsigned i = 0; i < ParamCount; i++) {
+ Params[i] = clone_type(Params[i], Ctx);
----------------
deadalnix wrote:
> echristo wrote:
> > Can you try to explain a different way? I'm not sure what you mean.
> Sure. The trick part is that LLVMGetParamTypes require a buffer passed down as a pointer and will fill it all. So we need to create a buffer and fill it. Vector like API do not really lend itself to this.
It's pretty common to use std::vector when interacting with C APIs from C++ - not sure if we're picturing the same thing. This is what I'd imagine:
std::vector<LLVMTypeRef> Params(ParamCount);
LLVMGetParamTypes(Src, Params.data());
... (probably use Params directly without using ParamCount at this point)
... (skip the "if ParamCount / free" part, because it'll be cleaned up naturally)
Is there something about that that doesn't work/did you have something else in mind, etc?
http://reviews.llvm.org/D10725
More information about the llvm-commits
mailing list