Hello,

Am 02.07.2015 um 00:38 schrieb Albert Astals Cid:
>> Of course, it might not be reason enough to include the patch. Do you
>> consider taking just the memory layout fix so that the misleading
>> comment about the final object size is resolved?
> 
> The simpler the better, and from there we can build up :)

As discussed, attached is only the first part of the complete patch
which adjusts GooString internal static buffer size computation so that
the final object size will be 32 on both LP32 and LP64 architectures.

Best regards, Adam.
From 7b61f47ddfbb77c08382da924a9fd804b351e7a4 Mon Sep 17 00:00:00 2001
From: Adam Reichold <[email protected]>
Date: Mon, 29 Jun 2015 10:57:20 +0200
Subject: [PATCH] Adjust memory layout computation of GooString

GooString uses the small string optimization but the static buffer size is
hard-coded and hence the final object size becomes dependent on architecture.
This adds a helper class to compute the memory layout at compile time so that
the target object size of e.g. 32 or another multiple of 16 is achieved.

This also adds an overload so that the C string returned by GooString's
getCString method respect the constness of this and fixes a constness issue
in the lexer tests.
---
 goo/GooString.h           | 16 +++++++++++-----
 qt4/tests/check_lexer.cpp |  2 +-
 qt5/tests/check_lexer.cpp |  2 +-
 3 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/goo/GooString.h b/goo/GooString.h
index c6fb100..b9e45f3 100644
--- a/goo/GooString.h
+++ b/goo/GooString.h
@@ -114,13 +114,14 @@ public:
   ~GooString();
 
   // Get length.
-  int getLength() { return length; }
+  int getLength() const { return length; }
 
   // Get C string.
-  char *getCString() const { return s; }
+  char *getCString() { return s; }
+  const char *getCString() const { return s; }
 
   // Get <i>th character.
-  char getChar(int i) { return s[i]; }
+  char getChar(int i) const { return s[i]; }
 
   // Change <i>th character.
   void setChar(int i, char c) { s[i] = c; }
@@ -173,8 +174,13 @@ private:
   // you can tweak this number for a different speed/memory usage tradeoffs.
   // In libc malloc() rounding is 16 so it's best to choose a value that
   // results in sizeof(GooString) be a multiple of 16.
-  // 24 makes sizeof(GooString) to be 32.
-  static const int STR_STATIC_SIZE = 24;
+  class MemoryLayout {
+      char c[sizeof(char*)];
+      int i;
+      char* s;
+  };
+
+  static const int STR_STATIC_SIZE = 32 - sizeof(MemoryLayout) + sizeof(char*);
 
   int  roundedSize(int len);
 
diff --git a/qt4/tests/check_lexer.cpp b/qt4/tests/check_lexer.cpp
index ea834c8..243a592 100644
--- a/qt4/tests/check_lexer.cpp
+++ b/qt4/tests/check_lexer.cpp
@@ -12,7 +12,7 @@ private slots:
 
 void TestLexer::testNumbers()
 {
-    char *data = "0 1 -1 2147483647 -2147483647 2147483648 -2147483648 4294967297 -2147483649 0.1 1.1 -1.1 2147483647.1 -2147483647.1 2147483648.1 -2147483648.1 4294967297.1 -2147483649.1 9223372036854775807 18446744073709551615";
+    char data[] = "0 1 -1 2147483647 -2147483647 2147483648 -2147483648 4294967297 -2147483649 0.1 1.1 -1.1 2147483647.1 -2147483647.1 2147483648.1 -2147483648.1 4294967297.1 -2147483649.1 9223372036854775807 18446744073709551615";
     Object dummy;
     MemStream *stream = new MemStream(data, 0, strlen(data), &dummy);
     Lexer *lexer = new Lexer(NULL, stream);
diff --git a/qt5/tests/check_lexer.cpp b/qt5/tests/check_lexer.cpp
index ea834c8..243a592 100644
--- a/qt5/tests/check_lexer.cpp
+++ b/qt5/tests/check_lexer.cpp
@@ -12,7 +12,7 @@ private slots:
 
 void TestLexer::testNumbers()
 {
-    char *data = "0 1 -1 2147483647 -2147483647 2147483648 -2147483648 4294967297 -2147483649 0.1 1.1 -1.1 2147483647.1 -2147483647.1 2147483648.1 -2147483648.1 4294967297.1 -2147483649.1 9223372036854775807 18446744073709551615";
+    char data[] = "0 1 -1 2147483647 -2147483647 2147483648 -2147483648 4294967297 -2147483649 0.1 1.1 -1.1 2147483647.1 -2147483647.1 2147483648.1 -2147483648.1 4294967297.1 -2147483649.1 9223372036854775807 18446744073709551615";
     Object dummy;
     MemStream *stream = new MemStream(data, 0, strlen(data), &dummy);
     Lexer *lexer = new Lexer(NULL, stream);
-- 
2.4.5

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler

Reply via email to