help-smalltalk
[Top][All Lists]
Advanced

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

[Help-smalltalk] Fix for strange CObject at:type: behavior


From: David Forster
Subject: [Help-smalltalk] Fix for strange CObject at:type: behavior
Date: Wed, 1 Jan 2003 16:50:10 -0700
User-agent: Mutt/1.3.28i

Per Paolo Bonzini's request, I'm CC:'ing this post to
address@hidden for archival purposes...

Date: Mon, 30 Dec 2002 15:15:30 -0700
Subject: Fix (?) for strange CObject at:type: behavior

Hi Paolo,

I've discovered what appears to be a bug in VMpr_CObject_at
(prims.inl:4533).  When the passed type is a real CType instead of an
integer type, the stack gets messed up:

SET_STACKTOP (_gst_c_object_new_typed (addr, oop3));

As far as I could figure out, _gst_c_object_new_typed does not place
it's return OOP on the stack, thus messing the stack up (?).  Or at
the very least, there's something else below it on the stack.  At any
rate, changing SET_STACKTOP to PUSH_OOP solved the problem for me and
seems to work...

Here's the code that triggered it for me:

listDepthsOfScreen: aScreen
    "Return a list of all depths supported by the given screen."
    | nCReturn cList result block v idx |
    nCReturn := CInt new: (CInt sizeof).
    cList := self cXListDepths: self a2: aScreen a3: nCReturn.
    result := Set new.
    (nCReturn value) printNl.

    block := [ :x |
        x display.
        ' ' display.
        idx := ((CIntType sizeof) * x).
        x display.
        ' ' display.
        idx display.
        ' ' display.
        v := (cList at: idx type: CIntType).
        x display.
        ' ' display.
        v := v value.
        x display.
        ' - ' display.
        v displayNl.
        result add: v.].
 
    0 to: ((nCReturn value) - 1) do: block.
    
    nCReturn free.
    cList free. "FIXME: Use XFree"
    ^result.                 
!

This returns the correct result, but it prints out:

st> x listDepthsOfScreen: 0!
7
0 0 0 CInt(16r83D2010) 24 - 24
1 1 4 CInt(16r83D2014) 1 - 1
2 2 8 CInt(16r83D2018) 4 - 4
3 3 12 CInt(16r83D201C) 8 - 8
4 4 16 CInt(16r83D2020) 15 - 15
5 5 20 CInt(16r83D2024) 16 - 16
6 6 24 CInt(16r83D2028) 32 - 32

Somehow `x' is getting corrupted with the value of `v'.  And if I
eliminate `block' and just pass the block directly to to:do: it works
OK, but will only call the block ONCE (thus only returning a set with
`24' in it.).  If I make `v' a temporary inside the block, it enters
an infinite loop.

If I pass `10' as the type everything works OK.

The above method can be pasted right into my previous Xlib bindings
code in Xlib_Display.st:269.  Then to repeat run under X:

FileStream fileIn: 'Xlib.st'!
Smalltalk at: #x put: (Xlib Display new)!
x listDepthsOfScreen: 0!

This is with Debian GNU/Linux 3.0 and GNU Smalltalk 2.0.10.

Thanks,
-Dave



reply via email to

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