Status report (June 9th)

For some reason I haven’t posted my status report from June 9th here. It is rather out of date, but I’m posting it here for completeness 😉

I haven’t been able to do as much as I planned for this week, partly because of some other things I needed to do (I have been working on a paper for a conference). Support for generating IDL code for classes and member functions is still not available at this time (the wrapping itself works OK, as it is basically the same code as for globals); instead I have done some further work on wrapping global functions and variables. The C/C++ wrapper code for each function now actually does some work – namely it converts the parameters (if specified by the typemap), calls the wrapped function and then converts the result. What it still does not get right are parameters which are not simple types. The following code is useful for demonstrating this:

class aClass {
  virtual int memberFunc(int);

This is wrapped as:

/* ctype */ void * _wrap_new_aClass() {
  /* ctype */ void * jresult ;
  aClass *result = 0 ;

  result = (aClass *)new aClass();
  /* out */ jresult = result;
  return jresult;

/* ctype */ int _wrap_aClass_memberFunc(/* ctype */ void * jarg1, /*  ctype */ int jarg2) {
  /* ctype */ int jresult ;
  aClass *arg1 = (aClass *) 0 ;
  int arg2 ;
  int result;

  /* in */ arg1 = (aClass *)jarg1;
  /* in */ arg2 = (int)jarg2;
  result = (int)(arg1)->memberFunc(arg2);
  /* out */ jresult = result;
  return jresult;

void _wrap_delete_aClass(/* ctype */ void * jarg1) {
  aClass *arg1 = (aClass *) 0 ;

  /* in */ arg1 = (aClass *)jarg1;
  delete arg1;

Here the first parameters of _wrap_aClass_memberFunc and _wrap_delete_aClass are handled incorrectly; they should be expected to be COM objects, and therefore should not be just casted to (aClass *). Thus I think that they should be casted to IUnknown* (or even the argument itself should be IUnknown* instead of void*). Now this means that the wrapper will need a way to access the underlying C++ object. What I am proposing is to create a special interface for objects wrapped by SWIG which returns a pointer to the underlying object, e.g.:

interface ISWIGWrappedObject : IUnknown {
  void *getCPtr();

The other option is to add a ‘getCPtr’ method to each interface created by SWIG; but the solution I propose seems more elegant to me. I do not change the user-visible interface, and in addition I can easily tell if an object has been created by SWIG or in a different way – this might be very useful when implementing directors


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: