<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -51,7 +51,7 @@ GCC_FILES = $(OBJC_FILES) $(C_FILES)
 GCC_OBJS = $(patsubst %.m, %.o, $(OBJC_FILES)) $(patsubst %.c, %.o, $(C_FILES))
 
 CC = gcc
-CFLAGS = -g -O2 -Wall -DMININUSH -std=gnu99
+CFLAGS = -g -Wall -DMININUSH -std=gnu99
 MFLAGS = -fobjc-exceptions
 
 ifeq ($(SYSTEM), Darwin)</diff>
      <filename>Makefile</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>810b90424858d2e2c293059f766fefb02912af26</id>
    </parent>
  </parents>
  <author>
    <name>Tim Burks</name>
    <email>tim@iron.(none)</email>
  </author>
  <url>http://github.com/timburks/nu/commit/948aee84d11ac9d4b8573de38823e1ed32afc02f</url>
  <id>948aee84d11ac9d4b8573de38823e1ed32afc02f</id>
  <committed-date>2008-12-27T14:06:25-08:00</committed-date>
  <authored-date>2008-12-27T14:06:25-08:00</authored-date>
  <message>Removed -O2 optimization from bootstrap Makefile to avoid odd compilation problem.

Building on Debian Etch, I began noticing crashes due to memory corruption.
Thanks to Valgrind, I traced the problem to this function. Invalid writes
were occurring when the method count was zero but methods were still being
copied. When I added print statements to the first while loop, the count
became correct (it should have been 8). Also dropping -O2 appears to fix
the problem.

Method *class_copyMethodList(Class cls, unsigned int *outCount)
Method_t *class_copyMethodList(Class cls, unsigned int *outCount)
{
    // first count the methods
    int count = 0;
    struct objc_method_list *mlist;
    void *iterator = 0;
    while (( mlist = class_nextMethodList( cls, &amp;iterator ) ))
        count += mlist-&gt;method_count;
    // then copy the methods into the list
    Method *list = (Method *) malloc (count * sizeof(Method));
    Method_t *list = (Method_t *) malloc (count * sizeof(Method));
    int index = 0;
    iterator = 0;
    while (( mlist = class_nextMethodList( cls, &amp;iterator ) )) {
        int i;
        for (i = 0; i &lt; mlist-&gt;method_count; i++) {
            list[index++] = &amp;(mlist-&gt;method_list[i]);
        }
    }
    *outCount = count;
    return list;
}

This looks like a compiler optimization problem to me and rather than debug
gcc on Debian, I've removed -O2 optimization from the bootstrap Makefile.

It seemed odd to me that this problem wasn't occurring for the final Nu
build products, and on investigation I've discovered (realized) that we're
not building them with -O2 either. Oops. I'll fix that in another revision
(for Darwin only) after I've tested it on OS X.</message>
  <tree>1b4614df6fdcb4faf8de0da5032e72762a61d42b</tree>
  <committer>
    <name>Tim Burks</name>
    <email>tim@iron.(none)</email>
  </committer>
</commit>
