William S Fulton
2003-12-12 23:40:15 UTC
I've reprotected the director methods for Java. I see that the wrappers for
protected methods call SWIG_exception after trying a downcast. What is the logic
here? From a Java perspective, I don't see this cast and exception being
necessary as the method will be protected from the Java side. Am I missing
something? If it is redundant, I'd like to get rid of the exception being thrown
as it is not implemented correctly. The method must return as soon as
SWIG_exception is called otherwise unpredictable results will occur on calling
any further JNI methods.
A suggestion for the future for wrapping of director protected methods. The
director class is generated into the xxxx_wrap.h file. I'm not quite sure why
these need to be put into a wrapper file, maybe someone can enlighten me? Anyway
the problem is that the director classes break the encapsulation of the
protected methods should anyone use the header file. We could maintain/enforce
the encapsulation by modifying the generated code to use friends. Currently we
have when wrapping a protected method Bar::pang() :
class SwigDirector_Bar : public Bar, public Swig::Director {
...
public:
virtual std::string pang();
...
};
We could instead generate this:
class SwigDirector_Bar : public Bar, public Swig::Director {
...
protected:
virtual std::string pang();
// Python
friend PyObject * ::_wrap_Bar_pang(PyObject *self, PyObject *args);
// Java
friend JNIEXPORT jstring JNICALL ::Java_exampleJNI_Bar_1pang(JNIEnv *jenv,
jclass jcls, jlong jarg1);
...
};
Thoughts?
William
protected methods call SWIG_exception after trying a downcast. What is the logic
here? From a Java perspective, I don't see this cast and exception being
necessary as the method will be protected from the Java side. Am I missing
something? If it is redundant, I'd like to get rid of the exception being thrown
as it is not implemented correctly. The method must return as soon as
SWIG_exception is called otherwise unpredictable results will occur on calling
any further JNI methods.
A suggestion for the future for wrapping of director protected methods. The
director class is generated into the xxxx_wrap.h file. I'm not quite sure why
these need to be put into a wrapper file, maybe someone can enlighten me? Anyway
the problem is that the director classes break the encapsulation of the
protected methods should anyone use the header file. We could maintain/enforce
the encapsulation by modifying the generated code to use friends. Currently we
have when wrapping a protected method Bar::pang() :
class SwigDirector_Bar : public Bar, public Swig::Director {
...
public:
virtual std::string pang();
...
};
We could instead generate this:
class SwigDirector_Bar : public Bar, public Swig::Director {
...
protected:
virtual std::string pang();
// Python
friend PyObject * ::_wrap_Bar_pang(PyObject *self, PyObject *args);
// Java
friend JNIEXPORT jstring JNICALL ::Java_exampleJNI_Bar_1pang(JNIEnv *jenv,
jclass jcls, jlong jarg1);
...
};
Thoughts?
William