f



Need help on how to handle C level exceptions

We are loading multiple tcl sessions into a java environment using TclBle=
nd.=20
When an exception occurs in TCL we need to ensure this doesn=92t cause th=
e=20
Java process to exit but allows us to handle the cleanup and removal of t=
he=20
interpreter in a controlled and known manner. To attempt to do this, We d=
id=20
the following:

     1)      Redefine the TCL Panic handler to prevent the abort function=
=20
from being called and throw an exception (windows only).
     2)      Modify the JNI wrapper to catch the exception.
     3)      Construct a suitable error message to return to Java, and he=
nce=20
to the end user.
     4)      Mark the interpreter as damaged and destroy it.

What we found with this approach was the panic handler could be kicked in=
 at=20
any point in the call stack and so when the exception was thrown and we=20
tried to dispose of the interpreter it wouldn=92t allow it because the ca=
ll=20
stack was larger than 1 and so it wouldn=92t let it happen.

What we really need to do is follow similar steps to the items above but =

rather than throw an exception in the panic handler, be able to mark the =

interpreter as damaged and so be able to dispose of it without issues. Th=
is=20
will require us to be able to do something in our custom panic handler to=
=20
basically perform a return from the panic handler back to the top of the =

command stack to prevent anything else from being processed and the eval =

command stack would be reset.

Any pointers on what C level command can be used in the panic handler wou=
ld=20
be greatly appreciated.

--=20
--=20
+------------------------------------------------------------------------=
+
| Gerald W. Lester, President, KNG Consulting LLC                        =
|
| Email: Gerald.Lester@kng-consulting.net                                =
|
+------------------------------------------------------------------------=
+

0
Gerald
10/10/2014 12:05:26 AM
comp.lang.tcl 23429 articles. 2 followers. Post Follow

2 Replies
353 Views

Similar Articles

[PageSpeed] 29

Quote: gwlester wrote on Fri, 10 October 2014 02:05
----------------------------------------------------
> 
> This 
> will require us to be able to do something in our custom panic handler to 
> basically perform a return from the panic handler back to the top of the 
> command stack to prevent anything else from being processed and the eval 
> command stack would be reset.
> 
> Any pointers on what C level command can be used in the panic handler would 
> be greatly appreciated.

"Popping back" an arbitrary amount of C stack in one leap is what longjmp() does.

However, I'm a bit worried by what you call 'C level exceptions' and equate to Tcl_Panic(). You must keep in mind that Tcl_Panic() is called in situations where we really have no way to get out in a more graceful manner. Very frequently, it means "Hey, our internal data structures are now *cked up beyond repair". In such cases, it is *extremely* dangerous to keep making assumptions about these data structures. And when unwinding the various parts of an interpreter, you're bound to rely on many of them...

If you really encounter a panicking Tcl and really need to keep going, I'd suggest (after the longjmp()) to just leave the interp alone, mark it as no longer usable, but not try any deallocation or similar internal resource release. Keep clear from its guts and you may survive.

-Alex

0
Alexandre
10/10/2014 7:09:15 PM
On 10/10/2014 20:09, Alexandre Ferrieux wrote:
> However, I'm a bit worried by what you call 'C level exceptions' and
> equate to Tcl_Panic(). You must keep in mind that Tcl_Panic() is called
> in situations where we really have no way to get out in a more graceful
> manner. Very frequently, it means "Hey, our internal data structures are
> now *cked up beyond repair". In such cases, it is *extremely* dangerous
> to keep making assumptions about these data structures. And when
> unwinding the various parts of an interpreter, you're bound to rely on
> many of them...
>
> If you really encounter a panicking Tcl and really need to keep going,
> I'd suggest (after the longjmp()) to just leave the interp alone, mark
> it as no longer usable, but not try any deallocation or similar internal
> resource release. Keep clear from its guts and you may survive.

But for the case of an allocation failure, a custom Tcl_Alloc that 
doesn't just Tcl_Panic on failure could do something smarter; it's one 
of the cases that is relatively easy to recover from. (This is different 
to a detected memory corruption or a call from a state that is 
documented to be meaningless and illegal.) It probably needs to release 
a small pool of memory to the thread to give it some working room, 
longjmp back to somewhere where there's sanity available :-) (which need 
not be too far in 8.6, which mostly doesn't build very deep C stacks) 
Tcl_CancelEval to clear out what can be done, and then kill the thread 
and nuke any remaining memory assigned to the thread (having virtually 
all memory be thread-specific helps ever so much).

Tricky, imperfect (the potential for trouble with locks held at the 
point of failure is the biggest deal I think; other resources probably 
have an exit- or thread-exit-handler already) but might just work in a 
lot of cases.

