Hi George,

Without a complete testcase (Test.cpp + Makefile), it's hard for me to replicate your problem exactly. I can only speculate as to what might be going on here.


George Zhang wrote:

Hi Darin,

Thank a lot for the comments. It's really encouraging if I can work around that by building
it in "the right way" !!! Sorry for a long message below. I use below sample app to check
your suggestion:
......
#include <gtkmozembed.h> #include <gtk/gtk.h>


int main(int argc, char **argv) {
gtk_init(&argc, &argv);


GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_signal_connect(GTK_OBJECT(window), "delete_event", GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
GtkWidget* gtkmoz = gtk_moz_embed_new();
gtk_container_add(GTK_CONTAINER(window), gtkmoz);
gtk_widget_show_all(window);


gtk_moz_embed_load_url(GTK_MOZ_EMBED(gtkmoz), "http://sceri";);


   gtk_main();
}

I build it with mozilla 1.4 using below setting, and it works both with 1.4 and 1.7.
......
c++ -o mozembed-test -fno-rtti -fno-exceptions -Wall -Wconversion -Wpointer-arith -Wcast-align -Woverloaded-virtual -Wsynth -Wno-ctor-dtor-privacy -pedantic -Wno-long-long -fshort-wchar -pthread
-pipe -DNDEBUG -DTRIMMED -O GtkMozEmbed.o -L/home/george/mozilla_all/mozilla1.4/mozilla/dist/bin -L/home/george/mozilla_all/mozilla1.4/mozilla/dist/lib -lgtkembedmoz -lmozjs -lpthread -ldl -Wl,--export-dynamic -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangoxft-1.0 -lpangox-1.0 -lpango-1.0 -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0 -lxpcom


Then I tried to add some new code (one new function), including:
......
nsCOMPtr<nsIStringInputStream> stream;
stream = do_CreateInstance(NS_STRINGINPUTSTREAM_CONTRACTID, &rv);
if (NS_FAILED(rv) || !stream)
{ ... }


     stream->AdoptData(tmp, nSize);
     headersStream = do_QueryInterface(stream);


Please note that do_CreateInstance is not part of GeckoSDK-1.4.2, so I do not think you should be using it. Using it in your application ties your application to the version of libxpcom.so that you compiled and linked it against. That could be a problem in the future even if it isn't showing up right now.

You should use NS_GetComponentManager, and then make calls on nsIComponentManager instead of relying on do_CreateInstance.


......
After I build it with the same setting, it works for 1.4, but there is below error with 1.7:
/>mozembed-test
mozembed-test: relocation error: mozembed-test: undefined symbol: _ZTV16nsQueryInterface




So, I changed the building setting following your suggestion:
......
c++ -o mozembed-linux-gtk2 -fno-rtti -fno-exceptions -Wall -Wconversion -Wpointer-arith -Wcast-align -Woverloaded-virtual -Wsynth -Wno-ctor-dtor-privacy -pedantic -Wno-long-long -fshort-wchar -pthread -pipe -DNDEBUG -DTRIMMED -O GtkMozEmbed.o -L/home/george/mozilla_all/mozilla1.4/mozilla/dist/bin -lgtkembedmoz -lmozjs -lpthread -ldl -Wl,--export-dynamic -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangoxft-1.0 -lpangox-1.0 -lpango-1.0 -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0 -L/home/george/mozilla_all/mozilla1.4/mozilla/dist/sdk/embedstring/bin -lembedstring -L/home/george/mozilla_all/mozilla1.4/mozilla/dist/sdk/embed_base/bin -lembed_base_s -L/home/george/mozilla_all/mozilla1.4/mozilla/dist/sdk/xpcom/bin -lxpcomglue_s -lxpcom -L/home/george/mozilla_all/mozilla1.4/mozilla/dist/sdk/nspr/bin -lnspr4 -lplds4 -lplc4


But it "Segmentation fault" with 1.7, the stack trace is:
(gdb) run
Starting program: /tmp/test_gtk/mozembed-test
[New Thread 1024 (LWP 2566)]



Hmm... nsQueryInterface is interesting because I know for a fact that 1) it is part of the xpcom/glue code, and 2) that it has changed between Mozilla 1.4 and 1.7. This crash appears to be caused by libxpcom.so from Mozilla 1.7 trying to use the version of nsQueryInterface from Mozilla 1.4. That can be solved by making sure that your executable does not "export" its version of nsQueryInterface.


Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1024 (LWP 2566)]
0x0805583d in nsQueryInterface::operator()(nsID const&, void**) const ()
(gdb) where
#0 0x0805583d in nsQueryInterface::operator()(nsID const&, void**) const ()
#1 0x40759f97 in nsCOMPtr_base::assign_from_qi(nsQueryInterface, nsID const&) ()
from /home/george/mozilla_all/mozilla1.7/mozilla/dist/bin/libxpcom.so
#2 0x407137e6 in FindProviderFile(nsISupports*, void*) ()
from /home/george/mozilla_all/mozilla1.7/mozilla/dist/bin/libxpcom.so
#3 0x4070398c in nsSupportsArray::EnumerateBackwards(int (*)(nsISupports*, void*), void*) ()
from /home/george/mozilla_all/mozilla1.7/mozilla/dist/bin/libxpcom.so
#4 0x4071393a in nsDirectoryService::Get(char const*, nsID const&, void**) ()
from /home/george/mozilla_all/mozilla1.7/mozilla/dist/bin/libxpcom.so
#5 0x406f6fb5 in NS_InitXPCOM2 () from /home/george/mozilla_all/mozilla1.7/mozilla/dist/bin/libxpcom.so
#6 0x40029f70 in NS_InitEmbedding () from /home/george/mozilla_all/mozilla1.7/mozilla/dist/bin/libgtkembedmoz.so
#7 0x40022622 in EmbedPrivate::PushStartup() ()
from /home/george/mozilla_all/mozilla1.7/mozilla/dist/bin/libgtkembedmoz.so
#8 0x40021c7f in EmbedPrivate::EmbedPrivate() ()
from /home/george/mozilla_all/mozilla1.7/mozilla/dist/bin/libgtkembedmoz.so
#9 0x4001faf5 in gtk_moz_embed_init(_GtkMozEmbed*) ()
from /home/george/mozilla_all/mozilla1.7/mozilla/dist/bin/libgtkembedmoz.so
#10 0x403f6859 in g_type_create_instance () from /usr/lib/libgobject-2.0.so.0
#11 0x403e460e in g_object_constructor () from /usr/lib/libgobject-2.0.so.0
#12 0x403e3f21 in g_object_newv () from /usr/lib/libgobject-2.0.so.0
#13 0x403e45ac in g_object_new_valist () from /usr/lib/libgobject-2.0.so.0
#14 0x403e3d04 in g_object_new () from /usr/lib/libgobject-2.0.so.0
#15 0x40248576 in gtk_type_new () from /usr/lib/libgtk-x11-2.0.so.0
#16 0x4001fb76 in gtk_moz_embed_new () from /home/george/mozilla_all/mozilla1.7/mozilla/dist/bin/libgtkembedmoz.so
#17 0x0804ec1c in main ()
#18 0x405a64c2 in __libc_start_main () from /lib/i686/libc.so.6


The output of "nm -uC mozembed-test" is:
/tmp/test_gtk> nm -uC mozembed-test
__ctype_tolower@@GLIBC_2.0
__cxa_pure_virtual@@CXXABI_1.2
free@@GLIBC_2.0
__gmon_start__
gtk_container_add
gtk_container_get_type
gtk_init
gtk_main
gtk_main_quit
gtk_moz_embed_get_nsIWebBrowser
gtk_moz_embed_get_type
gtk_moz_embed_load_url
gtk_moz_embed_new
gtk_object_get_type
gtk_signal_connect_full
gtk_widget_show_all
gtk_window_new
g_type_check_instance_cast
_Jv_RegisterClasses
__libc_start_main@@GLIBC_2.0
malloc@@GLIBC_2.0
memchr@@GLIBC_2.0
memcpy@@GLIBC_2.0
memmove@@GLIBC_2.0
NS_GetComponentManager
NS_GetMemoryManager
NS_GetServiceManager
NS_RegisterXPCOMExitRoutine
PL_strncasecmp
PR_AtomicDecrement
PR_AtomicIncrement
realloc@@GLIBC_2.0
sprintf@@GLIBC_2.0
strcpy@@GLIBC_2.0
_ZdaPv@@GLIBCPP_3.2
_ZdlPv@@GLIBCPP_3.2
nsAutoString::nsAutoString[not-in-charge]()


