You Are Here:

Community: Developer Discussion Boards

#1 Old Lightbulb Low-memory errors - 2006-07-23, 02:24

Join Date: Mar 2003
Posts: 88
mikaraento's Avatar
mikaraento
Offline
Forum Nokia Champion
Hi

I'm embedding the python interpreter into our code, and have noticed that stdlib, CSPyInterpreter and the TLS usage in Python are not safe if memory allocation fails in startup.

For example. ~CSPyInterpreter looks like
__ASSERT_DEBUG(_PyThreadState_Current !=PYTHON_TLS->thread_state,
User::Panic(_L("CSPyInterpreter"), 5));
PyEval_RestoreThread(PYTHON_TLS->thread_state);
Py_Finalize();
SPy_globals_finalize();
if (iCloseStdlib) CloseSTDLIB();
iPyheap->Close();
which will of course crash if PYTHON_TLS returns 0 or iPyheap is zero.

Same kind of code appears all over python_globals.cpp when accessing the TLS.

These are quite easy to fix, e.g., my copy of SPy_tls_finalize looks like
void SPy_tls_finalize(int fini_globals)
{
SPy_Tls* ptls = (SPy_Tls*)Dll::Tls();
if (ptls)
delete ptls->thread_locals;
if (fini_globals && ptls)
delete ptls->globals;
delete ptls;
Dll::SetTls(0);
}
now.

It's a little frustrating that Nokia doesn't apply the same testing criteria to their own code they demand from 3rd parties. This code would never pass the LOWMEM tests.

The worst is still the Symbian stdlib tho. The _REENT macro allocates the reent structure and puts it in TLS as necessary. If that code runs out of memory you get a ESTLIB-INIT 0 Panic. I guess the only way to get that to pass LOWMEM is to pre-allocate a chunk of memory in the beginning InitStdio and free it. For testing code using User::__DbgSetAllocFail() I'm having to dig into the private fields of RHeap to raise an appropriate error beforehand...

Just ranting,
Mika
Reply With Quote

#2 Old Re: Low-memory errors - 2006-07-24, 11:43

Join Date: Nov 2004
Posts: 105
rexwal
Offline
Regular Contributor
- Oops wrong thread .. moved -
Last edited by rexwal : 2006-07-25 at 09:48.
Reply With Quote

#3 Old Re: Low-memory errors - 2006-07-31, 22:46

Join Date: Aug 2004
Posts: 290
simo.salminen
Offline
Regular Contributor
Quote:
Originally Posted by mikaraento
For testing code using User::__DbgSetAllocFail() I'm having to dig into the private fields of RHeap to raise an appropriate error beforehand...
Just curious, why you have to do that?
Reply With Quote

#4 Old Thumbs up Re: Low-memory errors - 2006-08-01, 20:22

Join Date: Mar 2003
Posts: 88
mikaraento's Avatar
mikaraento
Offline
Forum Nokia Champion
(Re: digging into RHeap)

Quote:
Originally Posted by simo.salminen
Just curious, why you have to do that?
So I'm running a normal out-of-memory test loop:

while (err==KErrNoMemory) {
User::__DbgSetAllocFail(RHeap::EUser, RHeap::EDeterministic, fail_on);
TRAP(err, r.run());
User::__DbgSetAllocFail(RHeap::EUser, RHeap::ENone, 1);
++fail_on;
}

Now if the fail_on is set so that the _REENT macro cannot allocate the memory it needs I get a ESTLIB-INIT 0 panic and my test run stops. What I n eed to do is to not call the _REENT macro in that case, but to call User::LeaveNoMemory myself instea. To know whether that is the case, I need to go into RHeap and check iFailAllocCount and iFailRate:

if (h->iFailRate > 0 &&
(h->iFailAllocCount % h->iFailRate) < h->iFailRate &&
(h->iFailAllocCount % h->iFailRate) > h->iFailRate - 8) {
User::LeaveNoMemory();
}

I just figured out by testing that _REENT will try to allocate memory 7 times.

The other (better) option would be to reset iFailRate before calling _REENT, and set it to what it was + number of allocations afterward.

Mika
Reply With Quote

#5 Old Re: Low-memory errors - 2006-08-08, 15:36

Join Date: Dec 2004
Posts: 646
jplauril's Avatar
jplauril
Offline
Forum Nokia Expert
Quote:
Originally Posted by mikaraento
Hi
I'm embedding the python interpreter into our code, and have noticed that stdlib, CSPyInterpreter and the TLS usage in Python are not safe if memory allocation fails in startup.
Quote:
Originally Posted by mikaraento
It's a little frustrating that Nokia doesn't apply the same testing criteria to their own code they demand from 3rd parties. This code would never pass the LOWMEM tests.
You are quite right on both counts. Thanks for pointing out that bug.

You're probably cool with us integrating that fix to the next version, licensed under the Apache 2 license like the rest of that file?
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
VERY LOW MEMORY PERFOMANCE ON NOKIA 7710 roy_biswajit1 General Discussion 1 2006-03-27 03:06
Not closing when system tries to close due to low memory mtg101 General Symbian C++ 0 2006-02-07 12:01
Low Memory Test / C++ andreasklein General Symbian C++ 2 2004-02-16 13:06
Low Memory Test / C++ andreasklein General Symbian C++ 0 2004-01-29 14:16
can not successfully link any sample using .NET lobotomat Symbian Tools & SDKs 2 2002-08-20 01:29

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d81449X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZpythonQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZuserE5ftagQSxpythonX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