Monday 16 October 2006
Journal
Last week we found out with Jouni how to workaround the problem of static datain dll for 1st and 2nd edition. It's quite simple... when we know how to do. Here are the big lines: If we need to have SHA224type and SHA256type as global reference (static data) for all our functions we start with
/* ============================================================================================= This structure embeed all the static object definition we would need. That will allow use to use TLS ============================================================================================= */ struct myWrapper { PyTypeObject SHA224type; PyTypeObject SHA256type; };
Then we'll create constant structures for both type:
const PyTypeObject SHA224typeConst = { PyObject_HEAD_INIT(NULL) 0, /*ob_size*/ "pys60crypto.sha224", /*tp_name*/ ... }; const PyTypeObject SHA256typeConst = { PyObject_HEAD_INIT(NULL) 0, /*ob_size*/ "pys60crypto.sha256", /*tp_name*/ ... };
Now we are about to set those data in the Tls:
PyMODINIT_FUNC init_sha256(void) { PyObject *m; /* first we create a pointer to a new myWrapper structure */ struct myWrapper* xx = new struct myWrapper; if (xx) { /* now we copy the data of SHA224typeConst & SHA256typeConst to the structure that will be accessible from every functions */ memcpy((PyTypeObject*)&xx->SHA224type, (PyTypeObject*) &SHA224typeConst, sizeof(SHA224typeConst)); memcpy((PyTypeObject*)&xx->SHA256type, (PyTypeObject*) &SHA256typeConst, sizeof(SHA256typeConst)); /* finaly we try to set the TLS with the myWrapper structure */ TRAPD(err, Dll::SetTls(xx)); if (err != KErrNone) { return; } ....
Quite simple isn't it? Only 3 weeks to figure that out :D