Changeset 671

Show
Ignore:
Timestamp:
10/08/08 13:50:47 (1 month ago)
Author:
mdroe
Message:

Change the criteria for reallocation of temporary buffers.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/pywcs/src/pipeline.c

    r660 r671  
    7272pipeline_free_tmp(pipeline_t* pipeline) { 
    7373  /* Free all temporary buffers and reset pointers to NULL */ 
     74  pipeline->alloc_nelem = 0; 
     75  pipeline->alloc_ncoord = 0; 
    7476  free(pipeline->tmp); 
    7577  pipeline->tmp = NULL; 
     
    9496    unsigned int ncoord, 
    9597    unsigned int nelem) { 
    96   if (pipeline->alloc_ncoord < ncoord || pipeline->alloc_nelem < nelem) { 
     98  if (pipeline->alloc_ncoord < ncoord || 
     99      pipeline->alloc_nelem * pipeline->alloc_ncoord < nelem * ncoord) { 
    97100    pipeline_free_tmp(pipeline); 
     101 
     102    pipeline->imgcrd = malloc(ncoord * nelem * sizeof(double)); 
     103    if (pipeline->imgcrd == NULL) { 
     104      goto out_of_memory; 
     105    } 
     106 
     107    pipeline->phi = malloc(ncoord * sizeof(double)); 
     108    if (pipeline->phi == NULL) { 
     109      goto out_of_memory; 
     110    } 
     111 
     112    pipeline->theta = malloc(ncoord * sizeof(double)); 
     113    if (pipeline->theta == NULL) { 
     114      goto out_of_memory; 
     115    } 
     116 
     117    pipeline->stat = malloc(ncoord * nelem * sizeof(int)); 
     118    if (pipeline->stat == NULL) { 
     119      goto out_of_memory; 
     120    } 
     121 
     122    pipeline->tmp = malloc(ncoord * nelem * sizeof(double)); 
     123    if (pipeline->tmp == NULL) { 
     124      goto out_of_memory; 
     125    } 
    98126 
    99127    pipeline->alloc_ncoord = ncoord; 
    100128    pipeline->alloc_nelem = nelem; 
    101  
    102     pipeline->imgcrd = malloc(ncoord * nelem * sizeof(double)); 
    103     if (pipeline->imgcrd == NULL) { 
    104       goto out_of_memory; 
    105     } 
    106  
    107     pipeline->phi = malloc(ncoord * sizeof(double)); 
    108     if (pipeline->phi == NULL) { 
    109       goto out_of_memory; 
    110     } 
    111  
    112     pipeline->theta = malloc(ncoord * sizeof(double)); 
    113     if (pipeline->theta == NULL) { 
    114       goto out_of_memory; 
    115     } 
    116  
    117     pipeline->stat = malloc(ncoord * nelem * sizeof(int)); 
    118     if (pipeline->stat == NULL) { 
    119       goto out_of_memory; 
    120     } 
    121  
    122     pipeline->tmp = malloc(ncoord * nelem * sizeof(double)); 
    123     if (pipeline->tmp == NULL) { 
    124       goto out_of_memory; 
    125     } 
    126129  } 
    127130