this symbol is going to be a problem... if your executable uses non-frozen string classes, then it won't be portable to future versions of Mozilla. if you are compiling against mozilla 1.4, then you should be using nsEmbedString and nsEmbedCString whenever you need a Mozilla string object.


NS_ConvertASCIItoUCS2::Init(char const*, unsigned)
nsString::SetCapacity(unsigned)
nsString::GetWritableFragment(nsWritableFragment<unsigned short>&, nsFragmentRequest, unsigned)
nsString::do_AppendFromElement(unsigned short)
nsString::SetLength(unsigned)
nsString::~nsString [not-in-charge]()
_Znaj@@GLIBCPP_3.2
nsString::GetFlatBufferHandle() const
nsString::GetReadableFragment(nsReadableFragment<unsigned short>&, nsFragmentRequest, unsigned) const
_Znwj@@GLIBCPP_3.2
.................


Any more ideas I can try out ?


be careful with gtkembedmoz... it uses many internal Mozilla APIs. you should make sure that the version of gtkembedmoz that you are using is matched with the version of Mozilla that you are using. Do not try to mix the version of gtkembedmoz from Mozilla 1.4 with Mozilla 1.7!


-Darin



Much appreciated !

-George.

If you build your app against 1.4 in "the right way", then it will work in 1.4 though 1.7. Make sure that when you build against the 1.4 gecko sdk, that you link against libembedstring, libxpcomglue, and libxpcom, like this:

-L$(GECKO_SDK)/embedstring/bin -lembedstring \
-L$(GECKO_SDK)/xpcom/bin -lxpcomglue_s -lxpcom \
-L$(GECKO_SDK)/nspr/bin -lnspr4 -lplds4 -lplc4

If you are using NS_InitEmbedding and NS_TermEmbedding, then you should change this link line to:

-L$(GECKO_SDK)/embedstring/bin -lembedstring \
-L$(GECKO_SDK)/embed_base/bin -lembed_base_s \
-L$(GECKO_SDK)/xpcom/bin -lxpcomglue_s -lxpcom \
-L$(GECKO_SDK)/nspr/bin -lnspr4 -lplds4 -lplc4

Doing this ensures that your executable has a copy of the 1.4 version of the string code. This is necessary since the string classes were never frozen, only the vtable for the string classes was frozen. The vtable is unchanged in 1.7, so a string object from the 1.4 code can be used safely by mozilla 1.7.

If you encounter further trouble, please provide the link commands that you are using. It might also be good if you provided the output of "nm -uC mozembed-test"

Regards,

-Darin


George Zhang wrote:

Hi,
I'm working to embedding Mozilla in a Java app/library. On Linux, I modified the test app (located in <MOZILLA_SRC_HOME>/embedding/browser/gtk/tests/) for Gtk Mozilla embedding widget, to add features like profile management, post data, etc.


After building it with Mozilla 1.4, it works well with Mozilla 1.4. It also works with 1.7 if the source is built with the 1.7 source.

But the executable built with Mozilla 1.4 doesn't work with Mozilla 1.7.
there is below error:
~> ./mozembed-test
./mozembed-test: relocation error: ./mozembed-test: undefined symbol:
_ZTV9nsAString


Seems that it's due to the modified code links to XPCOM APIs, and XPCOM libraries
changed between 1.4 and 1.7.


Though I want to use XPCOM Glue, but it only provides limited APIs, not satisfying
the new code. Which looks like quite a common problem, how an application work around the dependency on XPCOM APIs, since it keeps changing between Mozilla version?


Are there any other solutions to that ? or examples on how other apps solve the problem ? Thanks for any fixes or comments !

George.

_______________________________________________
Mozilla-xpcom mailing list
[EMAIL PROTECTED]
http://mail.mozilla.org/listinfo/mozilla-xpcom




_______________________________________________
Mozilla-xpcom mailing list
[EMAIL PROTECTED]
http://mail.mozilla.org/listinfo/mozilla-xpcom




_______________________________________________
Mozilla-xpcom mailing list
[EMAIL PROTECTED]
http://mail.mozilla.org/listinfo/mozilla-xpcom


_______________________________________________
Mozilla-xpcom mailing list
[EMAIL PROTECTED]
http://mail.mozilla.org/listinfo/mozilla-xpcom

Reply via email to