2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:21:17 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
2004-04-18 18:21:17 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
2001-07-31 23:05:34 +04:00
|
|
|
* The Original Code is Mozilla FastLoad code.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
2004-04-18 18:21:17 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2001
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2001-07-31 23:05:34 +04:00
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Brendan Eich <brendan@mozilla.org> (original author)
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:21:17 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-29 00:14:13 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 18:21:17 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 18:21:17 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2001-07-31 23:05:34 +04:00
|
|
|
|
|
|
|
#include "nsISupports.idl"
|
|
|
|
#include "nsrootidl.idl"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An interface for access to a buffering stream implementation's underlying
|
|
|
|
* memory buffer.
|
|
|
|
*
|
|
|
|
* Stream implementations that QueryInterface to nsIStreamBufferAccess must
|
|
|
|
* ensure that all buffers are aligned on the most restrictive type size for
|
|
|
|
* the current architecture (e.g., sizeof(double) for RISCy CPUs). malloc(3)
|
|
|
|
* satisfies this requirement.
|
|
|
|
*/
|
|
|
|
[uuid(ac923b72-ac87-4892-ac7a-ca385d429435)]
|
|
|
|
interface nsIStreamBufferAccess : nsISupports
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Get access to a contiguous, aligned run of bytes in the stream's buffer.
|
|
|
|
* Exactly one successful getBuffer call must occur before a putBuffer call
|
|
|
|
* taking the non-null pointer returned by the successful getBuffer.
|
|
|
|
*
|
|
|
|
* The run of bytes are the next bytes (modulo alignment padding) to read
|
|
|
|
* for an input stream, and the next bytes (modulo alignment padding) to
|
|
|
|
* store before (eventually) writing buffered data to an output stream.
|
|
|
|
* There can be space beyond this run of bytes in the buffer for further
|
|
|
|
* accesses before the fill or flush point is reached.
|
|
|
|
*
|
|
|
|
* @param aLength
|
|
|
|
* Count of contiguous bytes requested at the address A that satisfies
|
|
|
|
* (A & aAlignMask) == 0 in the buffer, starting from the current stream
|
|
|
|
* position, mapped to a buffer address B. The stream implementation
|
|
|
|
* must pad from B to A by skipping bytes (if input stream) or storing
|
|
|
|
* zero bytes (if output stream).
|
|
|
|
*
|
|
|
|
* @param aAlignMask
|
|
|
|
* Bit-mask computed by subtracting 1 from the power-of-two alignment
|
|
|
|
* modulus (e.g., 3 or sizeof(PRUint32)-1 for PRUint32 alignment).
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* The aligned pointer to aLength bytes in the buffer, or null if the
|
|
|
|
* buffer has no room for aLength bytes starting at the next address A
|
|
|
|
* after the current position that satisfies (A & aAlignMask) == 0.
|
|
|
|
*/
|
|
|
|
[notxpcom] charPtr getBuffer(in PRUint32 aLength, in PRUint32 aAlignMask);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Relinquish access to the stream's buffer, filling if at end of an input
|
|
|
|
* buffer, flushing if completing an output buffer. After a getBuffer call
|
|
|
|
* that returns non-null, putBuffer must be called.
|
|
|
|
*
|
|
|
|
* @param aBuffer
|
|
|
|
* A non-null pointer returned by getBuffer on the same stream buffer
|
|
|
|
* access object.
|
|
|
|
*
|
|
|
|
* @param aLength
|
|
|
|
* The same count of contiguous bytes passed to the getBuffer call that
|
|
|
|
* returned aBuffer.
|
|
|
|
*/
|
|
|
|
[notxpcom] void putBuffer(in charPtr aBuffer, in PRUint32 aLength);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disable and enable buffering on the stream implementing this interface.
|
|
|
|
* DisableBuffering flushes an output stream's buffer, and invalidates an
|
|
|
|
* input stream's buffer.
|
|
|
|
*/
|
|
|
|
void disableBuffering();
|
|
|
|
void enableBuffering();
|
Bit checkin for bug 68045, r/sr=waterson&shaver, second attempt. It all works
for me on optimized and debug gcc2.96, rh7.1.
- Better failure codes from nsXULPrototypeScript::Deserialize.
- Call nsXULDocument::AbortFastLoads after nsXULPrototypeScript::Serialize
failure, instead of just nulling the FastLoad service's output stream.
- Expose nsXULDocument::AbortFastLoads via nsIXULPrototypeCache, for use from
nsChromeProtocolHandler.cpp. AbortFastLoads flushes the XUL cache now, for
good measure.
- The needless "Current" adjective in nsIFastLoadService attribute and method
names is no more.
- Add a do_GetFastLoadService() helper, to use CID instead of contractid, and
to let the compiler consolidate the static inline CID.
- Add "nglayout.debug.checksum_xul_fastload_file" pref so people can do without
the checksum verification step when reading a FastLoad file.
- Verify the FastLoad file checksum, by default. Also, cache it in the FastLoad
service so we don't recompute it when re-opening the FastLoad file as mailnews
and other top-levels start up. Fill the checksum cache in EndFastLoad, when
the last pseudo-concurrent top-level finishes loading.
My hope to compute the checksum while writing the FastLoad file ran afoul of
misordered writes. The old code to checksum the in-memory nsFastLoadHeader
also was broken on little endian platforms. Now all checksumming is done via
a separate read pass over the complete file, save for the header's checksum
field, which is summed as if it contained zero.
- Track and check FastLoad file dependencies. This required groveling with a
bunch of Necko interfaces in nsChromeProtocolHandler::NewChannel -- read it
and weep. Dependency checking, as well as checksum access and computation,
use better-factored nsIFastLoad{File,Read,Write}Control interfaces.
- nsBufferedStream::Seek wasn't flushing the buffer when seeking backward
within the buffer, but it must, because mCursor bounds the amount to write
if the buffer contains the end of file.
- Add an unbufferedStream readonly attribute to nsIStreamBufferAccess, so we
don't have to screw around with the bufferying layer when checksumming. Also
implement nsIStreamBufferAccess in nsBufferedOutputStream.
- nsISeekableOutputStream was bogus, based on a bad state I had put the
nsBufferedOutputStream code in on its way from being completely broken when
you seek backwards outside of the buffer. Removing this interface required
using nsIFastLoadFileIO in nsFastLoadFileWriter, and it also required careful
ordering of Close calls (the Reader must close after the Writer or Updater,
so that the Reader's underlying, unbuffered input stream can be read by
nsFastLoadFileWriter::Close to compute the checksum.
- Miscellaneous tab/indentation, comment typo, bracing, if( => if ( style,
nsnull vs. 0, useless variable elimination, tortured control flow,
AutoString instead of String, and gratuitous ; after nsISupportsUtils.h
macro call cleanups.
2001-08-22 00:51:34 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The underlying, unbuffered input or output stream.
|
|
|
|
*/
|
|
|
|
readonly attribute nsISupports unbufferedStream;
|
2001-07-31 23:05:34 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
%{C++
|
|
|
|
|
|
|
|
// Swap macros, used to convert to/from canonical (big-endian) format
|
|
|
|
#if defined IS_LITTLE_ENDIAN
|
|
|
|
|
|
|
|
# define NS_SWAP16(x) ((((x) & 0xff) << 8) | (((x) >> 8) & 0xff))
|
|
|
|
# define NS_SWAP32(x) ((NS_SWAP16((x) & 0xffff) << 16) | (NS_SWAP16((x) >> 16)))
|
|
|
|
|
2002-06-29 09:13:59 +04:00
|
|
|
// We want to avoid casting to 32-bit types if possible, since that violates
|
|
|
|
// aliasing rules (a standard compiler may assume that pointers of two types
|
|
|
|
// do not address overlapping storage).
|
|
|
|
//
|
|
|
|
// XXX What if we have a compiler that follows aliasing rules strictly but
|
|
|
|
// doesn't have a 64-bit int type?
|
|
|
|
//
|
2001-07-31 23:05:34 +04:00
|
|
|
// XXXbe shouldn't NSPR's LL_INIT work for non-constant arguments in all cases?
|
2002-06-29 09:13:59 +04:00
|
|
|
|
|
|
|
# if defined HAVE_LONG_LONG
|
2002-07-09 07:37:50 +04:00
|
|
|
# if PR_BYTES_PER_LONG == 8
|
|
|
|
# define ULL_(x) x ## UL
|
|
|
|
# elif (defined WIN32 || defined WIN16) && !defined __GNUC__
|
|
|
|
# define ULL_(x) ((uint64) x ## i64)
|
|
|
|
# else
|
|
|
|
# define ULL_(x) x ## ULL
|
|
|
|
# endif
|
|
|
|
|
2002-07-10 09:18:58 +04:00
|
|
|
# define NS_SWAP64(x) ((((x) & ULL_(0xff00000000000000)) >> 56) | \
|
2002-07-09 07:37:50 +04:00
|
|
|
(((x) & ULL_(0x00ff000000000000)) >> 40) | \
|
|
|
|
(((x) & ULL_(0x0000ff0000000000)) >> 24) | \
|
|
|
|
(((x) & ULL_(0x000000ff00000000)) >> 8) | \
|
|
|
|
(((x) & ULL_(0x00000000ff000000)) << 8) | \
|
|
|
|
(((x) & ULL_(0x0000000000ff0000)) << 24) | \
|
|
|
|
(((x) & ULL_(0x000000000000ff00)) << 40) | \
|
|
|
|
(((x) /* & ULL_(0x00000000000000ff) */) << 56))
|
2001-07-31 23:05:34 +04:00
|
|
|
# else
|
2002-07-09 07:37:50 +04:00
|
|
|
# define NS_SWAP64(x) LL_INIT((((x).lo /* & 0xff000000ul */) >> 24) | \
|
|
|
|
(((x).lo & 0x00ff0000ul) >> 8) | \
|
|
|
|
(((x).lo & 0x0000ff00ul) << 8) | \
|
|
|
|
(((x).lo /* & 0x000000fful */) << 24), \
|
|
|
|
(((x).hi /* & 0xff000000ul */) >> 24) | \
|
|
|
|
(((x).hi & 0x00ff0000ul) >> 8) | \
|
|
|
|
(((x).hi & 0x0000ff00ul) << 8) | \
|
|
|
|
(((x).hi /* & 0x000000fful */) << 24))
|
2001-07-31 23:05:34 +04:00
|
|
|
# endif
|
|
|
|
|
|
|
|
#elif defined IS_BIG_ENDIAN
|
|
|
|
|
|
|
|
# define NS_SWAP16(x) (x)
|
|
|
|
# define NS_SWAP32(x) (x)
|
|
|
|
# define NS_SWAP64(x) (x)
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
# error "Unknown byte order"
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* These macros get and put a buffer given either an sba parameter that may
|
|
|
|
* point to an object implementing nsIStreamBufferAccess, nsIObjectInputStream,
|
|
|
|
* or nsIObjectOutputStream.
|
|
|
|
*/
|
|
|
|
#define NS_GET_BUFFER(sba,n,a) ((sba)->GetBuffer(n, a))
|
|
|
|
#define NS_PUT_BUFFER(sba,p,n) ((sba)->PutBuffer(p, n))
|
|
|
|
|
|
|
|
#define NS_GET8(p) (*(PRUint8*)(p))
|
|
|
|
#define NS_GET16(p) NS_SWAP16(*(PRUint16*)(p))
|
|
|
|
#define NS_GET32(p) NS_SWAP32(*(PRUint32*)(p))
|
|
|
|
#define NS_GET64(p) NS_SWAP64(*(PRUint64*)(p))
|
|
|
|
#define NS_GET_FLOAT(p) ((float)NS_SWAP32(*(PRUint32*)(p)))
|
|
|
|
#define NS_GET_DOUBLE(p) ((double)NS_SWAP64(*(PRUint64*)(p)))
|
|
|
|
|
|
|
|
#define NS_PUT8(p,x) (*(PRUint8*)(p) = (x))
|
|
|
|
#define NS_PUT16(p,x) (*(PRUint16*)(p) = NS_SWAP16(x))
|
|
|
|
#define NS_PUT32(p,x) (*(PRUint32*)(p) = NS_SWAP32(x))
|
|
|
|
#define NS_PUT64(p,x) (*(PRUint64*)(p) = NS_SWAP64(x))
|
|
|
|
#define NS_PUT_FLOAT(p,x) (*(PRUint32*)(p) = NS_SWAP32(*(PRUint32*)&(x)))
|
|
|
|
#define NS_PUT_DOUBLE(p,x) (*(PRUint64*)(p) = NS_SWAP64(*(PRUint64*)&(x)))
|
|
|
|
|
|
|
|
%}
|