int opal_dss_unpack_string(opal_buffer_t *buffer, void *dest, int32_t *num_vals, opal_data_type_t type) { int ret; int32_t i, len, n=1; char **sdest = (char**) dest; for (i = 0; i < (*num_vals); ++i) { if (OPAL_SUCCESS != (ret = opal_dss_unpack_int32(buffer, &len, &n, OPAL_INT32))) { return ret; } if (0 == len) { /* zero-length string - unpack the NULL */ sdest[i] = NULL; } else { sdest[i] = (char*)malloc(len); if (NULL == sdest[i]) { return OPAL_ERR_OUT_OF_RESOURCE; } if (OPAL_SUCCESS != (ret = opal_dss_unpack_byte(buffer, sdest[i], &len, OPAL_BYTE))) { return ret; } } } return OPAL_SUCCESS; }
/* * OPAL_BYTE_OBJECT */ int opal_dss_unpack_byte_object(opal_buffer_t *buffer, void *dest, int32_t *num, opal_data_type_t type) { int ret; int32_t i, n, m=1; opal_byte_object_t **dbyteptr; dbyteptr = (opal_byte_object_t**)dest; n = *num; for(i=0; i<n; i++) { /* allocate memory for the byte object itself */ dbyteptr[i] = (opal_byte_object_t*)malloc(sizeof(opal_byte_object_t)); if (NULL == dbyteptr[i]) { return OPAL_ERR_OUT_OF_RESOURCE; } /* unpack object size in bytes */ if (OPAL_SUCCESS != (ret = opal_dss_unpack_int32(buffer, &(dbyteptr[i]->size), &m, OPAL_INT32))) { return ret; } if (0 < dbyteptr[i]->size) { dbyteptr[i]->bytes = (uint8_t*)malloc(dbyteptr[i]->size); if (NULL == dbyteptr[i]->bytes) { return OPAL_ERR_OUT_OF_RESOURCE; } if (OPAL_SUCCESS != (ret = opal_dss_unpack_byte(buffer, (dbyteptr[i]->bytes), &(dbyteptr[i]->size), OPAL_BYTE))) { return ret; } } } return OPAL_SUCCESS; }
int orte_dt_unpack_attr(opal_buffer_t *buffer, void *dest, int32_t *num_vals, opal_data_type_t type) { orte_attribute_t **ptr; int32_t i, n, m; int ret; ptr = (orte_attribute_t **) dest; n = *num_vals; for (i = 0; i < n; ++i) { /* allocate the new object */ ptr[i] = OBJ_NEW(orte_attribute_t); if (NULL == ptr[i]) { return OPAL_ERR_OUT_OF_RESOURCE; } /* unpack the key and type */ m=1; if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->key, &m, ORTE_ATTR_KEY_T))) { return ret; } m=1; if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->type, &m, OPAL_DATA_TYPE))) { return ret; } /* now unpack the right field */ m=1; switch (ptr[i]->type) { case OPAL_BOOL: if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.flag, &m, OPAL_BOOL))) { return ret; } break; case OPAL_BYTE: if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.byte, &m, OPAL_BYTE))) { return ret; } break; case OPAL_STRING: if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.string, &m, OPAL_STRING))) { return ret; } break; case OPAL_SIZE: if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.size, &m, OPAL_SIZE))) { return ret; } break; case OPAL_PID: if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.pid, &m, OPAL_PID))) { return ret; } break; case OPAL_INT: if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.integer, &m, OPAL_INT))) { return ret; } break; case OPAL_INT8: if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.int8, &m, OPAL_INT8))) { return ret; } break; case OPAL_INT16: if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.int16, &m, OPAL_INT16))) { return ret; } break; case OPAL_INT32: if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.int32, &m, OPAL_INT32))) { return ret; } break; case OPAL_INT64: if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.int64, &m, OPAL_INT64))) { return ret; } break; case OPAL_UINT: if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.uint, &m, OPAL_UINT))) { return ret; } break; case OPAL_UINT8: if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.uint8, &m, OPAL_UINT8))) { return ret; } break; case OPAL_UINT16: if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.uint16, &m, OPAL_UINT16))) { return ret; } break; case OPAL_UINT32: if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.uint32, &m, OPAL_UINT32))) { return ret; } break; case OPAL_UINT64: if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.uint64, &m, OPAL_UINT64))) { return ret; } break; case OPAL_BYTE_OBJECT: /* cannot use byte object unpack as it allocates memory, so unpack object size in bytes */ if (OPAL_SUCCESS != (ret = opal_dss_unpack_int32(buffer, &(ptr[i]->data.bo.size), &m, OPAL_INT32))) { return ret; } if (0 < ptr[i]->data.bo.size) { ptr[i]->data.bo.bytes = (uint8_t*)malloc(ptr[i]->data.bo.size); if (NULL == ptr[i]->data.bo.bytes) { return OPAL_ERR_OUT_OF_RESOURCE; } if (OPAL_SUCCESS != (ret = opal_dss_unpack_byte(buffer, ptr[i]->data.bo.bytes, &(ptr[i]->data.bo.size), OPAL_BYTE))) { return ret; } } else { ptr[i]->data.bo.bytes = NULL; } break; case OPAL_FLOAT: if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.fval, &m, OPAL_FLOAT))) { return ret; } break; case OPAL_TIMEVAL: if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.tv, &m, OPAL_TIMEVAL))) { return ret; } break; case ORTE_VPID: if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.vpid, &m, ORTE_VPID))) { return ret; } break; case ORTE_JOBID: if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.jobid, &m, ORTE_JOBID))) { return ret; } break; default: opal_output(0, "PACK-ORTE-ATTR: UNSUPPORTED TYPE"); return OPAL_ERROR; } } return OPAL_SUCCESS; }
int opal_dss_unpack(opal_buffer_t *buffer, void *dst, int32_t *num_vals, opal_data_type_t type) { int rc, ret; int32_t local_num, n=1; opal_data_type_t local_type; /* check for error */ if (NULL == buffer || NULL == dst || NULL == num_vals) { return OPAL_ERR_BAD_PARAM; } /* if user provides a zero for num_vals, then there is no storage allocated * so return an appropriate error */ if (0 == *num_vals) { return OPAL_ERR_UNPACK_INADEQUATE_SPACE; } /** Unpack the declared number of values * REMINDER: it is possible that the buffer is corrupted and that * the DSS will *think* there is a proper int32_t variable at the * beginning of the unpack region - but that the value is bogus (e.g., just * a byte field in a string array that so happens to have a value that * matches the int32_t data type flag). Therefore, this error check is * NOT completely safe. This is true for ALL unpack functions, not just * int32_t as used here. */ if (OPAL_DSS_BUFFER_FULLY_DESC == buffer->type) { if (OPAL_SUCCESS != ( rc = opal_dss_get_data_type(buffer, &local_type))) { *num_vals = 0; return rc; } if (OPAL_INT32 != local_type) { /* if the length wasn't first, then error */ *num_vals = 0; return OPAL_ERR_UNPACK_FAILURE; } } n=1; if (OPAL_SUCCESS != (rc = opal_dss_unpack_int32(buffer, &local_num, &n, OPAL_INT32))) { *num_vals = 0; return rc; } /** if the storage provided is inadequate, set things up * to unpack as much as we can and to return an error code * indicating that everything was not unpacked - the buffer * is left in a state where it can not be further unpacked. */ if (local_num > *num_vals) { local_num = *num_vals; ret = OPAL_ERR_UNPACK_INADEQUATE_SPACE; } else { /** enough or more than enough storage */ *num_vals = local_num; /** let the user know how many we actually unpacked */ ret = OPAL_SUCCESS; } /** Unpack the value(s) */ if (OPAL_SUCCESS != (rc = opal_dss_unpack_buffer(buffer, dst, &local_num, type))) { *num_vals = 0; ret = rc; } return ret; }