@ben 1) thanks for the stickers, they’re great (already on laptop) 2) would def buy a Racket shirt from DevSwag or similar
Anyone with more FFI experience than me, I’ve written the following code using mmap()
, but it always segfaults:
(define _mmap
(get-ffi-obj 'mmap #f
(_fun _pointer _ssize _int _int _int _int -> _pointer)))
(define (mmap f len)
(define fp (open-input-file f))
(_mmap #f len (bitwise-xor PROT_WRITE PROT_READ) MAP_SHARED (get_port_fd fp) 0))
(ptr-ref (mmap "/tmp/x" 100) _byte 0)
I assume I’m doing something wrong, but I don’t know what
@samth Trying using #:save-errno 'posix
and (saved-errno)
; probably the OS reports an error
samth: taking a look now…. where can I import get_port_fd from?
For me, it’s EACCES
, and using MAP_PRIVATE
makes it succeed
(define get_port_fd (get-ffi-obj 'scheme_get_port_fd #f (_fun _racket -> _int)))
ah, using PROT_READ
only makes it work
yeah, mmap returns –1 for your invocation
samth: use open-input-output-file instead of open-input-file
@thinkmoore I’ve tried that, but it gives me an error (with 25 as errno, which isn’t EACCES
)
instead it appears to be ENOTTY
which is very odd
@samth Does mmap
return –1 in that case?
I don’t think so
I get 35 as the first byte of the file I’m reading (my source code itself), which is unicode for #
errno does happen to be set to 25
ah, ok
so it just sets errno wrongly
well, more likely just doesn’t set it at all
one last q: is the best way to check that the pointer returned by mmap is sensible is just (cast m _pointer _long)
and see if it’s positive?
also, @thinkmoore @mflatt thanks for the help — now working
Good morning all — In v6.8 is there a way to force DrRacket to open files in new windows? I can’t find the option :disappointed:
nevermind, found it :slightly_smiling_face:
If I have a class
and inside I define a helper function using (define (helper a b) (+ a b))
, how can I access this function from another module in order to test it?
@pocmatos There isn’t really a way to access that, it’s local to the class definition, but if you have methods or fields that use the helper
function you can use those to test the behavior of the object and make sure helper
works the way you expect
@dan shame there isn’t some kind of override, but thanks.
It’s basically the same reason that you can’t access a definition local to a function ie: (define (foo x y z)
(define (helper a b) (+ a b))
(... some-expression-maybe-using-helper ...))
There’s no way to test that helper
is correct inside of foo
other than testing foo
itself
Yes, I understand that however there are exceptions to accesses when testing, for example, you can do require/expose
to access non provided members of a module. I had hoped there was something similar for local definitions. :slightly_smiling_face:
@pocmatos The require/expose
form only works for modules, not helpers inside a function. In general it’s not possible to extract a locally defined helper because it might have closed over local variables that wouldn’t exist once you’ve extracted it. If your helper doesn’t depend on the local context it’s defined in, lift it into a regular module-level definition so you can test it
@recon419 has joined the channel
pops out of a manhole holding a spatula and a pair of pliers, wearing a chef’s apron and a toque
flips up the lenses of his goggles and rubs his eyes, trying to gauge the welcomeness or lack thereof of his presence
:wave: s back
was dragged kicking and screaming from his beloved Common Lisp not three days ago, but thinks the Racketeers here seem quite nice so far.
what brought you to Racket from CL? If I may ask