[pypy-svn] r58236 - in pypy/branch/new-platformcheck/pypy/rpython/tool: . test

nshepperd at codespeak.net nshepperd at codespeak.net
Fri Sep 19 11:19:42 CEST 2008


Author: nshepperd
Date: Fri Sep 19 11:19:40 2008
New Revision: 58236

Modified:
   pypy/branch/new-platformcheck/pypy/rpython/tool/rffi_platform.py
   pypy/branch/new-platformcheck/pypy/rpython/tool/test/test_rffi_platform.py
Log:
Fixed a potential bug with rffi_platform.ConstantString.


Modified: pypy/branch/new-platformcheck/pypy/rpython/tool/rffi_platform.py
==============================================================================
--- pypy/branch/new-platformcheck/pypy/rpython/tool/rffi_platform.py	(original)
+++ pypy/branch/new-platformcheck/pypy/rpython/tool/rffi_platform.py	Fri Sep 19 11:19:40 2008
@@ -224,14 +224,15 @@
 # ____________________________________________________________
 
 def c_safe_string(string):
-    return string.replace('\\', '\\\\').replace('"', '\\"')
+    for (one, two) in [('\\', '\\\\'), ('"', '\\"'),
+                        ('\0', '\\0')]:
+        string = string.replace(one, two)
+    return string
 
 class CConfigEntry(object):
     "Abstract base class."
     def dump(self, name, expr):
-        beginpad = "__START_PLATCHECK_%s\0%s\0" % (
-            c_safe_string(self.key),
-            c_safe_string(name))
+        beginpad = "__START_PLATCHECK_%s\0%s\0" % (self.key, name)
         return '''
         struct __attribute__((packed)) {
             char begin_pad[%(sizeof_beginpad)i];
@@ -242,7 +243,7 @@
             .contents = %(expr)s,
             .end_pad = "__END_PLATCHECK__"
         };
-        ''' % {'expr' : expr, 'beginpad' : beginpad.replace('\0', '\\0'),
+        ''' % {'expr' : expr, 'beginpad' : c_safe_string(beginpad),
                 'sizeof_beginpad' : len(beginpad),
                 'id' : filter(str.isalnum, self.key+'PLATCHECK'+name)}
     def dump_by_size(self, name, expr):
@@ -283,7 +284,7 @@
     exe.write(data)
     exe.close()
     
-    nm = Popen(NM + ' -f sysv ' + exepath, shell=True, stdout=PIPE, stderr=PIPE)
+    nm = Popen(NM + ' -f sysv ' + exepath, shell=True, stdout=PIPE)
     nm = list(nm.stdout.readlines())
     for line in nm:
         line = [part.strip() for part in line.split('|')]
@@ -521,7 +522,7 @@
         yield self.dump('value', self.name)
 
     def build_result(self, info, config_result):
-        return info['value']
+        return info['value'].partition('\0')[0]
 
 class DefinedConstantInteger(ConstantInteger):
     """An entry in a CConfig class that stands for an externally

Modified: pypy/branch/new-platformcheck/pypy/rpython/tool/test/test_rffi_platform.py
==============================================================================
--- pypy/branch/new-platformcheck/pypy/rpython/tool/test/test_rffi_platform.py	(original)
+++ pypy/branch/new-platformcheck/pypy/rpython/tool/test/test_rffi_platform.py	Fri Sep 19 11:19:40 2008
@@ -235,6 +235,17 @@
     print a
     assert a % struct.calcsize("P") == 0
 
+def test_constant_string():
+    class CConfig:
+        _compilation_info_ = ExternalCompilationInfo(
+            pre_include_bits=['#define STR "string"']
+        )
+        STR = rffi_platform.ConstantString('STR')
+        STR2 = rffi_platform.ConstantString('"inline string"')
+    data = rffi_platform.configure(CConfig)
+    assert data['STR'] == 'string'
+    assert data['STR2'] == 'inline string'
+
 def test_extern_string():
     from tempfile import mkdtemp
     dir = mkdtemp()



More information about the Pypy-commit mailing list