This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

XDCtools - Module instance names should be xdc_CString

Hi,

Currently XDCtools define:

struct xdc_runtime_IInstance_Params {
    size_t __size;
    xdc_String name;
};

However, there is no reason for the module name to be mutable string. There is no place where the name buffer is accessed and modified. So it shall be changed to xdc_CString, otherwise an error is generated when the module name is initialized with const string.

P.S. I wanted to patch it myself and try it out, however, I don't fully understand how I can rebuild the XDCtools package.

Best,
Vasili

  • Vasili,
    it's true that there is no place in XDCtools runtime code where the buffer is modified. A user may need to modify that buffer after the assignment, as in the artificial example below but I guess it's not commonly done.
    Still, I don't want to promise you we will make that change until I examine if the change impacts backward compatibility with packages built with older XDCtools.

    Mod_Params params;

    /* create a "dynamic" instance */
    Mod_Params_init(&params);
    params.instance->name = "boom";
    if (whatever condition) {
        params.instance->name[0] = 'r';
    }

    inst = Mod_create(&params, NULL);

     

  • Hi Sasha,

    Indeed a code like you showed won't be possible. However, I doubt that one would need to do such thing as modifying the object name. If one does - she always can allocate a new buffer (or store non constant pointer to same buffer somewhere).

    On the other hand, having the pointer mutable as it is now, leads us to the following problem. Consider this code:

    params.instance->name = "MyName";

    It will compile in C language, but leads to undefined behaviour if one tries to modify the buffer using the pointer.

    In C++ language, it will generate a warning, as the conversion from string literal to char* is deprecated (since string literal is essentially constant).

    It's up to you to consider which one is the least evil :-)

    Best,
    Vasili

  • Vasili,
    I have filed an enhancement request:
    https://bugs.eclipse.org/bugs/show_bug.cgi?id=433467

    You can add your email to the CC list if you want to receive updates.

    As for your second question, how to rebuild XDCtools, your first step would be to go to the directory xdc/runtime in your XDCtools installation and then run the xdc command. You are probably going to get a warning about a missing config.bld file, but it's safe to ignore it for that specific package. Once you rebuild xdc.runtime, follow the steps here:
    http://rtsc.eclipse.org/docs-tip/Working_with_xdc.runtime#Re-building_xdc.runtime_Support_Packages

     

  • Thank you very much!