A list for the developers of CellML tools

Text archives Help


[cellml-dev] CellML wchar sizes


Chronological Thread 
  • From: ak.miller at auckland.ac.nz (Andrew Miller)
  • Subject: [cellml-dev] CellML wchar sizes
  • Date: Wed, 02 Dec 2009 09:35:57 +1300

Lucian Smith wrote:
> * Andrew Miller <ak.miller at auckland.ac.nz> [2009-12-01 02:11] writes:
>> Lucian Smith wrote:
>>> I have the following code in my own program:
>>>
>>> cellml_api::CellMLBootstrap* boot = CreateCellMLBootstrap();
>>> wstring lev;
>>> lev = L"1.1";
>>> m_cellmlmodel = boot->createModel(lev.c_str());
>>>
>>> In GDB, I can look at lev.c_str()[0] - [3] and see that it is 49 46 49
>>> 00.
>>> So far, so good. However, once the program steps into the 'createModel'
>>> function, suddenly the passed-in string is no longer the same--it's
>>> 3014705 49 795046515 [etc etc]. And the wchar_t* is exactly the same,
>>> and
>>> if I do a 'frame 1' to go back to my code, *that* part still sees 49 46
>>> 49
>>> 0. The net result is that 'createModel' throws an exception because the
>>> passed-in 'version' is not what it thinks is "1.0" or "1.1".
>>>
>>> I think I can trace this down to the fact that in order to successfully
>>> #include <nsStringAPI.h>, I had to use the compiler flag '-fshort-wchar'.
>>>
>> Indeed - we need to be compatible with existing compiled libraries on
>> the system (which typically use 32 bit wchar_t strings), as well as with
>> XPCOM, so we have to explicitly convert between coding systems (see
>> http://cellml-api.hg.sf.net/hgweb/cellml-api/cellml-api/file/42412b41ed02/simple_interface_generators/glue/xpcom/WideCharSupport.cpp)
>>
>> For the API user, this means that you have two choices:
>> * Compile your code for use through XPCOM and only use the CellML API
>> through XPCOM (with the exception of setting up the bootstrap). In this
>> case build with -fshort-wchar
>> * Don't use XPCOM, don't include XPCOM headers like nsStringAPI.h,
>> and build without -fshort-wchar
>>
>> For example, you could compile your code with -fshort-wchar and write
>> what you had above as:
>>
>> nsresult rv;
>> nsCOMPtr<cellml_apiICellMLBootstrap>
>> boot(do_GetService(CELLML_BOOTSTRAP_CID, &rv));
>> NS_ENSURE_SUCCESS(rv, rv);
>> nsCOMPtr<cellml_apiIModel> mod;
>> rv = boot->CreateModel(NS_LITERAL_STRING("1.1"), getter_AddRefs(mod));
>> NS_ENSURE_SUCCESS(rv, rv);
>>
>> i.e. the same thing as what you already have, but using XPCOM instead
>> (note that I haven't checked that the above compiles, but it should at
>> least give you the idea of what you need to do if you want to access the
>> API through XPCOM from C++).
>>
>> OpenCell mainly accesses the API through Javascript where you can do a
>> similar thing using notation like
>>
>> Components.classes["@cellml.org/cellml-bootstrap;1"].getService(Components.interfaces.cellml_apiICellMLBootstrap).createModel("1.1");
>
> Am I right in assuming that if I want to use OpenCell's DataCollector
> library (cellml-opencell/opencellStage/components/libDataCollector.so ) I
> will need to use XPCOM, and write code like the above, in order to use
> functions like MathMLToInputFormat, which takes an nsCString as an
> argument?

Yes, unless you want to port it to not use XPCOM.

>
> If so, where do the functions 'boot' and 'do_GetService' come from (as
> well as the (I assume) #define's) from your example?

boot is not a function - this is C++ syntax for passing arguments to an
object constructor. nsCOMPtr<cellml_apiICellMLBootstrap> boot(x); means
make a new nsCOMPtr<cellml_apiICellMLBootstrap> called boot, call the
constructor, and pass x as an argument to the constructor. For an
nsCOMPtr, this sets the value of the nsCOMPtr (nsCOMPtr is a reference
counting pointer that will release the reference when it goes out of scope).

do_GetService is also part of the XPCOM nsCOMPtr template library - you
will get all that from nsCOMPtr.h I think.

See https://wiki.mozilla.org/Education/Learning/UsingXpcom for more
information on using nsCOMPtr.

NS_ENSURE_SUCCESS comes from nsDebug.h, and NS_LITERAL_STRING comes from
nsStringAPI.h. CELLML_BOOTSTRAP_CID may need to be pasted in from
CellMLBootstrapXPCOM.cpp explicitly, we don't seem to have a header for
it (but maybe we should consider this).
#define CELLML_BOOTSTRAP_CID \
{ /* 56849f69-c321-4be6-9191-1bb2ee0a76e0 */ \
0x56849f69, \
0xc321, \
0x4be6, \
{0x91, 0x91, 0x1b, 0xb2, 0xee, 0x0a, 0x75, 0xe0} \
}

Generally speaking, if you want to find some code in the Mozilla
codebase, search using http://mxr.mozilla.org/mozilla-central/

Note that the code you can use directly, without going through XPCOM, is in:
http://mxr.mozilla.org/mozilla-central/source/xpcom/glue
Everything else is generally accessed through XPCOM.

Best wishes,
Andrew

>
> -Lucian
> _______________________________________________
> cellml-tools-developers mailing list
> cellml-tools-developers at cellml.org
> http://www.cellml.org/mailman/listinfo/cellml-tools-developers





Archive powered by MHonArc 2.6.18.

Top of page