Can this be done with SWIG?

View: New views
3 Messages — Rating Filter:   Alert me  

Can this be done with SWIG?

by Georgios Petasis-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,

I have a simple class:

%nodefaultctor nsIDOMHTMLCollection;
%nodefaultdtor nsIDOMHTMLCollection;
class nsIDOMHTMLCollection {
public:
  void Release          (void);
  void Item               (PRUint32 index,        nsIDOMNode **OUTPUT);
  void NamedItem    (const nsAString &name, nsIDOMNode **OUTPUT);
}; /* nsIDOMHTMLCollection */

%nodefaultdtor nsIDOMNode;
class nsIDOMNode {
  void Release(void);
}

What I want to do:

1) Tell SWIG that the arguments "nsIDOMNode **OUTPUT" are actually the
return values of the methods Item & NamedItem, and that the returned
value is actually a new allocated pointer. I can do this with the following:

%typemap(in, numinputs=0)  nsIDOMNode **OUTPUT(nsIDOMNode *temp) {
   $1 = &temp;
}
%typemap(argout) nsIDOMNode **OUTPUT {
  Tcl_SetObjResult(interp, SWIG_NewInstanceObj(
         SWIG_as_voidptr(*($1)), SWIGTYPE_p_nsIDOMNode, 1));
}
%newobject nsIDOMHTMLCollection::Item;
%newobject nsIDOMHTMLCollection::NamedItem;

2) I want to tell SWIG to delete nsIDOMNode * by calling Release(). How
can I do this?

If I enable the default destructor, swig always uses delete on the
object. How can I change that, and actually call Release() ?

Thanks,

George



------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Re: Can this be done with SWIG? - [BUG in Tcl generator?]

by Georgios Petasis-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

O/H Georgios Petasis έγραψε:

> Hi all,
>
> I have a simple class:
>
> %nodefaultctor nsIDOMHTMLCollection;
> %nodefaultdtor nsIDOMHTMLCollection;
> class nsIDOMHTMLCollection {
> public:
>  void Release          (void);
>  void Item               (PRUint32 index,        nsIDOMNode **OUTPUT);
>  void NamedItem    (const nsAString &name, nsIDOMNode **OUTPUT);
> }; /* nsIDOMHTMLCollection */
>
> %nodefaultdtor nsIDOMNode;
> class nsIDOMNode {
>  void Release(void);
> }
>
> What I want to do:
>
> 1) Tell SWIG that the arguments "nsIDOMNode **OUTPUT" are actually the
> return values of the methods Item & NamedItem, and that the returned
> value is actually a new allocated pointer. I can do this with the
> following:
>
> %typemap(in, numinputs=0)  nsIDOMNode **OUTPUT(nsIDOMNode *temp) {
>   $1 = &temp;
> }
> %typemap(argout) nsIDOMNode **OUTPUT {
>  Tcl_SetObjResult(interp, SWIG_NewInstanceObj(
>         SWIG_as_voidptr(*($1)), SWIGTYPE_p_nsIDOMNode, 1));
> }
> %newobject nsIDOMHTMLCollection::Item;
> %newobject nsIDOMHTMLCollection::NamedItem;
>
> 2) I want to tell SWIG to delete nsIDOMNode * by calling Release().
> How can I do this?
>
> If I enable the default destructor, swig always uses delete on the
> object. How can I change that, and actually call Release() ?
>
> Thanks,
>
> George

Is it possible the Tcl wrapper generator to have a bug?
I tried the following:

%nodefaultctor nsIDOMHTMLCollection;
%feature("action") nsIDOMHTMLCollection::~nsIDOMHTMLCollection {
  arg1->MyRelease();
}
class nsIDOMHTMLCollection {
public:
  nref AddRef             (void);
  nref Release            (void);
  void Item               (PRUint32 index,        nsIDOMNode **OUTPUT);
  void NamedItem          (const nsAString &name, nsIDOMNode **OUTPUT);
  void GetLength          (PRUint32 *OUTPUT);
}; /* nsIDOMHTMLCollection */

The wrapper was generated just fine (i.e.
_wrap_delete_nsIDOMHTMLCollection calls MyRelease()),
but the class destructor is still:

SWIGINTERN void swig_delete_nsIDOMHTMLCollection(void *obj) {
nsIDOMHTMLCollection *arg1 = (nsIDOMHTMLCollection *) obj;
delete arg1;
}

Is this what I am supposed to get?

Regards,