Donal.
-- 
Donal Fellows — Tcl user, Tcl maintainer, TIP editor.
0
Donal
10/13/2014 9:53:26 AM
Reply:

Similar Artilces:

Need help understanding exceptions handling from C extensions
I'm working on the test cases for my AIO extension library on windows and I have been running into this error consistently on one of my tests: test_addr_lookup_name_async(ClientTest): ArgumentError: NULL pointer given tc_client.rb:129:in `to_s' tc_client.rb:129:in `test_addr_lookup_name_async' The offending line is in the rescue block: begin q =3D AIOQueue.new a =3D AIOAddr.new(q) c =3D Callback.new n =3D 0 assert(a.is_attached?, "should be attached") a.lookup("www.google.com&qu...

!!! need to write an agent in C++ or C
Hi All, I'm newbie in SNMP. I NEED to write snmp agent in c++ or c for solaris. Is there a free agent toolkit available on SUN.com site? I know that there is a JDMK available. Is there any other toolkit (on SUN.com)? If no, can I use JDMK to develop an agent in c++ or c language? I'm not interested in AdventNet toolkit. BTW: is this good toolkit? Help me please, Thanks. Regards P miniu wrote: > I NEED to write snmp agent in c++ or c for solaris. Do you need to write one from scratch, or can you build on existing software? You might like to have a l...

Objective-C Exception Handling (Re: benchmark exception handling)
David Stes <stes@D5E02895.kabel.telenet.be> writes: .... > However, I am not sure that the end-product is really slower than the Apple > exception handling, which is something that was created by 'fixating' on > practical - short-term - problems. David, this is the new GCC 3.3 way of handling exceptions in Objective-C: ObjC/ObjC++ exception and synchronization support The Objective-C language now offers syntactic support for structured exception handling that is similar to what is offered by C++ and Java. To enable the new syntax, you must pass th...

I need help with xerces-c and xalan-c, please help -------------------------------
I am new to Xerces, Xalan and C++ but not to XML and XSL. I have been looking at the example but they are over my head. <doc> <item type="x"></item> <item type="y"></item> <item type="z"></item> .... <!-- I need to add/remove <item/> here --> </doc> Any help is appreciated. Thanks. -Tamim ...

Help needed with a C++ syntax (legal in C, but not C++)
Greetings, I'm trying to use a vender-supplied API in my C++ program. The vender's API is in C and it contains something similar to: type int INT; struct S { int i; double INT; /* OK in C, not C++ */ } According to a C/C++ book (C, A reference manual by S Harbison and G. Steele JR), the above struct is actually legal in C, as typedef names can be redeclared as objects in inner scopes. However, in C++ it is not permitted to do so within a structure or union -- which are scopes -- if the original typedef name has been used in the structure or union already. The problem I'm f...

wiki need a Tcl exception handling example
Hi, a exception handling example have to be added: -> http://en.wikipedia.org/wiki/Exception_handling_syntax#C.2B.2B mfg Andreas Otto On Jul 7, 3:24=A0am, Andreas Otto <aotto1...@users.sourceforge.net> wrote: > Hi, > > =A0 a exception handling example have to be added: > > =A0 ->http://en.wikipedia.org/wiki/Exception_handling_syntax#C.2B.2B > Do you suppose examples from beta release versions of the langauge count? Tcl 8.6 has try/catch/finally in it. Before that, catch is pretty much what is available "out of the box". Larry W. Virden w...

C++ exception handling : impacted by gcc optimizaton level?
Hi, I am using gcc3.2.3 on Red Hat Linux. I just find a strange thing of exception handling:if I compile the code in debug level, then the exception can be caught; if I compile it in optimized level , then the exception can not be caught. The compile option for debug is -c -DUNIX -fexceptions -g3 -DDEBUG -DLIN The compile option for optimize is -c -DUNIX -fexceptions -O3 -DNDEBUG -DLIN Basically here is the code, ====== On the Top ===================== try{ ... some function calls ... } catch (...){ printf("Caught...\n"); retu...

PLEASE HELP
Hi Everyone, I'm passing handles into a timer program within my GUI : handles.t = timer('Period',handles.period); %default = 1.0 seconds set(handles.t,'ExecutionMode','fixedrate'); set(handles.t,'TimerFcn',{'thread', handles}); % output theta1 theta2 theta3 on the screen start(handles.t); Inside the thread file is as follows: set(handles.ctheta_screen1,'string',num2str(handles.c_theta1,'%3.1f')); set(handles.ctheta_screen2,'string',num2str(handles.c_theta2,'%3.1f')); set(handles.ctheta_screen3,'st...

Exceptional C++ item 30. need help to understand thx.
Item 30 page 115: template <size_t S> class FixedAllocator { public: void* Allocate (/*requested size is always S*/); void Deallocate (void *); private: /*implemented using statics*/ }; "... Because the private details are likely to use statics,however, there could be problems if Deallocate is ever called from a static object's destructor. Probably safer is a singleton that manages a sepearate free list..." First of all how is it possible to ahave a static object? Why would there be a problem, where (could someone please provide an exa...

Need help with help need
Friends and wormbots: I am looking for some intrepid souls to try out and comment on a perl script I wrote. (What, perl in SAS-L and it's not David Cassell ?) The script takes the SAS help files apart and does some analysis (orphans, linkrot and duplicates) and inserts back links. What do back links do ? It ensures every page in the help system has a link to every page that links to it. (Actually only the the subset of the help system represented by the modules you choose to play with [there are over 140 help modules]) 1,000 lines of perl that sprouted out of a two line seed (or should...

Help needed: try/except -idiom vs. C-style coding
Hi there, I have defined function that calls another functions like this (modified for this mail): def main_function(): if not function1(): m = "main_function: function1 failed" print_error(m) return False if not function2(): m = "main_function: function2 failed" print_error(m) return False if not function3(): m = "main_function: function3 failed" print_error(m) return False return True In book "Learning Python 1st edition" is was said that this ...

need help converting string in double in one line!! lang C
i have a C exam for tomorrow and i have a copy of the last year exam i coudlnt resolve this question convert x to defo double x= 3.14159; char defo[20]; i must respond in one line any idea ??? please help i know atoi but its the inverse operation ;-( In article <40d0b7d5$1@news.vo.lu>, beltane@rocketmail.com wrote: >i have a C exam for tomorrow and i have a copy of the last year exam >i coudlnt resolve this question > >convert x to defo > >double x= 3.14159; > > char defo[20]; > >i must respond in one line any idea ??? please help > sprin...

RE: Help needed: try/except -idiom vs. C-style coding
pekka niiranen wrote: > I have defined function that calls another functions like this > (modified for this mail): >=20 > def main_function(): > if not function1(): > m =3D "main_function: function1 failed" =09 > print_error(m) > return False > if not function2(): > m =3D "main_function: function2 failed" =09 > print_error(m) > return False > if not function3(): > m =3D "main_function: function3 failed" =09 > print_error(m) > ...

Help Needed: C/C++ Standard Libraries
Hi. I am starting to learn C++ and am curious to find out if there are any Word documents or PDF files that list all of the standard libraries, the functions contained within them, a short description of them, and how to use them. Basically, what is listed on www.cplusplus.com under the reference area. It would be a major help to have a hard copy reference list on hand that lists all of this data. Thanks in advance... DV [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] da Vinci wrote: > I am start...

Web resources about - Need help on how to handle C level exceptions - comp.lang.tcl

United States free speech exceptions - Wikipedia, the free encyclopedia
Exceptions to free speech in the United States are limitations on the First Amendment's guarantee of free speech and expression as recognized ...

Podcast #42 – It’s The Exception That Proves The Rule
... Language and Usage , which was frustrated by the high number of certain types of questions that were coming in. Is this podcast the exception ...

Paul Ryan - Mother's health exception to abortion is "Mack truck" sized loophole - YouTube
April 5, 2000 - During the debate on a partial-birth abortion ban, Paul Ryan says that "the [mother's] health exception is a loophole wide enough ...

Why Kevin Pietersen is the exception to the No Dickhead Rule
Something fascinating is going on in English cricket at the moment.

Exception to Origin rule
Exception to Origin rule

India becomes the exception to US nuclear ban
President George Bush has agreed to share civilian nuclear technology with India, reversing decades of US policies designed to discourage countries ...

Is Richard Umbers, Bernie Brookes' replacement as Myer CEO, an exception?
Myer's CIO was recently elevated to the top job, but he's in a very small minority.

Men Need to Admit That Jian Ghomeshi Is No Exception
That men like Jian Ghomeshi are a terrible exception and if we as men simply stand up and say we are not as bad as that, or that we are not rapists ...

No exception in punishing the corrupt: People's Daily
No exception in punishing the corrupt: People's Daily People's Daily Online BEIJING, June 30 People's Daily , the flagship newspaper of the ...

No exception allowed in graft crackdown: People's Daily
No exception allowed in graft crackdown: People's Daily - Ecns.cn ecns The expulsion of Ling Jihua from the Communist Party of China (CPC) ...

Resources last updated: 1/26/2016 10:32:22 AM