On Sun, Oct 28, 2012 at 10:12:41AM -0400, Evan Huus wrote:
> We might be able to fake the proper scoping using thread-local globals
> if we wrap everything in functions that assert the state of a
> dissection. Something like:
>
> __thread wmem_allocator_t *packet_scope;
> __thread gboolean packet_in_scope = FALSE;
Just a note before commiting:
__thread is GCC extension, MVSC has got __declspec(thread) and
C11 has got _Thread_local.
So to be portable we must use glib GStaticPrivate.
> wmem_allocator_t *
> wmem_packet_scope(void)
> {
> g_assert(packet_in_scope);
> return packet_scope;
> }
>
> void
> wmem_start_packet_scope(void)
> {
> g_assert(!packet_in_scope);
> packet_in_scope = TRUE;
> }
>
> void
> wmem_stop_packet_scope(void)
> {
> g_assert(packet_in_scope);
> packet_in_scope = FALSE;
> wmem_free_all(packet_scope);
> }
>
> Invalid accesses would still compile, but at least they would throw an
> assertion as soon as the code path was hit. Thoughts on something like
> this?
I'm not sure if you want to replace all ep_ pool with packet_scope pool,
but if yes what kind of memory you want to use in GUI, or for error messages
in epan/dfilter/? glib allocator?
Cheers,
Kuba.