ecl_thread_internal_error: add C api, protect get_env

Problem reported and fixed by Marius Gerbershagen. Fixes #382.
This commit is contained in:
Daniel Kochmański 2017-05-22 22:58:15 +02:00
parent b75802f122
commit 052155c6c3
3 changed files with 21 additions and 3 deletions

View file

@ -61,6 +61,20 @@ ecl_internal_error(const char *s)
abort();
}
#ifdef ECL_THREADS
void
ecl_thread_internal_error(const char *s)
{
int saved_errno = errno;
fprintf(stderr, "\nInternal thread error in:\n%s\n", s);
if (saved_errno) {
fprintf(stderr, " [%d: %s]\n", saved_errno,
strerror(saved_errno));
}
fflush(stderr);
pthread_exit(NULL);
}
#endif
void
ecl_unrecoverable_error(cl_env_ptr the_env, const char *message)

View file

@ -52,7 +52,7 @@ ecl_process_env(void)
struct cl_env_struct *rv = pthread_getspecific(cl_env_key);
if (rv)
return rv;
FElibc_error("pthread_getspecific() failed.", 0);
ecl_thread_internal_error("pthread_getspecific() failed.");
return NULL;
#endif
}
@ -67,8 +67,9 @@ ecl_set_process_env(cl_env_ptr env)
# ifdef ECL_WINDOWS_THREADS
TlsSetValue(cl_env_key, env);
# else
if (pthread_setspecific(cl_env_key, env))
FElibc_error("pthread_setspecific() failed.", 0);
if (pthread_setspecific(cl_env_key, env)) {
ecl_thread_internal_error("pthread_setspecific() failed.");
}
# endif
#endif
}

View file

@ -553,6 +553,9 @@ extern ECL_API cl_object cl_error _ECL_ARGS((cl_narg narg, cl_object eformat, ..
extern ECL_API cl_object cl_cerror _ECL_ARGS((cl_narg narg, cl_object cformat, cl_object eformat, ...));
extern ECL_API void ecl_internal_error(const char *s) ecl_attr_noreturn;
#ifdef ECL_THREADS
extern ECL_API void ecl_thread_internal_error(const char *s) ecl_attr_noreturn;
#endif
extern ECL_API void ecl_unrecoverable_error(cl_env_ptr the_env, const char *message) ecl_attr_noreturn;
extern ECL_API void ecl_cs_overflow(void) /*ecl_attr_noreturn*/;
extern ECL_API void FEprogram_error(const char *s, int narg, ...) ecl_attr_noreturn;