On Tuesday 16 December 2008 14:31:44 Guy K. Kloss wrote: > Hi, > > I'm playing a bit with the preview of lcms 2.0 right now (more particularly > with ctypes based Python bindings). I've seen in the code that the error > handler again is just a callback function that is globally set. > > I'd appreciate it if some mechanism for error handling/reporting could be > found that is more robust towards e. g. concurrent systems. Especially as > lcms is now being used in many larger applications as well, having > particularly Mozilla in mind. How is a calling code supposed to find out if > an error with lcms has happened, if some global/remote call back is called. > The code itself cannot handle that situation locally with the mechanism in > place in lcms 1.x and as well the current preview of 2.0. > > Especially stack traces in the error handler function assigned are also > quite pointless as it's very hard to trace back the origin of some error > within the code. > > Any other opinions? > > Guy
What I do in my code is use this type of thing: #include <setjmp.h> jmp_buf cmsJumpBuffer; int cmsErrorHandler(int /*ErrorCode*/, const char *ErrorText) { QMessageBox mb( QTranslator::tr("Invalid ICC Profile."), QTranslator::tr("Littlecms : ") + QString::fromLocal8Bit(ErrorText) + QTranslator::tr(" in file ") + fName, QMessageBox::Critical, QMessageBox::Ok | QMessageBox::Default, Qt::NoButton, Qt::NoButton); mb.exec(); longjmp(cmsJumpBuffer, 1); return 1; } Then in the code where I am making lcms calls that could fail I do: if (setjmp(cmsJumpBuffer)) { cmsSetErrorHandler(NULL); if (hICM) { if (profileOpen) cmsCloseProfile(hICM); hICM = NULL; } cmsSetErrorHandler(&cmsErrorHandler); continue; } This works but is very ugly and I too would like to see a better way of handling this. Another issue is that doing this can cause significant problems in C++ code that is using exceptions and exception handlers since it causes a jump to an unexpected location that can cause the other exception handlers to not unwind things correctly. This is probably also true for other languages that use exceptions as well. This is also how the Scribus folks handle this and they were the ones who pointed me in this direction. Just to clarify things when the call to setjmp() is done it limits the scope of the jump buffer to the calling function and the jump buffer become invalid once things are outside of the scope of the function that called setjmp() and any calls to longjmp() become invalid (IE. they will just fall through). So you have to be careful to clean up the cmsErrorHandler before exiting the function that made the setjmp() call. Hal ------------------------------------------------------------------------------ SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada. The future of the web can't happen without you. Join us at MIX09 to help pave the way to the Next Web now. Learn more and register at http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/ _______________________________________________ Lcms-user mailing list Lcms-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lcms-user