Commits

Anonymous committed 1697563

#95: mainlining directly

  • Participants
  • Parent commits 7f1e911

Comments (0)

Files changed (3)

File src/lib/sys.py

     PM_RETURN_IF_ERROR(retval);
 
     /* Allocate an int to hold the amount of heap available */
-    retval = int_new(0, &pavail);
+    retval = heap_getAvail(&avail);
+    retval = int_new(avail - sizeof(PmInt_t), &pavail);
     PM_RETURN_IF_ERROR(retval);
 
-    /* Now that all objs are allocated, get the available heap */
-    retval = heap_getAvail(&avail);
-    PM_RETURN_IF_ERROR(retval);
-    ((pPmInt_t)pavail)->val = avail;
-
     /* Put the two heap values in the tuple */
     ((pPmTuple_t)ptup)->val[0] = pavail;
     ((pPmTuple_t)ptup)->val[1] = pmax;

File src/tests/system/t095.c

+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+/**
+ * System Test 095
+ *
+ * Regression test for issue #95:
+ * Fix sys.heap() so it doesn't overwrite the static const 0 integer obj
+ *
+ * Log
+ * ---
+ *
+ * 2007/02/06   #95: First
+ */
+
+#include "pm.h"
+#include "stdio.h"
+
+
+extern unsigned char usrlib_img[];
+
+
+int main(void)
+{
+    PmReturn_t retval;
+
+    retval = pm_init(MEMSPACE_FLASH, usrlib_img);
+    PM_RETURN_IF_ERROR(retval);
+
+    retval = pm_run((uint8_t *)"t095");
+    pm_reportResult(retval);
+    return (int)retval;
+}

File src/tests/system/t095.py

+# PyMite - A flyweight Python interpreter for 8-bit microcontrollers and more.
+# Copyright 2002 Dean Hall
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+#
+
+#
+# System Test 095
+#
+# Regression test for issue #95:
+# Fix sys.heap() so it doesn't overwrite the static const 0 integer obj
+#
+
+import sys
+
+h = sys.heap()
+
+assert h[0] != (1-1)