[cfe-dev] Selector::getAsString problem in CIndex

John Thompson john.thompson.jtsoftware at gmail.com
Tue Oct 20 08:03:41 PDT 2009


Now that I have electricity again...

Sorry, I was looking too deep, not noticing that the function returned a
std::string.  The problem was up higher in CIndex.cpp, in a couple of the
functions that return const char *, with the same problem I described of the
temporary going away before the string can be used.

I worked around it by using a static buffer, which is admittedly not so
good.  A cleaner way might be to have the user pass in a string buffer,
since it seems this needs to be a C interface.  Should I do that, or does
the API need to remain unchanged?  Let me know if there's a better way.

The enclosed patch contains my hacked version, which also includes the DLL
exporting glue (redone in the naming style I'm used to - apologies to Jeff
Krall, who'd already done it).

Note that I moved the getLocationFromCursor function out of the extern "C"
{} because MSVC was complaining about it because of the object return type.

Where does "basename" come from on the non-Windows platforms?  It was
unresolved, so I guessed at it, but which seems to work.

The c-index-api-test.m test passes on Windows with these changes.

-John
On Mon, Oct 19, 2009 at 12:14 PM, John Thompson <
john.thompson.jtsoftware at gmail.com> wrote:

> I'm looking at a test failure of c-index-api-test.m on Windows, and I've
> run into a problem I don't know how to easily fix.
>
> In the function Selector::getAsString function in IdentifierTable.cpp at
> line 330:
>
>     return II->getName().str() + ":";
>
> On Windows, at least, this isn't working as expected.  I think
> it's because a tempory string created gets destructed before the return
> completes, causing the resulting string pointer to point to garbage,
> resulting in garbage for the identifier name in the index output.
>
> If someone more knowlegeable about it could take a look at it, I'd
> appreciate it.
>
> Note that if you need to run it on windows, you'll need some CIndex changes
> I'm working on, but haven't completed yet, so let me know if you need them.
>
> -John
>
> --
> John Thompson
> John.Thompson.JTSoftware at gmail.com
>
>


-- 
John Thompson
John.Thompson.JTSoftware at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20091020/a12482bb/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cindex.patch
Type: application/octet-stream
Size: 14752 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20091020/a12482bb/attachment.obj>


More information about the cfe-dev mailing list