Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

opEquals now doen't work


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
13 replies to this topic

#1 Papirosnik   Members   -  Reputation: 125

Like
0Likes
Like

Posted 14 November 2012 - 03:17 PM

Hi.
I've got one question and one suggestion (not related).

The questions is: What happened with opEquals operator?
In earlier versions this code worked properly:
r |= ase->RegisterObjectMethod("Color", "bool opEquals(const Color &in) const", asMETHODPR(Color, operator==, (const Color &in) const, bool), asCALL_THISCALL);
  r |= ase->RegisterObjectMethod("Color", "bool opEquals(const Color &in) const", asMETHODPR(Color, operator!=, (const Color &in) const, bool), asCALL_THISCALL);
But in 2.25.1 I get r = -1 after execution of the second line.
How can I get working operator!= ?

the suggestion:
I use angelscript within marmalade sdk and upon the whole all works fine...excluding one moment:
The marmalade memory manager doesn't like static non-POD (plain of data) objects. Often in that case It detects that there are some memory leaks. Are there really memory leaks or not - I can't judge, but those assertions are annoying.
In particular, within StringFactory function (scriptstdstring.cpp) there is such line:
static string dummy;
Marmalade memory manager considers that here is memory leak.
My workaround is take out this line from StringFactory body:
static string dummy;
static const string &StringFactory(asUINT length, const char *s)
I can't say why this workaround works but it works.
Now marmalade doesn't see any memory leaks.

Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3263

Like
0Likes
Like

Posted 14 November 2012 - 04:01 PM

You shouldn't register the operator!=() method. AngelScript handles both == and != with the same opEquals() method. In previous versions AngelScript wasn't detecting that you registered the same method multiple times but this doesn't mean that it worked the way you think. In fact it only worked for you because AngelScript ignored the registration of the operator!=() method, since it only expected a single method to be found.

About the warning in Marmalade. I think you should take this up with the Marmalade developers. It's not a memory leak to return a static local variable. In fact a static local variable is identical to a global variable, except that it is only visible from within the function, and only initialized upon first entry. The variable will be uninitialized upon exiting the application just like any other global variable.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#3 Papirosnik   Members   -  Reputation: 125

Like
0Likes
Like

Posted 15 November 2012 - 02:39 AM

Andreas, thank you for your answer.

operator!= is thrown now from the registration list )

About memory leak...actually there is no real  memory leak there.
But if some memory deallocations on the heap occur after the marmalade memory manager finalization - it considers that there is a memory leak.
Many of static objects (on the heap) will be deallocated after last line of code (where memory manager will be finalized).
The order of their allocation/deallocation may be a bit confusing.
And Marmalade developers cannot do anything with such static objects behaviour.
The only thing that they can do is to recommend don't use static non-POD objects.

So I'm happy that I managed to find the workaround that allows to shut up that annoying assertions.
I am sure that the windows with assertions about memory leaks irritate not only me (someone can  even get scared).

Edited by Papirosnik, 15 November 2012 - 02:42 AM.


#4 Andreas Jonsson   Moderators   -  Reputation: 3263

Like
0Likes
Like

Posted 15 November 2012 - 08:49 AM

The problem is that Marmalade tries to detect the memory leaks before the program has even finished. The memory manager needs to replace the default memory manager in the runtime library itself so it is there even before the main function is invoked, and still there after the main function ends. It seems to me that Marmalade already uses their own runtime library so it doesn't seem like it should be that difficult to keep the memory manager until the very end.

Still, I don't mean to question them. I just don't like being forced not to use proper C++, i.e. static local variables, due to limitations in a third party library.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#5 Papirosnik   Members   -  Reputation: 125

Like
0Likes
Like

Posted 15 November 2012 - 10:53 AM

Yes, you are right.
With marmalade we need to initialize graph unit via IwGxInit invoking and finalize it before the completion of the application (via IwGxTerminate).
and the marmalade memory manager is initialized and finalized inside this functions.
We cannot affect it and static objects are freed after the memory manager has completed its work.
But my workaround for some reason works.
You are not forced don't use static string variable. My suggestion is just declare it a bit in another place.
Thank you anyway.

#6 Andreas Jonsson   Moderators   -  Reputation: 3263

Like
0Likes
Like

Posted 15 November 2012 - 11:37 AM

My guess is that it works because by moving the static variable out of the function it will be initialized before you call lwGxInit, and thus won't be accounted for when lwGxTerminate is called.

My problem with this is that it restricts the use of static local variables which is a common optimization technique. Declaring the variables globally works, but clutters the global namespace with variables that shouldn't be seen there.

Still, I'll probably change it. After all, my goal with AngelScript is to keep it as portable as possible.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#7 Papirosnik   Members   -  Reputation: 125

Like
0Likes
Like

Posted 16 November 2012 - 01:56 AM

what's about namespace and/or unique names?

namespace AngelScript
{
	 ststic string dummyStringForStringFactoryRoutineToAvoidProblemsWithMarmaladeMemoryManager; // <img src='http://public.gamedev.net//public/style_emoticons/<#EMO_DIR#>/smile.png' class='bbc_emoticon' alt=':)' />
}

