google-code-export / gambas

Automatically exported from code.google.com/p/gambas
1 stars 0 forks source link

Can call non-static _unknown from a static context #268

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
1) Describe the problem.
You can call a non-static _unknown from a static context.

2) GIVE THE FOLLOWING INFORMATIONS (if they are appropriate):

Version: TRUNK
Revision: r4888

3) Provide a little project that reproduces the bug or the crash.
'Class1
Public a As Integer = 1337
Public Sub _unknown(...)
  Print a
End

In main:
Class1.blaha()

-> Segfault

Original issue reported on code.google.com by emil.len...@gmail.com on 3 Jul 2012 at 5:01

GoogleCodeExporter commented 9 years ago
One question: Are static _unknown and static _property allowed?

Original comment by emil.len...@gmail.com on 3 Jul 2012 at 5:44

GoogleCodeExporter commented 9 years ago

Original comment by benoit.m...@gmail.com on 3 Jul 2012 at 6:30

GoogleCodeExporter commented 9 years ago

Original comment by benoit.m...@gmail.com on 3 Jul 2012 at 6:30

GoogleCodeExporter commented 9 years ago
Yes, but the interpreter does not check when _unknown or _property must be 
static or not correctly.

Original comment by benoit.m...@gmail.com on 3 Jul 2012 at 7:41

GoogleCodeExporter commented 9 years ago
'Class1
Static Public Sub _unknown(...)
  Print "Test"
End

And then:
Dim a As New Class1
a.uu()

The call is completely ignored, no errors, and no "Test" on stdout.

Original comment by emil.len...@gmail.com on 3 Jul 2012 at 7:45

GoogleCodeExporter commented 9 years ago
Fixed in revision #4894.

Original comment by benoit.m...@gmail.com on 3 Jul 2012 at 11:46

GoogleCodeExporter commented 9 years ago
Some more things:
* What should happen if _property is static but _unknown is dynamic or vice 
versa? ;) This code:

Static Public Function _property() As Boolean
End

Public Sub _unknown(...)
End

Public Sub TestFunction()
  Me.uuh = 3
End

-> Segmentation fault (The gambas stack gets corrupted)

And

Static Public Function _property() As Boolean
  Print "This is not written to stdout"
End

Public Sub _unknown(...)
  Print "This is written to stdout"
End

Public Sub TestFunction()
  Me.uuh()
End

-> i.e. _property is silently ignored, but _unknown is executed.

* _property must also be checked in about the same way when a property is 
written to:
Static Public Function _property() As Boolean
  Print "This message will not be written to stdout."
  Return True
End

Static Public Sub _unknown(...)
  Print "Not this message either"
End

Public Sub TestFunction()
  Me.uuh = 3
End

-> Shows nothing on the screen, i.e. none of _property or _unknown are 
executed, and no error message.

* In revision #4894 you cannot call a static function when having an object, 
like obj.unknown_function(), err msg "static function". But the convension is 
that static functions can actually be called even if you have an object. 
obj.known_static_function() works.

Original comment by emil.len...@gmail.com on 4 Jul 2012 at 8:55

GoogleCodeExporter commented 9 years ago
Revision #4896 now can call _property according to its declaration 
independently of we are in a dynamic or static context.

As for the last point, it's pending...

Original comment by benoit.m...@gmail.com on 4 Jul 2012 at 10:01

GoogleCodeExporter commented 9 years ago
OK, in revision #4897 you can use a static unknown property in a dynamic 
context.

But I don't think it works with a static unknown method called in a dynamic 
context...

Original comment by benoit.m...@gmail.com on 4 Jul 2012 at 10:06

GoogleCodeExporter commented 9 years ago
Now some more headache :)

Public Function _property() As Boolean
  Return False
End

Public Function _unknown(...) As String
  Return "hello"
End

Public Sub TestFunction()
  Print Me.uuh()
End

-> "Wanted Stream, got String", i.e. stack is corrupted.

And as you say, static unknown method called in dynamic context does not work 
yet, like it should by convention...

Original comment by emil.len...@gmail.com on 4 Jul 2012 at 10:24

GoogleCodeExporter commented 9 years ago
Trying to print out properties does not seem to work either..

'Class1
Public Function _property() As Boolean
  Return True
End

Public Function _unknown(...) As String
  Return "hello"
End

Public Sub TestFunction()
  Print Me.uuh
End

-> "Wanted Stream, got Class1", i.e. stack is corrupted.

Original comment by emil.len...@gmail.com on 8 Jul 2012 at 12:41

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago

Original comment by benoit.m...@gmail.com on 8 Jul 2012 at 12:58

GoogleCodeExporter commented 9 years ago
I should also mention that, if you look at line 110 to 114 in gbx_exec.c, it 
seems like the object is not released if the unknown function (if _property 
returned True) threw an error.

Original comment by emil.len...@gmail.com on 8 Jul 2012 at 1:07

GoogleCodeExporter commented 9 years ago
Fixed in revision #4906.

Original comment by benoit.m...@gmail.com on 8 Jul 2012 at 1:28

GoogleCodeExporter commented 9 years ago
Yes there is a memory leak in the last revision:

Public Function _property() As Boolean
  Return True
End

Public Function _unknown(...) As String
  Print 3 / 0
  Return "hello"
End

Public Sub TestFunction()
  Try Print Me.aab
End

-> gbx3: warning: circular references detected:
gbx3:     1 Class1
gbx3: warning: 1 allocation(s) non freed.

I hope this is the last objection I have for a moment ;)

Original comment by emil.len...@gmail.com on 8 Jul 2012 at 1:44

GoogleCodeExporter commented 9 years ago
It should be fixed in revision #4907.

Original comment by benoit.m...@gmail.com on 8 Jul 2012 at 2:30