George

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Re: Can this be done with SWIG? - [BUG in Tcl generator?]

by wsfulton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Georgios Petasis wrote:

> O/H Georgios Petasis έγραψε:
>> Hi all,
>>
>> I have a simple class:
>>
>> %nodefaultctor nsIDOMHTMLCollection;
>> %nodefaultdtor nsIDOMHTMLCollection;
>> class nsIDOMHTMLCollection {
>> public:
>>  void Release          (void);
>>  void Item               (PRUint32 index,        nsIDOMNode **OUTPUT);
>>  void NamedItem    (const nsAString &name, nsIDOMNode **OUTPUT);
>> }; /* nsIDOMHTMLCollection */
>>
>> %nodefaultdtor nsIDOMNode;
>> class nsIDOMNode {
>>  void Release(void);
>> }
>>
>> What I want to do:
>>
>> 1) Tell SWIG that the arguments "nsIDOMNode **OUTPUT" are actually the
>> return values of the methods Item & NamedItem, and that the returned
>> value is actually a new allocated pointer. I can do this with the
>> following:
>>
>> %typemap(in, numinputs=0)  nsIDOMNode **OUTPUT(nsIDOMNode *temp) {
>>   $1 = &temp;
>> }
>> %typemap(argout) nsIDOMNode **OUTPUT {
>>  Tcl_SetObjResult(interp, SWIG_NewInstanceObj(
>>         SWIG_as_voidptr(*($1)), SWIGTYPE_p_nsIDOMNode, 1));
>> }
>> %newobject nsIDOMHTMLCollection::Item;
>> %newobject nsIDOMHTMLCollection::NamedItem;
>>
>> 2) I want to tell SWIG to delete nsIDOMNode * by calling Release().
>> How can I do this?
>>
>> If I enable the default destructor, swig always uses delete on the
>> object. How can I change that, and actually call Release() ?
>>
>> Thanks,
>>
>> George
>
> Is it possible the Tcl wrapper generator to have a bug?
> I tried the following:
>
> %nodefaultctor nsIDOMHTMLCollection;
> %feature("action") nsIDOMHTMLCollection::~nsIDOMHTMLCollection {
>   arg1->MyRelease();
> }
> class nsIDOMHTMLCollection {
> public:
>   nref AddRef             (void);
>   nref Release            (void);
>   void Item               (PRUint32 index,        nsIDOMNode **OUTPUT);
>   void NamedItem          (const nsAString &name, nsIDOMNode **OUTPUT);
>   void GetLength          (PRUint32 *OUTPUT);
> }; /* nsIDOMHTMLCollection */
>
> The wrapper was generated just fine (i.e.
> _wrap_delete_nsIDOMHTMLCollection calls MyRelease()),
> but the class destructor is still:
>
> SWIGINTERN void swig_delete_nsIDOMHTMLCollection(void *obj) {
> nsIDOMHTMLCollection *arg1 = (nsIDOMHTMLCollection *) obj;
> delete arg1;
> }
>
> Is this what I am supposed to get?

The action code appears in:

SWIGINTERN int
_wrap_delete_nsIDOMHTMLCollection(ClientData clientData SWIGUNUSED,
Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
   nsIDOMHTMLCollection *arg1 = (nsIDOMHTMLCollection *) 0 ;
   void *argp1 = 0 ;
   int res1 = 0 ;

   if (SWIG_GetArgs(interp, objc, objv,"o:delete_nsIDOMHTMLCollection
self ",(void *)0) == TCL_ERROR) SWIG_fail;
   res1 = SWIG_ConvertPtr(objv[1],
&argp1,SWIGTYPE_p_nsIDOMHTMLCollection, SWIG_POINTER_DISOWN |  0 );
   if (!SWIG_IsOK(res1)) {
     SWIG_exception_fail(SWIG_ArgError(res1), "in method '"
"delete_nsIDOMHTMLCollection" "', argument " "1"" of type '"
"nsIDOMHTMLCollection *""'");
   }
   arg1 = reinterpret_cast< nsIDOMHTMLCollection * >(argp1);
   {
     arg1->MyRelease();
   }

   return TCL_OK;
fail:
   return TCL_ERROR;
}

Which is where it should appear... the destructor wrapper. I'm not
familiar with the tcl module / C API, so I don't really know why there
is a swig_delete_nsIDOMHTMLCollection in addition to the
_wrap_delete_nsIDOMHTMLCollection.

William

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user