Merge places to mozilla-central.

This commit is contained in:
Shawn Wilsher 2009-07-23 13:10:26 -07:00
Родитель 7aa0c229f6 4cbbbfb168
Коммит 3b8c5a49ad
14 изменённых файлов: 82 добавлений и 662 удалений

Просмотреть файл

@ -83,7 +83,6 @@ EXPORTS
sqlite3_create_module
sqlite3_data_count
sqlite3_db_handle
sqlite3_db_mutex
sqlite3_declare_vtab
sqlite3_enable_load_extension
sqlite3_enable_shared_cache

Просмотреть файл

@ -115,8 +115,9 @@ NS_IMETHODIMP mozOSXSpell::GetLanguage(PRUnichar **aLanguage)
}
mLanguage.Assign(*aLanguage);
}
else
else {
*aLanguage = ToNewUnicode(mLanguage);
}
return *aLanguage ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
@ -299,6 +300,8 @@ NS_IMETHODIMP mozOSXSpell::Suggest(const PRUnichar *aWord, PRUnichar ***aSuggest
PRUint32 length = [self length];
PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
if (!retStr)
return NULL;
[self getCharacters:retStr];
retStr[length] = PRUnichar(0);
return retStr;

Просмотреть файл

@ -49,8 +49,6 @@
*/
#ifndef STANDALONE
#include "nsWildCard.h"
#include "nscore.h"
#include "prmem.h"
@ -76,52 +74,6 @@ nsRecyclingAllocator *gZlibAllocator = NULL;
#include NEW_H
#define ZIP_ARENABLOCKSIZE (1*1024)
#else /* STANDALONE */
#ifdef XP_WIN
#include "windows.h"
#endif
#undef MOZILLA_CLIENT // undoes prtypes damage in zlib.h
#define ZFILE_CREATE "wb"
#define READTYPE PRUint32
#include "zlib.h"
#undef PR_PUBLIC_API
#include "zipstub.h"
#ifdef XP_MAC
#include <string.h>
#include <stdlib.h>
char * strdup(const char *src);
char * strdup(const char *src)
{
long len = strlen(src);
char *dup = (char *)malloc(len+1 * sizeof(char));
memcpy(dup, src, len+1);
return dup;
}
#endif
#ifdef WINCE
int remove(const char* inPath)
{
unsigned short wPath[MAX_PATH];
MultiByteToWideChar(CP_ACP,
0,
inPath,
-1,
wPath,
MAX_PATH);
if(FALSE != DeleteFileW(wPath))
return 0;
return -1;
}
#endif
#endif /* STANDALONE */
#ifdef XP_UNIX
#include <sys/types.h>
#include <sys/stat.h>
@ -163,265 +115,6 @@ static PRBool IsSymlink(unsigned char *ll);
static nsresult ResolveSymlink(const char *path);
#endif
/*---------------------------------------------
* C API wrapper for nsZipArchive
*--------------------------------------------*/
#ifdef STANDALONE
/**
* ZIP_OpenArchive
*
* opens the named zip/jar archive and returns a handle that
* represents the archive in other ZIP_ calls.
*
* @param zipname archive filename
* @param hZip receives handle if archive opened OK
* @return status code
*/
PR_PUBLIC_API(PRInt32) ZIP_OpenArchive(const char * zipname, void** hZip)
{
PRInt32 status;
/*--- error check args ---*/
if (hZip == 0)
return ZIP_ERR_PARAM;
/*--- NULL output to prevent use by bozos who don't check errors ---*/
*hZip = 0;
/*--- create and open the archive ---*/
nsZipArchive* zip = new nsZipArchive();
if (zip == 0)
return ZIP_ERR_MEMORY;
PRFileDesc * fd = PR_Open(zipname, PR_RDONLY, 0400);
if (!fd) {
delete zip;
return ZIP_ERR_DISK;
}
status = zip->OpenArchive(fd);
if (status == ZIP_OK)
*hZip = static_cast<void*>(zip);
else {
delete zip;
PR_Close(fd);
}
return status;
}
/**
* ZIP_TestArchive
*
* Tests the integrity of this open zip archive by extracting each
* item to memory and performing a CRC check.
*
* @param hZip handle obtained from ZIP_OpenArchive
* @return status code (success indicated by ZIP_OK)
*/
PR_PUBLIC_API(PRInt32) ZIP_TestArchive(void *hZip)
{
/*--- error check args ---*/
if (hZip == 0)
return ZIP_ERR_PARAM;
nsZipArchive* zip = static_cast<nsZipArchive*>(hZip);
if (zip->kMagic != ZIP_MAGIC)
return ZIP_ERR_PARAM; /* whatever it is isn't one of ours! */
/*--- test the archive ---*/
return zip->Test(NULL);
}
/**
* ZIP_CloseArchive
*
* closes zip archive and frees memory
* @param hZip handle obtained from ZIP_OpenArchive
* @return status code
*/
PR_PUBLIC_API(PRInt32) ZIP_CloseArchive(void** hZip)
{
/*--- error check args ---*/
if (hZip == 0 || *hZip == 0)
return ZIP_ERR_PARAM;
nsZipArchive* zip = static_cast<nsZipArchive*>(*hZip);
if (zip->kMagic != ZIP_MAGIC)
return ZIP_ERR_PARAM; /* whatever it is isn't one of ours! */
/*--- close the archive ---*/
*hZip = 0;
delete zip;
return ZIP_OK;
}
/**
* ZIP_ExtractFile
*
* extracts named file from an opened archive
*
* @param hZip handle obtained from ZIP_OpenArchive
* @param filename name of file in archive
* @param outname filename to extract to
*/
PR_PUBLIC_API(PRInt32) ZIP_ExtractFile(void* hZip, const char * filename, const char * outname)
{
/*--- error check args ---*/
if (hZip == 0)
return ZIP_ERR_PARAM;
nsZipArchive* zip = static_cast<nsZipArchive*>(hZip);
if (zip->kMagic != ZIP_MAGIC)
return ZIP_ERR_PARAM; /* whatever it is isn't one of ours! */
//-- Find item in archive
nsZipItem* item = zip->GetItem(filename);
if (!item)
return ZIP_ERR_FNF;
// Can't extract a directory
if (item->isDirectory)
return ZIP_ERR_PARAM;
// delete any existing file so that we overwrite the file permissions
PR_Delete(outname);
PRFileDesc* fOut = PR_Open(outname, ZFILE_CREATE, item->mode);
if (!fOut)
return ZIP_ERR_DISK;
#if defined(XP_UNIX) && defined(STANDALONE)
// When STANDALONE is defined, PR_Open ignores its 3d argument.
mode_t msk = umask(0);
umask(msk);
chmod(outname, (item->mode | S_IRUSR) & ~msk);
#endif
// ExtractFile also closes the fOut handle and resolves the symlink if needed
return zip->ExtractFile(item, outname, fOut);
}
/**
* ZIP_FindInit
*
* Initializes an enumeration of files in the archive
*
* @param hZip handle obtained from ZIP_OpenArchive
* @param pattern regexp to match files in archive, the usual shell expressions.
* NULL pattern also matches all files, faster than "*"
*/
PR_PUBLIC_API(void*) ZIP_FindInit(void* hZip, const char * pattern)
{
/*--- error check args ---*/
if (hZip == 0)
return 0;
nsZipArchive* zip = static_cast<nsZipArchive*>(hZip);
if (zip->kMagic != ZIP_MAGIC)
return 0; /* whatever it is isn't one of ours! */
/*--- initialize the pattern search ---*/
nsZipFind* find;
PRInt32 rv = zip->FindInit(pattern, &find);
if (rv != ZIP_OK)
find = NULL;
return find;
}
/**
* ZIP_FindNext
*
* Puts the next name in the passed buffer. Returns ZIP_ERR_SMALLBUF when
* the name is too large for the buffer, and ZIP_ERR_FNF when there are no
* more files that match the pattern
*
* @param hFind handle obtained from ZIP_FindInit
* @param outbuf buffer to receive next filename
* @param bufsize size of allocated buffer
*/
PR_PUBLIC_API(PRInt32) ZIP_FindNext(void* hFind, char * outbuf, PRUint16 bufsize)
{
PRInt32 status;
/*--- error check args ---*/
if (hFind == 0)
return ZIP_ERR_PARAM;
nsZipFind* find = static_cast<nsZipFind*>(hFind);
if (find->kMagic != ZIPFIND_MAGIC)
return ZIP_ERR_PARAM; /* whatever it is isn't one of ours! */
/*--- return next filename file ---*/
const char* itemName;
status = find->FindNext(&itemName);
if (status == ZIP_OK)
{
PRUint16 namelen = (PRUint16)PL_strlen(itemName);
if (bufsize > namelen)
{
PL_strcpy(outbuf, itemName);
}
else
status = ZIP_ERR_SMALLBUF;
}
return status;
}
/**
* ZIP_FindFree
*
* Releases allocated memory associated with the find token
*
* @param hFind handle obtained from ZIP_FindInit
*/
PR_PUBLIC_API(PRInt32) ZIP_FindFree(void* hFind)
{
/*--- error check args ---*/
if (hFind == 0)
return ZIP_ERR_PARAM;
nsZipFind* find = static_cast<nsZipFind*>(hFind);
if (find->kMagic != ZIPFIND_MAGIC)
return ZIP_ERR_PARAM; /* whatever it is isn't one of ours! */
/* free the find structure */
delete find;
return ZIP_OK;
}
#if defined XP_WIN
void ProcessWindowsMessages()
{
MSG msg;
while(PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
#endif /* XP_WIN */
#else /* STANDALONE */
//***********************************************************
// Allocators for use with zlib
//
@ -493,12 +186,10 @@ zlibFree(void *opaque, void *ptr)
free(ptr);
return;
}
#endif /* STANDALONE */
nsresult gZlibInit(z_stream *zs)
{
memset(zs, 0, sizeof(z_stream));
#ifndef STANDALONE
//-- ensure we have our zlib allocator for better performance
if (!gZlibAllocator) {
gZlibAllocator = new nsRecyclingAllocator(NBUCKETS, NS_DEFAULT_RECYCLE_TIMEOUT, "libjar");
@ -508,7 +199,6 @@ nsresult gZlibInit(z_stream *zs)
zs->zfree = zlibFree;
zs->opaque = gZlibAllocator;
}
#endif /* STANDALONE */
int zerr = inflateInit2(zs, -MAX_WBITS);
if (zerr != Z_OK) return ZIP_ERR_MEMORY;
@ -528,10 +218,8 @@ nsresult nsZipArchive::OpenArchive(PRFileDesc * fd)
if (!fd)
return ZIP_ERR_PARAM;
#ifndef STANDALONE
// Initialize our arena
PL_INIT_ARENA_POOL(&mArena, "ZipArena", ZIP_ARENABLOCKSIZE);
#endif
//-- Keep the filedescriptor for further reading...
mFd = fd;
@ -567,9 +255,6 @@ nsresult nsZipArchive::Test(const char *aEntryName)
nsresult rv = ExtractFile(currItem, 0, 0);
if (rv != ZIP_OK)
return rv;
#if defined STANDALONE && defined XP_WIN
ProcessWindowsMessages();
#endif
}
}
@ -581,7 +266,6 @@ nsresult nsZipArchive::Test(const char *aEntryName)
//---------------------------------------------
nsresult nsZipArchive::CloseArchive()
{
#ifndef STANDALONE
if (mFd) {
PL_FinishArenaPool(&mArena);
}
@ -595,23 +279,7 @@ nsresult nsZipArchive::CloseArchive()
// Let us also cleanup the mFiles table for re-use on the next 'open' call
for (int i = 0; i < ZIP_TABSIZE; i++) {
mFiles[i] = 0;
}
#else
// delete nsZipItems in table
nsZipItem* pItem;
for (int i = 0; i < ZIP_TABSIZE; ++i)
{
pItem = mFiles[i];
while (pItem != 0)
{
mFiles[i] = pItem->next;
free(pItem);
pItem = mFiles[i];
}
mFiles[i] = 0; // make sure we don't double-delete
}
#endif
}
if (mFd) {
PR_Close(mFd);
mFd = 0;
@ -783,12 +451,7 @@ nsresult nsZipFind::FindNext(const char ** aResult)
else if (mRegExp)
found = (NS_WildCardMatch(mItem->name, mPattern, PR_FALSE) == MATCH);
else
#if defined(STANDALONE) && defined(XP_MAC)
// simulate <regexp>* matches
found = (strncmp(mItem->name, mPattern, strlen(mPattern)) == 0);
#else
found = (PL_strcmp(mItem->name, mPattern) == 0);
#endif
if (found) {
*aResult = mItem->name;
@ -835,14 +498,10 @@ static nsresult ResolveSymlink(const char *path)
nsZipItem* nsZipArchive::CreateZipItem(PRUint16 namelen)
{
// sizeof(nsZipItem) includes space for name's null byte
#ifndef STANDALONE
// Arena allocate the nsZipItem
void *mem;
PL_ARENA_ALLOCATE(mem, &mArena, sizeof(nsZipItem)+namelen);
return (nsZipItem*)mem;
#else
return (nsZipItem*)malloc(sizeof(nsZipItem)+namelen);
#endif
}
//---------------------------------------------
@ -858,11 +517,7 @@ nsresult nsZipArchive::BuildFileList()
//-- get archive size using end pos
PRInt32 pos = PR_Seek(mFd, 0, PR_SEEK_END);
#ifndef STANDALONE
if (pos <= 0)
#else
if (pos || ((pos = ftell(mFd)) <= 0))
#endif
return ZIP_ERR_CORRUPT;
PRBool bEndsigFound = PR_FALSE;
@ -1272,9 +927,6 @@ nsresult nsZipArchive::InflateItem(const nsZipItem* aItem, PRFileDesc* outFD)
else
zerr = Z_STREAM_END;
#if defined STANDALONE && defined XP_WIN
ProcessWindowsMessages();
#endif
} // while
//-- verify crc32
@ -1314,9 +966,6 @@ cleanup:
//------------------------------------------
nsZipArchive::nsZipArchive() :
#ifdef STANDALONE
kMagic(ZIP_MAGIC),
#endif
mFd(0),
mBuiltSynthetics(PR_FALSE)
{
@ -1339,9 +988,6 @@ nsZipArchive::~nsZipArchive()
//------------------------------------------
nsZipFind::nsZipFind(nsZipArchive* aZip, char* aPattern, PRBool aRegExp) :
#ifdef STANDALONE
kMagic(ZIPFIND_MAGIC),
#endif
mArchive(aZip),
mPattern(aPattern),
mItem(0),

Просмотреть файл

@ -48,28 +48,17 @@
// Keep this odd. The -1 is significant.
#define ZIP_BUFLEN (4 * 1024 - 1)
#ifdef STANDALONE
#define nsZipArchive nsZipArchiveStandalone
#define ZIP_Seek(fd,p,m) (fseek((fd),(p),(m))==0)
#else
#define PL_ARENA_CONST_ALIGN_MASK 7
#include "plarena.h"
#define ZIP_Seek(fd,p,m) (PR_Seek((fd),((PROffset32)p),(m))==((PROffset32)p))
#endif
#include "zlib.h"
class nsZipFind;
class nsZipReadState;
class nsZipItemMetadata;
#ifndef STANDALONE
struct PRFileDesc;
#endif
/**
* This file defines some of the basic structures used by libjar to
@ -81,18 +70,6 @@ struct PRFileDesc;
* nsZipItem represents a single item (file) in the Zip archive.
* nsZipFind represents the metadata involved in doing a search,
* and current state of the iteration of found objects.
*
* There is a lot of #ifdef STANDALONE here, and that is so that these
* basic structures can be reused in a standalone static
* library. In order for the code to be reused, these structures
* should never use anything from XPCOM, including such obvious things
* as NS_ASSERTION(). Instead, use the basic NSPR equivalents.
*
* There is one key difference in the way that this code behaves in
* STANDALONE mode. The nsZipArchive owns a single file descriptor and
* that is used to read the ZIP file index, and for 'Test' and 'Extract'.
* Since there is only one nsZipArchive per file, you can only Test/Extract
* one file at a time from the Zip file.
* 'MT''safe' reading from the zipfile is performed through JARInputStream,
* which maintains its own file descriptor, allowing for multiple reads
* concurrently from the same zip file.
@ -143,11 +120,6 @@ class nsZipArchive
friend class nsZipFind;
public:
#ifdef STANDALONE
/** cookie used to validate supposed objects passed from C code */
const PRInt32 kMagic;
#endif
/** constructing does not open the archive. See OpenArchive() */
nsZipArchive();
@ -225,9 +197,7 @@ private:
//--- private members ---
nsZipItem* mFiles[ZIP_TABSIZE];
#ifndef STANDALONE
PLArenaPool mArena;
#endif
// Used for central directory reading, and for Test and Extract
PRFileDesc *mFd;
@ -257,9 +227,6 @@ private:
class nsZipFind
{
public:
#ifdef STANDALONE
const PRInt32 kMagic;
#endif
nsZipFind(nsZipArchive* aZip, char* aPattern, PRBool regExp);
~nsZipFind();

Просмотреть файл

@ -35,12 +35,8 @@
#
# ***** END LICENSE BLOCK *****
MODULES_STANDALONE_LCPPSRCS = \
nsZipArchive.cpp \
$(NULL)
MODULES_LIBJAR_LCPPSRCS = \
$(MODULES_STANDALONE_LCPPSRCS) \
nsZipArchive.cpp \
nsJARInputStream.cpp \
nsJAR.cpp \
nsJARFactory.cpp \
@ -52,7 +48,6 @@ MODULES_LIBJAR_LCPPSRCS = \
MODULES_LIBJAR_LEXPORTS = \
zipfile.h \
zipstub.h \
zipstruct.h \
$(NULL)
@ -66,7 +61,5 @@ MODULES_LIBJAR_LXPIDLSRCS = \
MODULES_LIBJAR_CPPSRCS := $(addprefix $(topsrcdir)/modules/libjar/, $(MODULES_LIBJAR_LCPPSRCS))
MODULES_STANDALONE_CPPSRCS := $(addprefix $(topsrcdir)/modules/libjar/, $(MODULES_STANDALONE_LCPPSRCS))
MODULES_LIBJAR_XPIDLSRCS := $(addprefix $(topsrcdir)/modules/libjar/, $(MODULES_LIBJAR_LXPIDLSRCS))

Просмотреть файл

@ -48,64 +48,6 @@
* Currently only compression mode 8 (or none) is supported.
*/
#ifdef STANDALONE
#define ZIP_OK 0
#define ZIP_ERR_GENERAL -1
#define ZIP_ERR_MEMORY -2
#define ZIP_ERR_DISK -3
#define ZIP_ERR_CORRUPT -4
#define ZIP_ERR_PARAM -5
#define ZIP_ERR_FNF -6
#define ZIP_ERR_UNSUPPORTED -7
#define ZIP_ERR_SMALLBUF -8
PR_BEGIN_EXTERN_C
/* Open and close the archive
*
* If successful OpenArchive returns a handle in the hZip parameter
* that must be passed to all subsequent operations on the archive
*/
PR_EXTERN(PRInt32) ZIP_OpenArchive( const char * zipname, void** hZip );
PR_EXTERN(PRInt32) ZIP_CloseArchive( void** hZip );
/* Test the integrity of every item in this open archive
* by verifying each item's checksum against the stored
* CRC32 value.
*/
PR_EXTERN(PRInt32) ZIP_TestArchive( void* hZip );
/* Extract the named file in the archive to disk.
* This function will happily overwrite an existing Outfile if it can.
* It's up to the caller to detect or move it out of the way if it's important.
*/
PR_EXTERN(PRInt32) ZIP_ExtractFile( void* hZip, const char * filename, const char * outname );
/* Functions to list the files contained in the archive
*
* FindInit() initializes the search with the pattern and returns a find token,
* or NULL on an error. Then FindNext() is called with the token to get the
* matching filenames if any. When done you must call FindFree() with the
* token to release memory.
*
* a NULL pattern will find all the files in the archive, otherwise the
* pattern must be a shell regexp type pattern.
*
* if a matching filename is too small for the passed buffer FindNext()
* will return ZIP_ERR_SMALLBUF. When no more matches can be found in
* the archive it will return ZIP_ERR_FNF
*/
PR_EXTERN(void*) ZIP_FindInit( void* hZip, const char * pattern );
PR_EXTERN(PRInt32) ZIP_FindNext( void* hFind, char * outbuf, PRUint16 bufsize );
PR_EXTERN(PRInt32) ZIP_FindFree( void* hFind );
PR_END_EXTERN_C
#else
#define ZIP_OK NS_OK
#define ZIP_ERR_MEMORY NS_ERROR_OUT_OF_MEMORY
#define ZIP_ERR_DISK NS_ERROR_FILE_DISK_FULL
@ -115,6 +57,4 @@ PR_END_EXTERN_C
#define ZIP_ERR_UNSUPPORTED NS_ERROR_NOT_IMPLEMENTED
#define ZIP_ERR_GENERAL NS_ERROR_FAILURE
#endif /* STANDALONE */
#endif /* _zipfile_h */

Просмотреть файл

@ -1,123 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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/
*
* 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.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998-1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Veditz <dveditz@netscape.com>
* Samir Gehani <sgehani@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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"),
* 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
* use your version of this file under the terms of the MPL, indicate your
* 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
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include <stdio.h>
#include <string.h>
#include <assert.h>
#ifdef XP_MAC
#include <stdlib.h>
#else
#include <malloc.h>
#endif
#define NS_ASSERTION(c,m)
#define PR_ASSERT assert
#define PR_Malloc malloc
#define PR_Free free
#define PR_FREEIF(x) do { if (x) free(x); } while(0)
#define PL_strfree free
#define PL_strcmp strcmp
#define PL_strdup strdup
#define PL_strcpy strcpy
#define PL_strlen strlen
#define PR_Open(a,b,c) fopen((a),(b)) // XXX Ignores mode
#define PR_Read(f,d,n) fread((d),1,(n),(f))
#define PR_Write(f,s,n) fwrite((s),1,(n),(f))
#define PR_Close fclose
#define PR_Seek fseek
#define PR_Delete remove
#ifdef __cplusplus
#define PR_BEGIN_EXTERN_C extern "C" {
#define PR_END_EXTERN_C }
#else
#define PR_BEGIN_EXTERN_C
#define PR_END_EXTERN_C
#endif
#if defined(XP_MAC)
#define PR_EXTERN(__type) extern __declspec(export) __type
#define PR_PUBLIC_API(__type) __declspec(export) __type
#elif defined(XP_WIN)
#define PR_EXTERN(__type) extern _declspec(dllexport) __type
#define PR_PUBLIC_API(__type) _declspec(dllexport) __type
#elif defined(XP_OS2) && defined(__declspec)
#define PR_EXTERN(__type) extern __declspec(dllexport) __type
#define PR_PUBLIC_API(__type) __declspec(dllexport) __type
#else /* XP_UNIX */
#define PR_EXTERN(__type) extern __type
#define PR_PUBLIC_API(__type) __type
#endif
#define PR_CALLBACK
#define PR_STATIC_CALLBACK(__x) static __x
#define PRFileDesc FILE
typedef long PRInt32;
typedef PRInt32 PROffset32;
typedef unsigned long PRUint32;
typedef short PRInt16;
typedef unsigned short PRUint16;
typedef char PRBool;
typedef unsigned char PRUint8;
typedef PRUint8 PRPackedBool;
typedef PRInt32 nsresult;
#define PR_TRUE 1
#define PR_FALSE 0
#define INVALID_SXP -2
#define NON_SXP -1
#define VALID_SXP 1
#define MATCH 0
#define NOMATCH 1
#define ABORTED -1
#define PR_RDONLY "rb"
#define PR_SEEK_SET SEEK_SET
#define PR_SEEK_END SEEK_END
#define NS_WildCardValid(a) NON_SXP
#define NS_WildCardMatch(a,b,c) PR_FALSE
#define MOZ_COUNT_CTOR(x)
#define MOZ_COUNT_DTOR(x)

Просмотреть файл

@ -249,8 +249,10 @@ Connection::Connection(Service *aService)
, mDBConn(nsnull)
, mAsyncExecutionMutex(nsAutoLock::NewLock("AsyncExecutionMutex"))
, mAsyncExecutionThreadShuttingDown(PR_FALSE)
, mDBMutex("Connection::mDBMutex")
, mTransactionMutex(nsAutoLock::NewLock("TransactionMutex"))
, mTransactionInProgress(PR_FALSE)
, mFunctionsMutex(nsAutoLock::NewLock("FunctionsMutex"))
, mProgressHandlerMutex(nsAutoLock::NewLock("ProgressHandlerMutex"))
, mProgressHandler(nsnull)
, mStorageService(aService)
{
@ -261,6 +263,9 @@ Connection::~Connection()
{
(void)Close();
nsAutoLock::DestroyLock(mAsyncExecutionMutex);
nsAutoLock::DestroyLock(mTransactionMutex);
nsAutoLock::DestroyLock(mFunctionsMutex);
nsAutoLock::DestroyLock(mProgressHandlerMutex);
}
NS_IMPL_THREADSAFE_ISUPPORTS1(
@ -296,6 +301,9 @@ Connection::initialize(nsIFile *aDatabaseFile)
{
NS_ASSERTION (!mDBConn, "Initialize called on already opened database!");
NS_ENSURE_TRUE(mAsyncExecutionMutex, NS_ERROR_OUT_OF_MEMORY);
NS_ENSURE_TRUE(mTransactionMutex, NS_ERROR_OUT_OF_MEMORY);
NS_ENSURE_TRUE(mFunctionsMutex, NS_ERROR_OUT_OF_MEMORY);
NS_ENSURE_TRUE(mProgressHandlerMutex, NS_ERROR_OUT_OF_MEMORY);
int srv;
nsresult rv;
@ -318,9 +326,6 @@ Connection::initialize(nsIFile *aDatabaseFile)
return convertResultCode(srv);
}
// Properly wrap the database handle's mutex.
mDBMutex.initWithMutex(sqlite3_db_mutex(mDBConn));
#ifdef PR_LOGGING
if (!gStorageLog)
gStorageLog = ::PR_NewLogModule("mozStorage");
@ -439,7 +444,7 @@ Connection::databaseElementExists(enum DatabaseElementType aElementType,
bool
Connection::findFunctionByInstance(nsISupports *aInstance)
{
mDBMutex.assertCurrentThreadOwns();
PR_ASSERT_CURRENT_THREAD_OWNS_LOCK(mFunctionsMutex);
FFEArguments args = { aInstance, false };
mFunctions.EnumerateRead(findFunctionEnumerator, &args);
return args.found;
@ -455,7 +460,7 @@ Connection::sProgressHelper(void *aArg)
int
Connection::progressHandler()
{
mDBMutex.assertCurrentThreadOwns();
nsAutoLock mutex(mProgressHandlerMutex);
if (mProgressHandler) {
PRBool result;
nsresult rv = mProgressHandler->OnProgress(this, &result);
@ -507,6 +512,12 @@ Connection::Close()
}
#endif
{
nsAutoLock mutex(mProgressHandlerMutex);
if (mProgressHandler)
::sqlite3_progress_handler(mDBConn, 0, NULL, NULL);
}
int srv = ::sqlite3_close(mDBConn);
NS_ASSERTION(srv == SQLITE_OK,
"sqlite3_close failed. There are probably outstanding statements that are listed above!");
@ -630,45 +641,42 @@ Connection::ExecuteAsync(mozIStorageStatement **aStatements,
{
int rc = SQLITE_OK;
nsTArray<StatementData> stmts(aNumStatements);
{
SQLiteMutexAutoLock lockedScope(mDBMutex);
for (PRUint32 i = 0; i < aNumStatements && rc == SQLITE_OK; i++) {
sqlite3_stmt *old_stmt =
static_cast<Statement *>(aStatements[i])->nativeStatement();
if (!old_stmt) {
rc = SQLITE_MISUSE;
break;
}
NS_ASSERTION(::sqlite3_db_handle(old_stmt) == mDBConn,
"Statement must be from this database connection!");
for (PRUint32 i = 0; i < aNumStatements && rc == SQLITE_OK; i++) {
sqlite3_stmt *old_stmt =
static_cast<Statement *>(aStatements[i])->nativeStatement();
if (!old_stmt) {
rc = SQLITE_MISUSE;
break;
}
NS_ASSERTION(::sqlite3_db_handle(old_stmt) == mDBConn,
"Statement must be from this database connection!");
// Clone this statement. We only need a sqlite3_stmt object, so we can
// avoid all the extra work that making a new Statement would normally
// involve and use the SQLite API.
sqlite3_stmt *new_stmt;
rc = ::sqlite3_prepare_v2(mDBConn, ::sqlite3_sql(old_stmt), -1, &new_stmt,
NULL);
if (rc != SQLITE_OK)
break;
// Clone this statement. We only need a sqlite3_stmt object, so we can
// avoid all the extra work that making a new Statement would normally
// involve and use the SQLite API.
sqlite3_stmt *new_stmt;
rc = ::sqlite3_prepare_v2(mDBConn, ::sqlite3_sql(old_stmt), -1, &new_stmt,
NULL);
if (rc != SQLITE_OK)
break;
#ifdef PR_LOGGING
PR_LOG(gStorageLog, PR_LOG_NOTICE,
("Cloned statement 0x%p to 0x%p", old_stmt, new_stmt));
PR_LOG(gStorageLog, PR_LOG_NOTICE,
("Cloned statement 0x%p to 0x%p", old_stmt, new_stmt));
#endif
// Transfer the bindings
rc = sqlite3_transfer_bindings(old_stmt, new_stmt);
if (rc != SQLITE_OK)
break;
// Transfer the bindings
rc = sqlite3_transfer_bindings(old_stmt, new_stmt);
if (rc != SQLITE_OK)
break;
Statement *storageStmt = static_cast<Statement *>(aStatements[i]);
StatementData data(new_stmt, storageStmt->bindingParamsArray());
if (!stmts.AppendElement(data)) {
rc = SQLITE_NOMEM;
break;
}
} // for loop
} // locked Scope
Statement *storageStmt = static_cast<Statement *>(aStatements[i]);
StatementData data(new_stmt, storageStmt->bindingParamsArray());
if (!stmts.AppendElement(data)) {
rc = SQLITE_NOMEM;
break;
}
}
// Dispatch to the background
nsresult rv = NS_OK;
@ -685,11 +693,8 @@ Connection::ExecuteAsync(mozIStorageStatement **aStatements,
}
// Always reset all the statements
{
SQLiteMutexAutoLock lockedScope(mDBMutex);
for (PRUint32 i = 0; i < aNumStatements; i++)
(void)aStatements[i]->Reset();
}
for (PRUint32 i = 0; i < aNumStatements; i++)
(void)aStatements[i]->Reset();
return rv;
}
@ -711,7 +716,7 @@ Connection::IndexExists(const nsACString &aIndexName,
NS_IMETHODIMP
Connection::GetTransactionInProgress(PRBool *_inProgress)
{
SQLiteMutexAutoLock lockedScope(mDBMutex);
nsAutoLock mutex(mTransactionMutex);
*_inProgress = mTransactionInProgress;
return NS_OK;
}
@ -725,7 +730,7 @@ Connection::BeginTransaction()
NS_IMETHODIMP
Connection::BeginTransactionAs(PRInt32 aTransactionType)
{
SQLiteMutexAutoLock lockedScope(mDBMutex);
nsAutoLock mutex(mTransactionMutex);
if (mTransactionInProgress)
return NS_ERROR_FAILURE;
nsresult rv;
@ -750,7 +755,7 @@ Connection::BeginTransactionAs(PRInt32 aTransactionType)
NS_IMETHODIMP
Connection::CommitTransaction()
{
SQLiteMutexAutoLock lockedScope(mDBMutex);
nsAutoLock mutex(mTransactionMutex);
if (!mTransactionInProgress)
return NS_ERROR_FAILURE;
nsresult rv = ExecuteSimpleSQL(NS_LITERAL_CSTRING("COMMIT TRANSACTION"));
@ -762,7 +767,7 @@ Connection::CommitTransaction()
NS_IMETHODIMP
Connection::RollbackTransaction()
{
SQLiteMutexAutoLock lockedScope(mDBMutex);
nsAutoLock mutex(mTransactionMutex);
if (!mTransactionInProgress)
return NS_ERROR_FAILURE;
nsresult rv = ExecuteSimpleSQL(NS_LITERAL_CSTRING("ROLLBACK TRANSACTION"));
@ -796,7 +801,7 @@ Connection::CreateFunction(const nsACString &aFunctionName,
// Check to see if this function is already defined. We only check the name
// because a function can be defined with the same body but different names.
SQLiteMutexAutoLock lockedScope(mDBMutex);
nsAutoLock mutex(mFunctionsMutex);
NS_ENSURE_FALSE(mFunctions.Get(aFunctionName, NULL), NS_ERROR_FAILURE);
int srv = ::sqlite3_create_function(mDBConn,
@ -824,7 +829,7 @@ Connection::CreateAggregateFunction(const nsACString &aFunctionName,
if (!mDBConn) return NS_ERROR_NOT_INITIALIZED;
// Check to see if this function name is already defined.
SQLiteMutexAutoLock lockedScope(mDBMutex);
nsAutoLock mutex(mFunctionsMutex);
NS_ENSURE_FALSE(mFunctions.Get(aFunctionName, NULL), NS_ERROR_FAILURE);
// Because aggregate functions depend on state across calls, you cannot have
@ -854,7 +859,7 @@ Connection::RemoveFunction(const nsACString &aFunctionName)
{
if (!mDBConn) return NS_ERROR_NOT_INITIALIZED;
SQLiteMutexAutoLock lockedScope(mDBMutex);
nsAutoLock mutex(mFunctionsMutex);
NS_ENSURE_TRUE(mFunctions.Get(aFunctionName, NULL), NS_ERROR_FAILURE);
int srv = ::sqlite3_create_function(mDBConn,
@ -881,7 +886,7 @@ Connection::SetProgressHandler(PRInt32 aGranularity,
if (!mDBConn) return NS_ERROR_NOT_INITIALIZED;
// Return previous one
SQLiteMutexAutoLock lockedScope(mDBMutex);
nsAutoLock mutex(mProgressHandlerMutex);
NS_IF_ADDREF(*_oldHandler = mProgressHandler);
if (!aHandler || aGranularity <= 0) {
@ -900,7 +905,7 @@ Connection::RemoveProgressHandler(mozIStorageProgressHandler **_oldHandler)
if (!mDBConn) return NS_ERROR_NOT_INITIALIZED;
// Return previous one
SQLiteMutexAutoLock lockedScope(mDBMutex);
nsAutoLock mutex(mProgressHandlerMutex);
NS_IF_ADDREF(*_oldHandler = mProgressHandler);
mProgressHandler = nsnull;

Просмотреть файл

@ -48,7 +48,6 @@
#include "nsString.h"
#include "nsInterfaceHashtable.h"
#include "mozIStorageProgressHandler.h"
#include "SQLiteMutex.h"
#include "mozIStorageConnection.h"
#include "mozStorageService.h"
@ -159,27 +158,13 @@ private:
*/
PRBool mAsyncExecutionThreadShuttingDown;
/**
* Wraps the mutex that SQLite gives us from sqlite3_db_mutex.
*/
SQLiteMutex mDBMutex;
/**
* Tracks if we have a transaction in progress or not. Access protected by
* mDBMutex.
*/
PRLock *mTransactionMutex;
PRBool mTransactionInProgress;
/**
* Stores the mapping of a given function by name to its instance. Access is
* protected by mDBMutex.
*/
PRLock *mFunctionsMutex;
nsInterfaceHashtable<nsCStringHashKey, nsISupports> mFunctions;
/**
* Stores the registered progress handler for the database connection. Access
* is protected by mDBMutex.
*/
PRLock *mProgressHandlerMutex;
nsCOMPtr<mozIStorageProgressHandler> mProgressHandler;
// This is here for two reasons: 1) It's used to make sure that the

Просмотреть файл

@ -78,8 +78,8 @@ LOCAL_INCLUDES = \
LIBS = \
$(LIBS_DIR) \
$(XPCOM_GLUE_LDOPTS) \
$(NSPR_LIBS) \
$(LIBXUL_DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \
$(MOZ_COMPONENT_LIBS) \
$(SQLITE_LIBS) \
$(NULL)

Просмотреть файл

@ -656,6 +656,8 @@ nsresult SetupExtraData(nsILocalFile* aAppDataDirectory,
nsresult UnsetExceptionHandler()
{
delete gExceptionHandler;
// do this here in the unlikely case that we succeeded in allocating
// our strings but failed to allocate gExceptionHandler.
if (crashReporterAPIData_Hash) {
@ -681,7 +683,6 @@ nsresult UnsetExceptionHandler()
if (!gExceptionHandler)
return NS_ERROR_NOT_INITIALIZED;
delete gExceptionHandler;
gExceptionHandler = nsnull;
return NS_OK;

Просмотреть файл

@ -190,6 +190,10 @@ public:
operator FILE*() {
return mFile;
}
FILE* get() {
return mFile;
}
private:
FILE* mFile;
@ -409,7 +413,7 @@ static int ensure_remove(const char *path)
return rv;
}
static FILE* ensure_open(const char *path, char* flags, int options)
static FILE* ensure_open(const char *path, const char* flags, unsigned int options)
{
ensure_write_permissions(path);
FILE* f = fopen(path, flags);
@ -459,7 +463,7 @@ static int copy_file(const char *spath, const char *dpath)
AutoFile sfile = fopen(spath, "rb");
if (sfile == NULL || fstat(fileno(sfile), &ss)) {
LOG(("copy_file: failed to open or stat: %p,%s,%d\n", sfile, spath, errno));
LOG(("copy_file: failed to open or stat: %p,%s,%d\n", sfile.get(), spath, errno));
return READ_ERROR;
}
@ -1168,11 +1172,12 @@ LaunchWinPostProcess(const WCHAR *appExe)
static void
LaunchCallbackApp(const NS_tchar *workingDir, int argc, NS_tchar **argv)
{
putenv("NO_EM_RESTART=");
putenv("MOZ_LAUNCHED_CHILD=1");
putenv(const_cast<char*>("NO_EM_RESTART="));
putenv(const_cast<char*>("MOZ_LAUNCHED_CHILD=1"));
// Run from the specified working directory (see bug 312360).
NS_tchdir(workingDir);
if(NS_tchdir(workingDir) != 0)
LOG(("Warning: chdir failed"));
#if defined(USE_EXECV)
execv(argv[0], argv);

Просмотреть файл

@ -288,7 +288,6 @@ MAKEFILES_libimg="
MAKEFILES_libjar="
modules/libjar/Makefile
modules/libjar/standalone/Makefile
modules/libjar/test/Makefile
"

Просмотреть файл

@ -157,7 +157,7 @@ gboolean save_yourself_cb(GnomeClient *client, gint phase,
}
// Is there a request to suppress default binary launcher?
char* argv1 = getenv("MOZILLA_APP_LAUNCHER");
char* argv1 = getenv("MOZ_APP_LAUNCHER");
if(!argv1) {
// Tell GNOME the command for restarting us so that we can be part of XSMP session restore