You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consider the next use case:
I have class Foo described in lime.
I create object of class Foo which acquire some non-shareable resources.
I want to create second instance of class Foo which needs to acquire the same resources.
In swift it gonna work like this because it uses reference counter and release instances asap:
var foo = Foo()
foo = nil // Instance is released, resources are unlocked
foo = Foo()
In Java and Flutter such code doesn't work because those languages use garbage collectors:
Foo foo = new Foo()
foo = null // ooops, object is not actually destroyed, I love Java
foo = new Foo()
Usually such classes in Java have some method to close and release resources. Each method should check then if object is 'closed' and throw runtime exception if one tries to use closed object.
Currently there are two problems with code which generated by Gluecodium:
All developers should know about this mechanism when they implement functions
There is no support for RuntimeExceptions so all such methods should throw custom exceptions which are described in lime files and all code which already use those functions fill fail to compile because Java requires to catch such exceptions (or declare custom methods to throw those exceptions), etc.
There are few possible solutions which may help in this case.
Add method which should 'destroy' object (with keyword destructor in lime?). Make it possible to call this method from C++/Java/Dart. Each attempt to call any method in the object after destruction should lead to runtime exception:
// Lime
class Foo {
destructor dispose()
fun bar()
}
...
// Java
class Foo {
private boolean mIsDestroyed = false;
public void dispose() {
call_native_method_dispose();
mIsDestroyed = true;
}
public void bar()
{
if (mIsDestroyed)
{
throw new RuntimeException("...");
}
}
}
// C++
// ??? Somehow add possibility to notify Java that object os destroyed?
Add method which checks that object is destroyed and call this method each time when any other method/property is called. Probably some special syntax for such method is also necessary. As extension of idea this method can return string which is translated to runtime exception if not null.
// Lime
class Foo {
validator object_status()
fun bar()
}
...
// Java
class Foo {
public void bar()
{
String objectStatus = native_object_status();
if (objectStatus) {
throw new RuntimeException(objectStatus);
}
}
}
// C++
optional<std::string> Foo::object_status()
{
if (!my_object_is_ok()) {
return "My object is not OK"
}
return nullopt;
}
Extend Result class to return runtime error. This approach involves a lot of work to adopt existing code and spoils C++ interfaces.
The text was updated successfully, but these errors were encountered:
After additional discussions, we settled on option number 2 ("validator"). The exact LIME IDL language keyword is undecided yet, but the general structure of the functionality is the same as described in the ticket: the "validator" function is called by platform code on each non-static function call (which also includes property accessors). Constructors are excluded due to being static functions.
This functionality applies to classes only. It does not make sense for interfaces. It is also unneeded for structs, as platform representation of a struct is a "copy" of a C++ object, so their lifetimes are not related.
Updated LIME IDL grammar and model builder to add support for `validator` keyword in classes.
See: #637
Signed-off-by: Daniel Kamkha <[email protected]>
Consider the next use case:
I have class Foo described in lime.
I create object of class Foo which acquire some non-shareable resources.
I want to create second instance of class Foo which needs to acquire the same resources.
In swift it gonna work like this because it uses reference counter and release instances asap:
In Java and Flutter such code doesn't work because those languages use garbage collectors:
Usually such classes in Java have some method to close and release resources. Each method should check then if object is 'closed' and throw runtime exception if one tries to use closed object.
Currently there are two problems with code which generated by Gluecodium:
There are few possible solutions which may help in this case.
destructor
in lime?). Make it possible to call this method from C++/Java/Dart. Each attempt to call any method in the object after destruction should lead to runtime exception:Result
class to return runtime error. This approach involves a lot of work to adopt existing code and spoils C++ interfaces.The text was updated successfully, but these errors were encountered: