Changeset 4864


Ignore:
Timestamp:
07/28/10 20:05:07 (15 years ago)
Author:
Eric.Larour
Message:

More robust. Assuming M and m are not always non nill.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/c/objects/Params/DoubleMatArrayParam.cpp

    r4853 r4864  
    3535        enum_type=in_enum_type;
    3636        M=in_M;
    37         array=(double**)xmalloc(M*sizeof(double*));
    38         mdim_array=(int*)xmalloc(M*sizeof(int));
    39         ndim_array=(int*)xmalloc(M*sizeof(int));
    40 
    41         for(i=0;i<M;i++){
    42                 m=in_mdim_array[i];
    43                 n=in_mdim_array[i];
    44 
    45                 mdim_array[i]=m;
    46                 ndim_array[i]=n;
    47 
    48                 matrix=(double*)xmalloc(m*n*sizeof(double));
    49                 memcpy(matrix,in_array[i],m*n*sizeof(double));
    50 
    51                 array[i]=matrix;
     37        if(M){
     38                array=(double**)xmalloc(M*sizeof(double*));
     39                mdim_array=(int*)xmalloc(M*sizeof(int));
     40                ndim_array=(int*)xmalloc(M*sizeof(int));
     41
     42                for(i=0;i<M;i++){
     43                        m=in_mdim_array[i];
     44                        n=in_mdim_array[i];
     45
     46                        mdim_array[i]=m;
     47                        ndim_array[i]=n;
     48
     49                        if(m*n){
     50                                matrix=(double*)xmalloc(m*n*sizeof(double));
     51                                memcpy(matrix,in_array[i],m*n*sizeof(double));
     52                        }
     53                        else{
     54                                matrix=NULL;
     55                        }
     56                        array[i]=matrix;
     57                }
     58        }
     59        else{
     60                array=NULL;
     61                mdim_array=NULL;
     62                ndim_array=NULL;
    5263        }
    5364}
     
    135146        memcpy(marshalled_dataset,&enum_type,sizeof(enum_type));marshalled_dataset+=sizeof(enum_type);
    136147        memcpy(marshalled_dataset,&M,sizeof(M));marshalled_dataset+=sizeof(M);
    137         memcpy(marshalled_dataset,mdim_array,M*sizeof(double));marshalled_dataset+=M*sizeof(int);
    138         memcpy(marshalled_dataset,ndim_array,M*sizeof(double));marshalled_dataset+=M*sizeof(int);
    139         for(i=0;i<M;i++){
    140                 double* matrix=this->array[i];
    141                 int     m=this->mdim_array[i];
    142                 int     n=this->ndim_array[i];
    143                 memcpy(marshalled_dataset,&m,sizeof(m));marshalled_dataset+=sizeof(m);
    144                 memcpy(marshalled_dataset,&n,sizeof(n));marshalled_dataset+=sizeof(n);
    145                 memcpy(marshalled_dataset,matrix,m*n*sizeof(double));marshalled_dataset+=m*n*sizeof(double);
     148        if(M){
     149                memcpy(marshalled_dataset,mdim_array,M*sizeof(double));marshalled_dataset+=M*sizeof(int);
     150                memcpy(marshalled_dataset,ndim_array,M*sizeof(double));marshalled_dataset+=M*sizeof(int);
     151                for(i=0;i<M;i++){
     152                        double* matrix=this->array[i];
     153                        int     m=this->mdim_array[i];
     154                        int     n=this->ndim_array[i];
     155                        memcpy(marshalled_dataset,&m,sizeof(m));marshalled_dataset+=sizeof(m);
     156                        memcpy(marshalled_dataset,&n,sizeof(n));marshalled_dataset+=sizeof(n);
     157                        if(m*n)memcpy(marshalled_dataset,matrix,m*n*sizeof(double));marshalled_dataset+=m*n*sizeof(double);
     158                }
    146159        }
    147160       
     
    188201       
    189202        memcpy(&M,marshalled_dataset,sizeof(M));marshalled_dataset+=sizeof(M);
    190         this->mdim_array=(int*)xmalloc(M*sizeof(int));
    191         this->ndim_array=(int*)xmalloc(M*sizeof(int));
    192         memcpy(this->mdim_array,marshalled_dataset,M*sizeof(int));marshalled_dataset+=M*sizeof(int);
    193         memcpy(this->ndim_array,marshalled_dataset,M*sizeof(int));marshalled_dataset+=M*sizeof(int);
    194 
    195         this->array=(double**)xmalloc(M*sizeof(double*));
    196         for(i=0;i<M;i++){
    197                 memcpy(&m,marshalled_dataset,sizeof(m));marshalled_dataset+=sizeof(m);
    198                 memcpy(&n,marshalled_dataset,sizeof(n));marshalled_dataset+=sizeof(n);
    199                 matrix=(double*)xmalloc(m*n*sizeof(double));
    200                 memcpy(matrix,marshalled_dataset,m*n*sizeof(double));marshalled_dataset+=m*n*sizeof(double);
    201                 this->array[i]=matrix;
     203        if(M){
     204                this->mdim_array=(int*)xmalloc(M*sizeof(int));
     205                this->ndim_array=(int*)xmalloc(M*sizeof(int));
     206                memcpy(this->mdim_array,marshalled_dataset,M*sizeof(int));marshalled_dataset+=M*sizeof(int);
     207                memcpy(this->ndim_array,marshalled_dataset,M*sizeof(int));marshalled_dataset+=M*sizeof(int);
     208
     209                this->array=(double**)xmalloc(M*sizeof(double*));
     210                for(i=0;i<M;i++){
     211                        memcpy(&m,marshalled_dataset,sizeof(m));marshalled_dataset+=sizeof(m);
     212                        memcpy(&n,marshalled_dataset,sizeof(n));marshalled_dataset+=sizeof(n);
     213                        if(m*n){
     214                                matrix=(double*)xmalloc(m*n*sizeof(double));
     215                                memcpy(matrix,marshalled_dataset,m*n*sizeof(double));marshalled_dataset+=m*n*sizeof(double);
     216                        }
     217                        else{
     218                                matrix=NULL;
     219                        }
     220                        this->array[i]=matrix;
     221                }
     222        }
     223        else{
     224                this->array=NULL;
     225                this->mdim_array=NULL;
     226                this->ndim_array=NULL;
    202227        }
    203228
     
    238263
    239264        out_M=this->M;
    240         out_array=(double**)xmalloc(M*sizeof(double*));
    241         out_mdim_array=(int*)xmalloc(M*sizeof(int));
    242         out_ndim_array=(int*)xmalloc(M*sizeof(int));
    243 
    244         memcpy(out_mdim_array,this->mdim_array,M*sizeof(int));
    245         memcpy(out_ndim_array,this->ndim_array,M*sizeof(int));
    246 
    247         for(i=0;i<this->M;i++){
    248                 matrix=this->array[i];
    249                 m=this->mdim_array[i];
    250                 n=this->ndim_array[i];
    251                
    252                 out_matrix=(double*)xmalloc(m*n*sizeof(double));
    253                 memcpy(out_matrix,matrix,m*n*sizeof(double));
    254 
    255                 out_array[i]=out_matrix;
     265        if(out_M){
     266                out_array=(double**)xmalloc(M*sizeof(double*));
     267                out_mdim_array=(int*)xmalloc(M*sizeof(int));
     268                out_ndim_array=(int*)xmalloc(M*sizeof(int));
     269
     270                memcpy(out_mdim_array,this->mdim_array,M*sizeof(int));
     271                memcpy(out_ndim_array,this->ndim_array,M*sizeof(int));
     272
     273                for(i=0;i<this->M;i++){
     274                        matrix=this->array[i];
     275                        m=this->mdim_array[i];
     276                        n=this->ndim_array[i];
     277
     278                        if(m*n){
     279                                out_matrix=(double*)xmalloc(m*n*sizeof(double));
     280                                memcpy(out_matrix,matrix,m*n*sizeof(double));
     281                        }
     282                        else{
     283                                out_matrix=NULL;
     284                        }
     285                        out_array[i]=out_matrix;
     286                }
     287        }
     288        else{
     289                out_array=NULL;
     290                out_matrix=NULL;
     291                out_ndim_array=NULL;
    256292        }
    257293
Note: See TracChangeset for help on using the changeset viewer.