Changeset: 7486a7a3a5eb for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7486a7a3a5eb
Modified Files:
        clients/Tests/exports.stable.out
        clients/mapilib/mapi.c
        clients/mapilib/mapi.h
        common/stream/ChangeLog
        common/stream/stream.c
        common/stream/stream.h
        gdk/gdk_logger.c
        monetdb5/mal/mal_session.c
        monetdb5/modules/mal/tablet.c
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql_result.c
        sql/backends/monet5/wlr.c
Branch: default
Log Message:

All sorts of small fixes.
- Use more appropriate types (bool, const char *, uint32_t).
- open_rstream/open_wstream don't read/write an initial byteorder
  marker anymore: this is now done by the called.
- Function mnstr_type() is renamed mnstr_isbinary() and returns bool.
- Function mnstr_set_byteorder is replaced with mnstr_set_bigendian
  with a second parameter of type bool which is true if the stream
  should be big-endian.
- Function mnstr_byteorder is replaced with mnstr_set_swapbytes that
  returns true if the stream swaps bytes.
- In some places, use close_stream instead of mnstr_destroy to also
  close the stream (not just free the allocated memory).
- In wlr.c use open_rastream since the file was created with
  open_wastream (and it's a text file).
- The mnstr_write{Sht,Int,Lng,Hge} functions and their Array versions
  now swap bytes if the stream calls for byte swapping.  Before, only
  the read functions did that.


diffs (truncated from 1500 to 300 lines):

diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -2727,7 +2727,6 @@ size_t getFileSize(stream *s);
 stream *iconv_rstream(stream *restrict ss, const char *restrict charset, const 
char *restrict name);
 stream *iconv_wstream(stream *restrict ss, const char *restrict charset, const 
char *restrict name);
 bool isa_block_stream(stream *s);
-int mnstr_byteorder(stream *s);
 void mnstr_clearerr(stream *s);
 void mnstr_close(stream *s);
 void mnstr_destroy(stream *s);
@@ -2738,8 +2737,10 @@ int mnstr_flush(stream *s);
 int mnstr_fsetpos(stream *restrict s, fpos_t *restrict p);
 int mnstr_fsync(stream *s);
 buffer *mnstr_get_buffer(stream *s);
+bool mnstr_get_swapbytes(stream *s);
 int mnstr_init(void);
 int mnstr_isalive(stream *s);
+bool mnstr_isbinary(stream *s);
 char *mnstr_name(stream *s);
 int mnstr_printf(stream *restrict s, _In_z_ _Printf_format_string_ const char 
*restrict format, ...) __attribute__((__format__(__printf__, 2, 3)));
 ssize_t mnstr_read(stream *restrict s, void *restrict buf, size_t elmsize, 
size_t cnt);
@@ -2757,9 +2758,8 @@ int mnstr_readShtArray(stream *restrict 
 int mnstr_readStr(stream *restrict s, char *restrict val);
 ssize_t mnstr_read_block(stream *restrict s, void *restrict buf, size_t 
elmsize, size_t cnt);
 ssize_t mnstr_readline(stream *restrict s, void *restrict buf, size_t maxcnt);
-void mnstr_set_byteorder(stream *s, char bigendian);
+void mnstr_set_bigendian(stream *s, bool bigendian);
 void mnstr_settimeout(stream *s, unsigned int ms, bool( *func)(void));
-int mnstr_type(stream *s);
 ssize_t mnstr_write(stream *restrict s, const void *restrict buf, size_t 
elmsize, size_t cnt);
 int mnstr_writeBte(stream *s, int8_t val);
 int mnstr_writeBteArray(stream *restrict s, const int8_t *restrict val, size_t 
cnt);
diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -807,7 +807,7 @@ enum mapi_lang_t {
 */
 struct MapiStruct {
        char *server;           /* server version */
-       char *mapiversion;      /* mapi version */
+       const char *mapiversion; /* mapi version */
        char *hostname;
        int port;
        char *username;
@@ -838,7 +838,7 @@ struct MapiStruct {
 
        stream *tracelog;       /* keep a log for inspection */
        stream *from, *to;
-       int index;              /* to mark the log records */
+       uint32_t index;         /* to mark the log records */
 };
 
 struct MapiResultSet {
@@ -1333,18 +1333,19 @@ mapi_log_header(Mapi mid, char *mark)
        static int64_t firstcall = 0;
        int64_t now;
 
-       if (mid->tracelog == NULL)
-               return;
        if (firstcall == 0)
                firstcall = usec();
        now = (usec() - firstcall) / 1000;
-       mnstr_printf(mid->tracelog, ":%"PRId64"[%d]:%s\n", now, mid->index, 
mark);
+       mnstr_printf(mid->tracelog, ":%" PRId64 "[%" PRIu32 "]:%s\n",
+                    now, mid->index, mark);
        mnstr_flush(mid->tracelog);
 }
 
 static void
 mapi_log_record(Mapi mid, const char *msg)
 {
+       if (mid->tracelog == NULL)
+               return;
        mapi_log_header(mid, "W");
        mnstr_printf(mid->tracelog, "%s", msg);
        mnstr_flush(mid->tracelog);
@@ -1818,7 +1819,7 @@ static Mapi
 mapi_new(void)
 {
        Mapi mid;
-       static int index = 0;
+       static uint32_t index = 0;
 
        mid = calloc(1, sizeof(*mid));
        if (mid == NULL)
@@ -2713,7 +2714,7 @@ mapi_reconnect(Mapi mid)
                        return mapi_setError(mid, buf, "mapi_reconnect", 
MERROR);
                }
 
-               mnstr_set_byteorder(mid->from, strcmp(byteo, "BIG") == 0);
+               mnstr_set_bigendian(mid->from, strcmp(byteo, "BIG") == 0);
 
                /* note: if we make the database field an empty string, it
                 * means we want the default.  However, it *should* be there. */
@@ -3424,7 +3425,7 @@ read_line(Mapi mid)
        char *s;                /* from where to search for newline */
 
        if (mid->active == NULL)
-               return 0;
+               return NULL;
 
        /* check if we need to read more blocks to get a new line */
        mid->blk.eos = false;
@@ -3911,7 +3912,7 @@ parse_header_line(MapiHdl hdl, char *lin
 static MapiMsg
 read_into_cache(MapiHdl hdl, int lookahead)
 {
-       char *line, *copy;
+       char *line;
        Mapi mid;
        struct MapiResultSet *result;
 
@@ -3934,17 +3935,10 @@ read_into_cache(MapiHdl hdl, int lookahe
                        hdl->active = NULL;
                        /* set needmore flag if line equals PROMPT2 up
                           to newline */
-                       copy = PROMPT2; /* \001\002\n */
-                       while (*line) {
-                               if (*line != *copy) /* must be EOF or PROMPT1 
\001\001\n */
-                                       return mid->error;
-                               line++;
-                               copy++;
-                       }
-                       if (*copy == '\n' || *copy == 0) {
+                       if (line[1] == PROMPT2[1] && line[2] == '\0') {
                                /* skip end of block */
                                mid->active = hdl;
-                               read_line(mid);
+                               (void) read_line(mid);
                                hdl->needmore = true;
                                mid->active = hdl;
                        }
diff --git a/clients/mapilib/mapi.h b/clients/mapilib/mapi.h
--- a/clients/mapilib/mapi.h
+++ b/clients/mapilib/mapi.h
@@ -132,7 +132,7 @@ mapi_export void mapi_explain(Mapi mid, 
 mapi_export void mapi_explain_query(MapiHdl hdl, FILE *fd);
 mapi_export void mapi_explain_result(MapiHdl hdl, FILE *fd);
 mapi_export void mapi_trace(Mapi mid, bool flag);
-#ifdef ST_READ                 /* if stream.h was included */
+#ifdef _STREAM_H_              /* if stream.h was included */
 mapi_export stream *mapi_get_from(Mapi mid);
 mapi_export stream *mapi_get_to(Mapi mid);
 #endif
diff --git a/common/stream/ChangeLog b/common/stream/ChangeLog
--- a/common/stream/ChangeLog
+++ b/common/stream/ChangeLog
@@ -1,3 +1,19 @@
 # ChangeLog file for stream
 # This file is updated with Maddlog
 
+* Wed Sep 19 2018 Sjoerd Mullender <[email protected]>
+- The functions mnstr_write{Sht,Int,Lng,Hge} and their Array variants
+  now swap bytes of the written values if the stream is set to swap bytes
+  (i.e. big-endian on a little-endian machine and v.v.).
+- Removed defines ST_ASCII, ST_BIN, ST_READ, ST_WRITE from stream.h.
+- Changed function mnstr_set_byteorder(stream, char) to
+  mnstr_set_bigendian(stream, bool) where the second argument should
+  be `true' for specifying that the stream is bigendian.  This sets an
+  internal flag whether or not to swap bytes which can be retrieved
+  with mnstr_get_swapbytes(stream).
+- Changed function `int mnstr_byteorder(stream)' to `bool
+  mnstr_get_swapbytes(stream)'; it now returns whether bytes are
+  swapped.
+- Changed function `int mnstr_type(stream)' to `bool
+  mnstr_isbinary(stream)'.
+
diff --git a/common/stream/stream.c b/common/stream/stream.c
--- a/common/stream/stream.c
+++ b/common/stream/stream.c
@@ -45,7 +45,7 @@
  * -----------
  *
  * A tee stream is a write stream that duplicates all output to two
- * write streams of the same type (asc/bin).
+ * write streams of the same type (txt/bin).
  */
 
 
@@ -181,11 +181,11 @@
 
 
 struct stream {
-       short byteorder;
-       char access;            /* read/write */
-       char isutf8;            /* known to be UTF-8 due to BOM */
-       short type;             /* ascii/binary */
-       char *name;
+       char *name;             /* name of the stream */
+       bool swapbytes;         /* whether to swap bytes */
+       bool readonly;          /* only reading or only writing */
+       bool isutf8;            /* known to be UTF-8 due to BOM */
+       bool binary;            /* text/binary */
        unsigned int timeout;   /* timeout in ms */
        bool (*timeout_func)(void); /* callback function: NULL/true -> return */
        union {
@@ -211,7 +211,7 @@ struct stream {
 int
 mnstr_init(void)
 {
-       static int inited = 0;
+       static bool inited = false;
 
        if (inited)
                return 0;
@@ -224,7 +224,7 @@ mnstr_init(void)
                        return -1;
        }
 #endif
-       inited = 1;
+       inited = true;
        return 0;
 }
 
@@ -363,7 +363,7 @@ mnstr_read(stream *restrict s, void *res
        fprintf(stderr, "read %s %zu %zu\n",
                s->name ? s->name : "<unnamed>", elmsize, cnt);
 #endif
-       assert(s->access == ST_READ);
+       assert(s->readonly);
        if (s->errnr)
                return -1;
        return s->read(s, buf, elmsize, cnt);
@@ -383,7 +383,7 @@ mnstr_readline(stream *restrict s, void 
        fprintf(stderr, "readline %s %zu\n",
                s->name ? s->name : "<unnamed>", maxcnt);
 #endif
-       assert(s->access == ST_READ);
+       assert(s->readonly);
        if (s->errnr)
                return -1;
        if (maxcnt == 0)
@@ -402,13 +402,13 @@ mnstr_readline(stream *restrict s, void 
                        if (*start++ == '\n' || --maxcnt == 1) {
                                *start = 0;
 #if 0
-                               if (s->type == ST_ASCII &&
+                               if (!s->binary &&
                                    start[-1] == '\n' &&
                                    start > b + 1 &&
                                    start[-2] == '\r') {
                                        /* convert CR-LF to just LF */
                                        start[-2] = start[-1];
-                                       start--;
+                                       *--start = 0;
                                }
 #endif
                                return (ssize_t) (start - b);
@@ -441,7 +441,7 @@ mnstr_write(stream *restrict s, const vo
        fprintf(stderr, "write %s %zu %zu\n",
                s->name ? s->name : "<unnamed>", elmsize, cnt);
 #endif
-       assert(s->access == ST_WRITE);
+       assert(!s->readonly);
        if (s->errnr)
                return -1;
        return s->write(s, buf, elmsize, cnt);
@@ -498,7 +498,7 @@ mnstr_flush(stream *s)
 #ifdef STREAM_DEBUG
        fprintf(stderr, "flush %s\n", s->name ? s->name : "<unnamed>");
 #endif
-       assert(s->access == ST_WRITE);
+       assert(!s->readonly);
        if (s->errnr)
                return -1;
        if (s->flush)
@@ -516,7 +516,7 @@ mnstr_fsync(stream *s)
        fprintf(stderr, "fsync %s (%d)\n",
                s->name ? s->name : "<unnamed>", s->errnr);
 #endif
-       assert(s->access == ST_WRITE);
+       assert(!s->readonly);
        if (s->errnr)
                return -1;
        if (s->fsync)
@@ -592,37 +592,40 @@ mnstr_clearerr(stream *s)
        }
 }
 
-int
-mnstr_type(stream *s)
+bool
+mnstr_isbinary(stream *s)
+{
+       if (s == NULL)
+               return false;
+       return s->binary;
+}
+
+bool
+mnstr_get_swapbytes(stream *s)
 {
        if (s == NULL)
                return 0;
-       return s->type;
-}
-
-int
-mnstr_byteorder(stream *s)
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to