Re: Need help with TRAP: FailedAssertion("!(context != CurrentMemoryContext)" - Mailing list pgsql-hackers

From Stephen Woodbridge
Subject Re: Need help with TRAP: FailedAssertion("!(context != CurrentMemoryContext)"
Date
Msg-id 51734C43.40004@swoodbridge.com
Whole thread Raw
In response to Re: Need help with TRAP: FailedAssertion("!(context != CurrentMemoryContext)"  (Stephen Woodbridge <woodbri@swoodbridge.com>)
List pgsql-hackers
OK, it looks like there is a bug related to MinGW builds. If I remove 
both  --enable-cassert --enable-debug from my configure then I get a 
build that works. Removing just  --enable-cassert  did not solve the 
problem. I did not try just removing --enable-debug only.

Someone might want to look into this.

Thanks,  -Steve

On 4/20/2013 8:21 PM, Stephen Woodbridge wrote:
> On 4/20/2013 5:00 PM, Andres Freund wrote:
>> On 2013-04-20 16:32:36 -0400, Stephen Woodbridge wrote:
>>> Hi all,
>>>
>>> I have been writing pg extensions for a while but I just  ran into a
>>> problem
>>> that has me stumped.
>>>
>>> I have code for a SRF and it works fine on pg 9.2.2 on linux, but
>>> fails with
>>> am error in the logfile.
>>>
>>> TRAP: FailedAssertion("!(context != CurrentMemoryContext)", File:
>>> "mcxt.c",
>>> Line: 172)
>>
>> This means that the current memory context is being deleted. Are you
>> doing that or did you maybe MemoryContextSwitchTo to some context but
>> not back?
>
> Andres,
>
> Thank you for your reply. The frustrating thing about this is the same
> source works fine in Linux. So here is the pseudo code of my source
> removing non pgsql stuff and not expected to be runnable:
>
> PG_FUNCTION_INFO_V1(myfunc);
> Datum myfunc(PG_FUNCTION_ARGS)
> {
>    if (SRF_IS_FIRSTCALL()) {
>      funcctx = SRF_FIRSTCALL_INIT();
>      oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
>      SPIcode = SPI_connect();
>
>      // execute some SPI queries and load some structures
>      // execute a query and save the tuptable and
>      // other stuff in funcctx->user_fctx
>
>      MemoryContextSwitchTo(oldcontext);
>    }
>
>    funcctx = SRF_PERCALL_SETUP();
>
>    if (call_cntr < max_calls) {
>
>      // process a row in my saved tuptable
>
>      SRF_RETURN_NEXT(funcctx, result)
>    }
>    else { // we are all done cleanup
>      // free stuff from my library
>      SPI_freetuptable(my_tuptable);
>      SPIcode = SPI_finish();     // <<<<< CRASHES HERE >>>>>
>      SRF_RETURN_DONE(funcctx);
>    }
> }
>
> So, like I said, it runs on Linux not in MinGW on windows. Anyway, did I
> mess up the memory context switching? Is there a way I can force the
> context to the appropriate place.
>
> Thanks,
>    -Steve
>
>




pgsql-hackers by date:

Previous
From: Stephen Woodbridge
Date:
Subject: Re: Need help with TRAP: FailedAssertion("!(context != CurrentMemoryContext)"
Next
From: Tom Lane
Date:
Subject: Re: Need help with TRAP: FailedAssertion("!(context != CurrentMemoryContext)"