Hi Ehsan,

Yes, in my opinion that is the problem. I'm trying to use the global stream 
variable across module boundaries, more specifically from the following source 
files: content\base\src\Element.cpp; layout\style\nsCSSParser.cpp; 
content\base\src\nsINode.cpp, js\src\builtin\Eval.cpp, 
js\src\vm\Interpreter.cpp, js\src\jsfun.cpp, browser\app\nsBrowserApp.cpp, 
content\base\src\nsDocument.cpp, dom\base\nsGlobalWindow.cpp, 
parser\html\nsHtml5TreeOperation.cpp, 
content\html\document\src\nsHTMLContentSink.cpp 

So it's across at least two different modules.

I've tried to follow your advice in using MOZ_EXPORT and MOZ_IMPORT, but I'm 
not getting anywhere :-/ The application runs, but it crashes.

Of the top of your head, do you maybe know of a variable that is used in a 
similar way, so that I can look into how this is supposed to be done. 
For example, if I wanted to create a stream in nsBrowserApp.cpp and then use 
that stream from the other files what should I do? 

Do I put:

extern MOZ_EXPORT std::stringstream FC_LOG_STREAM; in that file (or in the 
header included from that file, and then i define the varible in the .cpp file) 
and then use MOZ_IMPORT std::stringstream FC_LOG_STREAM; in the other 
files/headers or?

Sorry for taking up your time, but getting into the source code of Firefox, 
especially since I've done very little real world development in C++ is a bit 
overwhelming. Any help will be appreciated!

Thank you


On Friday, October 24, 2014 7:26:00 PM UTC+2, Ehsan Akhgari wrote:
> It's hard to determine exactly what's happening because your post 
> doesn't explain where you're using this variable, but note that extern 
> variables cannot be used across module boundaries.  For example, 
> nsBrowserApp.cpp get compiled into firefox.exe, whereas most of our code 
> gets compiled in xul.dll.  If you define an extern variable somewhere in 
> firefox.exe, you cannot use it from xul.dll.  If you need this kind of 
> cross module access, you need to export a function/variable from one 
> module and import and call it in the other, using MOZ_EXPORT and 
> MOZ_IMPORT_API and friends.
> 
> On 2014-10-24 8:36 AM, Josip Maras wrote:
> > Hi,
> >
> > I'm extending the Firefox source in order to log some information during 
> > web app execution, for example event, script executions, new element 
> > creations, removals, attribute modifications, etc. Since these things occur 
> > often, when I load a more demanding application (e.g. facebook), everything 
> > hangs for a while, because there is a large number of relatively small 
> > pieces of information being written to a file.
> >
> > Because of this, i was thinking of doing it in batches, having one global 
> > extern stream variable where all longs are added to, and when enough 
> > information gets accumulated to write it to a file, and avoid these 
> > hangings.
> >
> > Since I'm a noob C++ "programmer" I will paste some code of what i've done, 
> > just in case:
> >
> > I have one header file with the extern variable:
> >
> > -- FC_ExternStreamDeclaration.h --
> >
> > #ifndef FC_EXTERN_VAR_DECL_H
> > #define FC_EXTERN_VAR_DECL_H
> >
> > #include <stdio.h>
> > #include <sstream>
> > #include <fstream>
> >
> > extern std::stringstream FC_LOG_STREAM;
> >
> > #endif //FC_EXTERN_VAR_DECL_H
> >
> >
> > and one header with the logging functionality
> >
> > -- FC_Log.h --
> >
> > #pragma once
> > #ifndef FC_LOG_H
> > #define FC_LOG_H
> >
> > #include <stdio.h>
> > #include <sstream>
> > #include <fstream>
> >
> > #include "FC_ExternStreamDeclaration.h"
> >
> > inline void WriteToStream(const char** fragments, int length)
> > {   
> >    //add to stream
> >    //if stream big enough write to file
> > }
> > #endif //FC_LOG_H
> >
> > and in nsBrowserApp.cpp where the main function is defined, i define the 
> > variable and include the headers
> >
> > ----- nsBrowserApp.cpp ---
> >
> > #include "FC_ExternStreamDeclaration.h"
> > #include "FC_Log.h"
> >
> > std::stringstream FC_LOG_STREAM;
> >
> > And then, in each file from which i do logging, i include the header files 
> > and call the WriteToStream function. For example, I'm doing it from 
> > Interpreter.cpp, Eval.cpp, nsINode.h, etc. (all over the code).
> >
> > And i thought that this will be enough. However, i get: error LNK2001 
> > unresolved external symbol stringstream FC_LOG_STREAM. If i define it 
> > there, the compilation succeeds, but I effectively get two different 
> > streams, one for the JavaScript execution, and the other for the DOM and 
> > the rest of the browser.
> >
> > I'm thinking this happens because these variables are in different dlls.
> > I would be grateful for any tips about fixing it.
> > Sorry for the long question.
> >
> > Thank you,
> >
> > Josip
> > _______________________________________________
> > dev-platform mailing list
> > dev-platform@lists.mozilla.org
> > https://lists.mozilla.org/listinfo/dev-platform
> >
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to