Re: [racket] Some problem with hash-update!

2014-09-15 Thread Evgeny Odegov
> Using `#:atomic? #t` disables Racket thread switches, but it doesn't > disable GC. > It's not so much about modification as referencing the memory --- > either reading or writing --- across a potential GC. Thank you! It's clear now. > Now that I look closely, I think you need the `bytes-copy!`

Re: [racket] Some problem with hash-update!

2014-09-15 Thread Evgeny Odegov
> I think that changing `_pointer` to `_DWORD` can't be the real answer, > since `_pointer` is at least as large as `_DWORD`. Facepalm. Of course, you're right! Somehow, I've thought that _pointer is twice shorter :) > But I agree that you should use `malloc`, and you should also supply > 'atomi

Re: [racket] Some problem with hash-update!

2014-09-14 Thread Matthew Flatt
I think that changing `_pointer` to `_DWORD` can't be the real answer, since `_pointer` is at least as large as `_DWORD`. But I agree that you should use `malloc`, and you should also supply 'atomic-interior: (malloc _DWORD 'atomic-interior) The 'atomic-interior flag ensures that the allocated

Re: [racket] Some problem with hash-update!

2014-09-14 Thread Evgeny Odegov
More complete example: http://pasterack.org/pastes/25901 I guess I've found reason of the problem. I think the problem was in that line: (define lpdwItems (make-bytes (ctype-sizeof _pointer) 0)) I've changed it to: (define lpdwItems (make-bytes (ctype-sizeof _DWORD) 0)) There is no visible prob

Re: [racket] Some problem with hash-update!

2014-09-14 Thread Matthew Flatt
My best guess is that it's an issue with memory management, because memory management gets a lot trickier when you call a function that can call back into Racket. A GC can happen during the callback, and therefore during the dynamic extent of the foreign-function call, which can move arguments that

Re: [racket] Some problem with hash-update!

2014-09-13 Thread Evgeny Odegov
Oh, I'm wrong. The last code is not equivalent to initial. The equivalent code has this problem: (define result (make-hash)) (define big-list (list)) (define (callback dwTextID lpszInfoText lpvUser) (if (equal? lpszInfoText "") (set! big-list (append big-list (list dwTextID))) (hash-

[racket] Some problem with hash-update!

2014-09-13 Thread Evgeny Odegov
Hi, all! I have a problem with the code below: (define result (make-hash)) (define (callback dwTextID lpszInfoText lpvUser) (hash-update! result lpszInfoText (lambda (id-lst) (define v (list dwTextID)) (if id-lst (append id-lst