Changeset: 0c05a2843ccc for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=0c05a2843ccc
Modified Files:
        sql/server/sql_parser.h
        sql/server/sql_parser.y
Branch: default
Log Message:

more usage of allocators (and cleanup of error functions) in sql_parser


diffs (truncated from 692 to 300 lines):

diff --git a/sql/server/sql_parser.h b/sql/server/sql_parser.h
--- a/sql/server/sql_parser.h
+++ b/sql/server/sql_parser.h
@@ -19,10 +19,9 @@
 #define YYDEBUG 1
 */
 
-extern int find_subgeometry_type(char*);
+extern int find_subgeometry_type(mvc *m, char*);
 extern char *token2string(tokens token);
 extern int sqlparse(mvc *m);
-extern int sqlerror(mvc *sql, const char *s);
 
 #include "mal_errors.h"                /* for SQLSTATE() */
 
diff --git a/sql/server/sql_parser.y b/sql/server/sql_parser.y
--- a/sql/server/sql_parser.y
+++ b/sql/server/sql_parser.y
@@ -20,6 +20,13 @@
 #include "mal.h"               /* for have_hge */
 #endif
 
+static int sqlerror(mvc *sql, const char *err);
+static int sqlformaterror(mvc *sql, _In_z_ _Printf_format_string_ const char 
*format, ...)
+               __attribute__((__format__(__printf__, 2, 3)));
+
+static void *ma_alloc(sql_allocator *sa, size_t sz);
+static void ma_free(void *p);
+
 #include <unistd.h>
 #include <string.h>
 
@@ -43,8 +50,9 @@
 
 #define _atom_string(t, v)   atom_string(SA, t, v)
 
-#define YYMALLOC GDKmalloc
-#define YYFREE GDKfree
+#define Malloc(sz) ma_alloc(m->ta,sz)
+#define YYMALLOC Malloc
+#define YYFREE ma_free 
 
 #define YY_parse_LSP_NEEDED    /* needed for bison++ 1.21.11-3 */
 
@@ -93,6 +101,7 @@ UTF8_strlen(const char *val)
        return pos;
 }
 
