Commits

Anonymous committed 6f122ac

#190 mainlined directly

  • Participants
  • Parent commits efa088f

Comments (0)

Files changed (3)

src/tests/system/t190.c

+/*
+ * PyMite - A flyweight Python interpreter for 8-bit and larger microcontrollers.
+ * Copyright 2002 Dean Hall.  All rights reserved.
+ * PyMite is offered through one of two licenses: commercial or open-source.
+ * See the LICENSE file at the root of this package for licensing details.
+ */
+
+/**
+ * System Test 190
+ * Fix segfault when num args is fewer than expected
+ */
+
+#include "pm.h"
+
+
+extern unsigned char usrlib_img[];
+
+
+int main(void)
+{
+    PmReturn_t retval;
+
+    retval = pm_init(MEMSPACE_PROG, usrlib_img);
+    PM_RETURN_IF_ERROR(retval);
+
+    retval = pm_run((uint8_t *)"t190");
+    return (int)retval;
+}

src/tests/system/t190.py

+#
+# PyMite - A flyweight Python interpreter for 8-bit and larger microcontrollers.
+# Copyright 2002 Dean Hall.  All rights reserved.
+# PyMite is offered through one of two licenses: commercial or open-source.
+# See the LICENSE file at the root of this package for licensing details.
+#
+
+#
+# System Test 190
+# Fix segfault when num args is fewer than expected
+#
+
+def foo():
+    return "foo"
+
+def foo1(a=42):
+    return a+1
+
+def foo2(a,b=42):
+    return a+b
+
+
+print foo()
+
+print foo1()
+print foo1(1)
+
+print foo2(1)
+print foo2(1,2)
+
+
+# NOTE: uncomment each of the following lines one at a time and test
+
+#print foo(1) # Expect TypeError (0xED)
+#print foo1(1,2) # Expect TypeError (0xED)
+#print foo2() # Expect TypeError (0xED)
+#print foo2(1,2,3) # Expect TypeError (0xED)
+
+# If the following line causes a segfault, it's a regression.
+#map(map, range(5)) # Expect TypeError (0xED)
                      */
 
 #ifdef HAVE_DEFAULTARGS
-                    /* If this func has no default arguments */
-                    if (((pPmFunc_t)pobj1)->f_defaultargs == C_NULL)
+                    /* Num required args := argcount - num default args */
+                    t8 = ((pPmFunc_t)pobj1)->f_co->co_argcount;
+                    if (((pPmFunc_t)pobj1)->f_defaultargs != C_NULL)
                     {
-                        t8 = 0;
-                    }
-
-                    /* Num required args := argcount - num default args */
-                    else
-                    {
-                        t8 = ((pPmFunc_t)pobj1)->f_co->co_argcount
-                            -
-                            ((pPmTuple_t)((pPmFunc_t)pobj1)->f_defaultargs)->
+                        t8 -= ((pPmTuple_t)((pPmFunc_t)pobj1)->f_defaultargs)->
                             length;
                     }