Changeset: b8a20639db14 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=b8a20639db14
Modified Files:
        clients/mapilib/mapi.c
        common/stream/stream.c
        common/stream/stream.h
        common/utils/conversion.c
        common/utils/conversion.h
        sql/backends/monet5/sql_result.c
Branch: protocol
Log Message:

Various compilation fixes.


diffs (210 lines):

diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -4191,7 +4191,7 @@ read_into_cache(MapiHdl hdl, int lookahe
                                return mapi_setError(mid, "read error from 
stream while reading result set", "read_into_cache", MERROR);
                        }
                        //fprintf(stderr, "result_set_id=%d, nr_rows=%llu, 
nr_cols=%lld\n", result_set_id, nr_rows, nr_cols);
-                       result->fieldcnt = nr_cols;
+                       result->fieldcnt = (int) nr_cols;
                        result->maxfields = (int) nr_cols;
                        result->row_count = nr_rows;
                        result->fields = calloc(result->fieldcnt, sizeof(struct 
MapiColumn));
@@ -5576,9 +5576,6 @@ mapi_fetch_row(MapiHdl hdl)
 
 #ifdef CONTINUATION_MESSAGE
                        if (!mnstr_writeChr(hdl->mid->to, 42) || 
mnstr_flush(hdl->mid->to)) {
-                               hdl->mid->errorstr = strdup("Failed to write 
confirm message to server.");
-                               hdl->mid->error = 0;
-                               fprintf(stderr, "Failure 2.\n");
                                return hdl->mid->error;
                        }
 #endif
@@ -5589,10 +5586,6 @@ mapi_fetch_row(MapiHdl hdl)
                        // after this point we operate on the buffer
                        while(nrows < 0) {
                                if (!mnstr_readLng(hdl->mid->from, &nrows)) {
-                                       // FIXME: set hdl->mid to something
-                                       hdl->mid->errorstr = strdup("Failed to 
read row response");
-                                       hdl->mid->error = 0;
-                                       fprintf(stderr, "Failure 3.\n");
                                        return hdl->mid->error;
                                }
                                if (nrows < 0) {
@@ -5602,22 +5595,26 @@ mapi_fetch_row(MapiHdl hdl)
                                        if (!mnstr_readLng(hdl->mid->from, 
&new_size)) {
                                                return hdl->mid->error;
                                        }
+                                       if (new_size < hdl->mid->blocksize) {
+                                               return mapi_setError(hdl->mid, 
"Request for buffer resize, but new size smaller than old size.", 
"mapi_fetch_row", MERROR);
+                                       }
                                        // consume flush
                                        mnstr_readChr(hdl->mid->from, &dummy);
                                        // resize buffer
-                                       bs2_resizebuf(hdl->mid->from, new_size);
-                                       hdl->mid->blocksize = new_size;
+                                       if (bs2_resizebuf(hdl->mid->from, 
(size_t) new_size) < 0) {
+                                               return mapi_setError(hdl->mid, 
"Failed to allocate space for stream buffer.", "mapi_fetch_row", MERROR);
+                                       }
+                                       hdl->mid->blocksize = (size_t) new_size;
                                }
                        }
 
                        assert(nrows <= result->row_count);
 
-
                        result->databuffer = bs2_stealbuf(hdl->mid->from);
+                       if (result->databuffer == NULL) {
+                               return mapi_setError(hdl->mid, "Failed to 
allocate space for stream buffer.", "mapi_fetch_row", MERROR);
+                       }
                        buf = (char*) result->databuffer + sizeof(lng);
-                       if (buf == NULL) {
-                               return mapi_setError(hdl->mid, "MALLOC 
failure.", "mapi_fetch_row", MERROR);
-                       }
 
                        // iterate over cols
                        for (i = 0; i < (size_t) result->fieldcnt; i++) {
diff --git a/common/stream/stream.c b/common/stream/stream.c
--- a/common/stream/stream.c
+++ b/common/stream/stream.c
@@ -4456,7 +4456,7 @@ bs2_stealbuf(stream *ss)
        return buffer;
 }
 
-void 
+int 
 bs2_resizebuf(stream *ss, size_t bufsiz) {
        size_t compress_bound;
        bs2 *s = (bs2 *) ss->stream_data.p;
@@ -4470,7 +4470,7 @@ bs2_resizebuf(stream *ss, size_t bufsiz)
        s->compbuf = NULL;
 
        if ((s->buf = malloc(bufsiz)) == NULL) {
-               return;
+               return -1;
        }
        s->bufsiz = bufsiz;
        compress_bound = compression_size_bound(s);
@@ -4480,10 +4480,11 @@ bs2_resizebuf(stream *ss, size_t bufsiz)
                if (!s->compbuf) {
                        free(s->buf);
                        s->buf = NULL;
-                       return;
+                       return -1;
                }
        }
        bs2_resetbuf(ss);
+       return 0;
 }
 
 void
diff --git a/common/stream/stream.h b/common/stream/stream.h
--- a/common/stream/stream.h
+++ b/common/stream/stream.h
@@ -256,10 +256,10 @@ typedef enum {
 
 stream_export stream *block_stream2(stream *s, size_t bufsiz, 
compression_method comp, column_compression colcomp);
 stream_export void* bs2_stealbuf(stream *ss);
-stream_export void bs2_resizebuf(stream *ss, size_t bufsiz);
+stream_export int bs2_resizebuf(stream *ss, size_t bufsiz);
 stream_export void bs2_resetbuf(stream *ss);
 stream_export buffer bs2_buffer(stream *s);
-column_compression bs2_colcomp(stream *ss);
+stream_export column_compression bs2_colcomp(stream *ss);
 stream_export void bs2_setpos(stream *ss, size_t pos);
 
 
diff --git a/common/utils/conversion.c b/common/utils/conversion.c
--- a/common/utils/conversion.c
+++ b/common/utils/conversion.c
@@ -287,7 +287,7 @@ conversion_time_to_string(char *dst, int
        sec = time / 1000;
        time -= sec * 1000;
        ms = time;
-       if (res = sprintf(dst, "%02d:%02d:%02d.%03d000", hour, min, sec, ms) < 
0) {
+       if ((res = sprintf(dst, "%02d:%02d:%02d.%03d000", hour, min, sec, ms)) 
< 0) {
                return res;
        }
        digits--;
@@ -329,10 +329,12 @@ conversion_epoch_optional_tz_to_string(c
        offset = conversion_date_to_string(dst, len, &days, -2147483647);
        if (offset < 0) return -1;
        if (include_timezone) {
+               int diff_hour, diff_min;
                int original_diff = timezone_diff;
-               int diff_hour = timezone_diff / 3600000;
+               
+               diff_hour = timezone_diff / 3600000;
                timezone_diff -= diff_hour * 3600000;
-               int diff_min = timezone_diff / 60000;
+               diff_min = timezone_diff / 60000;
                return snprintf(dst + offset, len - offset, " 
%02d:%02d:%02d.%06d%s%02d:%02d", hour, min, sec, ms, original_diff >= 0 ? "+" : 
"", diff_hour, diff_min);
        }
        return snprintf(dst + offset, len - offset, " %02d:%02d:%02d.%06d", 
hour, min, sec, ms);
diff --git a/common/utils/conversion.h b/common/utils/conversion.h
--- a/common/utils/conversion.h
+++ b/common/utils/conversion.h
@@ -58,8 +58,8 @@ numeric_conversion(float, flt);
 numeric_conversion(hge, hge);
 #endif
 
-// date conversion
-numeric_conversion(int, date);
+// date conversion, *src is days since 01-01-0001
+int conversion_date_to_string(char *dst, int len, const int *src, int 
null_value);
 
 // *src is ms since 00:00:00
 int conversion_time_to_string(char *dst, int len, const int *src, int 
null_value, int digits, int timezone_diff);
diff --git a/sql/backends/monet5/sql_result.c b/sql/backends/monet5/sql_result.c
--- a/sql/backends/monet5/sql_result.c
+++ b/sql/backends/monet5/sql_result.c
@@ -1438,8 +1438,8 @@ get_print_width(int mtype, int eclass, i
                        return l;
                }
        } else if (eclass == EC_NUM || eclass == EC_POS || eclass == EC_MONTH 
|| eclass == EC_SEC) {
+               BAT *b = NULL;
                count = 0;
-               BAT *b = NULL;
                if (bid) {
                        b = BATdescriptor(bid);
                        if (b) {
@@ -1910,8 +1910,8 @@ static int mvc_export_resultset_prot10(m
                int typelen = ATOMsize(mtype);
                int nil_len = -1;
                int retval = -1;
+               int convert_to_string = 
!type_supports_binary_transfer(c->type.type);
                iterators[i] = bat_iterator(b);
-               int convert_to_string = 
!type_supports_binary_transfer(c->type.type);
                sql_type *type = c->type.type;
 
                if (type->eclass == EC_TIMESTAMP) {
@@ -1924,7 +1924,7 @@ static int mvc_export_resultset_prot10(m
                        if (!convert_to_string && mtype == TYPE_str && 
c->type.digits > 0) {
                                // varchar with fixed max length
                                fixed_lengths += c->type.digits + 1;
-                               if (c->type.digits < VARCHAR_MAXIMUM_FIXED) {
+                               if ((int) c->type.digits < 
VARCHAR_MAXIMUM_FIXED) {
                                        typelen = c->type.digits;
                                        fixed_lengths -= 1;
                                } else {
@@ -2073,7 +2073,11 @@ static int mvc_export_resultset_prot10(m
                                        goto cleanup;
                                }
                                row = srow + 1;
-                               bs2_resizebuf(s, new_size);
+                               if (bs2_resizebuf(s, new_size) < 0) {
+                                       // failed to resize stream buffer
+                                       fres = -1;
+                                       goto cleanup;
+                               }
                                buf = bs2_buffer(s).buf;
                                bsize = new_size;
                        }
@@ -2132,7 +2136,6 @@ static int mvc_export_resultset_prot10(m
                                        char *startbuf = buf;
                                        buf += sizeof(lng);
                                        for (crow = srow; crow < row; crow++) {
-                                               int varsize;
                                                char *str = (char*) 
BUNtail(iterators[i], crow);
                                                buf = stpcpy(buf, str) + 1;
                                        }
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to