Skip to content

Commit

Permalink
Handle the condition where
Browse files Browse the repository at this point in the history
  • Loading branch information
philip-davis committed Nov 13, 2023
1 parent 60d1298 commit 40b40f6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
2 changes: 2 additions & 0 deletions include/dspaces-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ extern "C" {
#define dspaces_ERR_UNKNOWN_OBJ -8 /* Could not find the object*/
#define dspaces_ERR_END -9 /* End of range for valid error codes */

#define DS_OBJ_RESIZE 0x02

#if defined(__cplusplus)
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions include/ss_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#define MAX_VERSIONS 10

#define DS_CLIENT_STORAGE 0x01
#define DS_OBJ_RESIZE 0x02

typedef struct {
void *iov_base;
Expand Down Expand Up @@ -386,6 +387,7 @@ void meta_data_free(struct meta_data *mdata);

void obj_data_free(struct obj_data *od);
uint64_t obj_data_size(obj_descriptor *);
void obj_data_resize(obj_descriptor *obj_desc, uint64_t *new_dims);

int obj_desc_equals(obj_descriptor *, obj_descriptor *);
int obj_desc_equals_no_owner(const obj_descriptor *, const obj_descriptor *);
Expand Down
6 changes: 5 additions & 1 deletion src/dspaces-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1623,7 +1623,11 @@ int dspaces_aget(dspaces_client_t client, const char *var_name,
num_odscs = get_odscs(client, &odsc, timeout, &odsc_tab);

DEBUG_OUT("Finished query - need to fetch %d objects\n", num_odscs);
for(int i = 0; i < num_odscs; ++i) {
for(int i = 0; i < num_odscs; i++) {
if(odsc_tab[i].flags && DS_OBJ_RESIZE) {
DEBUG_OUT("the result is cropped.\n");
memcpy(&odsc.bb, &odsc_tab[i].bb, sizeof(odsc_tab[i].bb));
}
DEBUG_OUT("%s\n", obj_desc_sprint(&odsc_tab[i]));
}

Expand Down
18 changes: 17 additions & 1 deletion src/dspaces-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ struct dspaces_module_args {
struct dspaces_module_ret {
int type;
int len;
uint64_t *dim;
int ndim;
int tag;
int elem_size;
void *data;
Expand Down Expand Up @@ -1841,9 +1843,18 @@ static struct dspaces_module_ret *py_res_buf(PyObject *pResult)
PyArrayObject *pArray;
struct dspaces_module_ret *ret = malloc(sizeof(*ret));
size_t data_len;
npy_intp *dims;
int i;

pArray = (PyArrayObject *)pResult;
ret->len = PyArray_SIZE(pArray);
ret->ndim = PyArray_NDIM(pArray);
ret->dim = malloc(sizeof(*ret->dim * ret->ndim));
dims = PyArray_DIMS(pArray);
ret->len = 1;
for(i = 0; i < ret->ndim; i++) {
ret->dim[i] = dims[i];
ret->len *= dims[i];
}
ret->tag = PyArray_TYPE(pArray);
ret->elem_size = PyArray_ITEMSIZE(pArray);
data_len = ret->len * ret->elem_size;
Expand Down Expand Up @@ -2008,6 +2019,7 @@ static void route_request(dspaces_provider_t server, obj_descriptor *odsc,
struct obj_data *od;
obj_descriptor *od_odsc;
int nargs;
int i;

DEBUG_OUT("Routing '%s'\n", odsc->name);

Expand All @@ -2029,6 +2041,10 @@ static void route_request(dspaces_provider_t server, obj_descriptor *odsc,
free(res->data);
} else {
odsc->size = res->elem_size;
if((odsc->size * res->len) < obj_data_size(odsc)) {
DEBUG_OUT("returned data is cropped.\n");
obj_data_resize(odsc, res->dim);
}
od_odsc = malloc(sizeof(*od_odsc));
memcpy(od_odsc, odsc, sizeof(*od_odsc));
odsc_take_ownership(server, od_odsc);
Expand Down
11 changes: 11 additions & 0 deletions src/ss_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,17 @@ uint64_t obj_data_size(obj_descriptor *obj_desc)
return obj_desc->size * bbox_volume(&obj_desc->bb);
}

void obj_data_resize(obj_descriptor *obj_desc, uint64_t *new_dims)
{
struct bbox *bb = &obj_desc->bb;
int i;

for(i = 0; i < bb->num_dims; i++) {
bb->ub.c[i] = bb->lb.c[i] + (new_dims[i] - 1);
}
obj_desc->flags ^= DS_OBJ_RESIZE;
}

int obj_desc_equals_no_owner(const obj_descriptor *odsc1,
const obj_descriptor *odsc2)
{
Expand Down

0 comments on commit 40b40f6

Please sign in to comment.