Re: RFC: glocal - automatically freeing memory when it goes out of scope

2012-05-30 Thread Mikkel Kamstrup Erlandsen
On 05/29/2012 10:21 PM, Ben Pfaff wrote: Mikkel Kamstrup Erlandsenmikkel.kamst...@canonical.com writes: On 05/29/2012 07:23 PM, Ben Pfaff wrote: Mikkel Kamstrup Erlandsenmikkel.kamst...@canonical.com writes: I have been looking at gcc's cleanup attribute[1] that allows one to specify a

Re: RFC: glocal - automatically freeing memory when it goes out of scope

2012-05-30 Thread Behdad Esfahbod
On 05/30/2012 05:17 AM, Paul Davis wrote: On Wed, May 30, 2012 at 3:22 AM, Mikkel Kamstrup Erlandsen mikkel.kamst...@canonical.com mailto:mikkel.kamst...@canonical.com wrote: alloca() does not provide a callback when cleaning up, and we need that for anything that needs a

Re: RFC: glocal - automatically freeing memory when it goes out of scope

2012-05-30 Thread Ben Pfaff
Mikkel Kamstrup Erlandsen mikkel.kamst...@canonical.com writes: I have been looking at gcc's cleanup attribute[1] that allows one to specify a callback that will be invoked when a variable goes out of scope. This allows one to play with automatically freeing resources. Is it possible to

Re: RFC: glocal - automatically freeing memory when it goes out of scope

2012-05-30 Thread Ben Pfaff
Mikkel Kamstrup Erlandsen mikkel.kamst...@canonical.com writes: On 05/29/2012 07:23 PM, Ben Pfaff wrote: Mikkel Kamstrup Erlandsenmikkel.kamst...@canonical.com writes: I have been looking at gcc's cleanup attribute[1] that allows one to specify a callback that will be invoked when a

Re: RFC: glocal - automatically freeing memory when it goes out of scope

2012-05-29 Thread Colin Walters
On Sun, 2012-05-27 at 11:20 +0200, Mikkel Kamstrup Erlandsen wrote: Attached a new version as a late update to this thread, but better than nothing I hope :-) I still haven't gotten around to sticking it in libegg (or even a bug). Sorry! I'll do that when I am more happy with what I have.

Re: RFC: glocal - automatically freeing memory when it goes out of scope

2012-05-29 Thread Mikkel Kamstrup Erlandsen
On 05/29/2012 05:36 PM, Colin Walters wrote: On Sun, 2012-05-27 at 11:20 +0200, Mikkel Kamstrup Erlandsen wrote: Attached a new version as a late update to this thread, but better than nothing I hope :-) I still haven't gotten around to sticking it in libegg (or even a bug). Sorry! I'll do

Re: RFC: glocal - automatically freeing memory when it goes out of scope

2012-05-29 Thread Mikkel Kamstrup Erlandsen
On 05/29/2012 07:23 PM, Ben Pfaff wrote: Mikkel Kamstrup Erlandsenmikkel.kamst...@canonical.com writes: I have been looking at gcc's cleanup attribute[1] that allows one to specify a callback that will be invoked when a variable goes out of scope. This allows one to play with automatically

Re: RFC: glocal - automatically freeing memory when it goes out of scope

2012-05-27 Thread Mikkel Kamstrup Erlandsen
On 10 April 2012 11:28, Mikkel Kamstrup Erlandsen mikkel.kamst...@canonical.com wrote: On 04/04/2012 05:35 AM, Colin Walters wrote: On Wed, 2011-11-16 at 21:05 +0100, Mikkel Kamstrup Erlandsen wrote: Hi all, I have been looking at gcc's cleanup attribute[1] that allows one to specify a

Re: RFC: glocal - automatically freeing memory when it goes out of scope

2012-04-10 Thread Mikkel Kamstrup Erlandsen
On 04/04/2012 05:35 AM, Colin Walters wrote: On Wed, 2011-11-16 at 21:05 +0100, Mikkel Kamstrup Erlandsen wrote: Hi all, I have been looking at gcc's cleanup attribute[1] that allows one to specify a callback that will be invoked when a variable goes out of scope. This allows one to play with

Re: RFC: glocal - automatically freeing memory when it goes out of scope

2012-04-05 Thread Alexander Larsson
- Original Message - On Tue, 03 Apr 2012 23:35:46 -0400 Colin Walters walt...@verbum.org wrote: On Wed, 2011-11-16 at 21:05 +0100, Mikkel Kamstrup Erlandsen wrote: Hi all, I have been looking at gcc's cleanup attribute[1] that allows one to specify a callback that

