std::shared_ptr, RTTI, and LLDB

Greg Clayton wrote:

We use a lot of shared pointers, though we aren't currently using the fancy RTTI aspects of it. We really want _some_ sort of shared pointer so we can have STL collections of objects that don't move around when collections grow. Also with a lot of our partial parsing we can determine how many objects there are in a collection, resize the collection to contain that many objects, then lazily populate such objects.

<snip>

As long as it is a reference counted pointer that doesn't require us to build boost.

We can easily replace all shared pointers within LLDB by redefining "lldb::SharedPtr" in lldb-types.h.

Feel free to experiment, though I would rather not pull in all of boost just to get a shared pointer... We currently get that from a tr1 directory on MacOSX. Does linux have a similar implementation in tr1 (#include <tr1/memory>)? We do make use of putting objects into shared pointers that are the virtual base class impementations of pure virtual protocols, so I am not sure if this requires RTTI (I can't remember what role RTTI plays in the shared pointers...).

libc++ (http://libcxx.llvm.org/) has a std::shared_ptr:

http://llvm.org/svn/llvm-project/libcxx/trunk/include/memory

If desired I can pull the shared_ptr bits out of this file, reduce dependencies as much as possible, pull the rtti bits, and ship you a custom shared_ptr.

I should first peruse your source and find out just how much shared_ptr you need. For example if you don't need weak_ptr or enable_shared_from_this, I can trim shared_ptr from two reference counts down to one. This trimming is already done in libc++ as I needed it for locale anyway.

-Howard

Howard, that would be great if you could trim this down for us.

I don't believe we need anyting fancy (no RTTI, no weak_ptr (what I am aware of), no enable_shard_from_this). If you can send me a header that we can include into our Utility folder, I will check it in ASAP and see if we switch over to using it.

My goal is to get us off of RTTI in LLDB so we can start intermixing LLVM all over the place without any RTTI woes.

Greg Clayton

Howard, that would be great if you could trim this down for us.

Yep, thanks for doing this Howard!

I don't believe we need anyting fancy (no RTTI, no weak_ptr (what I am aware of), no enable_shard_from_this). If you can send me a header that we can include into our Utility folder, I will check it in ASAP and see if we switch over to using it.

It would be great to drop this into include/llvm/ADT. For example, we already have include/llvm/ADT/OwningPtr.h which is a close relation.

-Chris

Here is a much trimmed down refcounted ptr. The trimming reduces both dependencies and features.

-Howard

SharingPtr.h (4.61 KB)

SharingPtr.cpp (855 Bytes)

Okay; I can't test this properly, but the implementation appears to be
sufficient, although there appear to be a couple minor bugs (diff
attached).

In terms of completely turning off RTTI, there are a few more changes
required to eliminate the use of dynamic_cast; besides that, though,
it appears quite feasible (hacky diff attached).

-Eli

lldbdiff.txt (9.02 KB)

sharingptrheaderdiff.txt (543 Bytes)

Is this the only place we are currently using RTTI? If so that is great. Jim Ingham should be able to get rid of this RTTI pretty easily early next week.