Re: segfault while DELETE THIS

2005-08-18 Thread Dongxu Ma
Yes, you are right. I should dereference first. But now, the issue is,
who can explain why the wrong code could also invoke class' public
method via THIS-print() successfully.

_wrong code_ : $var = ($type) SvIV($arg);

On 8/17/05, Nicholas Clark [EMAIL PROTECTED] wrote:
 On Thu, Aug 11, 2005 at 11:55:49AM +0800, Dongxu Ma wrote:
 
  According to typemap in ExtUtils and perl.h, casting IV to pointer
  should be safe in this case, since on my machine(32bit, kernel
  2.6.12), sizeof(int) == 4, which is the same as a  pointer. Does
  anyone have any idea about this issue?
 
 I think that there's a bug in the typemap you're using:
 
  -typemap---
  TYPEMAP
  Test *T_OBJECT
 
  
  INPUT
  T_OBJECT
if(sv_isa($arg, \Test\)  sv_isobject($arg)) {
$var = INT2PTR($type, SvIV($arg));
 
   SvIV(SvRV($arg))
} else {
warn(\$arg is not a blessed object\);
XSRETURN_UNDEF;
}
 
 
 If I make the above change to use SvRV then I can avoid getting a segfault.
 
 Nicholas Clark
 


-- 
Bst Rgrs, Dongxu


Re: segfault while DELETE THIS

2005-08-17 Thread Nicholas Clark
On Thu, Aug 11, 2005 at 11:55:49AM +0800, Dongxu Ma wrote:

 According to typemap in ExtUtils and perl.h, casting IV to pointer
 should be safe in this case, since on my machine(32bit, kernel
 2.6.12), sizeof(int) == 4, which is the same as a  pointer. Does
 anyone have any idea about this issue?

I think that there's a bug in the typemap you're using:

 -typemap---
 TYPEMAP
 Test *T_OBJECT
 
 
 INPUT
 T_OBJECT
   if(sv_isa($arg, \Test\)  sv_isobject($arg)) {
   $var = INT2PTR($type, SvIV($arg));

  SvIV(SvRV($arg))
   } else {
   warn(\$arg is not a blessed object\);
   XSRETURN_UNDEF;
   }


If I make the above change to use SvRV then I can avoid getting a segfault.

Nicholas Clark