FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Template function argument changes address btw main exe and from inside shared object · Issue #109 · sba1/adtools · GitHub

Repository navigation

Template function argument changes address btw main exe and from inside shared object #109

Description

Build the following project :

sobj.h :

    #include <iostream>
    
    #define Q_DECL_EXPORT     __attribute__((visibility("default")))
    
    class Q_DECL_EXPORT Object
    {
    public:
      template <typename Func1>
        static inline  void connect(const Object *sender, Func1 signal)
        {
            std::cout << "From template : " << (void *)signal << "\n";
            connectImpl(sender, reinterpret_cast<void **>(&signal));
        }
    private:
        static void connectImpl(const Object *sender, void **signal);
    };
    
    class Q_DECL_EXPORT MyObject : public Object {
    public:
        MyObject();
    public:
        int signalFunction(int hello);
    };

sobj.cpp :

    #include "sobj.h"
    
    void Object::connectImpl(const Object *sender, void **signal)
    {
        std::cout << "From sobj : " << (void *)&MyObject::signalFunction << "\n";
    }
    
    MyObject::MyObject()
    {
        connect(this, &MyObject::signalFunction);
    }
    
    int MyObject::signalFunction(int hello)
    {
        hello++;
    }

main.cpp :

    #include "sobj.h"
        
    int main()
    {
        std::cout << "From main : " << (void *)&MyObject::signalFunction << "\n";
        MyObject o;
        return 0;
    }

Makefile :

    CXX           = ppc-amigaos-g++
    APP_CXXFLAGS      = -athread=native
    LINK          = ppc-amigaos-g++
    APP_LFLAGS        = -use-dynld -Wl,--export-dynamic -Wl,--no-undefined -athread=native
    
    APP_OBJECTS = main.o
    SOBJ_OBJECTS = sobj.o
    
    app: $(APP_OBJECTS) sobjs/sobj.so  
        $(LINK) $(APP_LFLAGS) -o app $(APP_OBJECTS) sobjs/sobj.so
    
    sobjs/sobj.so: $(SOBJ_OBJECTS)
        $(LINK) -shared -fPIC -o sobjs/sobj.so $(SOBJ_OBJECTS)
    
    sobj.o: sobj.cpp
        $(CXX) -c -fPIC -o sobj.o sobj.cpp
    
    main.o: main.cpp
        $(CXX) -c -o main.o main.cpp
    
    clean :
        rm *.o
        rm sobjs/sobj.so
        rm app

The resulting app will write different values for &MyObject::signalFunction, when run. They should of course be the same, which is why this is indeed a bug.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL