Author: Ned Batchelder <[email protected]>
Branch: nedbat-sandbox
Changeset: r50170:4fe097ff1a9b
Date: 2011-12-05 08:49 -0500
http://bitbucket.org/pypy/pypy/changeset/4fe097ff1a9b/

Log:    Remove some pypy dependencies from sandlib.

diff --git a/pypy/translator/sandbox/sandlib.py 
b/pypy/translator/sandbox/sandlib.py
--- a/pypy/translator/sandbox/sandlib.py
+++ b/pypy/translator/sandbox/sandlib.py
@@ -6,9 +6,7 @@
 
 import py
 import sys, os, posixpath, errno, stat, time
-from pypy.rpython.module.ll_os_stat import s_StatResult
 from pypy.tool.ansi_print import AnsiLog
-from pypy.rlib.rarithmetic import r_longlong
 import subprocess
 from pypy.tool.killsubprocess import killsubprocess
 
@@ -34,6 +32,9 @@
 from pypy.tool.lib_pypy import import_from_lib_pypy
 marshal = import_from_lib_pypy('marshal')
 
+# Non-marshal result types
+RESULTTYPE_STATRESULT, RESULTTYPE_LONGLONG = range(2)
+
 def read_message(f, timeout=None):
     # warning: 'timeout' is not really reliable and should only be used
     # for testing.  Also, it doesn't work if the file f does any buffering.
@@ -50,7 +51,7 @@
             marshal.dump(msg, g)
         else:
             marshal.dump(msg, g, 0)
-    elif resulttype is s_StatResult:
+    elif resulttype is RESULTTYPE_STATRESULT:
         # Hand-coded marshal for stat results that mimics what rmarshal 
expects.
         # marshal.dump(tuple(msg)) would have been too easy. rmarshal insists
         # on 64-bit ints at places, even when the value fits in 32 bits.
@@ -69,12 +70,11 @@
                 buf.append(struct.pack("<cB", c, len(fstr)))
                 buf.append(fstr)
         g.write(''.join(buf))
+    elif resulttype is RESULTTYPE_LONGLONG:
+        import struct
+        g.write(struct.pack("<cq", 'I', msg))
     else:
-        # use the exact result type for encoding
-        from pypy.rlib.rmarshal import get_marshaller
-        buf = []
-        get_marshaller(resulttype)(buf, msg)
-        g.write(''.join(buf))
+        raise Exception("Can't marshal: %r (%r)" % (msg, resulttype))
 
 # keep the table in sync with rsandbox.reraise_error()
 EXCEPTION_TABLE = [
@@ -444,7 +444,7 @@
     def do_ll_os__ll_os_stat(self, vpathname):
         node = self.get_node(vpathname)
         return node.stat()
-    do_ll_os__ll_os_stat.resulttype = s_StatResult
+    do_ll_os__ll_os_stat.resulttype = RESULTTYPE_STATRESULT
 
     do_ll_os__ll_os_lstat = do_ll_os__ll_os_stat
 
@@ -505,13 +505,13 @@
     def do_ll_os__ll_os_fstat(self, fd):
         f, node = self.get_fd(fd)
         return node.stat()
-    do_ll_os__ll_os_fstat.resulttype = s_StatResult
+    do_ll_os__ll_os_fstat.resulttype = RESULTTYPE_STATRESULT
 
     def do_ll_os__ll_os_lseek(self, fd, pos, how):
         f = self.get_file(fd)
         f.seek(pos, how)
         return f.tell()
-    do_ll_os__ll_os_lseek.resulttype = r_longlong
+    do_ll_os__ll_os_lseek.resulttype = RESULTTYPE_LONGLONG
 
     def do_ll_os__ll_os_getcwd(self):
         return self.virtual_cwd
diff --git a/pypy/translator/sandbox/test/test_sandbox.py 
b/pypy/translator/sandbox/test/test_sandbox.py
--- a/pypy/translator/sandbox/test/test_sandbox.py
+++ b/pypy/translator/sandbox/test/test_sandbox.py
@@ -80,7 +80,7 @@
     assert tail == ""
 
 def test_stat_ftruncate():
-    from pypy.rpython.module.ll_os_stat import s_StatResult
+    from pypy.translator.sandbox.sandlib import RESULTTYPE_STATRESULT
     from pypy.rlib.rarithmetic import r_longlong
     r0x12380000007 = r_longlong(0x12380000007)
 
@@ -93,7 +93,7 @@
     g, f = os.popen2(exe, "t", 0)
     st = os.stat_result((55, 0, 0, 0, 0, 0, 0x12380000007, 0, 0, 0))
     expect(f, g, "ll_os.ll_os_stat", ("somewhere",), st,
-           resulttype = s_StatResult)
+           resulttype = RESULTTYPE_STATRESULT)
     expect(f, g, "ll_os.ll_os_ftruncate", (55, 0x12380000007), None)
     g.close()
     tail = f.read()
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to