[PATCH] dynamic providers

Jim Meyering jim at meyering.net
Thu Dec 23 19:21:56 UTC 2010


Jim Meyering wrote:
> Jim Meyering wrote:
> ...
>> It looks like Boehm's GC code works fine in a multi-threaded
>> application, so I will try it.
>>
>> Not having to worry about explicitly freeing memory seems like
>> it will be quite liberating:
>>
>>   1) no need to ref-count; gc takes care of freeing as needed.
>>
>>   2) assuming write-once (no editing), there is no need to worry about
>>      which provider is "in use" or "deleted."  When deleting one,
>>      simply remove its name from the table.  Any existing users still
>>      have a pointer to the actual data.
>
> I've been pursuing this.
>
> The first hurdle was that a trivial use of GC_INIT triggers
> valgrind-reported failure.  That appears to be due to a weakness
> in GC_INIT, even with the latest sources.
> I subscribed to the GC list and reported it:
>
>  http://thread.gmane.org/gmane.comp.programming.garbage-collection.boehmgc/4237
>
> Luckily, as you can see in that thread, there is a work-around,
> and I confirmed that it works.
>
> I've begun adjusting for GC, and the simplest test (parser) now
> passes.  So far all I had to do (in addition to enabling use of
> GC_malloc, header #include adjustments, etc) was to avoid a few
> explicit free calls.
>
> Things to watch out for:
>
>     - in general, cannot put GC'd addresses in non-GC-controlled buffers.
>
>     - our use of glib (which defaults to using malloc) is unfortunate.
>         Making glib use GC_malloc, etc may be adequate.
>
>     - our use of C++/boost may complicate matters, as suggested in the gc FAQ.
>
> I'll report more tomorrow.

I have everything working with garbage collection enabled.
Getting that to work with valgrind was a little tricky,
since running valgrind even on a trivial gc-enabled
binary would result in a segfault.  The work-around:
(I learned, thanks to a quick reply on the GC list
 http://thread.gmane.org/gmane.comp.programming.garbage-collection.boehmgc/4237
 )
is to build the library from latest sources with
"CPPFLAGS=-DUSE_GET_STACKBASE_FOR_MAIN".  That solved the problem.

Hoping that I could simply adjust the current RPM
to use that, I did this:

    # Get sources and install under $HOME
    yumdownloader --source gc
    rpm -i gc-7.2-0.1.alpha4.fc13.src.rpm

    # Insert a line into the %configure section of the spec file:
    cd $HOME/rpmbuild/SPECS
    perl -ni -e \
   'print; /^%configure/ and print "CPPFLAGS=-DUSE_GET_STACKBASE_FOR_MAIN \\\n"'\
      gc.spec

    # Rebuild and install:
    rpmbuild -bb gc.spec
    sudo sh -c \
      "cd ~$USER/rpmbuild/RPMS/$(uname -m) && yum install --nogpgcheck gc-*"

Unfortunately, that libgc did not work in that via valgrind,
every program still segfaults.
So I conclude we require some patch that's on the trunk
since the 7.2alpha4 release we're using.


More information about the iwhd-devel mailing list