Hi,

It looks like the core.Stream class does not close the underlying streams. It 
does save reference to a svn_stream_t wrapper in self._stream, but does not 
call svn_stream_close() on its own deletion, nor does the auto-generated 
svn_stream_t class do so.

Obviously, it can be closed by calling core.svn_stream_close(s._stream) - but 
this accesses private fields not intended to be used as external interfaces.

Am I right that it leaks open streams? If I am - perhaps, fix as attached - to 
implement the file-object-like behavior for core.Stream?

Regards,
Alexey.
Index: subversion/bindings/swig/python/svn/core.py
===================================================================
--- subversion/bindings/swig/python/svn/core.py	(revision 1617858)
+++ subversion/bindings/swig/python/svn/core.py	(working copy)
@@ -169,6 +169,8 @@
     self._stream = stream
 
   def read(self, amt=None):
+    if self._stream is None:
+      raise ValueError
     if amt is None:
       # read the rest of the stream
       chunks = [ ]
@@ -183,9 +185,15 @@
     return svn_stream_read(self._stream, int(amt))
 
   def write(self, buf):
+    if self._stream is None:
+      raise ValueError
     ### what to do with the amount written? (the result value)
     svn_stream_write(self._stream, buf)
 
+  def close(self):
+    svn_stream_close(self._stream)
+    self._stream = None
+
 def secs_from_timestr(svn_datetime, pool=None):
   """Convert a Subversion datetime string into seconds since the Epoch."""
   aprtime = svn_time_from_cstring(svn_datetime, pool)

Reply via email to