Commits

Brian Kearns committed 48ee80c

fix usage of bufferstr_w in _io

Comments (0)

Files changed (4)

pypy/interpreter/baseobjspace.py

 
     @specialize.arg(1)
     def getarg_w(self, code, w_obj):
-        if code == 'w*':
+        if code == 's*':
+            if self.isinstance_w(w_obj, self.w_str):
+                return w_obj.readbuf_w(self)
+            if self.isinstance_w(w_obj, self.w_unicode):
+                return self.str(w_obj).readbuf_w(self)
+            try:
+                return w_obj.buffer_w(self, 0)
+            except TypeError:
+                pass
+            try:
+                return w_obj.readbuf_w(self)
+            except TypeError:
+                self._getarg_error("string or buffer", w_obj)
+        elif code == 'w*':
             try:
                 try:
                     return w_obj.buffer_w(self, self.BUF_WRITABLE)

pypy/module/_io/interp_bufferedio.py

     def write_w(self, space, w_data):
         self._check_init(space)
         self._check_closed(space, "write to closed file")
-        data = space.bufferstr_w(w_data)
+        data = space.getarg_w('s*', w_data).as_str()
         size = len(data)
 
         with self.lock:

pypy/module/_io/interp_bytesio.py

 
     def write_w(self, space, w_data):
         self._check_closed(space)
-        if space.isinstance_w(w_data, space.w_unicode):
-            raise OperationError(space.w_TypeError, space.wrap(
-                "bytes string of buffer expected"))
-        buf = space.bufferstr_w(w_data)
+        buf = space.buffer_w(w_data, space.BUF_CONTIG_RO).as_str()
         length = len(buf)
         if length <= 0:
             return space.wrap(0)

pypy/module/_io/interp_fileio.py

     def write_w(self, space, w_data):
         self._check_closed(space)
         self._check_writable(space)
-        data = space.bufferstr_w(w_data)
+        data = space.getarg_w('s*', w_data).as_str()
 
         try:
             n = os.write(self.fd, data)