Function parameter problem

Started by
18 comments, last by Heuristics 11 years, 6 months ago
I've updated the code::blocks project files in revision 1431.

I tried installing mingw too, but the installer from the mingw site appears to only install version 4.6, not 4.7. The mingw version that comes with code::blocks is even older.

Where do you get version 4.7 from? Is it necessary to download each file manually?

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement
I think I did something like getting this file: http://sourceforge.net/projects/mingw/files/Installer/mingw-get-inst/mingw-get-inst-20120426/
and during the installation I picked "download latest repository catalogues". From checking now that appears to download mingw 4.7
Thanks, I'll give that a try.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I'm making some progress.

However, there are more changes in MinGW 4.7 than I had expected. It will be a while longer before I can complete all the changes and tests needed to get this fully working.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

It appears that I made a break-through. As of revision 1435, all tests pass successfully with MinGW32 4.7.0 and 4.6.2.

The MinGW developers made some strange choices with the new ABI. For the most part they seem to have wanted to more closely follow the MS ABI, most likely to make it easier to use the many dlls available, but in some cases they ended up with something that is neither like the MS ABI nor the GNUC ABI. This doesn't make any sense at all to me, and quite frankly I believe they may very well change it again with a future version.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Great to hear!

I tested it as well with my own code and it does indeed appear to work. Thanks a lot, I very much appreciate the very quick fix to this issue. I now get to use fancy c++11 features with angelscript :)

Strange about the ABI though, but then again I know little about such things. But I do know that it is sometimes hard to understand how the GNU devs pick their priorities.
Hello again.

I extended my little test code with using a class as value instead of as reference and then it crashes in mingw 4.7.0 but works fine in 4.6.0. Perhaps this is another problem? (or I might just be doing it wrong :) )

Here is the modified example: http://pastebin.com/27BzeQcy
That it works on 4.6, but not on 4.7 does seem to indicate the problem is related to the changes done in MinGW, but I'll need to investigate it to be sure.

I'll let know when I figure it out. Thanks.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

The problem was not with MinGW after all.

You've implemented the constructor and destructor incorrectly. They should be global functions, or static members, and registered with asCALL_CDECL_OBJLAST instead of asCALL_THISCALL.

It didn't crash on MinGW 4.6.0 because before 4.7 the thiscall was practically identical to the cdecl calling convention.


class Person {
public:
Person() {cout<<(int)this<<endl;this->counter = 1;}
static void Constructor(void *memory) {new(memory) Person();}
static void Destructor(void *memory) {((Person*)memory)->~Person();}
void printTwoInts(int a, int b) { cout << (int)this << " " << a << " " << b << endl; }
void AddRef() {cout<<this<<" 1 "<<this->counter;}
void ReleaseRef() {cout<<this<<" 2 "<<this->counter;}
static Person *refFactory() {
return new Person();
};
int counter;
};

void main()
{
...
asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL);
r = engine->RegisterObjectType("Person", sizeof(Person), asOBJ_VALUE | asOBJ_POD); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("Person", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(Person::Constructor), asCALL_CDECL_OBJLAST); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("Person", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(Person::Destructor), asCALL_CDECL_OBJLAST); assert( r >= 0 );

r = engine->RegisterObjectMethod("Person", "void printTwoInts(int a, int b)", asMETHOD(Person, printTwoInts), asCALL_THISCALL);assert( r >= 0 );
}


Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Ah!

That makes sense, I feel a bit silly now :) (was mislead by it not crashing on 4.6.0). Sorry about that. But thank you very much for your help again!

This topic is closed to new replies.

Advertisement