- From: ak.miller at auckland.ac.nz (Andrew Miller)
- Subject: [cellml-dev] CellML wchar sizes
- Date: Tue, 01 Dec 2009 15:10:44 +1300
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");
Best wishes,
Andrew
>
If I don't, I get the error:
>
>
/home/lpsmith/xulrunner-sdk/include/xpcom/nsStringAPI.h:1054: error: size
>
of array 'arg' is negative
>
>
However, it seems you all managed to get around that incompatibility in
>
some other way when setting up the CellML API--there's no 'short-wchar'
>
flag anywhere in the Makefile that I can find. So presumably, the API's
>
compiled code thinks that wchar's are a different size than my own
>
compiled code's.
>
>
Does anyone know of a way to fix this?
>
>
-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.