×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Mar 2005
    Location
    Bucharest, Romania
    Posts
    10

    'PYD has initialised data' Petran error

    Does anyone happen to know how to get around the problem of 'PYD has initialised data' error.

    Is there a way of making a PYD module, that has object(s) accessible to all methods from the module, and that are not in fact global. If you have a solution, please let me know (example code would be great).

    Thanks in advance,

    Dan

  2. #2
    Super Contributor
    Join Date
    Dec 2004
    Posts
    643

    Re: 'PYD has initialised data' Petran error

    Originally posted by gotzingerdan
    Does anyone happen to know how to get around the problem of 'PYD has initialised data' error.

    Is there a way of making a PYD module, that has object(s) accessible to all methods from the module, and that are not in fact global. If you have a solution, please let me know (example code would be great).

    Thanks in advance,

    Dan
    First, consider whether or not you _really_ need globals in your module. Could you pass the data to the functions as parameters?

    If you feel you really want to use globals, then at least these two approaches work:

    1. Make a struct that contains all your global data, allocate it from the heap in your module init function, and place a pointer to it in TLS. Then do something like this:

    MyGlobalData* gd = new MyGlobalData;
    if (!gd)
    return PyErr_NoMemory();
    else
    Dll::SetTls(gd);

    #define MYGLOBALS ((MyGlobalData *)Dll::Tls())

    You can then make a macro for accessing those variables:

    #define MyGlobalVar (MYGLOBALS->g_myGlobalVar)

    2. Place your variables into the module global dictionary, and access them using the function in symbian_python_ext_util.h. Then wrap SPyGetGlobal("myvariable") into a macro :

    #define MyGlobalObject ((GlobalObject*)SPyGetGlobalString("MyGlobalObject"))

    Note that both of these approaches cause access to those variables to be _significantly_ slower than access to normal variables. Dll:Tls() is a surprisingly expensive call and SPyGetGlobalString even more so, since it contains a Dll::Tls call and a hash table lookup. If you access them a lot in some function, you should cache the pointers from Dll:Tls() or SPyGetGlobalString into a local variable and access the structure using that.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Location
    Bucharest, Romania
    Posts
    10
    Thanks jplauril, it worked like a charm.

    On a similar note, would you happen to know (with an example ) how to implement PyTypeObject in PYDs. I just can't get one in there without the "initialized data" error.

    Thanks in advance,

    Dan

  4. #4
    Super Contributor
    Join Date
    Dec 2004
    Posts
    643
    Originally posted by gotzingerdan
    Thanks jplauril, it worked like a charm.

    On a similar note, would you happen to know (with an example ) how to implement PyTypeObject in PYDs. I just can't get one in there without the "initialized data" error.

    Thanks in advance,

    Dan
    Make a static const version of your type object that has all the fields filled in, and copy its' contents into a new type object allocated from the heap in your module initializer function. A handy way to do this is to simply add the type object to your TLS struct as a member. This way you can have a type object that is writable and that has all the values filled in properly.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •