Author Topic: scriptbindings.cpp and GCC 4.1  (Read 11636 times)

Offline SharkCZ

  • Almost regular
  • **
  • Posts: 134
scriptbindings.cpp and GCC 4.1
« on: August 06, 2006, 01:11:20 pm »
I have played a bit with the scriptbindings.cpp with GCC 4.1 on Fedora development system and I have found that with the following patch I can compile the file. Couldn't be something wrong on the excluded lines? The problem with non-existent Push appears on line 337, so I have tried to exclude this line and some following and this is the result.


--- scriptbindings.cpp.orig   2006-08-06 12:56:11.000000000 +0200
+++ scriptbindings.cpp   2006-08-06 13:01:39.000000000 +0200
@@ -334,6 +334,7 @@
                 func(&CompileOptionsBase::SetLibDirs, "SetLibDirs").
                 func(&CompileOptionsBase::SetCommandsBeforeBuild, "SetCommandsBeforeBuild").
                 func(&CompileOptionsBase::SetCommandsAfterBuild, "SetCommandsAfterBuild").
+#if 0
                 func(&CompileOptionsBase::GetLinkerOptions, "GetLinkerOptions").
                 func(&CompileOptionsBase::GetLinkLibs, "GetLinkLibs").
                 func(&CompileOptionsBase::GetCompilerOptions, "GetCompilerOptions").
@@ -342,6 +343,7 @@
                 func(&CompileOptionsBase::GetLibDirs, "GetLibDirs").
                 func(&CompileOptionsBase::GetCommandsBeforeBuild, "GetCommandsBeforeBuild").
                 func(&CompileOptionsBase::GetCommandsAfterBuild, "GetCommandsAfterBuild").
+#endif
                 func(&CompileOptionsBase::GetModified, "GetModified").
                 func(&CompileOptionsBase::SetModified, "SetModified").
                 func(&CompileOptionsBase::AddLinkerOption, "AddLinkerOption").
« Last Edit: August 06, 2006, 01:13:18 pm by SharkCZ »
Code::Blocks package maintainer for Fedora and EPEL

Offline SharkCZ

  • Almost regular
  • **
  • Posts: 134
Re: scriptbindings.cpp and GCC 4.1
« Reply #1 on: August 06, 2006, 02:59:29 pm »
Oh, I see it - they are wxStringArray ;-)

But I was able to create an example with only 160 KB of preprocessed code which compiles cleanly with gcc 3.2 and gcc 3.4, but not with gcc 4.1. It is about 60 lines with classes definition and including only sqplus.h

Edit: Now I am on 32KB of preprocessed code and still shortening ;-)

Code
typedef char wxChar;

extern const wxChar* wxEmptyString;


class wxString
{
protected:
  wxChar *m_pchData;

  void Init() { m_pchData = (wxChar *)wxEmptyString; }
public:
  wxString() { Init(); }

  wxString(const wxString& stringSrc)
  {
      m_pchData = stringSrc.m_pchData;            // share same data
  }
};


class wxArrayString
{
public:
    wxArrayString() { }
    wxArrayString(const wxArrayString& a) { }
    wxArrayString(int sz, const wxChar** a);
    wxArrayString(int sz, const wxString* a);

};

class CompileOptionsBase
{
public:
CompileOptionsBase() {}
virtual ~CompileOptionsBase() {}

virtual const wxArrayString& GetLinkerOptions() const;
virtual const wxString& GetVar(const wxString& key) const;
virtual bool GetModified() const;
};

#include <sqplus.h>

DECLARE_INSTANCE_TYPE(wxString);
DECLARE_INSTANCE_TYPE(wxArrayString);
DECLARE_INSTANCE_TYPE(CompileOptionsBase);

namespace ScriptBindings
{
    void RegisterBindings()
    {
        SqPlus::SQClassDef<CompileOptionsBase>("CompileOptionsBase").
                func(&CompileOptionsBase::GetLinkerOptions, "GetLinkerOptions").
    func(&CompileOptionsBase::GetVar, "GetVar").
    func(&CompileOptionsBase::GetModified, "GetModified");
    }
} // namespace ScriptBindings
« Last Edit: August 06, 2006, 08:25:37 pm by SharkCZ »
Code::Blocks package maintainer for Fedora and EPEL

Offline TDragon

  • Lives here!
  • ****
  • Posts: 943
    • TDM-GCC
Re: scriptbindings.cpp and GCC 4.1
« Reply #2 on: August 06, 2006, 09:01:20 pm »
Excellent; if you can narrow this issue down to as small of a test case as possible, it can be submitted to the GCC bug/regression tracker. (There is another thread in the C::B forums dealing with this issue, though I fail to recall where.)
https://jmeubank.github.io/tdm-gcc/ - TDM-GCC compiler suite for Windows (GCC 9.2.0 2020-03-08, 32/64-bit, no extra DLLs)

Offline SharkCZ

  • Almost regular
  • **
  • Posts: 134