static const string &amp;amp;StringFactory(asUINT length, const char *s)
{
	 ...
	 AngelScript::dummyStringForStringFactoryRoutineToAvoidProblemsWithMarmaladeMemoryManager = "";
	 ...
}

Edited by Papirosnik, 16 November 2012 - 01:59 AM.


#8 Andreas Jonsson   Moderators   -  Reputation: 3263

Like
0Likes
Like

Posted 16 November 2012 - 07:49 AM

I think you'll agree with me that it is not a very nice solution. :)

But don't worry this. I'd prefer using static local variables but as these don't work, static global variables are the next best thing.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#9 Papirosnik   Members   -  Reputation: 125

Like
0Likes
Like

Posted 16 November 2012 - 01:03 PM

I think you'll agree with me that it is not a very nice solution. Posted Image


Yes, of course. )

And advantages of AngelScript are so strong that we can close our eyes even if there will be real memory leaks.
Thank for your work.
Have fun with your creativity.

Edited by Papirosnik, 16 November 2012 - 01:04 PM.


#10 Andreas Jonsson   Moderators   -  Reputation: 3263

Like
0Likes
Like

Posted 17 November 2012 - 09:14 AM

I've changed the static variable, and the comment style in the assembler code.

Would you mind testing revision 1474 with Marmalade to see if there is anything else that needs changes?
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#11 Papirosnik   Members   -  Reputation: 125

Like
0Likes
Like

Posted 19 November 2012 - 03:50 PM

I've tested 1474 revision.
it seems all works properly.....
The comments are correct from now
Fake warnings about memory leaks went away...although

There is a lot of warnings about comparison between signed and unsigned integer expressions

for example in scriptsstdstrings.cpp:
bool leftJustify = options.find("l") != -1;

I also wrote earlier so because it is very short and convenient way. But marmalade gcc compiler doesn't like such scriptures.
It wants something like this:

bool leftJustify = options.find("l") != std::string::npos;
or at least
bool leftJustify = options.find("l") != 0xFFFFFFFF;

Those warnings can be boldly ignored
But their count is significant and
between them may be overlooked some important warnings

PS. MS VS compiler silently permits those comparisons.

Edited by Papirosnik, 19 November 2012 - 03:52 PM.


#12 Andreas Jonsson   Moderators   -  Reputation: 3263

Like
0Likes
Like

Posted 19 November 2012 - 06:34 PM

If you can post the full compiler output I'll gladly take a look at it and fix what I can. Some compiler are overly critical on the code, but usually it is just smaller adjustments needed to make the compiler happy.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#13 Papirosnik   Members   -  Reputation: 125

Like
0Likes
Like

Posted 20 November 2012 - 03:30 AM

Notice also
as_scriptengine.cpp(3586): warning : 'stdcall' attribute directive ignored

