mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-12 20:34:19 +00:00
Make deconstructing foreign types thread safe.
runtime/mercury_ml_expand_body.h:
runtime/mercury_deconstruct.c:
As above.
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user