Fixed a number of build issues.

Fixed problem with missing I-cache flusing on ARM.

Changed space layout in memory management by splitting up code space into old data space and code space.

Added utf-8 conversion support to the API (issue 57).

Optimized repeated calls to eval with the same strings.  These repeated calls are common in web applications.

Added Xcode project file.

Optimized a couple of Array operation.

Fixed parser bug by checking for end-of-string when parsing break and continue (issue 35).

Fixed problem where asian characters were not categorized as letters.

Fixed bug that disallowed calling functions fetched from an array using a string as an array index (issue 32).

Fixed bug where the internal field count on object templates were sometimes ignored (issue 54).

Added -f option to the shell sample for compatibility with other engines (issue 18).

Added source info to TryCatches in the API.

Fixed problem where the seed for the random number generator was clipped in a double to unsigned int conversion.

Fixed bug where cons string symbols were sometimes converted to non-symbol flat strings during GC.

Fixed bug in error reporting when attempting to convert null to an object.


git-svn-id: http://v8.googlecode.com/svn/trunk@267 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
diff --git a/src/platform-linux.cc b/src/platform-linux.cc
index e19faad..ba72768 100644
--- a/src/platform-linux.cc
+++ b/src/platform-linux.cc
@@ -1,4 +1,4 @@
-// Copyright 2006-2008 Google Inc. All Rights Reserved.
+// Copyright 2006-2008 the V8 project authors. All rights reserved.
 // Redistribution and use in source and binary forms, with or without
 // modification, are permitted provided that the following conditions are
 // met:
@@ -67,7 +67,12 @@
 
 void OS::Setup() {
   // Seed the random number generator.
-  srandom(static_cast<unsigned int>(TimeCurrentMillis()));
+  // Convert the current time to a 64-bit integer first, before converting it
+  // to an unsigned. Going directly can cause an overflow and the seed to be
+  // set to all ones. The seed will be identical for different instances that
+  // call this setup code within the same millisecond.
+  uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis());
+  srandom(static_cast<unsigned int>(seed));
 }
 
 
@@ -256,7 +261,11 @@
     void* initial) {
   FILE* file = fopen(name, "w+");
   if (file == NULL) return NULL;
-  fwrite(initial, size, 1, file);
+  int result = fwrite(initial, size, 1, file);
+  if (result < 1) {
+    fclose(file);
+    return NULL;
+  }
   void* memory =
       mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
   return new PosixMemoryMappedFile(file, memory, size);
@@ -285,11 +294,14 @@
     addr_buffer[0] = '0';
     addr_buffer[1] = 'x';
     addr_buffer[10] = 0;
-    read(fd, addr_buffer + 2, 8);
+    int result = read(fd, addr_buffer + 2, 8);
+    if (result < 8) break;
     unsigned start = StringToLongLong(addr_buffer);
-    read(fd, addr_buffer + 2, 1);
-    if (addr_buffer[2] != '-') return;
-    read(fd, addr_buffer + 2, 8);
+    result = read(fd, addr_buffer + 2, 1);
+    if (result < 1) break;
+    if (addr_buffer[2] != '-') break;
+    result = read(fd, addr_buffer + 2, 8);
+    if (result < 8) break;
     unsigned end = StringToLongLong(addr_buffer);
     char buffer[MAP_LENGTH];
     int bytes_read = -1;
@@ -297,9 +309,8 @@
       bytes_read++;
       if (bytes_read >= MAP_LENGTH - 1)
         break;
-      int result = read(fd, buffer + bytes_read, 1);
-      // A read error means that -1 is returned.
-      if (result < 1) return;
+      result = read(fd, buffer + bytes_read, 1);
+      if (result < 1) break;
     } while (buffer[bytes_read] != '\n');
     buffer[bytes_read] = 0;
     // There are 56 chars to ignore at this point in the line.
@@ -309,6 +320,7 @@
     buffer[bytes_read] = 0;
     LOG(SharedLibraryEvent(buffer + 56, start, end));
   }
+  close(fd);
 #endif
 }
 
@@ -346,8 +358,8 @@
 static const int kMmapFdOffset = 0;
 
 
-VirtualMemory::VirtualMemory(size_t size, void* address_hint) {
-  address_ = mmap(address_hint, size, PROT_NONE,
+VirtualMemory::VirtualMemory(size_t size) {
+  address_ = mmap(NULL, size, PROT_NONE,
                   MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE,
                   kMmapFd, kMmapFdOffset);
   size_ = size;