Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

funcdef inside shared interface; "interface already implement" warning


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
14 replies to this topic

#1 Wipe   Members   -  Reputation: 259

Like
0Likes
Like

Posted 23 February 2013 - 12:56 AM

1st thing--

// module 1
funcdef void Func();

shared interface ielement
{
    Func@ f { get; set; }
}

// module 2
funcdef void Func();

shared interface ielement
{
    Func@ f { get; set; }
}

class celement : ielement
{
    Func@ fdef;

    Func@ get_f()
    {
       return( this.fdef ); 
    }
    void set_f( Func@ newF )
    {
       @this.fdef = newF;
    }
}

Used that way, makes  "Missing implementation of ..." error for both, getter and setter. So i tried to use "normal" functions.
 

// module 1
 
funcdef void Func();

shared interface ielement
{
     Func@ fGet();
     void fSet( Func@ );
}

// module 2

funcdef void Func();

shared interface ielement
{
    Func@ fGet();
    void fSet( Func@ );
}

class celement : ielement
{
    Func@ fdef;

    Func@ fGet()
    {
       return( this.fdef ); 
    }

    void fSet( Func@ newF )
    {
       @this.fdef = newF;
    }
}

Error changed to " Shared type 'ielement' doesn't match the original declaration in other module"
 
----

2nd thing--

shared interface ielement
{
   void dummy1();
}

shared interface isprite : ielement
{
    void dummy2();
}

class celement : ielement
{
   void dummy1() {}
}

class csprite : celement, isprite
{
    csprite()
    {
        super();
    }

    void dummy2() {}
}

Makes warning "The interface 'ielement' is already implemented" - is that possible to make this warning go away? smile.png

EDIT: everything was tested with r1563


Edited by Andreas Jonsson, 24 February 2013 - 04:28 PM.


Sponsor:

#2 TheAtom   Members   -  Reputation: 330

Like
0Likes
Like

Posted 23 February 2013 - 01:07 AM

Makes warning "The interface 'ielement' is already implemented" - is that possible to make this warning go away?

 

I am wondering why this warning is even needed. We have:

1. Multiple inheritance for interfaces, i.e. abstract classes.

2. Single inheritance for regular classes.

3. All inheritance is virtual anyway.

 

This is a nice setup, and we can't ever suffer from the diamond problem. However,

4. It's impossible to decouple class declaration from its implementation (notwithstanding the shared keyword).

 

Because of 4. it's still reasonable to create otherwise superfluous interfaces, if only to make script headers more readable. For now I don't see a reason to report that an interface is already implemented as it manifests itself in typical and practical situations. But maybe I don't see the entire picture (how do mixin classes come into this?).

 

edit: this might be interesting:

 

interface I
{
    void f();
}

interface J : I
{
}

mixin class M1 : I
{
    void f() { x = 1; }
};

mixin class M2 : I
{
    void f() { x = 2; }
};

class T : M1, M2
{
    X() { x = 0; }
    int x;
};

This does not generate any warning, but it does if I change "mixin class M : I" to "mixin class M : J". But in both cases T inherits I along two paths.

 

edit2: Another issue:

 

mixin class M1
{
    void f() { x = 1; }
};

mixin class M2
{
    void f() { x = 2; }
};

class T : M1, M2
{
    T() { x = 0; }
    void g()
    {
        f(); // cannot use qualified names: M1::f() or M2::f()
    }
    int x;
};

There is no warning that T inherits f() twice (but g() calls f() in M1, the closest base class, I assume this is correct) and maybe this actually should warrant a warning, since it's actually a real function being inherited, not just an an interface method. Especially since there appers to be no way to explicitly call f() from the other base class, M2 (is this at all intended?).


Edited by TheAtom, 23 February 2013 - 12:38 PM.


#3 Andreas Jonsson   Moderators   -  Reputation: 3293

Like
0Likes
Like

Posted 23 February 2013 - 09:20 AM

I'll look into the problems reported.

 

As for mixin classes; they are not really inherited. When including a mixin class only the parts that are not already in the class will be included, for example, if the class already has a property that is also in the mixin class, the version from the mixin class won't be included again. The same goes for methods and implemented interfaces.

 

You can think of mixin classes as macros for providing default implementations. 


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

#4 Andreas Jonsson   Moderators   -  Reputation: 3293

Like
0Likes
Like

Posted 24 February 2013 - 04:28 PM