1>------ Build started: Project: TheStack_vc10, Configuration: GCC ARM Release Win32 ------
1>Build started 11/20/2012 12:23:54 PM.
1>InitializeBuildStatus:
1>  Creating "Release_TheStack_vc10_gcc_arm\TheStack_vc10.unsuccessfulbuild" because "AlwaysCreate" was specified.
1>CustomBuild:
1>  All outputs are up-to-date.
1>ClCompile:
1>  ARM Compiling(GCC) d:\bumper\_prj\_thestack\src\age\3rd_party\angelscript\source\as_scriptengine.cpp ...
1>  d:/bumper/_prj/_thestack/src/age/3rd_party/angelscript/source/as_scriptengine.cpp( In member function 'void* asCScriptEngine) ::CallGlobalFunctionRetPtr(asSSystemFunctionInterface*, asCScriptFunction*)':
1> 
1> 
1>d:/bumper/_prj/_thestack/src/age/3rd_party/angelscript/source/as_scriptengine.cpp(3586): warning : 'stdcall' attribute directive ignored
1> 
1> 
1>d:/bumper/_prj/_thestack/src/age/3rd_party/angelscript/source/as_scriptengine.cpp(3586): warning : 'stdcall' attribute directive ignored
1> 
1> 
1>  d:/bumper/_prj/_thestack/src/age/3rd_party/angelscript/source/as_scriptengine.cpp( In member function 'void* asCScriptEngine) ::CallGlobalFunctionRetPtr(asSSystemFunctionInterface*, asCScriptFunction*, void*)':
1> 
1> 
1>d:/bumper/_prj/_thestack/src/age/3rd_party/angelscript/source/as_scriptengine.cpp(3607): warning : 'stdcall' attribute directive ignored
1> 
1> 
1>d:/bumper/_prj/_thestack/src/age/3rd_party/angelscript/source/as_scriptengine.cpp(3607): warning : 'stdcall' attribute directive ignored
1> 
1> 
1>  d:/bumper/_prj/_thestack/src/age/3rd_party/angelscript/source/as_scriptengine.cpp( In member function 'void asCScriptEngine) ::CallGlobalFunction(void*, void*, asSSystemFunctionInterface*, asCScriptFunction*)':
1> 
1> 
1>d:/bumper/_prj/_thestack/src/age/3rd_party/angelscript/source/as_scriptengine.cpp(3707): warning : 'stdcall' attribute directive ignored
1> 
1> 
1>d:/bumper/_prj/_thestack/src/age/3rd_party/angelscript/source/as_scriptengine.cpp(3707): warning : 'stdcall' attribute directive ignored
1> 
1> 
1>  d:/bumper/_prj/_thestack/src/age/3rd_party/angelscript/source/as_scriptengine.cpp( In member function 'bool asCScriptEngine) ::CallGlobalFunctionRetBool(void*, void*, asSSystemFunctionInterface*, asCScriptFunction*)':
1> 
1> 
1>d:/bumper/_prj/_thestack/src/age/3rd_party/angelscript/source/as_scriptengine.cpp(3727): warning : 'stdcall' attribute directive ignored
1> 
1> 
1>d:/bumper/_prj/_thestack/src/age/3rd_party/angelscript/source/as_scriptengine.cpp(3727): warning : 'stdcall' attribute directive ignored
1> 
1> 
1>  d:/bumper/_prj/_thestack/src/age/3rd_party/angelscript/add_on/scriptstdstring/scriptstdstring.cpp( In function '_STL) ::string formatInt(asINT64, const _STL::string&, asUINT)':
1> 
1> 
1>d:/bumper/_prj/_thestack/src/age/3rd_party/angelscript/add_on/scriptstdstring/scriptstdstring.cpp(344): warning : comparison between signed and unsigned integer expressions
1> 
1> 
1>d:/bumper/_prj/_thestack/src/age/3rd_party/angelscript/add_on/scriptstdstring/scriptstdstring.cpp(345): warning : comparison between signed and unsigned integer expressions
1> 
1> 
1>d:/bumper/_prj/_thestack/src/age/3rd_party/angelscript/add_on/scriptstdstring/scriptstdstring.cpp(346): warning : comparison between signed and unsigned integer expressions
1> 
1> 
1>d:/bumper/_prj/_thestack/src/age/3rd_party/angelscript/add_on/scriptstdstring/scriptstdstring.cpp(347): warning : comparison between signed and unsigned integer expressions
1> 
1> 
1>d:/bumper/_prj/_thestack/src/age/3rd_party/angelscript/add_on/scriptstdstring/scriptstdstring.cpp(348): warning : comparison between signed and unsigned integer expressions
1> 
1> 
1>d:/bumper/_prj/_thestack/src/age/3rd_party/angelscript/add_on/scriptstdstring/scriptstdstring.cpp(349): warning : comparison between signed and unsigned integer expressions
1> 
1> 
1>  d:/bumper/_prj/_thestack/src/age/3rd_party/angelscript/add_on/scriptstdstring/scriptstdstring.cpp( In function '_STL) ::string formatFloat(double, const _STL::string&, asUINT, asUINT)':
1> 
1> 
1>d:/bumper/_prj/_thestack/src/age/3rd_party/angelscript/add_on/scriptstdstring/scriptstdstring.cpp(388): warning : comparison between signed and unsigned integer expressions
1> 
1> 
1>d:/bumper/_prj/_thestack/src/age/3rd_party/angelscript/add_on/scriptstdstring/scriptstdstring.cpp(389): warning : comparison between signed and unsigned integer expressions
1> 
1> 
1>d:/bumper/_prj/_thestack/src/age/3rd_party/angelscript/add_on/scriptstdstring/scriptstdstring.cpp(390): warning : comparison between signed and unsigned integer expressions
1> 
1> 
1>d:/bumper/_prj/_thestack/src/age/3rd_party/angelscript/add_on/scriptstdstring/scriptstdstring.cpp(391): warning : comparison between signed and unsigned integer expressions
1> 
1> 
1>d:/bumper/_prj/_thestack/src/age/3rd_party/angelscript/add_on/scriptstdstring/scriptstdstring.cpp(392): warning : comparison between signed and unsigned integer expressions
1> 
1> 
1>d:/bumper/_prj/_thestack/src/age/3rd_party/angelscript/add_on/scriptstdstring/scriptstdstring.cpp(393): warning : comparison between signed and unsigned integer expressions
1> 
1> 
1>Link:
1>  ARM Linking(GCC) ...
1>  TheStack_vc10.vcxproj -> d:\Bumper\_Prj\_TheStack\bin\TheStack.s3e
1>PostBuildEvent:
1>  D:\Marmalade\6.1\s3e\python\python.exe .\process_map.py "d:\Bumper\_Prj\_TheStack\bin\TheStack.s3e"
1>FinalizeBuildStatus:
1>  Deleting file "Release_TheStack_vc10_gcc_arm\TheStack_vc10.unsuccessfulbuild".
1>  Touching "Release_TheStack_vc10_gcc_arm\TheStack_vc10.lastbuildstate".
1>
1>Build succeeded.
1>
1>Time Elapsed 00:01:08.01
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========


#14 Andreas Jonsson   Moderators   -  Reputation: 3263

Like
0Likes
Like

Posted 20 November 2012 - 09:11 AM

Thanks. I believe I have fixed these compiler warnings in revision 1476.

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS