Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Topic started by: SharkCZ on August 06, 2006, 01:11:20 pm

Title: scriptbindings.cpp and GCC 4.1
Post by: SharkCZ 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").
Title: Re: scriptbindings.cpp and GCC 4.1
Post by: SharkCZ 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
Title: Re: scriptbindings.cpp and GCC 4.1
Post by: TDragon 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.)
Title: Re: scriptbindings.cpp and GCC 4.1
Post by: SharkCZ 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);
}
Title: Re: scriptbindings.cpp and GCC 4.1
Post by: SharkCZ on August 07, 2006, 12:00:16 pm
It is filled as http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28631 (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28631)
Title: Re: scriptbindings.cpp and GCC 4.1
Post by: killerbot on August 07, 2006, 12:12:47 pm
It is filled as http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28631 (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28631)

many many thanks for your research !!!
Title: Re: scriptbindings.cpp and GCC 4.1
Post by: mandrav on August 07, 2006, 01:02:15 pm
Thank you SharkCZ, excellent job :)
Title: Re: scriptbindings.cpp and GCC 4.1
Post by: SharkCZ 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.
Title: Re: scriptbindings.cpp and GCC 4.1
Post by: mandrav 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:
Title: Re: scriptbindings.cpp and GCC 4.1
Post by: killerbot on August 07, 2006, 07:45:11 pm
SharkCZ once again : super thanks !!!   :P :P :P :P
Title: Re: scriptbindings.cpp and GCC 4.1
Post by: SharkCZ 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.
Title: Re: scriptbindings.cpp and GCC 4.1
Post by: SharkCZ 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.
Title: Re: scriptbindings.cpp and GCC 4.1
Post by: TDragon on August 13, 2006, 08:20:38 pm
Compiles and runs fine with GCC 4.1.1, Windows XP.