* for some reason, was having issues with C bool vs C++ bool on odin.
cast the return to an int in the C++ test case, just in case. * C++ sucks. If compiling with C++ on some GNU compiler/linker combos, the initialize hook isn't automagically fired for the malloc code. Add a backup setting during opal_init, which is early enough not to cause any damage. This commit was SVN r6983.
Этот коммит содержится в:
родитель
a3f73429b2
Коммит
1454e40f0e
@ -25,22 +25,32 @@
|
||||
#include "opal/memory/memory_internal.h"
|
||||
|
||||
/* Prototypes for our hooks. */
|
||||
static void opal_mem_free_init_hook (void);
|
||||
void opal_memory_malloc_hooks_init(void);
|
||||
static void opal_mem_free_free_hook (void*, const void *);
|
||||
static void* opal_mem_free_realloc_hook (void*, size_t, const void *);
|
||||
|
||||
/* Override initializing hook from the C library. */
|
||||
void (*__malloc_initialize_hook) (void) = opal_mem_free_init_hook;
|
||||
void (*__malloc_initialize_hook) (void) = opal_memory_malloc_hooks_init;
|
||||
|
||||
|
||||
/* local variable - next in stack of free hooks */
|
||||
static void (*old_free_hook)(void*, const void*);
|
||||
static void* (*old_realloc_hook)(void*, size_t, const void*);
|
||||
|
||||
static int initialized = 0;
|
||||
|
||||
static void
|
||||
opal_mem_free_init_hook (void)
|
||||
void
|
||||
opal_memory_malloc_hooks_init(void)
|
||||
{
|
||||
/* for some dumb reason, when libopal is compiled statically a C
|
||||
application will fire this at malloc initialization time, but a
|
||||
C++ application will not. So we also try to set our hooks from
|
||||
the module initialization */
|
||||
if (initialized != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
initialized = 1;
|
||||
opal_mem_free_set_free_support(1);
|
||||
old_free_hook = __free_hook;
|
||||
old_realloc_hook = __realloc_hook;
|
||||
|
@ -17,6 +17,11 @@
|
||||
#include "ompi_config.h"
|
||||
|
||||
#include "opal/mca/memory/memory.h"
|
||||
#include "opal/include/constants.h"
|
||||
|
||||
extern void opal_memory_malloc_hooks_init(void);
|
||||
|
||||
static int opal_memory_malloc_open(void);
|
||||
|
||||
const opal_memory_base_component_1_0_0_t mca_memory_malloc_hooks_component = {
|
||||
/* First, the mca_component_t struct containing meta information
|
||||
@ -33,7 +38,7 @@ const opal_memory_base_component_1_0_0_t mca_memory_malloc_hooks_component = {
|
||||
OPAL_RELEASE_VERSION,
|
||||
|
||||
/* Component open and close functions */
|
||||
NULL,
|
||||
opal_memory_malloc_open,
|
||||
NULL
|
||||
},
|
||||
|
||||
@ -43,3 +48,11 @@ const opal_memory_base_component_1_0_0_t mca_memory_malloc_hooks_component = {
|
||||
true
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
static int
|
||||
opal_memory_malloc_open(void)
|
||||
{
|
||||
opal_memory_malloc_hooks_init();
|
||||
return OPAL_SUCCESS;
|
||||
}
|
||||
|
@ -27,12 +27,14 @@ using namespace std;
|
||||
int ret = 1;
|
||||
int size = 10 * 1024 * 1024;
|
||||
|
||||
extern "C" {
|
||||
static void
|
||||
callback(void *buf, size_t length, void *cbdata)
|
||||
{
|
||||
printf("\tcallback with %lx, %d\n", (unsigned long) buf, (int) length);
|
||||
ret--;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
@ -41,7 +43,7 @@ main(int argc, char *argv[])
|
||||
|
||||
opal_init();
|
||||
|
||||
if (!opal_mem_free_is_supported()) {
|
||||
if (0 == (int) opal_mem_free_is_supported()) {
|
||||
printf("no memory registration supported. skipping\n");
|
||||
return 77;
|
||||
}
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user