Changeset: 28ad1f67ab91 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=28ad1f67ab91 Modified Files: monetdb5/modules/atoms/blob.c Branch: Jun2016 Log Message:
Use MAL-style errors and remove some functions that are called only once. diffs (118 lines): diff --git a/monetdb5/modules/atoms/blob.c b/monetdb5/modules/atoms/blob.c --- a/monetdb5/modules/atoms/blob.c +++ b/monetdb5/modules/atoms/blob.c @@ -146,19 +146,6 @@ blob_read(blob *a, stream *s, size_t cnt return a; } -static gdk_return -blob_write(blob *a, stream *s, size_t cnt) -{ - var_t len = blobsize(a->nitems); - - (void) cnt; - assert(cnt == 1); - if (!mnstr_writeInt(s, (int) len) /* 64bit: check for overflow */ || - mnstr_write(s, (char *) a, len, 1) < 0) - return GDK_FAIL; - return GDK_SUCCEED; -} - static int blob_length(blob *p) { @@ -434,7 +421,7 @@ sqlblob_fromstr(char *instr, int *l, blo } -static int +static str fromblob_idx(str *retval, blob *b, int *idx) { str s, p = b->data + *idx; @@ -446,33 +433,11 @@ fromblob_idx(str *retval, blob *b, int * } *retval = s = (str) GDKmalloc(1 + r - p); if( *retval == NULL) - return GDK_SUCCEED; + throw(MAL, "blob.tostring", MAL_MALLOC_FAIL); for (; p < r; p++, s++) *s = *p; *s = 0; - return GDK_SUCCEED; -} - -static int -fromblob(str *retval, blob *b) -{ - int zero = 0; - - return fromblob_idx(retval, b, &zero); -} - -static int -toblob(blob **retval, str s) -{ - int len = strLen(s); - blob *b = (blob *) GDKmalloc(blobsize(len)); - - if( b == NULL) - return GDK_SUCCEED; - b->nitems = len; - memcpy(b->data, s, len); - *retval = b; - return GDK_SUCCEED; + return MAL_SUCCEED; } /* @@ -517,7 +482,14 @@ BLOBread(blob *a, stream *s, size_t cnt) gdk_return BLOBwrite(blob *a, stream *s, size_t cnt) { - return blob_write(a,s,cnt); + var_t len = blobsize(a->nitems); + + (void) cnt; + assert(cnt == 1); + if (!mnstr_writeInt(s, (int) len) /* 64bit: check for overflow */ || + mnstr_write(s, (char *) a, len, 1) < 0) + return GDK_FAIL; + return GDK_SUCCEED; } int @@ -561,21 +533,28 @@ BLOBfromstr(char *instr, int *l, blob ** str BLOBfromidx(str *retval, blob **binp, int *idx) { - fromblob_idx(retval, *binp, idx); - return MAL_SUCCEED; + return fromblob_idx(retval, *binp, idx); } str BLOBfromblob(str *retval, blob **b) { - fromblob(retval, *b); - return MAL_SUCCEED; + int zero = 0; + + return fromblob_idx(retval, *b, &zero); } str BLOBtoblob(blob **retval, str *s) { - toblob(retval, *s); + int len = strLen(*s); + blob *b = (blob *) GDKmalloc(blobsize(len)); + + if( b == NULL) + throw(MAL, "blob.toblob", MAL_MALLOC_FAIL); + b->nitems = len; + memcpy(b->data, *s, len); + *retval = b; return MAL_SUCCEED; } _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list