[PATCH] D10725: Improve testing for the C API
Amaury SECHET via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 21 15:18:32 PST 2016
deadalnix added inline comments.
================
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);
----------------
dblaikie wrote:
> 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?
Yeah I can do that, but at the end, the Vector is fed to the C API as pointer + length, so none of the feature of vector are use or are usable.
http://reviews.llvm.org/D10725
More information about the llvm-commits
mailing list