Eliminating the risk of dangling pointers in GTK+


I have developed a technology (called libstent) that prevents the risk
of dangling pointers in the C language. Due to the functionality of
g_object_weak_ref provided by GTK+ (well, GLIB), it has been easy to
integrate the two projects together.

If any of you have time, you might find it interesting to have a look
through a small example code. It would also be fantastic to hear your
feedback and any suggestions / issues you can find.


In general the following snippet describes what libstent does. First,
the problem:

----------------------- 8< -----------------------
struct SomeStruct *ptr = SomeStructCreate();


// is ptr still valid? How do we know if DoSomething has freed the data or not?
----------------------- >8 -----------------------

So now a potential solution with libstent:

----------------------- 8< -----------------------
REF(SomeStruct) ptr = SomeStructCreate();


// GET(ptr) is guaranteed to return NULL if DoSomething has freed the data
----------------------- >8 -----------------------

GTK+ has been a great project to test this with because not only is it
very large but it also provides a lot of potential complexities such
as callbacks providing raw pointers rather than the “smart” pointers
provided by libstent.


Karsten Pedersen

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]