int roll_left(dice* d, dice* pai) { copy_values(pai, d); int old_left_side_value = 7 - (*d).right; (*d).right = (*d).bottom; (*d).bottom = old_left_side_value; return (*d).bottom; }
int roll_up(dice* d, dice* pai){ copy_values(pai, d); int old_top_side_value = 7 - (*d).bottom; (*d).bottom = (*d).front; (*d).front = old_top_side_value; return (*d).bottom; }
int roll_down(dice* d, dice* pai){ copy_values(pai, d); int old_down_side_value = 7 - (*d).front; (*d).front = (*d).bottom; (*d).bottom = old_down_side_value; return (*d).bottom; }
static int py_to_array(PyObject *seq, PointerRNA *ptr, PropertyRNA *prop, char *param_data, ItemTypeCheckFunc check_item_type, const char *item_type_str, int item_size, ItemConvertFunc convert_item, RNA_SetArrayFunc rna_set_array, const char *error_prefix) { /*int totdim, dim_size[MAX_ARRAY_DIMENSION];*/ int totitem; char *data = NULL; /*totdim = RNA_property_array_dimension(ptr, prop, dim_size);*/ /*UNUSED*/ if (validate_array(seq, ptr, prop, 0, check_item_type, item_type_str, &totitem, error_prefix) == -1) { return -1; } if (totitem) { /* note: this code is confusing */ if (param_data && RNA_property_flag(prop) & PROP_DYNAMIC) { /* not freeing allocated mem, RNA_parameter_list_free() will do this */ ParameterDynAlloc *param_alloc = (ParameterDynAlloc *)param_data; param_alloc->array_tot = (int)totitem; param_alloc->array = MEM_callocN(item_size * totitem, "py_to_array dyn"); /* freeing param list will free */ data = param_alloc->array; } else if (param_data) { data = param_data; } else { data = PyMem_MALLOC(item_size * totitem); } /* will only fail in very rare cases since we already validated the * python data, the check here is mainly for completeness. */ if (copy_values(seq, ptr, prop, 0, data, item_size, NULL, convert_item, NULL) != NULL) { if (param_data == NULL) { /* NULL can only pass through in case RNA property arraylength is 0 (impossible?) */ rna_set_array(ptr, prop, data); PyMem_FREE(data); } } else { if (param_data == NULL) { PyMem_FREE(data); } PyErr_Format(PyExc_TypeError, "%s internal error parsing sequence of type '%s' after successful validation", error_prefix, Py_TYPE(seq)->tp_name); return -1; } } return 0; }
static int py_to_array_index(PyObject *py, PointerRNA *ptr, PropertyRNA *prop, int lvalue_dim, int arrayoffset, int index, ItemTypeCheckFunc check_item_type, const char *item_type_str, ItemConvertFunc convert_item, RNA_SetIndexFunc rna_set_index, const char *error_prefix) { int totdim, dimsize[MAX_ARRAY_DIMENSION]; int totitem, i; totdim = RNA_property_array_dimension(ptr, prop, dimsize); /* convert index */ /* arr[3][4][5] * * arr[2] = x * lvalue_dim = 0, index = 0 + 2 * 4 * 5 * * arr[2][3] = x * lvalue_dim = 1, index = 40 + 3 * 5 */ lvalue_dim++; for (i = lvalue_dim; i < totdim; i++) index *= dimsize[i]; index += arrayoffset; if (lvalue_dim == totdim) { /* single item, assign directly */ if (!check_item_type(py)) { PyErr_Format(PyExc_TypeError, "%s %.200s.%.200s, expected a %s type, not %s", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), item_type_str, Py_TYPE(py)->tp_name); return -1; } copy_value_single(py, ptr, prop, NULL, 0, &index, convert_item, rna_set_index); } else { if (validate_array(py, ptr, prop, lvalue_dim, check_item_type, item_type_str, &totitem, error_prefix) == -1) { return -1; } if (totitem) { copy_values(py, ptr, prop, lvalue_dim, NULL, 0, &index, convert_item, rna_set_index); } } return 0; }
void SPARSE::operator=(const MTX& B) { SPARSE* A = (SPARSE*)&B; copy_values((*A).row_number,(*A).column_number,(*A).value_number,(*A).value_length,(*A).value_start,(*A).column_start,(*A).diagonal); }
int grib_init_accessor_from_handle(grib_loader* loader,grib_accessor* ga,grib_arguments* default_value) { grib_handle* h = (grib_handle*)loader->data; int ret = GRIB_SUCCESS; size_t len = 0; char* sval = NULL; unsigned char* uval = NULL; long* lval = NULL; double* dval = NULL; static int first = 1; static const char* missing = 0; const char* name = NULL; int k = 0; grib_handle *g; int e, pack_missing = 0; grib_context_log(h->context,GRIB_LOG_DEBUG, "XXXXX Copying %s", ga->name); if(default_value) { grib_context_log(h->context,GRIB_LOG_DEBUG, "Copying: setting %s to default value", ga->name); grib_pack_expression(ga,grib_arguments_get_expression(h,default_value,0)); } if( (ga->flags & GRIB_ACCESSOR_FLAG_NO_COPY) || ((ga->flags & GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC) && loader->changing_edition ) || (ga->flags & GRIB_ACCESSOR_FLAG_FUNCTION) || ( (ga->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) && !(ga->flags & GRIB_ACCESSOR_FLAG_COPY_OK) ) ) { grib_context_log(h->context,GRIB_LOG_DEBUG, "Copying %s ignored", ga->name); return GRIB_SUCCESS; } #if 0 if(h->values) if(copy_values(h,ga) == GRIB_SUCCESS) { grib_context_log(h->context,GRIB_LOG_DEBUG, "Copying: setting %s to multi-set-value", ga->name); return GRIB_SUCCESS; } #endif #if 0 if(h->loader) h->loader->init_accessor(h->loader,ga,default_value); #else /* COMEBACK here this is needed if we reparse during reparse.... */ g = h; while(g) { if(g->values) { if(copy_values(g,ga) == GRIB_SUCCESS) { grib_context_log(h->context,GRIB_LOG_DEBUG, "Copying: setting %s to multi-set-value", ga->name); return GRIB_SUCCESS; } } g = g->main; } #endif /* Check if the same name exists in the original message ... */ k = 0; while( (k < MAX_ACCESSOR_NAMES) && ((name = ga->all_names[k]) != NULL) && ((ret = grib_get_size(h,name,&len)) != GRIB_SUCCESS)) k++; if(ret != GRIB_SUCCESS) { name = ga->name; if(first) { missing = getenv("GRIB_PRINT_MISSING"); first = 0; } grib_context_log(h->context,GRIB_LOG_DEBUG, "Copying [%s] failed: %s", name,grib_get_error_message(ret)); if(missing) { fprintf(stdout,"REPARSE: no value for %s",name); if(default_value) fprintf(stdout," (default value)"); fprintf(stdout,"\n"); } return GRIB_SUCCESS; } /* we copy also virtual keys*/ if(len == 0) { grib_context_log(h->context,GRIB_LOG_DEBUG, "Copying %s failed, length is 0", name); return GRIB_SUCCESS; } if((ga->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) && grib_is_missing(h,name,&e) && e == GRIB_SUCCESS && len == 1) { grib_pack_missing(ga); pack_missing = 1; } switch(grib_accessor_get_native_type(ga)) { case GRIB_TYPE_STRING: /* len = len > 1024 ? len : 1024; */ grib_get_string_length(h,name,&len); sval = (char*)grib_context_malloc(h->context,len); ret = grib_get_string_internal(h,name,sval,&len); if(ret == GRIB_SUCCESS) { grib_context_log(h->context,GRIB_LOG_DEBUG, "Copying string %s to %s", sval, name); ret = grib_pack_string(ga,sval,&len); } grib_context_free(h->context,sval); break; case GRIB_TYPE_LONG: lval = (long*)grib_context_malloc(h->context,len*sizeof(long)); ret = grib_get_long_array_internal(h,name,lval,&len); if(ret == GRIB_SUCCESS) { grib_context_log(h->context,GRIB_LOG_DEBUG, "Copying %d long(s) %d to %s", len, lval[0], name); if(ga->same) { ret = grib_set_long_array(ga->parent->h,ga->name,lval,len); /* Allow for lists to be resized */ if((ret == GRIB_WRONG_ARRAY_SIZE || ret == GRIB_ARRAY_TOO_SMALL) && loader->list_is_resized) ret = GRIB_SUCCESS; } else { /* See GRIB-492. This is NOT an ideal solution! */ if (*lval == GRIB_MISSING_LONG || pack_missing) { ; /* No checks needed */ } else { /* If we have just one key of type long which has one octet, then do not exceed maximum value */ const long num_octets = ga->length; if (len == 1 && num_octets == 1 && *lval > 255) { *lval = 0; /* Reset to a reasonable value */ } } ret = grib_pack_long(ga,lval,&len); } } grib_context_free(h->context,lval); break; case GRIB_TYPE_DOUBLE: dval = (double*)grib_context_malloc(h->context,len*sizeof(double)); ret = grib_get_double_array_internal(h,name,dval,&len); if(ret == GRIB_SUCCESS) { grib_context_log(h->context,GRIB_LOG_DEBUG, "Copying %d double(s) %g to %s", len, dval[0], name); if(ga->same) { ret = grib_set_double_array(ga->parent->h,ga->name,dval,len); /* Allow for lists to be resized */ if((ret == GRIB_WRONG_ARRAY_SIZE || ret == GRIB_ARRAY_TOO_SMALL) && loader->list_is_resized) ret = GRIB_SUCCESS; } else ret = grib_pack_double(ga,dval,&len); } grib_context_free(h->context,dval); break; case GRIB_TYPE_BYTES: uval = (unsigned char*)grib_context_malloc(h->context,len*sizeof(char)); ret = grib_get_bytes_internal(h,name,uval,&len); if(ret == GRIB_SUCCESS) { grib_context_log(h->context,GRIB_LOG_DEBUG, "Copying %d byte(s) to %s", len, name); ret = grib_pack_bytes(ga,uval,&len); } grib_context_free(h->context,uval); break; case GRIB_TYPE_LABEL: break; default: grib_context_log(h->context,GRIB_LOG_ERROR, "Copying %s, cannot establish type %d [%s]" , name,grib_accessor_get_native_type(ga),ga->creator->cclass->name); break; } return ret; }
static char *copy_values(PyObject *seq, PointerRNA *ptr, PropertyRNA *prop, int dim, char *data, unsigned int item_size, int *index, ItemConvertFunc convert_item, RNA_SetIndexFunc rna_set_index) { int totdim = RNA_property_array_dimension(ptr, prop, NULL); const Py_ssize_t seq_size = PySequence_Size(seq); Py_ssize_t i; /* Regarding PySequence_GetItem() failing. * * This should never be NULL since we validated it, _but_ some tricky python * developer could write their own sequence type which succeeds on * validating but fails later somehow, so include checks for safety. */ /* Note that 'data can be NULL' */ if (seq_size == -1) { return NULL; } #ifdef USE_MATHUTILS if (dim == 0) { if (MatrixObject_Check(seq)) { MatrixObject *pymat = (MatrixObject *)seq; size_t allocsize = pymat->num_col * pymat->num_row * sizeof(float); /* read callback already done by validate */ /* since this is the first iteration we can assume data is allocated */ memcpy(data, pymat->matrix, allocsize); /* not really needed but do for completeness */ data += allocsize; return data; } } #endif /* USE_MATHUTILS */ for (i = 0; i < seq_size; i++) { PyObject *item = PySequence_GetItem(seq, i); if (item) { if (dim + 1 < totdim) { data = copy_values(item, ptr, prop, dim + 1, data, item_size, index, convert_item, rna_set_index); } else { data = copy_value_single(item, ptr, prop, data, item_size, index, convert_item, rna_set_index); } Py_DECREF(item); /* data may be NULL, but the for loop checks */ } else { return NULL; } } return data; }