d_run
2017-1-26 13:08:55

@ben 1) thanks for the stickers, they’re great (already on laptop) 2) would def buy a Racket shirt from DevSwag or similar


samth
2017-1-26 14:54:28

Anyone with more FFI experience than me, I’ve written the following code using mmap(), but it always segfaults:


samth
2017-1-26 14:54:31
(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)

samth
2017-1-26 14:54:57

I assume I’m doing something wrong, but I don’t know what


mflatt
2017-1-26 15:09:28

@samth Trying using #:save-errno 'posix and (saved-errno); probably the OS reports an error


thinkmoore
2017-1-26 15:09:39

samth: taking a look now…. where can I import get_port_fd from?


mflatt
2017-1-26 15:09:53

For me, it’s EACCES, and using MAP_PRIVATE makes it succeed


samth
2017-1-26 15:10:00

(define get_port_fd (get-ffi-obj 'scheme_get_port_fd #f (_fun _racket -> _int)))


samth
2017-1-26 15:10:55

ah, using PROT_READ only makes it work


thinkmoore
2017-1-26 15:11:11

yeah, mmap returns –1 for your invocation


thinkmoore
2017-1-26 15:14:36

samth: use open-input-output-file instead of open-input-file


samth
2017-1-26 15:20:27

@thinkmoore I’ve tried that, but it gives me an error (with 25 as errno, which isn’t EACCES)


samth
2017-1-26 15:21:04

instead it appears to be ENOTTY which is very odd


mflatt
2017-1-26 15:23:08

@samth Does mmap return –1 in that case?


thinkmoore
2017-1-26 15:23:12

I don’t think so


thinkmoore
2017-1-26 15:23:49

I get 35 as the first byte of the file I’m reading (my source code itself), which is unicode for #


thinkmoore
2017-1-26 15:24:02

errno does happen to be set to 25


samth
2017-1-26 15:24:32

ah, ok


samth
2017-1-26 15:24:40

so it just sets errno wrongly


thinkmoore
2017-1-26 15:24:48

well, more likely just doesn’t set it at all


samth
2017-1-26 15:33:30

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?


samth
2017-1-26 15:40:10

also, @thinkmoore @mflatt thanks for the help — now working


samth
2017-1-26 16:06:43

jerryj
2017-1-26 17:56:15

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:


jerryj
2017-1-26 17:59:25

nevermind, found it :slightly_smiling_face:


pocmatos
2017-1-26 20:03:18

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?


dan
2017-1-26 20:08:16

@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


pocmatos
2017-1-26 20:09:14

@dan shame there isn’t some kind of override, but thanks.


dan
2017-1-26 20:14:26

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


pocmatos
2017-1-26 20:15:38

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:


notjack
2017-1-26 20:27:08

@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
2017-1-27 02:20:25

@recon419 has joined the channel


recon419
2017-1-27 02:26:20

pops out of a manhole holding a spatula and a pair of pliers, wearing a chef’s apron and a toque


recon419
2017-1-27 02:28:58

flips up the lenses of his goggles and rubs his eyes, trying to gauge the welcomeness or lack thereof of his presence


recon419
2017-1-27 02:31:37

:wave: s back


recon419
2017-1-27 02:34:21

was dragged kicking and screaming from his beloved Common Lisp not three days ago, but thinks the Racketeers here seem quite nice so far.


abmclin
2017-1-27 03:03:42

what brought you to Racket from CL? If I may ask