[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: svn commit: r931162 - in /subversion/trunk: ./ subversion/libsvn_diff/parse-diff.c subversion/tests/cmdline/patch_tests.py

From: Greg Stein <gstein_at_gmail.com>
Date: Mon, 12 Apr 2010 09:09:29 -0400

On Thu, Apr 8, 2010 at 04:32, Bert Huijben <bert_at_qqmail.nl> wrote:
>...
>> +def patch_no_index_line(sbox):
>> +  "patch with no index lines"
>> +
>> +  sbox.build()
>> +  wc_dir = sbox.wc_dir
>> +
>> +  patch_file_path =
>> tempfile.mkstemp(dir=os.path.abspath(svntest.main.temp_dir))[1]
>
> This line reintroduces the issue I fixed in the other tests in r930990.
>
> Stefan: Answering your question: It seems the handle must be closed before leaving the function. (I don't mind where, as long as it fixes the errors)
>
> Greg: You just fixed several other functions to use open(...).read(), without closing the handle. This doesn't cause the same error, so this file is somehow closed without the explicit close required above. Do you have any idea why mkstemp() does need the explicit close? (Python bug?)

I see you removed the mkstemp() today, but let me explain anyways...

Python uses explicit reference counting on its objects, and will
destroy them when no references exist. The file object will close its
handle at destruction time. Thus, in a statement like:

contents = open(file).read()

The file handle returned by open() exists during the evaluation of the
expression. First, it is held by the internals as the result of
open(). Then the "read" method is looked up on it, and a "bound
method" object is the result. That object holds a reference to the
file object. Then the bound method is called, returning the contents.
The bound method then has its reference count decremented, hitting
zero, so it gets destroyed. Which decref's the file object, which gets
destroyed, which closes the file handle.

In the mkstemp case, you're returned a file descriptor -- a simple
integer. Integers don't have file-closing behavior associated with
them :-P

Cheers,
-g

ps. technically, some Python implementations (eg IronPython or Jython)
do not refcount, but that has no bearing on our test suite
Received on 2010-04-12 15:09:58 CEST

This is an archived mail posted to the Subversion Dev mailing list.