segfault/abort in CPtr>>#value

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

segfault/abort in CPtr>>#value

S11001001
wcstok on ##smalltalk asked about a method on gst latest running on
FreeBSD:

|x y|
    x := CPtrCType elementType: #int.
    y := x new.
    y value
!

whereas replacing the last statement with "Memory intAt: y address"
would operate as expected.

I tried it on Linux nocandy.dyndns.org 2.6.12-12mdk #1 Fri Sep 9
18:15:22 CEST 2005 i686 AMD Athlon(tm) XP 2800+ GNU/Linux (built with
 --enable-jit --enable-gtk=no) with
[hidden email]--2004b/smalltalk--devo--2.2--patch-166:

st> |x y| x:=CPtrCType elementType: #int. y:=x new. y value!
stdin:1: Aborted
(ip 10)CPtr>>#value
(ip 12)UndefinedObject>>#executeStatements
(ip 0)<bottom>
Aborted
...
st> |x y| x:=CPtrCType elementType: #int. y:=x new.
st>       Memory intAt: y address!
138315336

wcstok reported a segfault on line 4437 in prims.def.

--
Stephen Compall
http://scompall.nocandysw.com/blog
#gnu-smalltalk,##smalltalk on Freenode IRC


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: segfault/abort in CPtr>>#value

Paolo Bonzini
Stephen Compall wrote:

> wcstok on ##smalltalk asked about a method on gst latest running on
> FreeBSD:
>
> |x y|
>     x := CPtrCType elementType: #int.
>     y := x new.
>     y value
> !
>
> whereas replacing the last statement with "Memory intAt: y address"
> would operate as expected.
>  
The reason is that you have to do "CPtrCType elementType: CIntType" instead.

A more complete example could be something like this:

    |x y|
    x := CPtrCType elementType: CIntType.
    y := x new.
    y value: (CInt value: 15).
    y value printNl.   "Print a CInt"
    y value value printNl.   "Print 15"
    y value free.    "Free the CInt"
    y free    "Free y too"!

Remember that CInt is itself a "int *", so "y" is more like a "int **".

While segfaults should be expected when tinkering with CObjects, getting
one for an object of the wrong class is a bit too greedy indeed!  That
will be fixed for 2.3, thanks.

Paolo


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: segfault/abort in CPtr>>#value

Paolo Bonzini

> A more complete example could be something like this:
>
>    |x y|
>    x := CPtrCType elementType: CIntType.
Or even better, "x := CIntType ptrType".

Paolo


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk