[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-glpk] Re: Application crash due to assert in GLPK - glp_error_hook
From: |
Xypron |
Subject: |
[Help-glpk] Re: Application crash due to assert in GLPK - glp_error_hook |
Date: |
Tue, 16 Feb 2010 23:39:27 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.4) Gecko/20091017 SeaMonkey/2.0 |
Hello Andrew,
I have had a look at the definition of glp_error_hook() in the GLPK 4.43
pre release.
The function is sufficient to safely catch an error situation. I guess
it is a big step
forward for safely using GLPK inside C programs.
When providing language wrappers like GLPK-Java it will require to wrap
every single
API function.
The typical use in a language wrapper would probably be something like:
JNIEXPORT int JNICALL wrap_some_function(JNIENV *env, some args) {
int ret = 0;
MYENV *info
info = (myenv) malloc(sizeof(myenv));
info->env = env;
info->jmp = jmp;
if (!setjmp(info->jmp)) {
glp_error_hook(myhook, info);
ret = glp_some_function(args)
}
free(info);
return ret;
}
void myhook(void *info) {
MYENV env = (MYENV) *info;
/* throw exception */
jclass newExcCls;
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
newExcCls = (*env)->FindClass(env, "java/lang/IllegalArgumentException");
if (newExcCls != NULL)
(*env)->ThrowNew(env, newExcCls, "thrown from C code");
/* unset hook */
glp_error_hook(NULL, NULL);
/* safely return */
longjmp(env->jmp, 1);
}
I am wondering how maintaining the wrapper functions can be done
efficiently. I guess
SWIG cannot do it.
The next step should be writing example code in C demonstrating the
function of
the hook. I will give it a try.
Best regards
Xypron
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Help-glpk] Re: Application crash due to assert in GLPK - glp_error_hook,
Xypron <=