On Mon, Dec 20, 1999 at 10:38:26PM +0900, Osamu Shigematsu ([EMAIL PROTECTED]) wrote
> I got a promblem when porting L.A.M.E for Macintosh as REALbasic plugin. The
> problem is almost of L.A.M.E codes are abruptly quit with calling exit()
> function. However, I have to return error code and I am not allowed call
> exit() in the code resource.
> 
> I know, that GPL must be opened the source, thouth, the work to rewrite all
> functions to return error, don't call exit() is troublesome job and to give
> them comments of changings are more nuisance thing for me.
> 
> So, I wonder, how can I make L.A.M.E does not quit abruptly with exit(). I
> think I could check errors with stderr file.

I've never done any mac programming, but there are two ways I'd get
around that problem on a unix machine without changing the LAME code
at all.

1: Run calls to LAME functions in a child process.  That way, the main
process can keep running and wait for the child to exit.  The main
process can look at the exit code an see what to do next.  You can
also use atexit() or on_exit() in the child process if you have some
code you want to run if it ever does call exit().

2: If you can't, or don't want to create a new process for each lame
call, the following should work.  I've never tested it.  Before
calling one of LAME's library functions, call setjmp(), and set up an
"exit handler" with on_exit() or at_exit().  If the exit handler gets
called, use longjmp() to return to the point before the call to LAME,
and return the error code.

example:
-----------------
jmp_buf lame_exit;
int exit_handler( int exit_reason, void *unused) {
  if( exit_reason )
    longjmp( jmp_buf, exit_reason );
  /* if we get here, this is normal program termination */
}

... in the code
on_exit( exit_handler, NULL );
... more code
/* now we want to call a LAME function */
if( !error = set_jmp( lame_exit ) ) {
  lame_function( my_info );
} else {
  display_lame_error( error );
}


The reason I'm not sure if #2 will work is that exit() closes open
files.  I don't know if this happens before or after the functions
registered with on_exit() and atexit().



John
--
MP3 ENCODER mailing list ( http://geek.rcc.se/mp3encoder/ )

Reply via email to