help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] segfault/abort in CPtr>>#value


From: Paolo Bonzini
Subject: Re: [Help-smalltalk] segfault/abort in CPtr>>#value
Date: Tue, 31 Oct 2006 09:12:34 +0100
User-agent: Thunderbird 1.5.0.7 (Macintosh/20060909)

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]