X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/3a3bf65fe403e30d7d21b88ceb4fc11d39af5713..aee58827f69b637a767d51db4c5a0f14aefce3b9:/include/smpi/smpi_cocci.h diff --git a/include/smpi/smpi_cocci.h b/include/smpi/smpi_cocci.h index 2aff10b7af..c4ea46fdbf 100644 --- a/include/smpi/smpi_cocci.h +++ b/include/smpi/smpi_cocci.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2011. The SimGrid Team. +/* Copyright (c) 2011-2014. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -13,18 +13,18 @@ #define SMPI_VARINIT_GLOBAL(name,type) \ type *name = NULL; \ -void __attribute__((weak,constructor)) __preinit_##name(void) { \ +static void __attribute__((constructor)) __preinit_##name(void) { \ if(!name) \ - name = (type*)malloc(smpi_global_size() * sizeof(type)); \ + name = (type*)calloc(smpi_global_size(), sizeof(type)); \ } \ -void __attribute__((weak,destructor)) __postfini_##name(void) { \ +static void __attribute__((destructor)) __postfini_##name(void) { \ free(name); \ name = NULL; \ } #define SMPI_VARINIT_GLOBAL_AND_SET(name,type,expr) \ type *name = NULL; \ -void __attribute__((weak,constructor)) __preinit_##name(void) { \ +static void __attribute__((constructor)) __preinit_##name(void) { \ size_t size = smpi_global_size(); \ size_t i; \ type value = expr; \ @@ -35,7 +35,7 @@ void __attribute__((weak,constructor)) __preinit_##name(void) { \ } \ } \ } \ -void __attribute__((weak,destructor)) __postfini_##name(void) { \ +static void __attribute__((destructor)) __postfini_##name(void) { \ free(name); \ name = NULL; \ } @@ -47,21 +47,16 @@ void __attribute__((weak,destructor)) __postfini_##name(void) { \ * * This function is rather internal, mainly used for the * privatization of global variables through coccinelle. - * - * Since its implementation relies on the on_exit() function that - * is not implemented on Mac, this function is a no-op on that - * architecture. But the only issue raised is that the memory is - * not raised right before the process terminaison. This is only - * important if you want to run valgrind on the code, or - * equivalent. */ -XBT_PUBLIC(void) smpi_register_static(void* arg); +XBT_PUBLIC(void) smpi_register_static(void* arg, void_f_pvoid_t free_fn); + +XBT_PUBLIC(void) smpi_free_static(void); #define SMPI_VARINIT_STATIC(name,type) \ static type *name = NULL; \ if(!name) { \ - name = (type*)malloc(smpi_global_size() * sizeof(type)); \ - smpi_register_static(name); \ + name = (type*)calloc(smpi_global_size(), sizeof(type)); \ + smpi_register_static(name, xbt_free); \ } #define SMPI_VARINIT_STATIC_AND_SET(name,type,expr) \ @@ -74,7 +69,7 @@ if(!name) { \ for(i = 0; i < size; i++) { \ name[i] = value; \ } \ - smpi_register_static(name); \ + smpi_register_static(name, xbt_free); \ } #define SMPI_VARGET_STATIC(name) name[smpi_process_index()]