Commits

Armin Rigo  committed 0388bb7

Prevent a race condition whereby thread B can still use an RFile
while thread A is blocked in the call to fclose() or pclose().

  • Participants
  • Parent commits 56fc72b

Comments (0)

Files changed (1)

File rpython/rlib/rfile.py

             rffi.free_nonmovingbuffer(value, ll_value)
 
     def close(self):
-        if self.ll_file:
+        ll_f = self.ll_file
+        if ll_f:
             # double close is allowed
-            res = self._do_close()
             self.ll_file = lltype.nullptr(FILE)
+            res = self._do_close(ll_f)
             if res == -1:
                 errno = rposix.get_errno()
                 raise OSError(errno, os.strerror(errno))
 
-    def _do_close(self):
-        return c_close(self.ll_file)
+    _do_close = staticmethod(c_close)    # overridden in RPopenFile
 
     def read(self, size=-1):
         # XXX CPython uses a more delicate logic here
 
 
 class RPopenFile(RFile):
-
-    def _do_close(self):
-        return c_pclose(self.ll_file)
+    _do_close = staticmethod(c_pclose)