All problems reported should now be fixed in revision 1573.

 

Thanks,

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

#5 Wipe   Members   -  Reputation: 259

Like
0Likes
Like

Posted 24 February 2013 - 10:25 PM

Hm, looks like there are still problems when loading from bytecode (shared type doesn't match the original declaration).


Edited by Wipe, 24 February 2013 - 10:27 PM.


#6 Andreas Jonsson   Moderators   -  Reputation: 3293

Like
0Likes
Like

Posted 25 February 2013 - 07:44 AM

That's strange. I fixed that too yesterday. Loading from bytecode had the same problem as compiling the script in the first place, in that the funcdef didn't get the same type in both modules.

 

What script is failing to load from bytecode? I'll have to do some further investigation on it.


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 Wipe   Members   -  Reputation: 259

Like
0Likes
Like

Posted 25 February 2013 - 08:24 PM

Two modules with same code; both need to be loaded from bytecode or error won't show up.
funcdef void fdef();

shared interface iface
{
	fdef@ dummy();
}


#8 Andreas Jonsson   Moderators   -  Reputation: 3293

Like
0Likes
Like

Posted 26 February 2013 - 07:50 AM

Thanks. I'll investigate it.


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 Andreas Jonsson   Moderators   -  Reputation: 3293

Like
0Likes
Like

Posted 26 February 2013 - 06:42 PM

You were right (of course). My previous test didn't catch this problem because I loaded the bytecode right after having compiled the script from source. Only when loading the bytecode into a fresh engine did the problem appear.

 

The bug was a bit more complex than I had imagined, but it should now be fixed in revision 1574.


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

#10 Wipe   Members   -  Reputation: 259

Like
0Likes
Like

Posted 27 February 2013 - 03:55 AM

Another dark secrets of funcdefs found, sorry! ;) We call start() function and expect to reach end().
 
Let's start from crash in cfuncdef1_1::crashme().
Spoiler

 
If we change crashme() a bit, everything looks like it works without any problems (we can reach end()), but generated bytecode cannot be loaded (LoadByteCode() returns -1).
 
    void crashme()
    {
        if( @this._events_ != null && @this._events_.f != null )
        {
            funcdef1@ crash = this.events.f;
            crash( this );
        }
    }
 
And finally, different edit makes "GC cannot free an object of type '_builtin_function_', it is kept alive by the application." error show up.
cfuncdef1_1() { @this._events_ = null; }

Edited by Wipe, 27 February 2013 - 04:02 AM.


#11 Andreas Jonsson   Moderators   -  Reputation: 3293

Like
0Likes
Like

Posted 27 February 2013 - 06:41 AM

No problem. At least you're able to provide examples that makes it easy for me to reproduce the problems for the investigation.

 

I'll look into this. Hopefully I'll have the fix tonight.


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

#12 Andreas Jonsson   Moderators   -  Reputation: 3293

Like
0Likes
Like

Posted 27 February 2013 - 03:25 PM

I believe the problem is actually with virtual property accessors, and not function pointers here.

 

By manually calling the get functions everything works.

 

 
                void crashme() 
                { 
                     if( @this._events_ != null && @this._events_.f != null ) 
                     { 
//                      this.events.f( this ); 
                        this.get_events().get_f()( this ); 
                     } 
                }

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 Andreas Jonsson   Moderators   -  Reputation: 3293

Like
0Likes
Like

Posted 27 February 2013 - 06:49 PM

The crash has been fixed in revision 1575.

 

The memory leak upon the null pointer access exception is still there. I'm still investigating that, but it looks like a problem in the clean up of the callstack after an exception.


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

#14 Andreas Jonsson   Moderators   -  Reputation: 3293

Like
1Likes
Like

Posted 27 February 2013 - 07:51 PM

Indeed. The memory leak is a bug with the logic for cleaning up the callstack after an exception. The problem happens when attempting to call a class method on a null pointer and the method takes a handle as argument. The cleanup of the callstack doesn't release that handle in this situation, thus causing the leak.

 

I know what is causing the leak, but I'll have to work on the fix at a later time as it's getting late and this won't be a trivial change with just a couple of lines that needs to change.


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

#15 Andreas Jonsson   Moderators   -  Reputation: 3293

Like
0Likes
Like

Posted 02 March 2013 - 01:14 PM

I've fixed the memory leak in revision 1580. 

 

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