"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "Basic/Core/pdlconv.c" between
PDL-2.077.tar.gz and PDL-2.078.tar.gz

About: PDL (Perl Data Language) aims to turn perl into an efficient numerical language for scientific computing (similar to IDL and MatLab).

pdlconv.c  (PDL-2.077):pdlconv.c  (PDL-2.078)
skipping to change at line 46 skipping to change at line 46
#define X(...) XCODE(*ap = *pp, __VA_ARGS__) #define X(...) XCODE(*ap = *pp, __VA_ARGS__)
VAFF_IO(readdata_vaffine, X) VAFF_IO(readdata_vaffine, X)
#undef X #undef X
#define X(...) XCODE(*pp = *ap, __VA_ARGS__) #define X(...) XCODE(*pp = *ap, __VA_ARGS__)
VAFF_IO(writebackdata_vaffine, X) VAFF_IO(writebackdata_vaffine, X)
#undef X #undef X
#undef XCODE #undef XCODE
pdl_error pdl_converttype( pdl* a, int targtype ) { pdl_error pdl_converttype( pdl* a, int targtype ) {
pdl_error PDL_err = {0, NULL, 0}; pdl_error PDL_err = {0, NULL, 0};
PDLDEBUG_f(printf("pdl_converttype %p, %d, %d\n", (void*)a, a->datatype, PDLDEBUG_f(printf("pdl_converttype to %d: ", targtype); pdl_dump(a));
targtype));
if(a->state & PDL_DONTTOUCHDATA) if(a->state & PDL_DONTTOUCHDATA)
return pdl_make_error_simple(PDL_EUSERERROR, "Trying to converttype magica l (mmaped?) pdl"); return pdl_make_error_simple(PDL_EUSERERROR, "Trying to converttype magica l (mmaped?) pdl");
int intype = a->datatype; int intype = a->datatype;
if (intype == targtype) if (intype == targtype)
return PDL_err; return PDL_err;
STRLEN nbytes = a->nvals * pdl_howbig(targtype); /* Size of converted data * / STRLEN nbytes = a->nvals * pdl_howbig(targtype); /* Size of converted data * /
STRLEN ncurr = a->nvals * pdl_howbig(intype); STRLEN ncurr = a->nvals * pdl_howbig(intype);
char diffsize = ncurr != nbytes; PDL_Value value;
char diffsize = ncurr != nbytes,
was_useheap = (ncurr > sizeof(value)),
will_useheap = (nbytes > sizeof(value));
void *b = a->data; /* pointer to old data */ void *data_from_void = a->data, *data_to_void = a->data;
if (diffsize) if (diffsize)
a->data = pdl_smalloc(nbytes); /* Space for changed data */ data_to_void = will_useheap ? pdl_smalloc(nbytes) : &value;
#define THIS_ISBAD(from_badval_isnan, from_badval, from_val) \ #define THIS_ISBAD(from_badval_isnan, from_badval, from_val) \
((from_badval_isnan) \ ((from_badval_isnan) \
? isnan((double)(from_val)) \ ? isnan((double)(from_val)) \
: (from_val) == (from_badval)) : (from_val) == (from_badval))
#define X_OUTER(datatype_from, ctype_from, ppsym_from, ...) \ #define X_OUTER(datatype_from, ctype_from, ppsym_from, ...) \
PDL_Indx i = a->nvals; \ PDL_Indx i = a->nvals; \
ctype_from *bb = (ctype_from *) b; \ ctype_from *data_from_typed = (ctype_from *) data_from_void; \
ctype_from from_badval = pdl_get_pdl_badvalue(a).value.ppsym_from; \ ctype_from from_badval = pdl_get_pdl_badvalue(a).value.ppsym_from; \
char from_badval_isnan = PDL_ISNAN_##ppsym_from(from_badval); \ char from_badval_isnan = PDL_ISNAN_##ppsym_from(from_badval); \
PDL_GENERICSWITCH2(PDL_TYPELIST2_ALL_, targtype, X_INNER, return pdl_make_er ror(PDL_EUSERERROR, "Not a known data type code=%d", targtype)) PDL_GENERICSWITCH2(PDL_TYPELIST2_ALL_, targtype, X_INNER, return pdl_make_er ror(PDL_EUSERERROR, "Not a known data type code=%d", targtype))
#define X_INNER(datatype_to, ctype_to, ppsym_to, shortctype_to, defbval_to, ...) \ #define X_INNER(datatype_to, ctype_to, ppsym_to, shortctype_to, defbval_to, ...) \
ctype_to *aa = (ctype_to *) a->data; \ ctype_to *data_to_typed = (ctype_to *) data_to_void; \
aa += i-1; bb += i-1; \ data_to_typed += i-1; data_from_typed += i-1; \
if (a->state & PDL_BADVAL) { \ if (a->state & PDL_BADVAL) { \
ctype_to to_badval = defbval_to; \ ctype_to to_badval = defbval_to; \
a->has_badvalue = 0; \ a->has_badvalue = 0; \
while (i--) { \ while (i--) { \
*aa-- = THIS_ISBAD(from_badval_isnan, from_badval, *bb) \ *data_to_typed-- = THIS_ISBAD(from_badval_isnan, from_badval, *data_from
? to_badval : (ctype_to) *bb; \ _typed) \
bb--; \ ? to_badval : (ctype_to) *data_from_typed; \
data_from_typed--; \
} \ } \
} else \ } else \
while (i--) \ while (i--) \
*aa-- = (ctype_to) *bb--; *data_to_typed-- = (ctype_to) *data_from_typed--;
PDL_GENERICSWITCH(PDL_TYPELIST2_ALL, intype, X_OUTER, return pdl_make_error( PDL_EUSERERROR, "Not a known data type code=%d", intype)) PDL_GENERICSWITCH(PDL_TYPELIST2_ALL, intype, X_OUTER, return pdl_make_error( PDL_EUSERERROR, "Not a known data type code=%d", intype))
#undef X_INNER #undef X_INNER
#undef X_OUTER #undef X_OUTER
#undef THIS_ISBAD #undef THIS_ISBAD
/* Store new data */ /* Store new data */
if (diffsize) { if (diffsize) {
sv_setpvn((SV*) a->datasv, (char*) a->data, nbytes); if (!was_useheap && !will_useheap) {
a->data = SvPV_nolen((SV*) a->datasv); memmove(&a->value, data_to_void, nbytes);
} else if (!will_useheap) {
/* was heap, now not */
memmove(a->data = &a->value, data_to_void, nbytes);
SvREFCNT_dec((SV*)a->datasv);
a->datasv = NULL;
} else {
/* now change to be heap */
if (a->datasv == NULL)
a->datasv = newSVpvn("", 0);
(void)SvGROW((SV*)a->datasv, nbytes);
SvCUR_set((SV*)a->datasv, nbytes);
memmove(a->data = SvPV_nolen((SV*)a->datasv), data_to_void, nbytes);
}
} }
a->datatype = targtype; a->datatype = targtype;
PDLDEBUG_f(printf("pdl_converttype after: "); pdl_dump(a));
return PDL_err; return PDL_err;
} }
 End of changes. 10 change blocks. 
14 lines changed or deleted 31 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)