On 4/30/2015 1:25 PM, ISHIKAWA, Chiaki wrote:
* 787 nsCOMPtr <nsIInputStream> inboxInputStream =
do_QueryInterface(m_outFileStream);
788 rv = MsgReopenFileStream(m_tmpDownloadFile, inboxInputStream);
Before, as in the current release, m_outFileStream is not buffered.
And the code on line 787 produces non-null inboxInputStream.
However, once m_outFileStream is turned into a buffered output stream
using, say,
m_outFileStream = NS_BufferOutputStream(m_outFileStream, 64 * 1024 );
the code on line 787 produces nullptr.
Is this to be expected?
In short, yes. What happens is that the original m_outFileStream happens
to be of type nsFileStreams (or something like that), which inherits
from both nsIInputStream and nsIOutputStream. When you wrap that in a
buffered output stream, the resulting type of m_outFileStream is of
nsBufferedOutputStream, which does not inherit nsIInputStream; therefore
the cast to nsIInputStream fails.
Up until now, I thought of do_QueryInterface() as mere sugar-coating for
certain type-mutation or something. But I now know I am wrong.
do_QueryInterface is the equivalent of a type-checked downcast, e.g.
(ClassName)foo in Java. (Regular C++ downcasts are not dynamically
type-checked).
I read a page about do_QueryInterface() but it does not
explain the principle very much.
Is the reason of failure something like as follows.
I am using a very general class hierarchy.
A base class
|
+---+---+
B C B and C are derived from base class A
|
--+--+
|
D D is derived further from Class D.
Let's say Class B and C are derived from Class A.
Class D is further derived from Class C.
Let us assume there are corresponding XPCOM class/object A', B', C', D'.
By using do_QueryInterface() on objects,
we can follow the path of direct "derives" relation
B' <= do_QueryInterface (A') (or is it the other way round?)
and maybe between B' and C' (? Not sure about this.)
but we can NOT follow the direction of
B' <= do_QueryInterface (D')
That is
X = do_QeuryInterface(Y) is possible only when X is the direct or
indirect descendant of Y?
No, you are incorrect. The issue is the dynamic type of the object (if
you have A *x = new B, the static type of x is A whereas the dynamic
type is B). In the pre-modified code, the dynamic type of
m_outFileStream supported the interface in question, but your
modification changed the dynamic type to one that did not support the
interface.
--
Joshua Cranmer
Thunderbird and DXR developer
Source code archæologist
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform