@@ -637,11 +637,13 @@ def init_code(self):
637637 code = [f'int size_{ self .tmpname } = { self .count_param } ;' ]
638638 code .append (f'MPI_Datatype *{ self .tmpname } = NULL;' )
639639 code .append ('if(' + f'{ self .name } ' + '!= NULL)' + '{' )
640- code .append (f'{ self .tmpname } = (MPI_Datatype *)malloc(sizeof(MPI_Datatype) * size_{ self .tmpname } );' )
641- code .append (f'for(int i=0;i<size_{ self .tmpname } ;i++){{' )
640+ code .append (f'{ self .tmpname } = (MPI_Datatype *)ompi_abi_malloc(size_{ self .tmpname } , sizeof(MPI_Datatype));' )
641+ code .append (f'if(NULL != { self .tmpname } )' + '{' )
642+ code .append (f'for(int i=0;i<size_{ self .tmpname } ;i++)' + '{' )
642643 code .append (f'{ self .tmpname } [i] = { ConvertFuncs .DATATYPE } ({ self .name } [i]);' )
643- code .append (f'}}' )
644- code .append (f'}}' )
644+ code .append ('}' )
645+ code .append ('}' )
646+ code .append ('}' )
645647 return code
646648
647649 @property
@@ -681,7 +683,7 @@ def final_code(self):
681683 code .append (f'nb_request->data.release_arrays[idx++] = (void *){ self .tmpname } ;' )
682684 code .append ('nb_request->data.release_arrays[idx] = NULL;' )
683685 code .append ('} else {' )
684- code .append (f'free({ self .tmpname } );' )
686+ code .append (f'if (NULL != { self . tmpname } ) free({ self .tmpname } );' )
685687 code .append ('}' )
686688 return code
687689
@@ -691,15 +693,17 @@ class TypeDatatypeArrayOutStandard(StandardABIType):
691693 @property
692694 def init_code (self ):
693695 code = [f'int size_{ self .tmpname } = { self .count_param } ;' ]
694- code .append (f'MPI_Datatype *{ self .tmpname } = (MPI_Datatype *)malloc ({ self .count_param } * sizeof(MPI_Datatype));' )
696+ code .append (f'MPI_Datatype *{ self .tmpname } = (MPI_Datatype *)ompi_abi_malloc ({ self .count_param } , sizeof(MPI_Datatype));' )
695697 return code
696698
697699 @property
698700 def final_code (self ):
699- code = [f'for(int i=0;i<size_{ self .tmpname } ;i++){{' ]
701+ code = [f'if(NULL != { self .tmpname } )' + '{' ]
702+ code .append (f'for(int i=0;i<size_{ self .tmpname } ;i++)' + '{' )
700703 code .append (f'{ self .name } [i] = { ConvertOMPIToStandard .DATATYPE } ({ self .tmpname } [i]);' )
701- code .append (f'} }' )
704+ code .append (' }' )
702705 code .append (f'free({ self .tmpname } );' )
706+ code .append ('}' )
703707 return code
704708
705709 @property
@@ -730,11 +734,13 @@ def init_code(self):
730734 if self .name == "recvtypes" :
731735 code .append (f'size_{ self .tmpname } = indegree_{ self .tmpname } ;' )
732736 code .append ('if(' + f'{ self .name } ' + '!= NULL)' + '{' )
733- code .append (f'{ self .tmpname } = (MPI_Datatype *)malloc(sizeof(MPI_Datatype) * size_{ self .tmpname } );' )
737+ code .append (f'{ self .tmpname } = (MPI_Datatype *)ompi_abi_malloc(size_{ self .tmpname } , sizeof(MPI_Datatype));' )
738+ code .append ('if(' + f'{ self .tmpname } ' + '!= NULL)' + '{' )
734739 code .append (f'for(int i=0;i<size_{ self .tmpname } ;i++){{' )
735740 code .append (f'{ self .tmpname } [i] = { ConvertFuncs .DATATYPE } ({ self .name } [i]);' )
736- code .append (f'}}' )
737- code .append (f'}}' )
741+ code .append ('}' )
742+ code .append ('}' )
743+ code .append ('}' )
738744 return code
739745
740746@Type .add_type ('NEIGHBOR_DATATYPE_ARRAY_ASYNC' , abi_type = ['standard' ])
@@ -753,7 +759,7 @@ def final_code(self):
753759 code .append (f'nb_request->data.release_arrays[idx++] = (void *){ self .tmpname } ;' )
754760 code .append ('nb_request->data.release_arrays[idx] = NULL;' )
755761 code .append ('} else {' )
756- code .append (f'free({ self .tmpname } );' )
762+ code .append (f'if (NULL != { self . tmpname } ) free({ self .tmpname } );' )
757763 code .append ('}' )
758764 return code
759765
@@ -908,11 +914,13 @@ class TypeSourceArrayStandard(StandardABIType):
908914 def init_code (self ):
909915 code = [(f'int *{ self .tmpname } = NULL;' )]
910916 code .append ('if(' + f'{ self .name } ' + '!= NULL)' + '{' )
911- code .append (f'{ self .tmpname } = (int *)malloc(sizeof(int) * { self .count_param } );' )
917+ code .append (f'{ self .tmpname } = (int *)ompi_abi_malloc({ self .count_param } , sizeof(int));' )
918+ code .append (f'if (NULL != { self .tmpname } )' + '{' )
912919 code .append (f'for(int i=0;i<{ self .count_param } ;i++){{' )
913920 code .append (f'{ self .tmpname } [i] = { ConvertFuncs .SOURCE } ({ self .name } [i]);' )
914921 code .append ('}' )
915922 code .append ('}' )
923+ code .append ('}' )
916924 return code
917925
918926 @property
@@ -962,17 +970,19 @@ class TypeSourceArrayOutStandard(StandardABIType):
962970
963971 @property
964972 def init_code (self ):
965- code = [f'int *{ self .tmpname } = (int*)malloc ({ self .count_param } * sizeof(int));' ]
973+ code = [f'int *{ self .tmpname } = (int*)ompi_abi_malloc ({ self .count_param } , sizeof(int));' ]
966974 return code
967975
968976 @property
969977 def final_code (self ):
970978 code = [f'if (NULL != { self .name } ){{' ]
979+ code .append (f'if (NULL != { self .tmpname } ){{' )
971980 code .append (f'for(int i=0;i<{ self .count_param } ;i++){{' )
972981 code .append (f'{ self .name } [i] = { ConvertOMPIToStandard .SOURCE } ({ self .tmpname } [i]);' )
973982 code .append ('}' )
974983 code .append ('}' )
975- code .append (f'free({ self .tmpname } );' )
984+ code .append ('}' )
985+ code .append (f'if (NULL != { self .tmpname } ) free({ self .tmpname } );' )
976986 return code
977987
978988 def type_text (self , enable_count = False ):
@@ -1158,9 +1168,6 @@ def parameter(self, enable_count=False, **kwargs):
11581168 else :
11591169 return f'const MPI_Request { self .name } []'
11601170
1161- #
1162- # TODO ABI NEEDS WORK
1163- #
11641171@Type .add_type ('REQUEST_CONST' , abi_type = ['standard' ])
11651172class TypeConstRequestStandard (TypeRequestStandard ):
11661173
@@ -1170,16 +1177,18 @@ def init_code(self):
11701177 code = [f'MPI_Request { self .tmpname } = { ConvertFuncs .REQUEST } ({ self .name } );' ]
11711178 else :
11721179 code = [f'int size_{ self .tmpname } = { self .count_param } ;' ]
1173- code .append (f'MPI_Request *{ self .tmpname } = (MPI_Request *)malloc(sizeof(MPI_Request) * size_{ self .tmpname } );' )
1180+ code .append (f'MPI_Request *{ self .tmpname } = (MPI_Request *)ompi_abi_malloc(size_{ self .tmpname } , sizeof(MPI_Request));' )
1181+ code .append (f'if(NULL !={ self .tmpname } )' + '{' )
11741182 code .append (f'for(int i=0;i<size_{ self .tmpname } ;i++){{' )
11751183 code .append (f'{ self .tmpname } [i] = { ConvertFuncs .REQUEST } ({ self .name } [i]);' )
1176- code .append (f'}}' )
1184+ code .append ('}' )
1185+ code .append ('}' )
11771186 return code
11781187
11791188 @property
11801189 def final_code (self ):
11811190 if self .count_param is not None :
1182- code = [f'free({ self .tmpname } );' ]
1191+ code = [f'if(NULL != { self . tmpname } ) free({ self .tmpname } );' ]
11831192 return code
11841193
11851194 def type_text (self , enable_count = False ):
@@ -1219,12 +1228,15 @@ def init_code(self):
12191228 code = [f'MPI_Request { self .tmpname } = { ConvertFuncs .REQUEST } (*{ self .name } );' ]
12201229 else :
12211230 code = [f'int size_{ self .tmpname } = { self .count_param } ;' ]
1222- code .append (f'MPI_Request *{ self .tmpname } = (MPI_Request *)malloc(sizeof(MPI_Request) * size_{ self .tmpname } );' )
1231+ code .append (f'MPI_Request *{ self .tmpname } = (MPI_Request *)ompi_abi_malloc(size_{ self .tmpname } , sizeof(MPI_Request));' )
1232+ code .append (f'if (NULL != { self .tmpname } )' + '{' )
12231233 code .append (f'for(int i=0;i<size_{ self .tmpname } ;i++){{' )
12241234 code .append (f'{ self .tmpname } [i] = { ConvertFuncs .REQUEST } ({ self .name } [i]);' )
1225- code .append (f'}}' )
1235+ code .append ('}' )
1236+ code .append ('}' )
12261237 return code
12271238
1239+ # TODO: need to free up array
12281240 @property
12291241 def final_code (self ):
12301242 if self .count_param is None :
@@ -1317,7 +1329,7 @@ def init_code(self):
13171329 code .append (f'MPI_Status *{ self .tmpname } = NULL;' )
13181330 code .append (self .if_should_set_status ())
13191331 if self .count_param is not None :
1320- code .append (f'{ self .tmpname } = malloc ({ self .count_param } * sizeof(MPI_Status));' )
1332+ code .append (f'{ self .tmpname } = ompi_abi_malloc ({ self .count_param } , sizeof(MPI_Status));' )
13211333 code .append (f'{ self .status_argument } = { self .tmpname } ;' )
13221334 else :
13231335 code .append (f'{ self .status_argument } = &{ self .tmpname } ;' )
@@ -1559,10 +1571,12 @@ class TypeInfoArray(StandardABIType):
15591571 @property
15601572 def init_code (self ):
15611573 code = [f'int size_{ self .tmpname } = { self .count_param } ;' ]
1562- code .append (f'MPI_Info *{ self .tmpname } = (MPI_Info *)malloc(sizeof(MPI_Info) * size_{ self .tmpname } );' )
1574+ code .append (f'MPI_Info *{ self .tmpname } = (MPI_Info *)ompi_abi_malloc(size_{ self .tmpname } , sizeof(MPI_Info));' )
1575+ code .append (f'if (NULL != { self .tmpname } ){{' )
15631576 code .append (f'for(int i=0;i<size_{ self .tmpname } ;i++){{' )
15641577 code .append (f'{ self .tmpname } [i] = { ConvertFuncs .INFO } ({ self .name } [i]);' )
1565- code .append (f'}}' )
1578+ code .append ('}' )
1579+ code .append ('}' )
15661580 return code
15671581
15681582 @property
@@ -1875,7 +1889,7 @@ def init_code(self):
18751889 code = [f'MPI_Comm_copy_attr_function *{ self .tmpname } = { ConvertFuncs .COMM_COPY_ATTR_FUNCTION } ({ self .name } );' ]
18761890 code .append ('ompi_abi_wrapper_helper_t *helper = NULL;' )
18771891 code .append ('MPI_Comm_copy_attr_function_ABI_INTERNAL *copy_fn;' )
1878- code .append ('helper = ( ompi_abi_wrapper_helper_t *)malloc( sizeof(ompi_abi_wrapper_helper_t));' )
1892+ code .append ('helper = ( ompi_abi_wrapper_helper_t *)ompi_abi_malloc(1, sizeof(ompi_abi_wrapper_helper_t));' )
18791893 code .append ('if (NULL == helper) return MPI_ERR_NO_MEM;' )
18801894 code .append (f'if ({ self .name } == MPI_COMM_NULL_COPY_FN_ABI_INTERNAL)' + '{' )
18811895 code .append ('copy_fn = ABI_C_MPI_COMM_NULL_COPY_FN;' )
@@ -2069,7 +2083,7 @@ def init_code(self):
20692083 code = [f'MPI_Type_copy_attr_function *{ self .tmpname } = { ConvertFuncs .TYPE_COPY_ATTR_FUNCTION } ({ self .name } );' ]
20702084 code .append ('ompi_abi_wrapper_helper_t *helper = NULL;' )
20712085 code .append ('MPI_Type_copy_attr_function_ABI_INTERNAL *copy_fn;' )
2072- code .append ('helper = ( ompi_abi_wrapper_helper_t *)malloc( sizeof(ompi_abi_wrapper_helper_t));' )
2086+ code .append ('helper = ( ompi_abi_wrapper_helper_t *)ompi_abi_malloc(1, sizeof(ompi_abi_wrapper_helper_t));' )
20732087 code .append ('if (NULL == helper) return MPI_ERR_NO_MEM;' )
20742088 code .append (f'if ({ self .name } == MPI_TYPE_NULL_COPY_FN_ABI_INTERNAL)' + '{' )
20752089 code .append ('copy_fn = ABI_C_MPI_TYPE_NULL_COPY_FN;' )
@@ -2183,7 +2197,7 @@ def init_code(self):
21832197 code = [f'MPI_Win_copy_attr_function *{ self .tmpname } = { ConvertFuncs .WIN_COPY_ATTR_FUNCTION } ({ self .name } );' ]
21842198 code .append ('ompi_abi_wrapper_helper_t *helper = NULL;' )
21852199 code .append ('MPI_Win_copy_attr_function_ABI_INTERNAL *copy_fn;' )
2186- code .append ('helper = ( ompi_abi_wrapper_helper_t *)malloc( sizeof(ompi_abi_wrapper_helper_t));' )
2200+ code .append ('helper = ( ompi_abi_wrapper_helper_t *)ompi_abi_malloc(1, sizeof(ompi_abi_wrapper_helper_t));' )
21872201 code .append ('if (NULL == helper) return MPI_ERR_NO_MEM;' )
21882202 code .append (f'if ({ self .name } == MPI_WIN_NULL_COPY_FN_ABI_INTERNAL)' + '{' )
21892203 code .append ('copy_fn = ABI_C_MPI_WIN_NULL_COPY_FN;' )
@@ -3157,11 +3171,13 @@ def init_code(self):
31573171 code = [f'int size_{ self .tmpname } = { self .count_param } ;' ]
31583172 code .append (f'int *{ self .tmpname } = NULL;' )
31593173 code .append ('if(' + f'{ self .name } ' + '!= NULL)' + '{' )
3160- code .append (f'{ self .tmpname } = (int *)malloc(sizeof(int) * size_{ self .tmpname } );' )
3174+ code .append (f'{ self .tmpname } = (int *)ompi_abi_malloc(size_{ self .tmpname } , sizeof(int));' )
3175+ code .append (f'if (NULL != { self .tmpname } ){{' )
31613176 code .append (f'for(int i=0;i<size_{ self .tmpname } ;i++){{' )
31623177 code .append (f'{ self .tmpname } [i] = { ConvertFuncs .SUBARRAY_DISTRIB_TYPES } ({ self .name } [i]);' )
3163- code .append (f'}}' )
3164- code .append (f'}}' )
3178+ code .append ('}' )
3179+ code .append ('}' )
3180+ code .append ('}' )
31653181 return code
31663182
31673183 @property
0 commit comments