Re: RFC: glocal - automatically freeing memory when it goes out of scope

2012-04-05 Thread Alexander Larsson
gcc's constructor and destructor attributes as I understand them are principally used in connection with the loading and unloading of shared libraries at program start-up and close down, although I imagine they have other uses. If you say those may require OS support I will believe you

Re: RFC: glocal - automatically freeing memory when it goes out of scope

2012-04-05 Thread Chris Vine
On Thu, 05 Apr 2012 10:58:24 -0400 (EDT) Alexander Larsson al...@redhat.com wrote: [snip] I might have been a bit sloppy with my words, but the following C++ code, in a shared library: MyClass my_object; Needs to have the MyClass constructor for the static object my_object run before the

Re: RFC: glocal - automatically freeing memory when it goes out of scope

2012-04-05 Thread Colin Walters
On Thu, 2012-04-05 at 17:47 +0100, Chris Vine wrote: On Thu, 05 Apr 2012 10:58:24 -0400 (EDT) Alexander Larsson al...@redhat.com wrote: [snip] I might have been a bit sloppy with my words, but the following C++ code, in a shared library: MyClass my_object; Needs to have the

Re: RFC: glocal - automatically freeing memory when it goes out of scope

2012-04-04 Thread Chris Vine
On Tue, 03 Apr 2012 23:35:46 -0400 Colin Walters walt...@verbum.org wrote: On Wed, 2011-11-16 at 21:05 +0100, Mikkel Kamstrup Erlandsen wrote: Hi all, I have been looking at gcc's cleanup attribute[1] that allows one to specify a callback that will be invoked when a variable goes out

Re: RFC: glocal - automatically freeing memory when it goes out of scope

2012-04-03 Thread Colin Walters
On Wed, 2011-11-16 at 21:05 +0100, Mikkel Kamstrup Erlandsen wrote: Hi all, I have been looking at gcc's cleanup attribute[1] that allows one to specify a callback that will be invoked when a variable goes out of scope. This allows one to play with automatically freeing resources. So this

Re: RFC: glocal - automatically freeing memory when it goes out of scope

2011-11-22 Thread Mikkel Kamstrup Erlandsen
On 11/21/2011 04:54 PM, Hub Figuière wrote: On 21/11/11 07:34 AM, Mikkel Kamstrup Erlandsen wrote: This is precisely my motivation for introducing this; ie. not to catch leaks, but to tidy the code. Bigger code bases almost always grow functions with multiple returns - notably when error

Re: RFC: glocal - automatically freeing memory when it goes out of scope

2011-11-22 Thread Mikkel Kamstrup Erlandsen
On 11/21/2011 04:51 PM, Ross Burton wrote: On 21 November 2011 15:43, Dominic Lachowiczdomlachow...@gmail.com wrote: If you want this sort of behavior, use a language like C++ that supports stack-allocated objects natively. GtkMM and GlibMM already do this wonderfully. Using a GNU-C ism which

Re: RFC: glocal - automatically freeing memory when it goes out of scope

2011-11-22 Thread Tristan Van Berkom
On Tue, 2011-11-22 at 09:03 +0100, Mikkel Kamstrup Erlandsen wrote: On 11/21/2011 04:54 PM, Hub Figuière wrote: On 21/11/11 07:34 AM, Mikkel Kamstrup Erlandsen wrote: This is precisely my motivation for introducing this; ie. not to catch leaks, but to tidy the code. Bigger code bases almost

Re: RFC: glocal - automatically freeing memory when it goes out of scope

