Backout bug 298047 per Chase as it breaks some downrev mac systems unexpectedly.

This commit is contained in:
bsmedberg%covad.net 2005-06-30 02:04:23 +00:00
Родитель f891816a6a
Коммит a451abf58c
16 изменённых файлов: 130 добавлений и 315 удалений

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

@ -147,7 +147,10 @@ MOZ_UI_LOCALE = @MOZ_UI_LOCALE@
MOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS = @MOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS@ MOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS = @MOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS@
MOZ_COMPONENT_NSPR_LIBS=@MOZ_COMPONENT_NSPR_LIBS@ MOZ_COMPONENT_NSPR_LIBS=@MOZ_COMPONENT_NSPR_LIBS@
ifdef MOZ_ENABLE_LIBXUL
MOZ_FIX_LINK_PATHS=@MOZ_FIX_LINK_PATHS@ MOZ_FIX_LINK_PATHS=@MOZ_FIX_LINK_PATHS@
endif
XPCOM_FROZEN_LDOPTS=@XPCOM_FROZEN_LDOPTS@ XPCOM_FROZEN_LDOPTS=@XPCOM_FROZEN_LDOPTS@
XPCOM_LIBS=@XPCOM_LIBS@ XPCOM_LIBS=@XPCOM_LIBS@
MOZ_REORDER=@MOZ_REORDER@ MOZ_REORDER=@MOZ_REORDER@

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

@ -242,18 +242,9 @@
#endif #endif
#ifdef MOZILLA_INTERNAL_API #ifdef MOZILLA_INTERNAL_API
# define NS_COM_GLUE NS_COM #define NS_COM_GLUE NS_COM
/*
The frozen string API has different definitions of nsAC?String
classes than the internal API. On systems that explicitly declare
dllexport symbols this is not a problem, but on ELF systems
internal symbols can accidentally "shine through"; we rename the
internal classes to avoid symbol conflicts.
*/
# define nsAString nsAString_internal
# define nsACString nsACString_internal
#else #else
# define NS_COM_GLUE #define NS_COM_GLUE
#endif #endif

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

@ -75,7 +75,6 @@ endif
CPPSRCS = \ CPPSRCS = \
$(XPCOM_GLUE_SRC_LCSRCS) \ $(XPCOM_GLUE_SRC_LCSRCS) \
$(XPCOM_GLUENS_SRC_LCSRCS) \
nsXPComInit.cpp \ nsXPComInit.cpp \
nsStringAPI.cpp \ nsStringAPI.cpp \
$(NULL) $(NULL)
@ -145,7 +144,7 @@ endif
# UNIX98 iconv support # UNIX98 iconv support
OS_LIBS += $(LIBICONV) OS_LIBS += $(LIBICONV)
GARBAGE += $(XPCOM_GLUE_SRC_LCSRCS) $(XPCOM_GLUENS_SRC_LCSRCS) $(wildcard *.$(OBJ_SUFFIX)) GARBAGE += $(XPCOM_GLUE_SRC_LCSRCS) $(wildcard *.$(OBJ_SUFFIX))
include $(topsrcdir)/config/rules.mk include $(topsrcdir)/config/rules.mk
@ -178,5 +177,5 @@ EXTRA_DSO_LDOPTS += $(call EXPAND_LIBNAME,imagehlp)
endif endif
endif # WINNT endif # WINNT
export:: $(XPCOM_GLUE_SRC_CSRCS) $(XPCOM_GLUENS_SRC_CSRCS) export:: $(XPCOM_GLUE_SRC_CSRCS)
$(INSTALL) $^ . $(INSTALL) $^ .

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

@ -58,7 +58,6 @@ LOCAL_INCLUDES = \
CPPSRCS = \ CPPSRCS = \
$(XPCOM_GLUE_SRC_LCSRCS) \ $(XPCOM_GLUE_SRC_LCSRCS) \
$(XPCOM_GLUENS_SRC_LCSRCS) \
$(NULL) $(NULL)
SDK_HEADERS = \ SDK_HEADERS = \

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

@ -270,11 +270,7 @@ public:
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#ifdef XPCOM_GLUE
#define NS_CheckThreadSafe
#else
#define NS_CheckThreadSafe(owningThread, msg) \ #define NS_CheckThreadSafe(owningThread, msg) \
NS_ASSERTION(owningThread == PR_GetCurrentThread(), msg) NS_ASSERTION(owningThread == PR_GetCurrentThread(), msg)
#endif
#endif /* nsDebug_h___ */ #endif /* nsDebug_h___ */

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

@ -44,6 +44,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "prenv.h"
#include "prio.h"
#include "plstr.h"
#ifdef XP_WIN32 #ifdef XP_WIN32
# include <windows.h> # include <windows.h>
# include <mbstring.h> # include <mbstring.h>
@ -59,7 +63,6 @@
#elif defined(XP_UNIX) #elif defined(XP_UNIX)
# include <unistd.h> # include <unistd.h>
# include <sys/param.h> # include <sys/param.h>
# include <dirent.h>
#elif defined(XP_BEOS) #elif defined(XP_BEOS)
# include <FindDirectory.h> # include <FindDirectory.h>
# include <Path.h> # include <Path.h>
@ -100,7 +103,7 @@ GRE_GetGREPathForVersion(const char *aVersion,
char *aBuffer, PRUint32 aBufLen) char *aBuffer, PRUint32 aBufLen)
{ {
// if GRE_HOME is in the environment, use that GRE // if GRE_HOME is in the environment, use that GRE
const char* env = getenv("GRE_HOME"); const char* env = PR_GetEnv("GRE_HOME");
if (env && *env) { if (env && *env) {
#if XP_UNIX #if XP_UNIX
if (realpath(env, aBuffer)) if (realpath(env, aBuffer))
@ -122,7 +125,7 @@ GRE_GetGREPathForVersion(const char *aVersion,
} }
// the Gecko bits that sit next to the application or in the LD_LIBRARY_PATH // the Gecko bits that sit next to the application or in the LD_LIBRARY_PATH
env = getenv("USE_LOCAL_GRE"); env = PR_GetEnv("USE_LOCAL_GRE");
if (env && *env) { if (env && *env) {
*aBuffer = nsnull; *aBuffer = nsnull;
return NS_OK; return NS_OK;
@ -164,7 +167,7 @@ GRE_GetGREPathForVersion(const char *aVersion,
return NS_OK; return NS_OK;
// Check ~/Library/Frameworks/XUL/Versions/<version>/libxpcom.dylib // Check ~/Library/Frameworks/XUL/Versions/<version>/libxpcom.dylib
const char *home = getenv("HOME"); const char *home = PR_GetEnv("HOME");
if (home && *home && GRE_FindGREFramework(aVersion, home, aBuffer, aBufLen)) { if (home && *home && GRE_FindGREFramework(aVersion, home, aBuffer, aBufLen)) {
return NS_OK; return NS_OK;
} }
@ -174,13 +177,13 @@ GRE_GetGREPathForVersion(const char *aVersion,
return NS_OK; return NS_OK;
} }
#elif defined(XP_UNIX) #elif defined(XP_UNIX)
env = getenv("MOZ_GRE_CONF"); env = PR_GetEnv("MOZ_GRE_CONF");
if (env && GRE_GetPathFromConfigFile(aVersion, env, aBuffer, aBufLen)) { if (env && GRE_GetPathFromConfigFile(aVersion, env, aBuffer, aBufLen)) {
return NS_OK; return NS_OK;
} }
env = getenv("HOME"); env = PR_GetEnv("HOME");
if (env && *env) { if (env && *env) {
char buffer[MAXPATHLEN]; char buffer[MAXPATHLEN];
@ -249,13 +252,6 @@ GRE_GetGREPathForVersion(const char *aVersion,
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
static PRBool IsConfFile(const char *filename)
{
const char *dot = strrchr(filename, '.');
return (dot && strcmp(dot, ".conf") == 0);
}
#ifdef XP_MACOSX #ifdef XP_MACOSX
PRBool PRBool
GRE_FindGREFramework(const char* version, const char* rootPath, GRE_FindGREFramework(const char* version, const char* rootPath,
@ -281,28 +277,33 @@ GRE_GetPathFromConfigDir(const char* version, const char* dirname,
// Open the directory provided and try to read any files in that // Open the directory provided and try to read any files in that
// directory that end with .conf. We look for an entry that might // directory that end with .conf. We look for an entry that might
// point to the GRE that we're interested in. // point to the GRE that we're interested in.
DIR *dir = opendir(dirname); PRDir *dir = PR_OpenDir(dirname);
if (!dir) if (!dir)
return nsnull; return nsnull;
PRBool found = PR_FALSE; PRBool found = PR_FALSE;
struct dirent *entry; PRDirEntry *entry;
while (!found && (entry = readdir(dir))) { while (!found && (entry = PR_ReadDir(dir, PR_SKIP_BOTH))) {
static const char kExt[] = ".conf";
// Only look for files that end in .conf // Only look for files that end in .conf
// IsConfFile will skip "." and ".." char *offset = PL_strrstr(entry->name, kExt);
if (!IsConfFile(entry->d_name)) if (!offset)
continue;
if (offset != entry->name + strlen(entry->name) - (sizeof(kExt) - 1))
continue; continue;
char fullPath[MAXPATHLEN]; char fullPath[MAXPATHLEN];
snprintf(fullPath, sizeof(fullPath), "%s" XPCOM_FILE_PATH_SEPARATOR "%s", snprintf(fullPath, sizeof(fullPath), "%s" XPCOM_FILE_PATH_SEPARATOR "%s",
dirname, entry->d_name); dirname, entry->name);
found = GRE_GetPathFromConfigFile(version, fullPath, buffer, buflen); found = GRE_GetPathFromConfigFile(version, fullPath, buffer, buflen);
} }
closedir(dir); PR_CloseDir(dir);
return found; return found;
} }

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

@ -382,6 +382,14 @@ nsGenericModule::GetClassObject(nsIComponentManager *aCompMgr,
desc++; desc++;
} }
// not found in descriptions // not found in descriptions
#ifndef XPCOM_GLUE
#ifdef DEBUG
char* cs = aClass.ToString();
fprintf(stderr, "+++ nsGenericModule %s: unable to create factory for %s\n", mModuleName, cs);
// leak until we resolve the nsID Allocator.
// nsCRT::free(cs);
#endif // XXX put in stop-gap so that we don't search for this one again
#endif
return NS_ERROR_FACTORY_NOT_REGISTERED; return NS_ERROR_FACTORY_NOT_REGISTERED;
} }

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

@ -45,13 +45,8 @@
#include "nsISupportsBase.h" #include "nsISupportsBase.h"
#endif #endif
#ifndef XPCOM_GLUE
// If we're being linked as standalone glue, we don't want a dynamic dependency
// on NSPR libs, so we skip the debug thread-safety checks.
#include "prthread.h" /* needed for thread-safety checks */ #include "prthread.h" /* needed for thread-safety checks */
#include "pratom.h" /* needed for PR_AtomicIncrement and PR_AtomicDecrement */ #include "pratom.h" /* needed for PR_AtomicIncrement and PR_AtomicDecrement */
#endif
#include "nsDebug.h" #include "nsDebug.h"
#include "nsTraceRefcnt.h" #include "nsTraceRefcnt.h"
@ -59,7 +54,7 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Macros to help detect thread-safety: // Macros to help detect thread-safety:
#if defined(NS_DEBUG) && !defined(XPCOM_GLUE) #if defined(NS_DEBUG)
class nsAutoOwningThread { class nsAutoOwningThread {
public: public:
@ -74,7 +69,7 @@ private:
#define NS_ASSERT_OWNINGTHREAD(_class) \ #define NS_ASSERT_OWNINGTHREAD(_class) \
NS_CheckThreadSafe(_mOwningThread.GetThread(), #_class " not thread-safe") NS_CheckThreadSafe(_mOwningThread.GetThread(), #_class " not thread-safe")
#else // !(defined(NS_DEBUG) && !defined(XPCOM_GLUE)) #else // !(defined(NS_DEBUG))
#define NS_DECL_OWNINGTHREAD /* nothing */ #define NS_DECL_OWNINGTHREAD /* nothing */
#define NS_ASSERT_OWNINGTHREAD(_class) ((void)0) #define NS_ASSERT_OWNINGTHREAD(_class) ((void)0)
@ -680,14 +675,10 @@ NS_IMETHODIMP_(nsrefcnt) Class::Release(void) \
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
/** /**
* *
* Threadsafe implementations of the ISupports convenience macros. * Threadsafe implementations of the ISupports convenience macros
* *
* @note These are not available when linking against the standalone glue,
* because the implementation requires PR_ symbols.
*/ */
#ifndef XPCOM_GLUE
/** /**
* Use this macro to implement the AddRef method for a given <i>_class</i> * Use this macro to implement the AddRef method for a given <i>_class</i>
* @param _class The name of the class implementing the method * @param _class The name of the class implementing the method
@ -725,15 +716,6 @@ NS_IMETHODIMP_(nsrefcnt) _class::Release(void) \
return count; \ return count; \
} }
#else // XPCOM_GLUE
#define NS_IMPL_THREADSAFE_ADDREF(_class) \
THREADSAFE_ISUPPORTS_NOT_AVAILABLE_IN_STANDALONE_GLUE;
#define NS_IMPL_THREADSAFE_RELEASE(_class) \
THREADSAFE_ISUPPORTS_NOT_AVAILABLE_IN_STANDALONE_GLUE;
#endif // XPCOM_GLUE
#define NS_IMPL_THREADSAFE_ISUPPORTS0(_class) \ #define NS_IMPL_THREADSAFE_ISUPPORTS0(_class) \
NS_IMPL_THREADSAFE_ADDREF(_class) \ NS_IMPL_THREADSAFE_ADDREF(_class) \
NS_IMPL_THREADSAFE_RELEASE(_class) \ NS_IMPL_THREADSAFE_RELEASE(_class) \

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

@ -38,21 +38,12 @@ XPCOM_GLUE_SRC_LCSRCS = \
nsCOMPtr.cpp \ nsCOMPtr.cpp \
nsComponentManagerUtils.cpp \ nsComponentManagerUtils.cpp \
nsDebug.cpp \ nsDebug.cpp \
nsGenericFactory.cpp \
nsIInterfaceRequestorUtils.cpp \ nsIInterfaceRequestorUtils.cpp \
nsMemory.cpp \ nsMemory.cpp \
nsTraceRefcnt.cpp \ nsTraceRefcnt.cpp \
nsWeakReference.cpp \ nsWeakReference.cpp \
nsGREGlue.cpp \ nsGREGlue.cpp \
$(NULL) $(NULL) \
XPCOM_GLUE_SRC_CSRCS := $(addprefix $(topsrcdir)/xpcom/glue/, $(XPCOM_GLUE_SRC_LCSRCS)) XPCOM_GLUE_SRC_CSRCS := $(addprefix $(topsrcdir)/xpcom/glue/, $(XPCOM_GLUE_SRC_LCSRCS))
# nsGenericFactory is not really all that helpful in the standalone glue,
# and it has a bad dependency on the NSPR AtomicIncrement function, so we
# only build it for the dependent XPCOM glue and builtin to xpcom-core.
XPCOM_GLUENS_SRC_LCSRCS = \
nsGenericFactory.cpp \
$(NULL)
XPCOM_GLUENS_SRC_CSRCS := $(addprefix $(topsrcdir)/xpcom/glue/,$(XPCOM_GLUENS_SRC_LCSRCS))

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

@ -182,13 +182,13 @@ GRE_GetCurrentProcessDirectory(char* buffer)
// We do this py putenv()ing the default value into the environment. Note that // We do this py putenv()ing the default value into the environment. Note that
// we only do this if it is not already set. // we only do this if it is not already set.
#ifdef MOZ_DEFAULT_MOZILLA_FIVE_HOME #ifdef MOZ_DEFAULT_MOZILLA_FIVE_HOME
if (getenv("MOZILLA_FIVE_HOME") == nsnull) if (PR_GetEnv("MOZILLA_FIVE_HOME") == nsnull)
{ {
putenv("MOZILLA_FIVE_HOME=" MOZ_DEFAULT_MOZILLA_FIVE_HOME); putenv("MOZILLA_FIVE_HOME=" MOZ_DEFAULT_MOZILLA_FIVE_HOME);
} }
#endif #endif
char *moz5 = getenv("MOZILLA_FIVE_HOME"); char *moz5 = PR_GetEnv("MOZILLA_FIVE_HOME");
if (moz5 && *moz5) if (moz5 && *moz5)
{ {
@ -332,7 +332,7 @@ GRE_GetXPCOMPath()
const char* grePath = GRE_GetGREPath(); const char* grePath = GRE_GetGREPath();
if (!grePath) { if (!grePath) {
grePath = getenv("MOZILLA_FIVE_HOME"); grePath = PR_GetEnv("MOZILLA_FIVE_HOME");
if (!grePath || !*grePath) { if (!grePath || !*grePath) {
return nsnull; return nsnull;
} }

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

@ -55,6 +55,8 @@
#include <mbstring.h> #include <mbstring.h>
#endif #endif
void GRE_AddGREToEnvironment();
// functions provided by nsDebug.cpp // functions provided by nsDebug.cpp
nsresult GlueStartupDebug(); nsresult GlueStartupDebug();
void GlueShutdownDebug(); void GlueShutdownDebug();
@ -109,6 +111,7 @@ nsresult XPCOMGlueStartup(const char* xpcomFile)
return rv; return rv;
} }
GRE_AddGREToEnvironment();
return NS_OK; return NS_OK;
#else #else
// //
@ -189,6 +192,7 @@ nsresult XPCOMGlueStartup(const char* xpcomFile)
if (NS_FAILED(rv)) if (NS_FAILED(rv))
goto bail; goto bail;
GRE_AddGREToEnvironment();
return NS_OK; return NS_OK;
bail: bail:
@ -514,6 +518,53 @@ NS_Free(void* ptr)
xpcomFunctions.freeFunc(ptr); xpcomFunctions.freeFunc(ptr);
} }
static char* spEnvString = 0;
void
GRE_AddGREToEnvironment()
{
#ifdef WINCE
return;
#else
const char* grePath = GRE_GetGREPath();
if (!grePath)
return;
const char* path = PR_GetEnv(XPCOM_SEARCH_KEY);
if (!path) {
path = "";
}
/**
* This buffer will leak at shutdown due to a restriction in PR_SetEnv
* See: https://bugzilla.mozilla.org/show_bug.cgi?id=25982#c3
* See-Also: http://lxr.mozilla.org/mozilla/source/nsprpub/pr/include/prenv.h
*/
char * tempPath = PR_smprintf(XPCOM_SEARCH_KEY "=%s" XPCOM_ENV_PATH_SEPARATOR "%s",
grePath, path);
if (tempPath){
if (PR_SetEnv(tempPath) == PR_SUCCESS){
if (spEnvString) PR_smprintf_free(spEnvString);
spEnvString = tempPath;
}else
PR_smprintf_free(tempPath);
}
#ifdef XP_WIN32
// On windows, the current directory is searched before the
// PATH environment variable. This is a very bad thing
// since libraries in the cwd will be picked up before
// any that are in either the application or GRE directory.
if (grePath) {
SetCurrentDirectory(grePath);
}
#endif // XP_WIN32
#endif // WINCE
}
// Default GRE startup/shutdown code // Default GRE startup/shutdown code
extern "C" extern "C"

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

@ -20,7 +20,6 @@
# the Initial Developer. All Rights Reserved. # the Initial Developer. All Rights Reserved.
# #
# Contributor(s): # Contributor(s):
# Benjamin Smedberg <benjamin@smedbergs.us>
# #
# Alternatively, the contents of this file may be used under the terms of # Alternatively, the contents of this file may be used under the terms of
# either of the GNU General Public License Version 2 or later (the "GPL"), # either of the GNU General Public License Version 2 or later (the "GPL"),
@ -43,9 +42,6 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk include $(DEPTH)/config/autoconf.mk
# This makefile builds the "program" subdirectory.
DIRS = program
# MODULE specifies where header files from this Makefile are installed, # MODULE specifies where header files from this Makefile are installed,
# i.e. dist/include/xpcomsample # i.e. dist/include/xpcomsample
MODULE = xpcomsample MODULE = xpcomsample
@ -69,6 +65,10 @@ IS_COMPONENT = 1
# name specified in NS_IMPL_NSGETMODULE # name specified in NS_IMPL_NSGETMODULE
MODULE_NAME = nsSampleModule MODULE_NAME = nsSampleModule
# Ensure that the xpcom classes that we build
# do not export themselves
DEFINES += -DXPCOM_GLUE
# CPPSRCS specifies C++ files to be built into a library. # CPPSRCS specifies C++ files to be built into a library.
CPPSRCS = \ CPPSRCS = \
nsSample.cpp \ nsSample.cpp \
@ -79,6 +79,11 @@ CPPSRCS = \
# files to generate C++ headers and .xpt typelib files. # files to generate C++ headers and .xpt typelib files.
XPIDLSRCS = nsISample.idl XPIDLSRCS = nsISample.idl
TESTCPPSRCS = nsTestSample.cpp
# SIMPLE_PROGRAMS builds an executable program from a single source file.
SIMPLE_PROGRAMS = $(TESTCPPSRCS:.cpp=$(BIN_SUFFIX))
include $(topsrcdir)/config/config.mk include $(topsrcdir)/config/config.mk
# EXTRA_COMPONENTS installs components written JavaScript to # EXTRA_COMPONENTS installs components written JavaScript to
@ -86,11 +91,16 @@ include $(topsrcdir)/config/config.mk
EXTRA_COMPONENTS = nsSample.js EXTRA_COMPONENTS = nsSample.js
# EXTRA_DSO_LDOPTS specifies linker flags when building a shared library # EXTRA_DSO_LDOPTS specifies linker flags when building a shared library
# from this Makefile. We link against the "dependent glue" and against the # from this Makefile
# frozen XPCOM shared library.
EXTRA_DSO_LDOPTS = \ EXTRA_DSO_LDOPTS = \
$(DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \ $(DIST)/lib/$(LIB_PREFIX)xpcomglue.$(LIB_SUFFIX) \
$(XPCOM_FROZEN_LDOPTS) \ $(NSPR_LIBS) \
$(NULL)
# LIBS specifies linker flags when building an executable program from
# this Makefile.
LIBS = \
$(DIST)/lib/$(LIB_PREFIX)xpcomglue.$(LIB_SUFFIX) \
$(NSPR_LIBS) \ $(NSPR_LIBS) \
$(NULL) $(NULL)

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

@ -1,80 +0,0 @@
#
# ***** 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.org code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Benjamin Smedberg <benjamin@smedbergs.us>
#
# Alternatively, the contents of this file may be used under the terms of
# 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"),
# 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 *****
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = xpcomsample
# We must specify CPPSRCS in order to link using the proper c++ linker
# on certain platforms.
CPPSRCS = nsTestSample.cpp
# SIMPLE_PROGRAMS compiles a single .cpp file into an executable
SIMPLE_PROGRAMS = nsTestSample$(BIN_SUFFIX)
# LIBS specifies linker flags when building an executable program from
# this Makefile. We link against the "standalone glue" which does not require
# that the application be linked against the XPCOM dynamic library or the NSPR
# dynamic libraries.
LIBS = \
$(XPCOM_STANDALONE_GLUE_LDOPTS) \
$(NULL)
# XXXbsmedberg temporary hack! The standalone glue still depends on NSPR
# except on mac; this will be fixed soon!
ifneq (Darwin,$(OS_ARCH))
LIBS += $(NSPR_LIBS)
endif
# Need to link with CoreFoundation on Mac
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
LIBS += \
$(TK_LIBS) \
$(NULL)
endif
# Whatever code is going to be linked with the *standalone* glue must be
# built with the XPCOM_GLUE define set.
DEFINES += -DXPCOM_GLUE
include $(topsrcdir)/config/rules.mk

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

@ -1,145 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Suresh Duddi <dp@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* 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"),
* 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 ***** */
/**
* A Test application that exercises the sample moudule. This is intented
* to be a sample application for using xpcom standalone.
*/
#include <stdio.h>
#include "nsXPCOMGlue.h"
#include "nsXPCOM.h"
#include "nsCOMPtr.h"
#include "nsISample.h"
#include "nsIServiceManager.h"
#include "nsIComponentManager.h"
#include "nsIComponentRegistrar.h"
#define NS_SAMPLE_CONTRACTID "@mozilla.org/sample;1"
int
main(void)
{
nsresult rv;
XPCOMGlueStartup(nsnull);
// Initialize XPCOM
nsCOMPtr<nsIServiceManager> servMan;
rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull);
if (NS_FAILED(rv))
{
printf("ERROR: XPCOM intialization error [%x].\n", rv);
return -1;
}
// register all components in our default component directory
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
registrar->AutoRegister(nsnull);
nsCOMPtr<nsIComponentManager> manager = do_QueryInterface(registrar);
NS_ASSERTION(registrar, "Null nsIComponentManager");
// Create an instance of our component
nsCOMPtr<nsISample> mysample;
rv = manager->CreateInstanceByContractID(NS_SAMPLE_CONTRACTID,
nsnull,
NS_GET_IID(nsISample),
getter_AddRefs(mysample));
if (NS_FAILED(rv))
{
printf("ERROR: Cannot create instance of component " NS_SAMPLE_CONTRACTID " [%x].\n"
"Debugging hint:\n"
"\tsetenv NSPR_LOG_MODULES nsComponentManager:5\n"
"\tsetenv NSPR_LOG_FILE xpcom.log\n"
"\t./nsTestSample\n"
"\t<check the contents for xpcom.log for possible cause of error>.\n",
rv);
return -2;
}
// Call methods on our sample to test it out.
rv = mysample->WriteValue("Inital print:");
if (NS_FAILED(rv))
{
printf("ERROR: Calling nsISample::WriteValue() [%x]\n", rv);
return -3;
}
const char *testValue = "XPCOM defies gravity";
rv = mysample->SetValue(testValue);
if (NS_FAILED(rv))
{
printf("ERROR: Calling nsISample::SetValue() [%x]\n", rv);
return -3;
}
printf("Set value to: %s\n", testValue);
char *str;
rv = mysample->GetValue(&str);
if (NS_FAILED(rv))
{
printf("ERROR: Calling nsISample::GetValue() [%x]\n", rv);
return -3;
}
if (strcmp(str, testValue))
{
printf("Test FAILED.\n");
return -4;
}
NS_Free(str);
rv = mysample->WriteValue("Final print :");
printf("Test passed.\n");
// All nsCOMPtr's must be deleted prior to calling shutdown XPCOM
// as we should not hold references passed XPCOM Shutdown.
servMan = 0;
registrar = 0;
manager = 0;
mysample = 0;
// Shutdown XPCOM
NS_ShutdownXPCOM(nsnull);
XPCOMGlueShutdown();
return 0;
}

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

@ -55,14 +55,9 @@ SIMPLE_PROGRAMS = $(CPPSRCS:.cpp=$(BIN_SUFFIX))
LIBS = \ LIBS = \
$(XPCOM_STANDALONE_GLUE_LDOPTS) \ $(XPCOM_STANDALONE_GLUE_LDOPTS) \
$(NSPR_LIBS) \
$(NULL) $(NULL)
# XXXbsmedberg temporary hack! The standalone glue still depends on NSPR
# except on mac; this will be fixed soon!
ifneq (Darwin,$(OS_ARCH))
LIBS += $(NSPR_LIBS)
endif
# Need to link with CoreFoundation on Mac # Need to link with CoreFoundation on Mac
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT))) ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
LIBS += \ LIBS += \

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

@ -59,6 +59,7 @@ static PRBool gUnreg = PR_FALSE, gQuiet = PR_FALSE;
static const char* gXPCOMLocation = nsnull; static const char* gXPCOMLocation = nsnull;
static const char* gCompRegLocation = nsnull; static const char* gCompRegLocation = nsnull;
static const char* gXPTIDatLocation = nsnull; static const char* gXPTIDatLocation = nsnull;
static char* gPathEnvString = nsnull;
class DirectoryServiceProvider : public nsIDirectoryServiceProvider class DirectoryServiceProvider : public nsIDirectoryServiceProvider
{ {
@ -119,10 +120,21 @@ int startup_xpcom()
free(xpcomPath); free(xpcomPath);
const char* path = getenv(XPCOM_SEARCH_KEY); const char* path = PR_GetEnv(XPCOM_SEARCH_KEY);
if (!path) { if (!path) {
path = ""; path = "";
} }
if (gPathEnvString)
PR_smprintf_free(gPathEnvString);
gPathEnvString = PR_smprintf("%s=%s;%s",
XPCOM_SEARCH_KEY,
gXPCOMLocation,
path);
if (gXPCOMLocation)
PR_SetEnv(gPathEnvString);
} }
else else
{ {
@ -179,6 +191,8 @@ void shutdown_xpcom()
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
printf("Can not shutdown XPCOM Glue cleanly\n"); printf("Can not shutdown XPCOM Glue cleanly\n");
} }
if (gPathEnvString)
PR_smprintf_free(gPathEnvString);
} }