<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://www.newlc.com" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>NewLC - What&amp;#039;s wrong with my code? Thread+CleanupStack+CEZGZipToFile - Comments</title>
 <link>http://www.newlc.com/en/topic-16605</link>
 <description>Comments for &quot;What&#039;s wrong with my code? Thread+CleanupStack+CEZGZipToFile&quot;</description>
 <language>en</language>
<item>
 <title>Help Please</title>
 <link>http://www.newlc.com/en/topic-16605#comment-41803</link>
 <description>&lt;p&gt;I have this function in one of my project , got from a web site. But not working. Please Help!!&lt;/p&gt;

&lt;p&gt;void DeCompressAFile(TDesC&amp; aSrcName, TDesC&amp; aDstName)&lt;br /&gt;
{&lt;br /&gt;
TBuf8&lt;256&gt; msg8;TBuf&lt;256&gt; msg16;&lt;/p&gt;

&lt;p&gt;RFs fs;User::LeaveIfError(fs.Connect());&lt;br /&gt;
fs.SetSessionPath(_L(&quot;C:\\&quot;)); &lt;br /&gt;
RFile file;&lt;br /&gt;
TInt err = file.Open(fs,aDstName,EFileRead);&lt;/p&gt;

&lt;p&gt;if(err != KErrNone)&lt;br /&gt;
{ &lt;br /&gt;
msg8.Format(_L8(&quot;Error Reading File&quot;)); &lt;br /&gt;
msg16.Copy(msg8); &lt;br /&gt;
ERRDLG(msg16);&lt;br /&gt;
return;&lt;br /&gt;
}&lt;br /&gt;
msg8.Format(_L8(&quot;Before&quot;)); &lt;br /&gt;
msg16.Copy(msg8); &lt;br /&gt;
ERRDLG(msg16);&lt;/p&gt;

&lt;p&gt;CEZGZipToFile *zip = CEZGZipToFile::NewLC(fs, aSrcName, file); &lt;span style=&quot;font-weight:bold&quot;&gt;//The function stops here witout crash and returns.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;msg8.Format(_L8(&quot;CEZGZipToFile::before loop&quot;)); &lt;br /&gt;
msg16.Copy(msg8); &lt;br /&gt;
ERRDLG(msg16);&lt;/p&gt;

&lt;p&gt;TInt tempi = 0;&lt;br /&gt;
while(zip-&gt;InflateL()) &lt;br /&gt;
{ &lt;br /&gt;
tempi++; &lt;br /&gt;
}&lt;/p&gt;

&lt;p&gt;msg8.Format(_L8(&quot;Completed&quot;)); &lt;br /&gt;
msg16.Copy(msg8); &lt;br /&gt;
ERRDLG(msg16);&lt;/p&gt;

&lt;p&gt;CleanupStack::PopAndDestroy();&lt;br /&gt;
file.Close();&lt;br /&gt;
fs.Close();&lt;br /&gt;
}&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;</description>
 <pubDate>Tue, 25 Sep 2007 12:50:46 +0200</pubDate>
 <dc:creator>jayakumar</dc:creator>
 <guid isPermaLink="false">comment 41803 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: What&#039;s wrong with my code? Thread+CleanupStack+CEZGZipToFile</title>
 <link>http://www.newlc.com/en/topic-16605#comment-35656</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;IÂ’ve solved the problem, the cause is the custom-built Cleanup Stack itself will allocate much memory on the threadÂ’s heap, so when allocate another object on the heap, the program crashed(no memory). I increased the initial heap memory size of the thread the problem solved.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;</description>
 <pubDate>Wed, 08 Nov 2006 03:59:27 +0100</pubDate>
 <dc:creator>rensijie</dc:creator>
 <guid isPermaLink="false">comment 35656 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: What&#039;s wrong with my code? Thread+CleanupStack+CEZGZipToFile</title>
 <link>http://www.newlc.com/en/topic-16605#comment-35655</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;I did a test, I use:&lt;br /&gt;&lt;br /&gt;User::Panic( _L(&amp;quot;&amp;quot;), err ); &lt;br /&gt;&lt;br /&gt;to check the error code when&lt;br /&gt;&lt;br /&gt;CEZGZipToFile::NewL( fs, _L(&amp;quot;C:\\test.txt.gz&amp;quot;), file ); &lt;br /&gt;&lt;br /&gt;leaves, and the error code is -4, const TInt KErrNoMemory=(-4);&lt;br /&gt;&lt;br /&gt;why??? Did I miss something?&lt;br /&gt;&lt;/div&gt;</description>
 <pubDate>Wed, 08 Nov 2006 02:21:15 +0100</pubDate>
 <dc:creator>rensijie</dc:creator>
 <guid isPermaLink="false">comment 35655 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: What&#039;s wrong with my code? Thread+CleanupStack+CEZGZipToFile</title>
 <link>http://www.newlc.com/en/topic-16605#comment-35654</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;There is a thread in the Symbian KB check it: &lt;a href=&quot;http&amp;#58;//www3.symbian.com/faq.nsf/0/C03D689B80E9BBCC80256F81004FFD75?OpenDocument&quot; target=&quot;_blank&quot;&gt;In my code I need to TRAP a &amp;#039;LC&amp;#039; method/function but I understand doing this directly results in an application panic. How can I achieve this result without causing a panic?&lt;/a&gt;&lt;/div&gt;</description>
 <pubDate>Tue, 07 Nov 2006 09:20:05 +0100</pubDate>
 <dc:creator>vin2ktalks</dc:creator>
 <guid isPermaLink="false">comment 35654 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: What&#039;s wrong with my code? Thread+CleanupStack+CEZGZipToFile</title>
 <link>http://www.newlc.com/en/topic-16605#comment-35653</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;Thank you vin2ktalks and Bo, but it&amp;#039;s not working using both of your method.&lt;br /&gt;&lt;br /&gt;The most strange thing is if I don&amp;#039;t instantiate CEZGZipToFile, everything is fine. If I do it, TRAPD will catch the error, BUT THE ERROR CODE IS 0! MEANS KERRNONE!&lt;br /&gt;&lt;br /&gt;I don&amp;#039;t know why.&lt;br /&gt;&lt;br /&gt;Please help...&lt;/div&gt;</description>
 <pubDate>Tue, 07 Nov 2006 08:53:11 +0100</pubDate>
 <dc:creator>rensijie</dc:creator>
 <guid isPermaLink="false">comment 35653 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: What&#039;s wrong with my code? Thread+CleanupStack+CEZGZipToFile</title>
 <link>http://www.newlc.com/en/topic-16605#comment-35652</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;&lt;div class=&quot;quoteheader&quot;&gt;Quote from: rensijie&lt;/div&gt;&lt;div class=&quot;quote&quot;&gt;The code is below:&lt;br /&gt;&lt;br /&gt;&amp;lt;snip&amp;gt;&lt;br /&gt;&lt;br /&gt;CEZGZipToFile* zip = CEZGZipToFile::NewL( fs, _L(&amp;quot;C:\\test.txt.gz&amp;quot;), file ); will crash, I don&amp;#039;t know why.&lt;br /&gt;&lt;br /&gt;I&amp;#039;ve already creata a cleanup stack for the thread and also use TRAP, what&amp;#039;s wrong with my code? Please help me!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Thank you!&lt;br /&gt;Jimmy&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;There are some leave safety issues with the code that should come through with the version below.Â  See if it works better.&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;codeheader&quot;&gt;Code:&lt;/div&gt;&lt;div class=&quot;code&quot;&gt;TInt CSingleConsumer::ThreadFun( TAny* aPara )&lt;br /&gt;Â  Â  {&lt;br /&gt;Â  Â  __UHEAP_MARK;&lt;br /&gt;Â  Â  CTrapCleanup* cleanup = CTrapCleanup::New();&lt;br /&gt;Â  Â  if( cleanup == NULL )&lt;br /&gt;Â  Â  Â  Â  {&lt;br /&gt;Â  Â  Â  Â  __UHEAP_MARKEND; // premature bail-out, need to take care of the marker.&lt;br /&gt;Â  Â  Â  Â  return KErrNoMemory;&lt;br /&gt;Â  Â  Â  Â  }&lt;br /&gt;&lt;br /&gt;Â  Â  TRAPD( err, ThreadFunCleanupL( aPara ) ); // invoke the function which use CleanupStack&lt;br /&gt;&lt;br /&gt;Â  Â  delete cleanup;&lt;br /&gt;Â  Â  __UHEAP_MARKEND;&lt;br /&gt;&lt;br /&gt;Â  Â  return err; // Is always KErrNone of no leave occurs.&lt;br /&gt;Â  Â  }&lt;br /&gt;&lt;br /&gt;void CSingleConsumer::ThreadFunCleanupL( TAny* aPara )&lt;br /&gt;Â  Â  {&lt;br /&gt;Â  Â  ThreadPara* para = static_cast&amp;lt; ThreadPara* &amp;gt;( aPara ); // don&amp;#039;t want to use C-style casts.&lt;br /&gt;&lt;br /&gt;Â  Â  RFs fs;&lt;br /&gt;Â  Â  User::LeaveIfError( fs.Connect() );&lt;br /&gt;Â  Â  CleanupClosePushL( fs ); // Need to close in a leave situation&lt;br /&gt;&lt;br /&gt;Â  Â  RFile file;&lt;br /&gt;Â  Â  User::LeaveIfError( file.Replace( fs, _L(&amp;quot;C:\\test.txt&amp;quot;), EFileRead|EFileWrite|EFileShareAny );&lt;br /&gt;Â  Â  CleanupClosePushL( file ); // Need to close in a leave situation&lt;br /&gt;&lt;br /&gt;Â  Â  // I&amp;#039;m sure that C:\test.txt.gz exists and&lt;br /&gt;Â  Â  // the code below runs at no thread project&lt;br /&gt;Â  Â  // But here the line below will crash!!!&lt;br /&gt;Â  Â  CEZGZipToFile* zip = CEZGZipToFile::NewLC( fs, _L(&amp;quot;C:\\test.txt.gz&amp;quot;), file ); // Use NewLC instead :)&lt;br /&gt;&lt;br /&gt;Â  Â  // Do your thing here&lt;br /&gt;&lt;br /&gt;Â  Â  CleanupStack::PopAndDestroy( &amp;amp;fs ); // zip, file, fs&lt;br /&gt;Â  Â  }&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;</description>
 <pubDate>Mon, 06 Nov 2006 23:14:32 +0100</pubDate>
 <dc:creator>Bo</dc:creator>
 <guid isPermaLink="false">comment 35652 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: What&#039;s wrong with my code? Thread+CleanupStack+CEZGZipToFile</title>
 <link>http://www.newlc.com/en/topic-16605#comment-35651</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;Check what the SDK Help says for &lt;b&gt;E32USER-CBase 71&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;quoteheader&quot;&gt;Quote&lt;/div&gt;&lt;div class=&quot;quote&quot;&gt;This panic is raised when TRAPs have been nested and an attempt is made to exit from a TRAP nest level before all the cleanup items belonging to that level have been popped off the cleanup stack. &lt;br /&gt;&lt;br /&gt;There must be the same number of items on the cleanup stack on entering a TRAP harness as there is on exiting. In other words, anything that is pushed onto the cleanup stack inside a TRAP harness must be popped off before leaving the harness. &lt;br /&gt;&lt;br /&gt;For example, the following code avoids this panic when FooLC() does not leave, by explicitly popping pointer before the end of the harness: &lt;br /&gt;&lt;br /&gt;TRAPD(error, pointer = FooLC(); CleanupStack::Pop(pointer));&lt;br /&gt;See also How to use TRAP. &lt;/div&gt; &lt;br /&gt;&lt;br /&gt;These are the things I&amp;#039;ve noticed:&lt;br /&gt;&lt;br /&gt;1. Each time you return from &lt;i&gt;ThreadFun&lt;/i&gt; function you haven&amp;#039;t deleted the &lt;i&gt;&lt;b&gt;cleanup&lt;/b&gt;&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;2. You&amp;#039;ve pushed the &lt;i&gt;&lt;b&gt;fs&lt;/b&gt;&lt;/i&gt; into cleanupstack but haven&amp;#039;t popped it.&lt;br /&gt;&lt;br /&gt;3. You&amp;#8217;re neither pushing nor popping &lt;i&gt;&lt;b&gt;zip&lt;/b&gt;&lt;/i&gt; in to cleanupstack.&lt;br /&gt;&lt;br /&gt;4. What does the &lt;i&gt;&lt;b&gt;iPara&lt;/b&gt;&lt;/i&gt; do in your code?&lt;br /&gt;&lt;/div&gt;</description>
 <pubDate>Mon, 06 Nov 2006 10:05:00 +0100</pubDate>
 <dc:creator>vin2ktalks</dc:creator>
 <guid isPermaLink="false">comment 35651 at http://www.newlc.com</guid>
</item>
<item>
 <title>What&#039;s wrong with my code? Thread+CleanupStack+CEZGZipToFile</title>
 <link>http://www.newlc.com/en/topic-16605</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;&lt;/div&gt;&lt;p&gt;&lt;a href=&quot;http://www.newlc.com/en/topic-16605&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://www.newlc.com/en/topic-16605#comments</comments>
 <category domain="http://www.newlc.com/en/forums/symbian-c">Symbian C++</category>
 <pubDate>Mon, 06 Nov 2006 09:32:12 +0100</pubDate>
 <dc:creator>rensijie</dc:creator>
 <guid isPermaLink="false">16235 at http://www.newlc.com</guid>
</item>
</channel>
</rss>
