classification
Title: _PyUnicode_New(), throw and memory problem
Type: crash Stage:
Components: Library (Lib) Versions: Python 3.1
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Trigve.Siver
Priority: normal Keywords:

Created on 2010-09-06 13:25 by Trigve.Siver, last changed 2010-09-06 17:17 by Trigve.Siver. This issue is now closed.

Messages (3)
msg115702 - (view) Author: Trigve Siver (Trigve.Siver) Date: 2010-09-06 13:25
I'm using C++ with python embeding.
I'm creating a couple of unicode objects and then some
exception is thrown. While handling exception I create othet unicode objects. Then when creating some unicode object crash occurs. The problem is in _PyUnicode_New():325 on line (1):

if (free_list) {
    unicode = free_list; /*<- (1)*/
    free_list = *(PyUnicodeObject **)unicode;

In statement "unicode = free_list;" "unicode" pointer is bad pointer, in fact it's address is 5 bytes "lower" (i.e. should be 0x030bc3ff but is 0x030bc3fa).

It looks like this only happens when exception is thrown.

When python exception is set I throw C++ exception to signal C++ code that py exception was set. Next in C++ exception handler I format the python exception using some python unicode objects and then the problem occurs.
Without the C++ throw (Only python exception formatting) it looks like everything is working OK.

I'm using python 3.1.2 on Vista with MSVS 2010. I've also tried python 3.2a2 but it was the same.

I've tried to isolate the problem in some simple example but haven't been successful yet.
msg115714 - (view) Author: Trigve Siver (Trigve.Siver) Date: 2010-09-06 16:27
I've tried to examine it in more depth.

Setting the python exception isn't necessary, only throwing the C++ exception is needed for demonstrating the problem.

Also sometimes the address is 6 bytes "lower" than should be.
msg115721 - (view) Author: Trigve Siver (Trigve.Siver) Date: 2010-09-06 17:17
Nevermind, I found out it was problem with ref count while using PyTuple_SetItem()
History
Date User Action Args
2010-09-06 17:17:59Trigve.Siversetstatus: open -> closed
resolution: not a bug
messages: + msg115721
2010-09-06 16:27:53Trigve.Siversetmessages: + msg115714
2010-09-06 13:25:10Trigve.Sivercreate