News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

scriptbindings.cpp and GCC 4.1

Started by SharkCZ, August 06, 2006, 01:11:20 PM

Previous topic - Next topic

SharkCZ

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").
Code::Blocks package maintainer for Fedora and EPEL

SharkCZ

#1
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 ;-)


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
Code::Blocks package maintainer for Fedora and EPEL

TDragon

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.)
[url="https://jmeubank.github.io/tdm-gcc/"]https://jmeubank.github.io/tdm-gcc/[/url] - TDM-GCC compiler suite for Windows (GCC 9.2.0 2020-03-08, 32/64-bit, no extra DLLs)

SharkCZ

#3
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 ;-)


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);
}
Code::Blocks package maintainer for Fedora and EPEL

SharkCZ

Code::Blocks package maintainer for Fedora and EPEL

killerbot


mandrav

Be patient!
This bug will be fixed soon...

SharkCZ

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

mandrav

Quote from: 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.

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

killerbot

SharkCZ once again : super thanks !!!   :P :P :P :P

SharkCZ

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

SharkCZ

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

TDragon

Compiles and runs fine with GCC 4.1.1, Windows XP.
[url="https://jmeubank.github.io/tdm-gcc/"]https://jmeubank.github.io/tdm-gcc/[/url] - TDM-GCC compiler suite for Windows (GCC 9.2.0 2020-03-08, 32/64-bit, no extra DLLs)