+
 static char *
 uescape_xform(char *restrict s, const char *restrict esc)
 {
@@ -2153,9 +2162,7 @@ func_def:
                        else if (l == 'J' || l == 'j')
                                lang = FUNC_LANG_J;
                        else {
-                               char *msg = sql_message("Language name R, C, 
PYTHON[3], PYTHON[3]_MAP or J(avascript):expected, received '%c'", l);
-                               yyerror(m, msg);
-                               _DELETE(msg);
+                               sqlformaterror(m, "Language name R, C, 
PYTHON[3], PYTHON[3]_MAP or J(avascript):expected, received '%c'", l);
                        }
 
                        append_list(f, $3);
@@ -3666,7 +3673,7 @@ like_exp:
  |  scalar_exp ESCAPE string
        { const char *s = $3;
          if (_strlen(s) != 1) {
-               yyerror(m, SQLSTATE(22019) "ESCAPE must be one character");
+               sqlformaterror(m, SQLSTATE(22019) "%s", "ESCAPE must be one 
character");
                $$ = NULL;
                YYABORT;
          } else {
@@ -4504,7 +4511,7 @@ interval_type:
 
                $$.type = NULL;
                if ( (tpe = parse_interval_qualifier( m, $2, &sk, &ek, &sp, &ep 
)) < 0){
-                       yyerror(m, SQLSTATE(22006) "incorrect interval");
+                       sqlformaterror(m, SQLSTATE(22006) "%s", "incorrect 
interval");
                        YYABORT;
                } else {
                        int d = inttype2digits(sk, ek);
@@ -4599,10 +4606,7 @@ literal:
                  }
 
                  if (err != 0) {
-                       char *msg = sql_message(SQLSTATE(22003) "Invalid 
hexadecimal number or hexadecimal too large (%s)", $1);
-
-                       yyerror(m, msg);
-                       _DELETE(msg);
+                       sqlformaterror(m, SQLSTATE(22003) "Invalid hexadecimal 
number or hexadecimal too large (%s)", $1);
                        $$ = NULL;
                        YYABORT;
                  } else {
@@ -4630,10 +4634,7 @@ literal:
                  }
 
                  if (err) {
-                       char *msg = sql_message(SQLSTATE(22003) "OID value too 
large or not a number (%s)", $1);
-
-                       yyerror(m, msg);
-                       _DELETE(msg);
+                       sqlformaterror(m, SQLSTATE(22003) "OID value too large 
or not a number (%s)", $1);
                        $$ = NULL;
                        YYABORT;
                  } else {
@@ -4691,10 +4692,7 @@ literal:
                  }
 
                  if (err) {
-                       char *msg = sql_message(SQLSTATE(22003) "integer value 
too large or not a number (%s)", $1);
-
-                       yyerror(m, msg);
-                       _DELETE(msg);
+                       sqlformaterror(m, SQLSTATE(22003) "integer value too 
large or not a number (%s)", $1);
                        $$ = NULL;
                        YYABORT;
                  } else {
@@ -4729,10 +4727,7 @@ literal:
                        errno = 0;
                        val = strtod($1,&p);
                        if (p == $1 || is_dbl_nil(val) || (errno == ERANGE && 
(val < -1 || val > 1))) {
-                               char *msg = sql_message(SQLSTATE(22003) "Double 
value too large or not a number (%s)", $1);
-
-                               yyerror(m, msg);
-                               _DELETE(msg);
+                               sqlformaterror(m, SQLSTATE(22003) "Double value 
too large or not a number (%s)", $1);
                                $$ = NULL;
                                YYABORT;
                        }
@@ -4748,10 +4743,7 @@ literal:
                  errno = 0;
                  val = strtod($1,&p);
                  if (p == $1 || is_dbl_nil(val) || (errno == ERANGE && (val < 
-1 || val > 1))) {
-                       char *msg = sql_message(SQLSTATE(22003) "Double value 
too large or not a number (%s)", $1);
-
-                       yyerror(m, msg);
-                       _DELETE(msg);
+                       sqlformaterror(m, SQLSTATE(22003) "Double value too 
large or not a number (%s)", $1);
                        $$ = NULL;
                        YYABORT;
                  }
@@ -4764,10 +4756,7 @@ literal:
 
                  r = sql_find_subtype(&t, "date", 0, 0 );
                  if (!r || (a = atom_general(SA, &t, $2)) == NULL) {
-                       char *msg = sql_message(SQLSTATE(22007) "Incorrect date 
value (%s)", $2);
-
-                       yyerror(m, msg);
-                       _DELETE(msg);
+                       sqlformaterror(m, SQLSTATE(22007) "Incorrect date value 
(%s)", $2);
                        $$ = NULL;
                        YYABORT;
                  } else {
@@ -4780,10 +4769,7 @@ literal:
 
                  r = sql_find_subtype(&t, ($3)?"timetz":"time", $2, 0);
                  if (!r || (a = atom_general(SA, &t, $4)) == NULL) {
-                       char *msg = sql_message(SQLSTATE(22007) "Incorrect time 
value (%s)", $4);
-
-                       yyerror(m, msg);
-                       _DELETE(msg);
+                       sqlformaterror(m, SQLSTATE(22007) "Incorrect time value 
(%s)", $4);
                        $$ = NULL;
                        YYABORT;
                  } else {
@@ -4796,10 +4782,7 @@ literal:
 
                  r = sql_find_subtype(&t, ($3)?"timestamptz":"timestamp",$2,0);
                  if (!r || (a = atom_general(SA, &t, $4)) == NULL) {
-                       char *msg = sql_message(SQLSTATE(22007) "Incorrect 
timestamp value (%s)", $4);
-
-                       yyerror(m, msg);
-                       _DELETE(msg);
+                       sqlformaterror(m, SQLSTATE(22007) "Incorrect timestamp 
value (%s)", $4);
                        $$ = NULL;
                        YYABORT;
                  } else {
@@ -4816,10 +4799,7 @@ literal:
                  if (r && (a = atom_general(SA, &t, $2)) != NULL)
                        $$ = _newAtomNode(a);
                  if (!$$) {
-                       char *msg = sql_message(SQLSTATE(22M28) "incorrect blob 
%s", $2);
-
-                       yyerror(m, msg);
-                       _DELETE(msg);
+                       sqlformaterror(m, SQLSTATE(22M28) "incorrect blob %s", 
$2);
                        YYABORT;
                  }
                }
@@ -4833,10 +4813,7 @@ literal:
                  if (r && (a = atom_general(SA, &t, $1)) != NULL)
                        $$ = _newAtomNode(a);
                  if (!$$) {
-                       char *msg = sql_message(SQLSTATE(22M28) "incorrect blob 
%s", $1);
-
-                       yyerror(m, msg);
-                       _DELETE(msg);
+                       sqlformaterror(m, SQLSTATE(22M28) "incorrect blob %s", 
$1);
                        YYABORT;
                  }
                }
@@ -4850,10 +4827,7 @@ literal:
                  if (r && (a = atom_general(SA, &t, $2)) != NULL)
                        $$ = _newAtomNode(a);
                  if (!$$) {
-                       char *msg = sql_message(SQLSTATE(22000) "incorrect %s 
%s", $1, $2);
-
-                       yyerror(m, msg);
-                       _DELETE(msg);
+                       sqlformaterror(m, SQLSTATE(22000) "incorrect %s %s", 
$1, $2);
                        YYABORT;
                  }
                }
@@ -4867,10 +4841,7 @@ literal:
                  if (r && (a = atom_general(SA, &t, $2)) != NULL)
                        $$ = _newAtomNode(a);
                  if (!$$) {
-                       char *msg = sql_message(SQLSTATE(22000) "incorrect %s 
%s", $1, $2);
-
-                       yyerror(m, msg);
-                       _DELETE(msg);
+                       sqlformaterror(m, SQLSTATE(22000) "incorrect %s %s", 
$1, $2);
                        YYABORT;
                  }
                }
@@ -4888,10 +4859,7 @@ literal:
                                $$ = _newAtomNode(a);
                  }
                  if (!t || !$$) {
-                       char *msg = sql_message(SQLSTATE(22000) "type (%s) 
unknown", $1);
-
-                       yyerror(m, msg);
-                       _DELETE(msg);
+                       sqlformaterror(m, SQLSTATE(22000) "type (%s) unknown", 
$1);
                        YYABORT;
                  }
                }
@@ -4937,8 +4905,7 @@ interval_expression:
                        while (cpyval /= 10)
                                inlen++;
                        if (inlen > t.digits) {
-                               char *msg = sql_message(SQLSTATE(22006) 
"incorrect interval (" LLFMT " > %d)", inlen, t.digits);
-                               yyerror(m, msg);
+                               sqlformaterror(m, SQLSTATE(22006) "incorrect 
interval (" LLFMT " > %d)", inlen, t.digits);
                                $$ = NULL;
                                YYABORT;
                        }
@@ -5156,9 +5123,7 @@ data_type:
                        { 
                          int d = $3;
                          if (d > MAX_DEC_DIGITS) {
-                               char *msg = sql_message(SQLSTATE(22003) 
"Decimal of %d digits are not supported", d);
-                               yyerror(m, msg);
-                               _DELETE(msg);
+                               sqlformaterror(m, SQLSTATE(22003) "Decimal of 
%d digits are not supported", d);
                                $$.type = NULL;
                                YYABORT;
                          } else {
@@ -5170,13 +5135,10 @@ data_type:
                          int d = $3;
                          int s = $5;
                          if (s > d || d > MAX_DEC_DIGITS) {
-                               char *msg = NULL;
                                if (s > d)
-                                       msg = sql_message(SQLSTATE(22003) 
"Scale (%d) should be less or equal to the precision (%d)", s, d);
+                                       sqlformaterror(m, SQLSTATE(22003) 
"Scale (%d) should be less or equal to the precision (%d)", s, d);
                                else
-                                       msg = sql_message(SQLSTATE(22003) 
"Decimal(%d,%d) isn't supported because P=%d > %d", d, s, d, MAX_DEC_DIGITS);
-                               yyerror(m, msg);
-                               _DELETE(msg);
+                                       sqlformaterror(m, SQLSTATE(22003) 
"Decimal(%d,%d) isn't supported because P=%d > %d", d, s, d, MAX_DEC_DIGITS);
                                $$.type = NULL;
                                YYABORT;
                          } else {
@@ -5190,20 +5152,14 @@ data_type:
                          } else if ($3 > 24 && $3 <= 53) {
                                sql_find_subtype(&$$, "double", $3, 0);
                          } else {
-                               char *msg = sql_message(SQLSTATE(22003) "Number 
of digits for FLOAT values should be between 1 and 53");
-
-                               yyerror(m, msg);
-                               _DELETE(msg);
+                               sqlformaterror(m, SQLSTATE(22003) "Number of 
digits for FLOAT values should be between 1 and 53");
                                $$.type = NULL;
                                YYABORT;
                          }
                        }
  |  sqlFLOAT '(' intval ',' intval ')'
                        { if ($5 >= $3) {
-                               char *msg = sql_message(SQLSTATE(22003) 
"Precision(%d) should be less than number of digits(%d)", $5, $3);
-
-                               yyerror(m, msg);
-                               _DELETE(msg);
+                               sqlformaterror(m, SQLSTATE(22003) 
"Precision(%d) should be less than number of digits(%d)", $5, $3);
                                $$.type = NULL;
                                YYABORT;
                          } else if ($3 > 0 && $3 <= 24) {
@@ -5211,9 +5167,7 @@ data_type:
                          } else if ($3 > 24 && $3 <= 53) {
                                sql_find_subtype(&$$, "double", $3, $5);
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to