2011-11-22 Thread Emmanuele Bassi
hi; On 22 November 2011 09:44, Tristan Van Berkom trista...@openismus.com wrote: Similarly the GMainLoop, by virtue of being a loop, should also push a pool onto the autorelease pool stack and pop it while dispatching GSources (and this is where you get the extra 'unref on mainloop hit'

Re: RFC: glocal - automatically freeing memory when it goes out of scope

2011-11-22 Thread Tristan Van Berkom
On Tue, Nov 22, 2011 at 4:48 AM, Emmanuele Bassi eba...@gmail.com wrote: hi; On 22 November 2011 09:44, Tristan Van Berkom trista...@openismus.com wrote: Similarly the GMainLoop, by virtue of being a loop, should also push a pool onto the autorelease pool stack and pop it while dispatching

Re: RFC: glocal - automatically freeing memory when it goes out of scope

2011-11-22 Thread Hub Figuière
On 22/11/11 01:48 AM, Emmanuele Bassi wrote: the obvious issue is: how does this interact with languages that do have a GC, and how does the API work to avoid making the life of developers for high-level languages apps and/or bindings a nightmare. if libraries start using this object for their

Re: RFC: glocal - automatically freeing memory when it goes out of scope

2011-11-22 Thread Steve Frécinaux
On 11/22/2011 10:24 PM, Hub Figuière wrote: On 22/11/11 01:48 AM, Emmanuele Bassi wrote: the obvious issue is: how does this interact with languages that do have a GC, and how does the API work to avoid making the life of developers for high-level languages apps and/or bindings a nightmare. if

Re: RFC: glocal - automatically freeing memory when it goes out of scope

2011-11-21 Thread Hub Figuière
On 16/11/11 12:05 PM, Mikkel Kamstrup Erlandsen wrote: So; what say you? If there is interest I'll gladly polish it up for inclusion. There are also tonnes of other low hanging fruits like freeing other ref counted types, closing of streams, etc. How about a g_autorelease_pool() or something

Re: RFC: glocal - automatically freeing memory when it goes out of scope

2011-11-21 Thread Xavier Claessens
Le lundi 21 novembre 2011 à 00:00 -0800, Hub Figuière a écrit : On 16/11/11 12:05 PM, Mikkel Kamstrup Erlandsen wrote: So; what say you? If there is interest I'll gladly polish it up for inclusion. There are also tonnes of other low hanging fruits like freeing other ref counted types,

Re: RFC: glocal - automatically freeing memory when it goes out of scope

2011-11-21 Thread Morten Welinder
 if (1)    {      glocal_object GFile *file =  g_file_new_for_path (/tmp);      glocal_string gchar *basename = g_file_get_basename (file);      g_debug (Basename is '%s', basename);      // look ma' no leaks!    } This is, of course, cute but I don't think this would actually catch many

Re: RFC: glocal - automatically freeing memory when it goes out of scope

2011-11-21 Thread Mikkel Kamstrup Erlandsen
On 11/21/2011 03:45 PM, Morten Welinder wrote: if (1) { glocal_object GFile *file = g_file_new_for_path (/tmp); glocal_string gchar *basename = g_file_get_basename (file); g_debug (Basename is '%s', basename); // look ma' no leaks! } This is, of course, cute

Re: RFC: glocal - automatically freeing memory when it goes out of scope

2011-11-21 Thread Dominic Lachowicz
If you want this sort of behavior, use a language like C++ that supports stack-allocated objects natively. GtkMM and GlibMM already do this wonderfully. Using a GNU-C ism which probably won't work with most other C compilers (MSVC, LLVM, ICC, ...) feels wrong to me. On Mon, Nov 21, 2011 at 10:34

Re: RFC: glocal - automatically freeing memory when it goes out of scope

2011-11-21 Thread Ross Burton
On 21 November 2011 15:43, Dominic Lachowicz domlachow...@gmail.com wrote: If you want this sort of behavior, use a language like C++ that supports stack-allocated objects natively. GtkMM and GlibMM already do this wonderfully. Using a GNU-C ism which probably won't work with most other C

Re: RFC: glocal - automatically freeing memory when it goes out of scope

2011-11-21 Thread Hub Figuière
On 21/11/11 07:34 AM, Mikkel Kamstrup Erlandsen wrote: This is precisely my motivation for introducing this; ie. not to catch leaks, but to tidy the code. Bigger code bases almost always grow functions with multiple returns - notably when error handling is introduced. Automatic freeing can cut

Re: RFC: glocal - automatically freeing memory when it goes out of scope

2011-11-21 Thread Hub Figuière
On 21/11/11 07:51 AM, Ross Burton wrote: We need a micro-C++ binding that looks exactly like traditional GObject C but also hooks up the nice features like stack allocated objects. I don't like C++ but I'd consider a C++ compiler to compile my C code if it could simplify memory management

Re: RFC: glocal - automatically freeing memory when it goes out of scope

2011-11-21 Thread Tristan Van Berkom
On Mon, 2011-11-21 at 00:00 -0800, Hub Figuière wrote: On 16/11/11 12:05 PM, Mikkel Kamstrup Erlandsen wrote: So; what say you? If there is interest I'll gladly polish it up for inclusion. There are also tonnes of other low hanging fruits like freeing other ref counted types, closing of