Provide convenience function for consuming an entire nsIInputStream

RESOLVED FIXED in mozilla1.9alpha1

Status

()

Core
XPCOM
--
enhancement
RESOLVED FIXED
12 years ago
12 years ago

People

(Reporter: Darin Fisher, Assigned: Darin Fisher)

Tracking

({fixed1.8.1})

Trunk
mozilla1.9alpha1
fixed1.8.1
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(2 attachments)

(Assignee)

Description

12 years ago
Provide convenience function for consuming an entire nsIInputStream
(Assignee)

Comment 1

12 years ago
Created attachment 205355 [details] [diff] [review]
v1 patch

Simple patch.  This is something the places project wants to use.
Attachment #205355 - Flags: superreview?(bzbarsky)
Attachment #205355 - Flags: review?(cbiesinger)
(Assignee)

Updated

12 years ago
Blocks: 317839
(Assignee)

Updated

12 years ago
Status: NEW → ASSIGNED
Target Milestone: --- → mozilla1.9alpha
Comment on attachment 205355 [details] [diff] [review]
v1 patch

>Index: io/nsStreamUtils.h
>Index: io/nsStreamUtils.cpp
>+NS_ConsumeStream(nsIInputStream *stream, nsACString &result)
>+        char *buf = result.BeginWriting();

Shouldn't you add |length| here?  Otherwise you're always reading into the beginning of the string...

sr=bzbarsky with that fixed.
Attachment #205355 - Flags: superreview?(bzbarsky) → superreview+
(Assignee)

Comment 3

12 years ago
Yes, indeed.  My testcase was apparently not comprehensive enough :-(
The stream in the testcase just handed back all the data in a single chunk is all... ;)
Comment on attachment 205355 [details] [diff] [review]
v1 patch

heh, the other day I was thinking that a function like this would be useful :)

should the comments say that the stream needs to be blocking for reasonable behaviour? (at least I think that's the case...)

shouldn't you truncate the string at the beginning of this function?
Attachment #205355 - Flags: review?(cbiesinger) → review+
(Assignee)

Comment 6

12 years ago
I decided to let this function work with non-blocking streams as well.  The comments say that the function will append to the buffer and return a failure if it encountered an error at some point, but any data in the buffer will remain in the buffer.  This allows the function to be used with either type of stream.

I can make the function Truncate up front I suppose.  That makes the function a little less useful, but it perhaps makes its behavior a bit more predictable.  Hmm...
(Assignee)

Comment 7

12 years ago
Created attachment 205418 [details] [diff] [review]
v1.1 patch

Here's the version of the patch that I checked in.
(Assignee)

Updated

12 years ago
Status: ASSIGNED → RESOLVED
Last Resolved: 12 years ago
Resolution: --- → FIXED

Comment 8

12 years ago
This patch is giving me the following error on WinXP/cygwin/Mingw

e:/mozilla/source/mozilla/xpcom/build/dlldeps.cpp: In function `void XXXNeverCal
led()':
e:/mozilla/source/mozilla/xpcom/build/dlldeps.cpp:122: error: cannot convert `ns
CString' to `PRUint32' for argument `2' to `nsresult NS_ConsumeStream(nsIInputSt
ream*, PRUint32, nsACString_internal&)'
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
(Assignee)

Comment 9

12 years ago
> CString' to `PRUint32' for argument `2' to `nsresult
> NS_ConsumeStream(nsIInputSt

crap, the line in dlldeps.cpp needs to have a "0" in the second parameter to NS_ConsumeStream.  It looks like the CVS servers are down for the count, so I won't be able to fix this until they come back online.

Comment 10

12 years ago
(In reply to comment #9)
> crap, the line in dlldeps.cpp needs to have a "0" in the second parameter to
> NS_ConsumeStream.  It looks like the CVS servers are down for the count, so I
> won't be able to fix this until they come back online.

I tried to build Sunbird from trunk today (dlldeps.cpp,v1.137 with "0") and get the following error: 

c:/dev/moz_build/mozilla/xpcom/build/dlldeps.cpp: 
   In function `void XXXNeverCalled()':

c:/dev/moz_build/mozilla/xpcom/build/dlldeps.cpp:122: 
   error: invalid initialization of non-const reference of type 
   'nsACString_internal&' from a temporary of type 'nsCString'

c:/dev/moz_build/mozilla/xpcom/build/../io/nsStreamUtils.h:136: 
   error: in passing argument 3 of `nsresult NS_ConsumeStream(nsIInputStream*, 
   PRUint32, nsACString_internal&)'
(Assignee)

Comment 11

12 years ago
I applied a fix for this.  Please update dlldeps.cpp
(Assignee)

Updated

12 years ago
Status: REOPENED → RESOLVED
Last Resolved: 12 years ago12 years ago
Resolution: --- → FIXED
Blocks: 324274
marking dependency for branch landing
Depends on: 315438
Keywords: fixed1.8.1
You need to log in before you can comment on or make changes to this bug.