Author: olehougaard
Date: Mon Jan 26 02:21:09 2009
New Revision: 1145

Modified:
    branches/bleeding_edge/src/mksnapshot.cc
    branches/bleeding_edge/src/serialize.cc
    branches/bleeding_edge/src/serialize.h
    branches/bleeding_edge/src/snapshot-common.cc
    branches/bleeding_edge/src/snapshot-empty.cc
    branches/bleeding_edge/src/snapshot.h
    branches/bleeding_edge/src/utils.cc
    branches/bleeding_edge/src/utils.h

Log:
Change type of snapshot from char array to byte array to avoid portability  
problems between different compilers.
Review URL: http://codereview.chromium.org/18583

Modified: branches/bleeding_edge/src/mksnapshot.cc
==============================================================================
--- branches/bleeding_edge/src/mksnapshot.cc    (original)
+++ branches/bleeding_edge/src/mksnapshot.cc    Mon Jan 26 02:21:09 2009
@@ -114,7 +114,7 @@
  // Write C++ code that defines Snapshot::snapshot_ to contain the snapshot
  // to the file given by filename. Only the first size chars are written.
  static int WriteInternalSnapshotToFile(const char* filename,
-                                       const char* str,
+                                       const v8::internal::byte* bytes,
                                         int size) {
    FILE* f = i::OS::FOpen(filename, "wb");
    if (f == NULL) {
@@ -126,11 +126,11 @@
    fprintf(f, "#include \"platform.h\"\n\n");
    fprintf(f, "#include \"snapshot.h\"\n\n");
    fprintf(f, "namespace v8 {\nnamespace internal {\n\n");
-  fprintf(f, "const char Snapshot::data_[] = {");
+  fprintf(f, "const byte Snapshot::data_[] = {");
    int written = 0;
-  written += fprintf(f, "%i", str[0]);
+  written += fprintf(f, "0x%x", bytes[0]);
    for (int i = 1; i < size; ++i) {
-    written += fprintf(f, ",%i", str[i]);
+    written += fprintf(f, ",0x%x", bytes[i]);
      // The following is needed to keep the line length low on Visual C++:
      if (i % 512 == 0) fprintf(f, "\n");
    }
@@ -174,13 +174,13 @@
    i::Heap::CollectAllGarbage();
    i::Serializer ser;
    ser.Serialize();
-  char* str;
+  v8::internal::byte* bytes;
    int len;
-  ser.Finalize(&str, &len);
+  ser.Finalize(&bytes, &len);

-  WriteInternalSnapshotToFile(argv[1], str, len);
+  WriteInternalSnapshotToFile(argv[1], bytes, len);

-  i::DeleteArray(str);
+  i::DeleteArray(bytes);

    return 0;
  }

Modified: branches/bleeding_edge/src/serialize.cc
==============================================================================
--- branches/bleeding_edge/src/serialize.cc     (original)
+++ branches/bleeding_edge/src/serialize.cc     Mon Jan 26 02:21:09 2009
@@ -686,15 +686,15 @@
    SnapshotWriter() {
      len_ = 0;
      max_ = 8 << 10;  // 8K initial size
-    str_ = NewArray<char>(max_);
+    str_ = NewArray<byte>(max_);
    }

    ~SnapshotWriter() {
      DeleteArray(str_);
    }

-  void GetString(char** str, int* len) {
-    *str = NewArray<char>(len_);
+  void GetBytes(byte** str, int* len) {
+    *str = NewArray<byte>(len_);
      memcpy(*str, str_, len_);
      *len = len_;
    }
@@ -742,7 +742,7 @@
    Address position() { return reinterpret_cast<Address>(&str_[len_]); }

   private:
-  char* str_;  // the snapshot
+  byte* str_;  // the snapshot
    int len_;   // the current length of str_
    int max_;   // the allocated size of str_
  };
@@ -752,14 +752,14 @@
    CHECK(0 <= pos && pos <= len_);
    while (len_ + bytes >= max_) {
      max_ *= 2;
-    char* old = str_;
-    str_ = NewArray<char>(max_);
+    byte* old = str_;
+    str_ = NewArray<byte>(max_);
      memcpy(str_, old, len_);
      DeleteArray(old);
    }
    if (pos < len_) {
-    char* old = str_;
-    str_ = NewArray<char>(max_);
+    byte* old = str_;
+    str_ = NewArray<byte>(max_);
      memcpy(str_, old, pos);
      memcpy(str_ + pos + bytes, old + pos, len_ - pos);
      DeleteArray(old);
@@ -929,8 +929,8 @@
  }


-void Serializer::Finalize(char** str, int* len) {
-  writer_->GetString(str, len);
+void Serializer::Finalize(byte** str, int* len) {
+  writer_->GetBytes(str, len);
  }


@@ -1180,7 +1180,7 @@
  static const int kInitArraySize = 32;


-Deserializer::Deserializer(const char* str, int len)
+Deserializer::Deserializer(const byte* str, int len)
    : reader_(str, len),
      map_pages_(kInitArraySize),
      old_pointer_pages_(kInitArraySize),

Modified: branches/bleeding_edge/src/serialize.h
==============================================================================
--- branches/bleeding_edge/src/serialize.h      (original)
+++ branches/bleeding_edge/src/serialize.h      Mon Jan 26 02:21:09 2009
@@ -135,7 +135,7 @@

    // Returns the serialized buffer. Ownership is transferred to the
    // caller. Only the destructor and getters may be called after this call.
-  void Finalize(char** str, int* len);
+  void Finalize(byte** str, int* len);

    int roots() { return roots_; }
    int objects() { return objects_; }
@@ -211,7 +211,7 @@

  class SnapshotReader {
   public:
-  SnapshotReader(const char* str, int len): str_(str), end_(str + len) {}
+  SnapshotReader(const byte* str, int len): str_(str), end_(str + len) {}

    void ExpectC(char expected) {
      int c = GetC();
@@ -247,8 +247,8 @@
    }

   private:
-  const char* str_;
-  const char* end_;
+  const byte* str_;
+  const byte* end_;
  };


@@ -257,7 +257,7 @@
  class Deserializer: public ObjectVisitor {
   public:
    // Create a deserializer. The snapshot is held in str and has size len.
-  Deserializer(const char* str, int len);
+  Deserializer(const byte* str, int len);

    virtual ~Deserializer();


Modified: branches/bleeding_edge/src/snapshot-common.cc
==============================================================================
--- branches/bleeding_edge/src/snapshot-common.cc       (original)
+++ branches/bleeding_edge/src/snapshot-common.cc       Mon Jan 26 02:21:09 2009
@@ -35,7 +35,7 @@

  namespace v8 { namespace internal {

-bool Snapshot::Deserialize(const char* content, int len) {
+bool Snapshot::Deserialize(const byte* content, int len) {
    Deserializer des(content, len);
    des.GetFlags();
    return V8::Initialize(&des);
@@ -45,7 +45,7 @@
  bool Snapshot::Initialize(const char* snapshot_file) {
    if (snapshot_file) {
      int len;
-    char* str = ReadChars(snapshot_file, &len);
+    byte* str = ReadBytes(snapshot_file, &len);
      if (!str) return false;
      bool result = Deserialize(str, len);
      DeleteArray(str);
@@ -60,11 +60,11 @@
  bool Snapshot::WriteToFile(const char* snapshot_file) {
    Serializer ser;
    ser.Serialize();
-  char* str;
+  byte* str;
    int len;
    ser.Finalize(&str, &len);

-  int written = WriteChars(snapshot_file, str, len);
+  int written = WriteBytes(snapshot_file, str, len);

    DeleteArray(str);
    return written == len;

Modified: branches/bleeding_edge/src/snapshot-empty.cc
==============================================================================
--- branches/bleeding_edge/src/snapshot-empty.cc        (original)
+++ branches/bleeding_edge/src/snapshot-empty.cc        Mon Jan 26 02:21:09 2009
@@ -33,7 +33,7 @@

  namespace v8 { namespace internal {

-const char Snapshot::data_[] = { 0 };
+const byte Snapshot::data_[] = { 0 };
  int Snapshot::size_ = 0;

  } }  // namespace v8::internal

Modified: branches/bleeding_edge/src/snapshot.h
==============================================================================
--- branches/bleeding_edge/src/snapshot.h       (original)
+++ branches/bleeding_edge/src/snapshot.h       Mon Jan 26 02:21:09 2009
@@ -45,10 +45,10 @@
    static bool WriteToFile(const char* snapshot_file);

   private:
-  static const char data_[];
+  static const byte data_[];
    static int size_;

-  static bool Deserialize(const char* content, int len);
+  static bool Deserialize(const byte* content, int len);

    DISALLOW_IMPLICIT_CONSTRUCTORS(Snapshot);
  };

Modified: branches/bleeding_edge/src/utils.cc
==============================================================================
--- branches/bleeding_edge/src/utils.cc (original)
+++ branches/bleeding_edge/src/utils.cc Mon Jan 26 02:21:09 2009
@@ -182,8 +182,9 @@
  }


-char* ReadChars(const char* filename, int* size, bool verbose) {
-  return ReadCharsFromFile(filename, size, 0, verbose);
+byte* ReadBytes(const char* filename, int* size, bool verbose) {
+  char* chars = ReadCharsFromFile(filename, size, 0, verbose);
+  return reinterpret_cast<byte*>(chars);
  }


@@ -230,6 +231,15 @@
    int written = WriteCharsToFile(str, size, f);
    fclose(f);
    return written;
+}
+
+
+int WriteBytes(const char* filename,
+               const byte* bytes,
+               int size,
+               bool verbose) {
+  const char* str = reinterpret_cast<const char*>(bytes);
+  return WriteChars(filename, str, size, verbose);
  }



Modified: branches/bleeding_edge/src/utils.h
==============================================================================
--- branches/bleeding_edge/src/utils.h  (original)
+++ branches/bleeding_edge/src/utils.h  Mon Jan 26 02:21:09 2009
@@ -224,16 +224,24 @@
  char* ReadLine(const char* prompt);


-// Read and return the raw chars in a file. the size of the buffer is  
returned
+// Read and return the raw bytes in a file. the size of the buffer is  
returned
  // in size.
-// The returned buffer is not 0-terminated. It must be freed by the caller.
-char* ReadChars(const char* filename, int* size, bool verbose = true);
+// The returned buffer must be freed by the caller.
+byte* ReadBytes(const char* filename, int* size, bool verbose = true);


  // Write size chars from str to the file given by filename.
  // The file is overwritten. Returns the number of chars written.
  int WriteChars(const char* filename,
                 const char* str,
+               int size,
+               bool verbose = true);
+
+
+// Write size bytes to the file given by filename.
+// The file is overwritten. Returns the number of bytes written.
+int WriteBytes(const char* filename,
+               const byte* bytes,
                 int size,
                 bool verbose = true);


--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to