Make deconstructing foreign types thread safe.

runtime/mercury_ml_expand_body.h:
runtime/mercury_deconstruct.c:
    As above.
This commit is contained in:
Zoltan Somogyi
2015-06-11 13:23:12 +02:00
parent 4d276a6505
commit e0dc857c9c
2 changed files with 30 additions and 23 deletions

View File

@@ -21,13 +21,10 @@
#include "mercury_minimal_model.h"
/*
** We reserve a static buffer to hold the names we dynamically generate
** for "functors" of foreign types. This should eliminate the possibility
** that the space we used to reserve on the stack for this may clobber
** other information there.
** We reserve a buffer to hold the names we dynamically generate
** for "functors" of foreign types. This macro gives its size.
*/
#define MR_FOREIGN_NAME_BUF_SIZE 256
static char MR_foreign_functor_name_buf[MR_FOREIGN_NAME_BUF_SIZE];
static MR_ConstString MR_expand_type_name(MR_TypeCtorInfo tci, MR_bool);

View File

@@ -1490,33 +1490,43 @@ EXPAND_FUNCTION_NAME(MR_TypeInfo type_info, MR_Word *data_word_ptr,
return;
case MR_TYPECTOR_REP_FOREIGN:
{
char buf[MR_FOREIGN_NAME_BUF_SIZE];
#ifdef MR_HAVE_SNPRINTF
snprintf(MR_foreign_functor_name_buf, MR_FOREIGN_NAME_BUF_SIZE,
"<<foreign(%s, %p)>>",
type_ctor_info->MR_type_ctor_name, (void *) *data_word_ptr);
snprintf(buf, MR_FOREIGN_NAME_BUF_SIZE,
"<<foreign(%s, %p)>>",
type_ctor_info->MR_type_ctor_name,
(void *) *data_word_ptr);
#else
sprintf(MR_foreign_functor_name_buf,
"<<foreign(%s, %p)>>",
type_ctor_info->MR_type_ctor_name, (void *) *data_word_ptr);
sprintf(buf,
"<<foreign(%s, %p)>>",
type_ctor_info->MR_type_ctor_name,
(void *) *data_word_ptr);
#endif
/* The contents of the buffer may change later. */
copy_and_handle_functor_name(MR_foreign_functor_name_buf);
handle_zero_arity_args();
/* The contents of the memory occupied by buf may change. */
copy_and_handle_functor_name(buf);
handle_zero_arity_args();
}
return;
case MR_TYPECTOR_REP_STABLE_FOREIGN:
{
char buf[MR_FOREIGN_NAME_BUF_SIZE];
#ifdef MR_HAVE_SNPRINTF
snprintf(MR_foreign_functor_name_buf, MR_FOREIGN_NAME_BUF_SIZE,
"<<stable_foreign(%s, %p)>>",
type_ctor_info->MR_type_ctor_name, (void *) *data_word_ptr);
snprintf(buf, MR_FOREIGN_NAME_BUF_SIZE,
"<<stable_foreign(%s, %p)>>",
type_ctor_info->MR_type_ctor_name,
(void *) *data_word_ptr);
#else
sprintf(MR_foreign_functor_name_buf,
"<<stable_foreign(%s, %p)>>",
type_ctor_info->MR_type_ctor_name, (void *) *data_word_ptr);
sprintf(buf,
"<<stable_foreign(%s, %p)>>",
type_ctor_info->MR_type_ctor_name,
(void *) *data_word_ptr);
#endif
/* The contents of the buffer may change later. */
copy_and_handle_functor_name(MR_foreign_functor_name_buf);
handle_zero_arity_args();
/* The contents of the memory occupied by buf may change. */
copy_and_handle_functor_name(buf);
handle_zero_arity_args();
}
return;
case MR_TYPECTOR_REP_REFERENCE: