Changeset: 2fecb681da80 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=2fecb681da80
Modified Files:
        clients/ChangeLog
        clients/examples/C/sample4.c
        clients/mapiclient/mclient.c
        clients/mapilib/mapi.c
        clients/mapilib/mapi.h
        clients/odbc/driver/SQLExecute.c
        monetdb5/modules/mal/mal_mapi.c
        sql/backends/monet5/prog.c
        tools/merovingian/daemon/multiplex-funnel.c
Branch: default
Log Message:

Use standard type int64_t (stdint.h) instead of home-made mapi_int64.
Internally use the PRId64 and related macros for formatting.


diffs (truncated from 565 to 300 lines):

diff --git a/clients/ChangeLog b/clients/ChangeLog
--- a/clients/ChangeLog
+++ b/clients/ChangeLog
@@ -1,6 +1,13 @@
 # ChangeLog file for clients
 # This file is updated with Maddlog
 
+* Thu Nov 16 2017 Sjoerd Mullender <[email protected]>
+- The functions in the mapi library that require 64 bit integers now
+  use the standard type int64_t instead of the non-standard mapi_int64.
+  This requires a compilation environment that has the stdint.h include
+  file (standardized in C99).  Compilation of the library also requires
+  the inttypes.h include file (also standardized in C99).
+
 * Mon Jul 17 2017 Panagiotis Koutsourakis <[email protected]>
 - Add a new pretty printing option to stethoscope
   Running stethoscope with the flag -j will produce not pretty printed
diff --git a/clients/examples/C/sample4.c b/clients/examples/C/sample4.c
--- a/clients/examples/C/sample4.c
+++ b/clients/examples/C/sample4.c
@@ -9,12 +9,8 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <inttypes.h>
 #include <mapi.h>
-#ifdef _MSC_VER
-#define LLFMT "%I64d"
-#else
-#define LLFMT "%lld"
-#endif
 
 #define die(dbh,hdl)   do {                                            \
                                if (hdl)                                \
@@ -31,7 +27,7 @@ main(int argc, char **argv)
 {
        Mapi dbh;
        MapiHdl hdl = NULL;
-       mapi_int64 rows;
+       int64_t rows;
 
        if (argc != 4) {
                printf("usage:%s <host> <port> <language>\n", argv[0]);
@@ -66,7 +62,7 @@ main(int argc, char **argv)
                rows = mapi_fetch_all_rows(hdl);
                if (mapi_error(dbh))
                        die(dbh, hdl);
-               printf("rows received " LLFMT "\n", rows);
+               printf("rows received %" PRId64 "\n", rows);
                while (mapi_fetch_row(hdl)) {
                        char *nme = mapi_fetch_field(hdl, 0);
                        char *age = mapi_fetch_field(hdl, 1);
@@ -97,7 +93,7 @@ main(int argc, char **argv)
                rows = mapi_fetch_all_rows(hdl);
                if (mapi_error(dbh))
                        die(dbh, hdl);
-               printf("rows received " LLFMT "\n", rows);
+               printf("rows received %" PRId64 "\n", rows);
                while (mapi_fetch_row(hdl)) {
                        char *nme = mapi_fetch_field(hdl, 1);
                        char *age = mapi_fetch_field(hdl, 2);
diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -22,6 +22,7 @@
 # endif
 #endif
 #include "mapi.h"
+#include <inttypes.h>          /* for PRId64 format macro */
 #include <unistd.h>
 #include <stdlib.h>
 #include <errno.h>
@@ -109,8 +110,8 @@ int csvheader = 0;          /* include header li
 #define DEFWIDTH 80
 
 /* use a 64 bit integer for the timer */
-typedef lng timertype;
-#define TTFMT LLFMT
+typedef int64_t timertype;
+#define TTFMT "%" PRId64
 #if 0
 static char *mark, *mark2;
 #endif
@@ -1463,7 +1464,7 @@ SQLrenderer(MapiHdl hdl, char singleinst
        char **rest = NULL;
        char buf[50];
        int ps = rowsperpage, silent = 0;
-       mapi_int64 rows = 0;
+       int64_t rows = 0;
 
        /* in case of interactive mode, we should show timing on request */
        singleinstr = showtiming? 1 :singleinstr;
@@ -1669,11 +1670,11 @@ SQLrenderer(MapiHdl hdl, char singleinst
        if (fields)
                SQLseparator(len, printfields, '-');
        rows = mapi_get_row_count(hdl);
-       snprintf(buf, sizeof(buf), LLFMT " rows", rows);
+       snprintf(buf, sizeof(buf), "%" PRId64 " rows", rows);
 #if 0
        mark2 = strdup(buf);    /* for the timer output */
 #endif
-       printf(LLFMT " tuple%s%s%s%s", rows, rows != 1 ? "s" : "",
+       printf("%" PRId64 " tuple%s%s%s%s", rows, rows != 1 ? "s" : "",
                        singleinstr ? " (" : "",
                        singleinstr && formatter != TESTformatter ? 
timerHuman() : "",
                        singleinstr ? ")" : "");
@@ -1682,7 +1683,7 @@ SQLrenderer(MapiHdl hdl, char singleinst
                printf(" !");
        if (fields != printfields) {
                rows = fields - printfields;
-               printf(LLFMT " column%s dropped", rows, rows != 1 ? "s" : "");
+               printf("%" PRId64 " column%s dropped", rows, rows != 1 ? "s" : 
"");
        }
        if (fields != printfields && croppedfields > 0)
                printf(", ");
@@ -1826,7 +1827,7 @@ static int
 format_result(Mapi mid, MapiHdl hdl, char singleinstr)
 {
        MapiMsg rc = MERROR;
-       mapi_int64 aff, lid;
+       int64_t aff, lid;
        char *reply;
 #ifdef HAVE_POPEN
        stream *saveFD;
@@ -1862,20 +1863,20 @@ format_result(Mapi mid, MapiHdl hdl, cha
                        SQLqueryEcho(hdl);
                        if (formatter == RAWformatter ||
                            formatter == TESTformatter)
-                               mnstr_printf(toConsole, "[ " LLFMT "\t]\n", 
mapi_rows_affected(hdl));
+                               mnstr_printf(toConsole, "[ %" PRId64 "\t]\n", 
mapi_rows_affected(hdl));
                        else if (formatter == TIMERformatter)
                                printf("%s\n", timerHuman());
                        else {
                                aff = mapi_rows_affected(hdl);
                                lid = mapi_get_last_id(hdl);
                                mnstr_printf(toConsole,
-                                            LLFMT " affected row%s",
+                                            "%" PRId64 " affected row%s",
                                             aff,
                                             aff != 1 ? "s" : "");
                                if (lid != -1) {
                                        mnstr_printf(toConsole,
                                                     ", last generated key: "
-                                                    LLFMT,
+                                                    "%" PRId64,
                                                     lid);
                                }
                                if (singleinstr && formatter != TESTformatter)
@@ -2949,7 +2950,7 @@ set_timezone(Mapi mid)
        tmp = localtime(&t);
        tmp->tm_isdst=0; /* We need the difference without dst */
        lt = mktime(tmp);
-       assert((lng) gt - (lng) lt >= (lng) INT_MIN && (lng) gt - (lng) lt <= 
(lng) INT_MAX);
+       assert((int64_t) gt - (int64_t) lt >= (int64_t) INT_MIN && (int64_t) gt 
- (int64_t) lt <= (int64_t) INT_MAX);
        tzone = (int) (gt - lt);
 #endif
        if (tzone < 0)
diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -484,19 +484,19 @@
  *
  * Return the number of fields in the current row.
  *
- * @item mapi_int64 mapi_get_row_count(MapiHdl mid)
+ * @item int64_t mapi_get_row_count(MapiHdl mid)
  *
  * If possible, return the number of rows in the last select call.  A -1
  * is returned if this information is not available.
  *
- * @item mapi_int64 mapi_get_last_id(MapiHdl mid)
+ * @item int64_t mapi_get_last_id(MapiHdl mid)
  *
  * If possible, return the last inserted id of auto_increment (or alike) 
column. 
  * A -1 is returned if this information is not available. We restrict this to
  * single row inserts and one auto_increment column per table. If the 
restrictions
  * do not hold, the result is unspecified.
  *
- * @item mapi_int64 mapi_rows_affected(MapiHdl hdl)
+ * @item int64_t mapi_rows_affected(MapiHdl hdl)
  *
  * Return the number of rows affected by a database update command
  * such as SQL's INSERT/DELETE/UPDATE statements.
@@ -509,13 +509,13 @@
  * returned upon encountering end of sequence or error. This can be
  * analyzed in using @code{mapi_error()}.
  *
- * @item mapi_int64 mapi_fetch_all_rows(MapiHdl hdl)
+ * @item int64_t mapi_fetch_all_rows(MapiHdl hdl)
  *
  * All rows are cached at the client side first. Subsequent calls to
  * @code{mapi_fetch_row()} will take the row from the cache. The number or
  * rows cached is returned.
  *
- * @item MapiMsg mapi_seek_row(MapiHdl hdl, mapi_int64 rownr, int whence)
+ * @item MapiMsg mapi_seek_row(MapiHdl hdl, int64_t rownr, int whence)
  *
  * Reset the row pointer to the requested row number.  If whence is
  * @code{MAPI_SEEK_SET}, rownr is the absolute row number (0 being the
@@ -716,6 +716,7 @@
 #include "monetdb_config.h"
 #include <stream.h>            /* include before mapi.h */
 #include <stream_socket.h>
+#include <inttypes.h>          /* for PRId64, PRIu64, SCNd64 format macros */
 #include "mapi.h"
 #include "mcrypt.h"
 
@@ -819,13 +820,13 @@ struct MapiRowBuf {
        int limit;              /* current storage space limit */
        int writer;
        int reader;
-       mapi_int64 first;       /* row # of first tuple */
-       mapi_int64 tuplecount;  /* number of tuples in the cache */
+       int64_t first;          /* row # of first tuple */
+       int64_t tuplecount;     /* number of tuples in the cache */
        struct {
                int fldcnt;     /* actual number of fields in each row */
                char *rows;     /* string representation of rows received */
                int tupleindex; /* index of tuple rows */
-               mapi_int64 tuplerev;    /* reverse map of tupleindex */
+               int64_t tuplerev;       /* reverse map of tupleindex */
                char **anchors; /* corresponding field pointers */
                size_t *lens;   /* corresponding field lenghts */
        } *line;
@@ -884,9 +885,9 @@ struct MapiResultSet {
        struct MapiStatement *hdl;
        int tableid;            /* SQL id of current result set */
        int querytype;          /* type of SQL query */
-       mapi_int64 tuple_count;
-       mapi_int64 row_count;
-       mapi_int64 last_id;
+       int64_t tuple_count;
+       int64_t row_count;
+       int64_t last_id;
        int fieldcnt;
        int maxfields;
        char *errorstr;         /* error from server */
@@ -1342,20 +1343,20 @@ mapi_get_autocommit(Mapi mid)
        return mid->auto_commit;
 }
 
-static mapi_int64
+static int64_t
 usec(void)
 {
 #ifdef HAVE_GETTIMEOFDAY
        struct timeval tp;
 
        gettimeofday(&tp, NULL);
-       return ((mapi_int64) tp.tv_sec) * 1000000 + (mapi_int64) tp.tv_usec;
+       return ((int64_t) tp.tv_sec) * 1000000 + (int64_t) tp.tv_usec;
 #else
 #ifdef HAVE_FTIME
        struct timeb tb;
 
        ftime(&tb);
-       return ((mapi_int64) tb.time) * 1000000 + ((mapi_int64) tb.millitm) * 
1000;
+       return ((int64_t) tb.time) * 1000000 + ((int64_t) tb.millitm) * 1000;
 #endif
 #endif
 }
@@ -1364,15 +1365,15 @@ usec(void)
 static void
 mapi_log_header(Mapi mid, char *mark)
 {
-       static mapi_int64 firstcall = 0;
-       mapi_int64 now;
+       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, ":"LLFMT"[%d]:%s\n", now, mid->index, mark);
+       mnstr_printf(mid->tracelog, ":%"PRId64"[%d]:%s\n", now, mid->index, 
mark);
        mnstr_flush(mid->tracelog);
 }
 
@@ -3328,11 +3329,11 @@ mapi_param_store(MapiHdl hdl)
                                break;
                        case MAPI_LONGLONG:
                                checkSpace(30);
-                               sprintf(hdl->query + k, LLFMT, *(mapi_int64 *) 
src);
+                               sprintf(hdl->query + k, "%"PRId64, *(int64_t *) 
src);
                                break;
                        case MAPI_ULONGLONG:
                                checkSpace(30);
-                               sprintf(hdl->query + k, ULLFMT, *(mapi_uint64 
*) src);
+                               sprintf(hdl->query + k, "%"PRIu64, *(uint64_t 
*) src);
                                break;
                        case MAPI_FLOAT:
                                checkSpace(30);
@@ -3603,7 +3604,7 @@ static MapiMsg
 mapi_cache_freeup_internal(struct MapiResultSet *result, int k)
 {
        int i;                  /* just a counter */
-       mapi_int64 n = 0;       /* # of tuples being deleted from front */
+       int64_t n = 0;  /* # of tuples being deleted from front */
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to