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.

Compiler/TDA2EVM5777: Issue while overloading delete operator

Part Number: TDA2EVM5777

Tool/software: TI C/C++ Compiler

Hi All

I am working on overloading delete operator on A15 core which uses gcc-arm-none-eabi-4_7-2013q3 as the compiler.Below is the piece of code which i used

void operator delete(void *pfs)
{
printf("deleted address: %x \n", pfs);
free(pfs);

return;

}

void operator delete[](void *pfs)
{

operator delete(pfs);
}

void deletep(const char *file, int lineno)
{

const char *fname_delete;
fname_delete = print_file_name(file);
printf("Memory deleted @ file %s \t ", fname_delete);
printf("Line number %d \n ", lineno);
return;
}

#define new new(__FILE__, __LINE__)
#define delete deletep(__FILE__, __LINE__),delete

In the above code it compiles but when i execute this code the deletep function is not called.  When i run the same piece of code on linux platform which uses gcc 4.6 it executes the function(deletep) and then delete operator is gets overloaded with user provided function. I would like to know what is causing this wired behavior?

  • Please show us an example of code which calls your delete macro and for which the TI compiler fails to call deletep
  • Hi

    I can provide an example that works with linux , which is as follows

    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    void operator delete(void *);
    void operator delete[](void *);
    void deletep(const char *, int);

    inline const char * print_file_name(const char *path)
    {
    for (size_t i = strlen(path) - 1; i; i--)
    {
    if ((path[i] == '/') || (path[i] == '\\'))
    {
    return &path[i + 1];
    }
    }
    }

    void operator delete(void *pfs)
    {
    printf("deleted address: %x \n", pfs);
    free(pfs);
    return;
    }

    void operator delete[](void *pfs)
    {

    operator delete(pfs);
    }

    void deletep(const char *file, int lineno)
    {

    const char *fname_delete;
    fname_delete = print_file_name(file);
    printf("Memory deleted @ file %s \t ", fname_delete);
    printf("Line number %d \n ", lineno);

    return;
    }

    #define delete deletep(__FILE__, __LINE__),delete

    class aclass
    {
    private:
    int num;
    char mychar;
    public:
    aclass(int num, char mychar) :num(num), mychar(mychar) {}
    aclass() { num = 0; mychar = 'a'; }
    };

    int main(int argc, char *argv[])
    {
    int *a = new int(100);
    aclass *b = new aclass(100, 'b');
    aclass *c = new aclass[2];
    delete a;
    delete b;
    delete[] c;
    return 0;

    }
  • Make sure function print_file_name returns a value even when you don't find a directory separator in the pathname. When I fix this and compile with C6x compiler version 7.4.19, I get what appears to be the correct answer:

    Memory deleted @ file foo.cpp Line number 61
    deleted address: 80006008
    Memory deleted @ file foo.cpp Line number 62
    deleted address: 80006018
    Memory deleted @ file foo.cpp Line number 63
    deleted address: 80006028

    Make sure you have enough stack and heap space. What version of the compiler are you using?
  • Hi 

    Thanks for the reply. I am using gcc-arm-none-eabi-4_7-2013q3 compiler for A15. Can you please compile using the gcc version which i have mentioned and execute the program?

  • Hi,

    I was lending a hand on this issue and try to reproduce this on this specific setup. 

    Please check the attached project at the end of this post. It contains all the required parameters to GCC and I was able to run your testcase on my AM572x EVM board. 

    Note the project runs on the external DDR, thus requiring your target configuration to use a board (I am using the configuration in the screenshot above).  

    Hope this helps,

    Rafael

    AM572x_CA15_testcase.zip