On Thu, 6 Jul 2006, Hans-Christoph Steiner wrote:
Yeah, its probably not fixable without limiting flexibility. Any good programming language will let you crash things in certain ways (fork bomb, infinite loops, rm -rf /, etc.). Exception handling would be a nice solution to this, but that's not an easy one to implement.
Yes. This is because externs (and interns) aren't built in an interruptible fashion. What Pd needs for that, is a macro-driven block like:
TRY { ... } ENSURE { ... }
Where a TRY section may be interrupted anytime (e.g. by a watchdog timeout) and the ENSURE section is always run after the TRY section even when it was interrupted. The ENSURE section does cleanup in order to prevent leaks and possible crashes/inconsistencies. e.g.:
void myobject_mymethod(myobject *self, t_symbol *phun) { /* you may assume self->foo is 0 at this point */ TRY { self->foo = malloc(666); outlet_symbol(self->out,phun); (stuff goes here involving self->foo) } ENSURE { if (self->foo) {free(self->foo); self->foo=0;} } }
The TRY {} ENSURE {} statement would be implemented using standard (though scary) C functions like setjmp() and longjmp(), which handle nonlocal returns.
Also other handling mechanisms like CATCH and RETRY and such can be thought of and implemented.
API versioning can be used to separate object-classes that were written with exceptions in mind, from those that weren't.
A problem with watchdog timeouts is that it's difficult and nonportable for a UNIX signal-handler to influence the normal execution of the thread it runs on top of. As a result, to be portable, those timeouts have to be implemented in a more explicit way than we might want to, and then it wouldn't catch all possible timeouts. (e.g. not while(1){})
_ _ __ ___ _____ ________ _____________ _____________________ ... | Mathieu Bouchard - tél:+1.514.383.3801 - http://artengine.ca/matju | Freelance Digital Arts Engineer, Montréal QC Canada