Changeset: 04b1d0718653 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=04b1d0718653
Added Files:
        sql/backends/monet5/Tests/pyapi20.sql
        sql/backends/monet5/Tests/pyapi20.stable.err
        sql/backends/monet5/Tests/pyapi20.stable.out
Modified Files:
        monetdb5/extras/pyapi/pyapi.c
Branch: pyapi
Log Message:

Display line number for all Python exceptions.


diffs (190 lines):

diff --git a/monetdb5/extras/pyapi/pyapi.c b/monetdb5/extras/pyapi/pyapi.c
--- a/monetdb5/extras/pyapi/pyapi.c
+++ b/monetdb5/extras/pyapi/pyapi.c
@@ -719,7 +719,7 @@ str PyAPIeval(Client cntxt, MalBlkPtr mb
                 ret->multidimensional = FALSE;
                 if (has_mask)
                 {
-                    lng mask_size = ret->count * sizeof(bool);
+                    size_t mask_size = ret->count * sizeof(bool);
 
                     assert(mask_size > 0);
                     MT_lock_set(&pyapiLock, "pyapi.evaluate");
@@ -1384,34 +1384,17 @@ static char *PyError_CreateException(cha
         py_error_string = PyString_AS_STRING(error);
         Py_XDECREF(error);
         if (pycall != NULL && strlen(pycall) > 0) {
-            // If pycall is given, we try to parse the line number from the 
error string and format pycall so it only displays the lines around the line 
number
-            // (This code is pretty ugly, sorry)
-            char line[] = "line ";
-            char linenr[32]; //we only support functions with at most 10^32 
lines, mostly out of philosophical reasons
-            size_t i = 0, j = 0, pos = 0, nrpos = 0;
+            if (py_error_traceback == NULL) {
+                //no traceback info, display normal error
+                goto finally;
+            } 
 
-            // First parse the line number from py_error_string
-            for(i = 0; i < strlen(py_error_string); i++) {
-                if (pos < strlen(line)) {
-                    if (py_error_string[i] == line[pos]) {
-                        pos++;
-                    }
-                } else {
-                    if (py_error_string[i] == '0' || py_error_string[i] == '1' 
|| py_error_string[i] == '2' ||
-                        py_error_string[i] == '3' || py_error_string[i] == '4' 
|| py_error_string[i] == '5' ||
-                        py_error_string[i] == '6' || py_error_string[i] == '7' 
|| py_error_string[i] == '8' || py_error_string[i] == '9') {
-                        linenr[nrpos++] = py_error_string[i];
-                    }
-                }
-            }
-            linenr[nrpos] = '\0';
-            if (!str_to_lng(linenr, nrpos, &line_number)) {
-                // No line number in the error, so just display a normal error
-                goto finally;
-            }
+            line_number = ((PyTracebackObject*)py_error_traceback)->tb_lineno;
 
             // Now only display the line numbers around the error message, we 
display 5 lines around the error message
             {
+                char linenr[32];
+                size_t nrpos, pos, i, j;
                 char lineinformation[5000]; //we only support 5000 characters 
for 5 lines of the program, should be enough
                 nrpos = 0; // Current line number
                 pos = 0; //Current position in the lineinformation result array
diff --git a/sql/backends/monet5/Tests/pyapi20.sql 
b/sql/backends/monet5/Tests/pyapi20.sql
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/Tests/pyapi20.sql
@@ -0,0 +1,21 @@
+
+START TRANSACTION;
+
+CREATE TABLE rval(i integer);
+INSERT INTO rval VALUES (1), (2), (3), (4), (5);
+
+CREATE FUNCTION pyapi20(i integer) returns integer
+language P
+{
+    a = 3
+    b = 0
+    c = a / b
+    return i
+};
+
+SELECT pyapi20(i) FROM rval;
+DROP FUNCTION pyapi20;
+DROP TABLE rval;
+
+ROLLBACK;
+
diff --git a/sql/backends/monet5/Tests/pyapi20.stable.err 
b/sql/backends/monet5/Tests/pyapi20.stable.err
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/Tests/pyapi20.stable.err
@@ -0,0 +1,53 @@
+stderr of test 'pyapi20` in directory 'sql/backends/monet5` itself:
+
+
+# 20:46:11 >  
+# 20:46:11 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=30765" "--set" 
"mapi_usock=/var/tmp/mtest-1892/.s.monetdb.30765" "--set" "monet_prompt=" 
"--forcemito" "--set" "mal_listing=2" 
"--dbpath=/home/mytherin/opt/var/MonetDB/mTests_sql_backends_monet5" "--set" 
"mal_listing=0" "--set" "embedded_r=true" "--set" "embedded_py=true"
+# 20:46:11 >  
+
+# builtin opt  gdk_dbpath = /home/mytherin/opt/var/monetdb5/dbfarm/demo
+# builtin opt  gdk_debug = 0
+# builtin opt  gdk_vmtrim = no
+# builtin opt  monet_prompt = >
+# builtin opt  monet_daemon = no
+# builtin opt  mapi_port = 50000
+# builtin opt  mapi_open = false
+# builtin opt  mapi_autosense = false
+# builtin opt  sql_optimizer = default_pipe
+# builtin opt  sql_debug = 0
+# cmdline opt  gdk_nr_threads = 0
+# cmdline opt  mapi_open = true
+# cmdline opt  mapi_port = 30765
+# cmdline opt  mapi_usock = /var/tmp/mtest-1892/.s.monetdb.30765
+# cmdline opt  monet_prompt = 
+# cmdline opt  mal_listing = 2
+# cmdline opt  gdk_dbpath = 
/home/mytherin/opt/var/MonetDB/mTests_sql_backends_monet5
+# cmdline opt  mal_listing = 0
+# cmdline opt  embedded_r = true
+# cmdline opt  embedded_py = true
+# cmdline opt  gdk_debug = 536870922
+
+# 20:46:11 >  
+# 20:46:11 >  "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-1892" "--port=30765"
+# 20:46:11 >  
+
+MAPI  = (monetdb) /var/tmp/mtest-1892/.s.monetdb.30765
+QUERY = SELECT pyapi20(i) FROM rval;
+ERROR = !Python exception
+        !  2.   a = 3
+        !  3.   b = 0
+        !> 4.   c = a / b
+        !  5.   return i
+        !  6. 
+        !integer division or modulo by zero
+MAPI  = (monetdb) /var/tmp/mtest-1892/.s.monetdb.30765
+QUERY = DROP FUNCTION pyapi20;
+ERROR = !current transaction is aborted (please ROLLBACK)
+MAPI  = (monetdb) /var/tmp/mtest-1892/.s.monetdb.30765
+QUERY = DROP TABLE rval;
+ERROR = !current transaction is aborted (please ROLLBACK)
+
+# 20:46:11 >  
+# 20:46:11 >  "Done."
+# 20:46:11 >  
+
diff --git a/sql/backends/monet5/Tests/pyapi20.stable.out 
b/sql/backends/monet5/Tests/pyapi20.stable.out
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/Tests/pyapi20.stable.out
@@ -0,0 +1,47 @@
+stdout of test 'pyapi20` in directory 'sql/backends/monet5` itself:
+
+
+# 20:46:11 >  
+# 20:46:11 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_open=true" "--set" "mapi_port=30765" "--set" 
"mapi_usock=/var/tmp/mtest-1892/.s.monetdb.30765" "--set" "monet_prompt=" 
"--forcemito" "--set" "mal_listing=2" 
"--dbpath=/home/mytherin/opt/var/MonetDB/mTests_sql_backends_monet5" "--set" 
"mal_listing=0" "--set" "embedded_r=true" "--set" "embedded_py=true"
+# 20:46:11 >  
+
+# MonetDB 5 server v11.22.0
+# This is an unreleased version
+# Serving database 'mTests_sql_backends_monet5', using 8 threads
+# Compiled for x86_64-unknown-linux-gnu/64bit with 64bit OIDs and 128bit 
integers dynamically linked
+# Found 7.684 GiB available main-memory.
+# Copyright (c) 1993-July 2008 CWI.
+# Copyright (c) August 2008-2015 MonetDB B.V., all rights reserved
+# Visit http://www.monetdb.org/ for further information
+# Listening for connection requests on mapi:monetdb://mytherin-N750JV:30765/
+# Listening for UNIX domain connection requests on 
mapi:monetdb:///var/tmp/mtest-1892/.s.monetdb.30765
+# Start processing logs sql/sql_logs version 52200
+# Finished processing logs sql/sql_logs
+# MonetDB/SQL module loaded
+# MonetDB/Python module loaded
+# MonetDB/R   module loaded
+
+Ready.
+
+# 20:46:11 >  
+# 20:46:11 >  "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-1892" "--port=30765"
+# 20:46:11 >  
+
+#START TRANSACTION;
+#CREATE TABLE rval(i integer);
+#INSERT INTO rval VALUES (1), (2), (3), (4), (5);
+[ 5    ]
+#CREATE FUNCTION pyapi20(i integer) returns integer
+#language P
+#{
+#    a = 3
+#    b = 0
+#    c = a / b
+#    return i
+#};
+#ROLLBACK;
+
+# 20:46:11 >  
+# 20:46:11 >  "Done."
+# 20:46:11 >  
+
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to