Re: scriptbindings.cpp and GCC 4.1
« Reply #3 on: August 07, 2006, 11:17:43 am »
Well, I am there - 90 lines and 1800 bytes. When take away the SqPlus namespace, the code compiles. So it looks like something between the templates and namespaces. When I move the Push(bool) and Push(int) down to the Push(string) or the other way Push(string) up to Push(bool), it compiles too. Really interesting compiler behaiour ;-)

Code
class String
{
public:
String();
};

class Base
{
public:
Base();

const String& GetString(const String& key) const;
bool GetBool() const;
};

namespace SqPlus {

template<class T>
struct TypeWrapper {
};

template<typename T>
T * GetInstance() {
return (T *)0;
}

inline void Push(bool value) { }
inline bool Get(TypeWrapper<bool>) { return *GetInstance<bool>(); }

inline void Push(int value) { }

template<class RT>
struct ReturnSpecialization {

template <typename Callee>
static void Call(Callee & callee,RT (Callee::*func)() const) {
RT ret = (callee.*func)();
Push(ret);
}

template <typename Callee,typename P1>
static void Call(Callee & callee,RT (Callee::*func)(P1) const) {
RT ret = (callee.*func)(Get(TypeWrapper<P1>()));
Push(ret);
}
};

template<typename Callee,typename RT>
void Call(Callee & callee, RT (Callee::*func)() const) {
ReturnSpecialization<RT>::Call(callee,func);
}

template<typename Callee,typename RT,typename P1>
void Call(Callee & callee,RT (Callee::*func)(P1) const) {
ReturnSpecialization<RT>::Call(callee,func);
}

template<typename Callee,typename Func>
inline void RegisterInstance(Callee & callee,Func func) {
Call(*(Callee *)0,*(Func *)0);
}

template<typename TClassType>
struct SQClassDef {
SQClassDef();

template<typename Func>
SQClassDef & func(Func pfunc) {
RegisterInstance(*(TClassType *)0,pfunc);
return *this;
}
};

inline void Push(const String & value) { }
inline const String & Get(TypeWrapper<const String &>) { return *GetInstance<String>(); }

inline void Push(Base * value) { }
inline Base & Get(TypeWrapper<Base &>) { return *GetInstance<Base>(); }
};

void RegisterBindings()
{
SqPlus::SQClassDef<Base>().
func(&Base::GetString).
func(&Base::GetBool);
}
« Last Edit: August 07, 2006, 11:36:56 am by SharkCZ »
Code::Blocks package maintainer for Fedora and EPEL

Offline SharkCZ

  • Almost regular
  • **
  • Posts: 134
Re: scriptbindings.cpp and GCC 4.1
« Reply #4 on: August 07, 2006, 12:00:16 pm »
Code::Blocks package maintainer for Fedora and EPEL

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: scriptbindings.cpp and GCC 4.1
« Reply #5 on: August 07, 2006, 12:12:47 pm »

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: scriptbindings.cpp and GCC 4.1
« Reply #6 on: August 07, 2006, 01:02:15 pm »
Thank you SharkCZ, excellent job :)
Be patient!
This bug will be fixed soon...

Offline SharkCZ

  • Almost regular
  • **
  • Posts: 134
Re: scriptbindings.cpp and GCC 4.1
« Reply #7 on: August 07, 2006, 05:23:42 pm »
So, the compiler is right and the code is wrong. Look at the bug in GCC Bugzilla.
Code::Blocks package maintainer for Fedora and EPEL

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: scriptbindings.cpp and GCC 4.1
« Reply #8 on: August 07, 2006, 07:37:14 pm »
So, the compiler is right and the code is wrong. Look at the bug in GCC Bugzilla.

SharkCZ, you 're a hero ;)
Fix commited (finally!) :lol:
Be patient!
This bug will be fixed soon...

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: scriptbindings.cpp and GCC 4.1
« Reply #9 on: August 07, 2006, 07:45:11 pm »
SharkCZ once again : super thanks !!!   :P :P :P :P

Offline SharkCZ

  • Almost regular
  • **
  • Posts: 134
Re: scriptbindings.cpp and GCC 4.1
« Reply #10 on: August 07, 2006, 08:59:06 pm »
We must also thank the GCC team, because they are really fast and they know what they are programming.
Code::Blocks package maintainer for Fedora and EPEL

Offline SharkCZ

  • Almost regular
  • **
  • Posts: 134
Re: scriptbindings.cpp and GCC 4.1
« Reply #11 on: August 08, 2006, 08:12:38 am »
I can confirm that svn rev 2824 not only compiles but also works on Fedora Development (to be FC6), gcc 4.1.1.
Code::Blocks package maintainer for Fedora and EPEL

Offline TDragon

  • Lives here!
  • ****
  • Posts: 943
    • TDM-GCC
Re: scriptbindings.cpp and GCC 4.1
« Reply #12 on: August 13, 2006, 08:20:38 pm »
Compiles and runs fine with GCC 4.1.1, Windows XP.
https://jmeubank.github.io/tdm-gcc/ - TDM-GCC compiler suite for Windows (GCC 9.2.0 2020-03-08, 32/64-bit, no extra DLLs)