[Bug 348426] Python extensions fail to build with libxul

r=benjamin@smedbergs.us, sr=jst


git-svn-id: svn://10.0.0.236/trunk@213164 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
mhammond%skippinet.com.au
2006-10-05 10:44:03 +00:00
parent 975a3fb3e5
commit d410bbfc5a
13 changed files with 90 additions and 62 deletions

View File

@@ -46,7 +46,7 @@
// (c) 2000, ActiveState corp.
#include "PyXPCOM_std.h"
#include "nsReadableUtils.h"
#include "nsStringAPI.h"
#include <nsIConsoleService.h>
#include "nspr.h" // PR_fprintf

View File

@@ -48,9 +48,7 @@ include $(DEPTH)/config/autoconf.mk
MODULE = pyxpcom
LIBRARY_NAME = pyxpcom
#MODULE_NAME =
REQUIRES = xpcom string $(NULL)
MOZILLA_INTERNAL_API = 1
FORCE_SHARED_LIB = 1
FORCE_USE_PIC = 1
@@ -83,10 +81,14 @@ CPPSRCS= \
$(NULL)
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/config/rules.mk
CXXFLAGS += -DPYTHON_SO=\"libpython$(MOZ_PYTHON_VER_DOTTED).so\"
EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_LIBS)
EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_LIBS) \
$(XPCOM_GLUE_LDOPTS) \
$(NULL)
include $(topsrcdir)/config/rules.mk
clobber::
rm -f *.ilk *.pdb *.exp *.lib *.pyd

View File

@@ -59,8 +59,9 @@
#include "nsIInputStream.h"
#include "nsIVariant.h"
#include "nsIModule.h"
#include "nsServiceManagerUtils.h"
#include "nsStringAPI.h"
#include "nsXPIDLString.h"
#include "nsCRT.h"
#include "xptcall.h"
#include "xpt_xdr.h"
@@ -77,6 +78,8 @@
#include <Python.h>
// PYXPCOM_EXPORT means 'exported from the pyxpcom core lib' - which changes
// spelling depending on whether pyxpcom is being built or just referenced.
#ifdef BUILD_PYXPCOM
/* We are building the main dll */
# define PYXPCOM_EXPORT NS_EXPORT

View File

@@ -49,10 +49,6 @@
// (c) 2000, ActiveState corp.
#include "PyXPCOM_std.h"
#include <nsIInterfaceInfoManager.h>
#include <nsAString.h>
#include <nsString.h>
#include <nsReadableUtils.h>
// ------------------------------------------------------------------------
// nsString utilities
@@ -116,16 +112,15 @@ PyObject_FromNSString( const nsACString &s, PRBool bAssumeUTF8 /*= PR_FALSE */)
Py_INCREF(Py_None);
} else {
if (bAssumeUTF8) {
const nsPromiseFlatCString& temp = PromiseFlatCString(s);
const nsCString temp(s);
ret = PyUnicode_DecodeUTF8(temp.get(), temp.Length(), NULL);
} else {
ret = PyString_FromStringAndSize(NULL, s.Length());
if (!ret)
return NULL;
// Need "CopyAsciiTo"!?
nsACString::const_iterator fromBegin, fromEnd;
char* dest = PyString_AS_STRING(ret);
copy_string(s.BeginReading(fromBegin), s.EndReading(fromEnd), dest);
PL_strncpy(dest, s.BeginReading(), s.Length());
}
}
return ret;
@@ -139,7 +134,7 @@ PyObject_FromNSString( const nsAString &s )
ret = Py_None;
Py_INCREF(Py_None);
} else {
const nsPromiseFlatString& temp = PromiseFlatString(s);
const nsString temp(s);
ret = PyUnicode_FromPRUnichar(temp.get(), temp.Length());
}
return ret;
@@ -988,13 +983,13 @@ PyXPCOM_InterfaceVariantHelper::~PyXPCOM_InterfaceVariantHelper()
}
}
if (ns_v.IsValDOMString() && ns_v.val.p) {
delete (const nsAString *)ns_v.val.p;
delete (const nsString *)ns_v.val.p;
}
if (ns_v.IsValCString() && ns_v.val.p) {
delete (const nsACString *)ns_v.val.p;
delete (const nsCString *)ns_v.val.p;
}
if (ns_v.IsValUTF8String() && ns_v.val.p) {
delete (const nsACString *)ns_v.val.p;
delete (const nsCString *)ns_v.val.p;
}
if (ns_v.IsValArray()) {
nsXPTCVariant &ns_v = m_var_array[i];

View File

@@ -47,6 +47,7 @@
#include "PyXPCOM_std.h"
#include "nsDirectoryServiceDefs.h"
#include "nsDirectoryServiceUtils.h"
#include "nsILocalFile.h"
#include "nsITimelineService.h"
@@ -131,7 +132,9 @@ void AddStandardPaths()
Py_XDECREF(newStr);
// And now try and get Python to process this directory as a "site dir"
// - ie, look for .pth files, etc
nsCAutoString cmdBuf(NS_LITERAL_CSTRING("import site;site.addsitedir(r'") + pathCBuf + NS_LITERAL_CSTRING("')\n"));
nsCAutoString cmdBuf(NS_LITERAL_CSTRING("import site;site.addsitedir(r'"));
cmdBuf.Append(pathCBuf);
cmdBuf.Append(NS_LITERAL_CSTRING("')\n"));
if (0 != PyRun_SimpleString((char *)cmdBuf.get())) {
PyXPCOM_LogError("The directory '%s' could not be added as a site directory", pathCBuf.get());
PyErr_Clear();

View File

@@ -47,7 +47,6 @@ include $(DEPTH)/config/autoconf.mk
LIBRARY_NAME = pyloader
IS_COMPONENT = 1
REQUIRES = pyxpcom xpcom string xpcom_obsolete $(NULL)
MOZILLA_INTERNAL_API = 1
FORCE_SHARED_LIB = 1
FORCE_USE_PIC = 1
@@ -68,8 +67,11 @@ CPPSRCS = \
include $(topsrcdir)/config/config.mk
EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_LIBS) \
$(XPCOM_GLUE_LDOPTS) \
$(NULL)
include $(topsrcdir)/config/rules.mk
EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_LIBS)
clobber::
rm -f *.ilk

View File

@@ -47,7 +47,6 @@ include $(DEPTH)/config/autoconf.mk
LIBRARY_NAME = _xpcom$(MOZ_PYTHON_DEBUG_SUFFIX)
REQUIRES = pyxpcom xpcom string $(NULL)
MOZILLA_INTERNAL_API = 1
FORCE_SHARED_LIB = 1
FORCE_USE_PIC = 1
@@ -71,9 +70,14 @@ include $(topsrcdir)/config/rules.mk
ifeq ($(OS_ARCH),Darwin)
# Don't use the EXTRA_DSO_LDOPTS from rules.mk, it breaks the python module
EXTRA_DSO_LDOPTS = -bundle $(MOZ_COMPONENT_LIBS)
EXTRA_DSO_LDOPTS = -bundle $(MOZ_COMPONENT_LIBS) \
$(XPCOM_GLUE_LDOPTS) \
$(NULL)
else
EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_LIBS)
EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_LIBS) \
$(XPCOM_GLUE_LDOPTS) \
$(NULL)
endif
IMPORT_LIBRARY := $(SHARED_LIBRARY:.pyd=.lib)

View File

@@ -52,6 +52,7 @@
#include "nsIComponentRegistrar.h"
#include "nsIConsoleService.h"
#include "nsDirectoryServiceDefs.h"
#include "nsDirectoryServiceUtils.h"
#include "nsILocalFile.h"
#include "nsTraceRefcntImpl.h"
@@ -475,10 +476,10 @@ static PRBool EnsureXPCOM()
{
static PRBool bHaveInitXPCOM = PR_FALSE;
if (!bHaveInitXPCOM) {
// xpcom appears to assert if already initialized
// Is there an official way to determine this?
// Been through lots of iterations - but getting the
// app directories appears to work.
// xpcom appears to assert if already initialized, but there
// is no official way to determine this! Sadly though,
// apparently this problem is not real ;) See bug 38671.
// For now, getting the app directories appears to work.
nsCOMPtr<nsIFile> file;
if (NS_FAILED(NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(file)))) {
// not already initialized.
@@ -503,16 +504,7 @@ static PRBool EnsureXPCOM()
nsCOMPtr<nsILocalFile> ns_bin_dir;
NS_ConvertASCIItoUTF16 strLandmark(landmark);
#ifdef NS_BUILD_REFCNT_LOGGING
// In an interesting chicken-and-egg problem, we
// throw assertions in creating the nsILocalFile
// we need to pass to InitXPCOM!
nsTraceRefcntImpl::SetActivityIsLegal(PR_TRUE);
#endif
NS_NewLocalFile(strLandmark, PR_FALSE, getter_AddRefs(ns_bin_dir));
#ifdef NS_BUILD_REFCNT_LOGGING
nsTraceRefcntImpl::SetActivityIsLegal(PR_FALSE);
#endif
nsresult rv = NS_InitXPCOM2(nsnull, ns_bin_dir, nsnull);
#else
// Elsewhere, Mozilla can find it itself (we hope!)