Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memory corruption on racketcs with reencode-output-port #2677

Closed
samth opened this issue Jun 3, 2019 · 4 comments
Closed

memory corruption on racketcs with reencode-output-port #2677

samth opened this issue Jun 3, 2019 · 4 comments

Comments

@samth
Copy link
Sponsor Member

samth commented Jun 3, 2019

This program:

#lang racket/base
(require scheme/port)
(define-struct transcoder (codec eol-style error-handling-mode))
(define-struct codec (enc))
(define utf-8 (make-codec "utf-8"))
(define-struct textual-output-port (port transcoder)
  #:property prop:output-port 0)

(define utf8-transcoder
  (make-transcoder utf-8 'none '?))
(define (transcode-output p t)
  (reencode-output-port p
                        (codec-enc (transcoder-codec t))
                        #f
                        #t
                        (object-name p)
                        #f
                        #f))

(let-values (((out) (make-textual-output-port (transcode-output (open-output-string) utf8-transcoder) utf8-transcoder)))
  (let-values
             (((r) (begin (newline out) #;(get-output-string out))))
  #t))

causes an "invalid memory reference" error on racketcs, but works correctly on racket.

@samth
Copy link
Sponsor Member Author

samth commented Jun 3, 2019

Originally reported in #2675.

@gus-massa
Copy link
Contributor

Minimized version:

#lang racket/base
(define-struct myport (port)
  #:property prop:output-port 0)

(define out
  (make-myport
   #;(current-output-port)
   (open-output-string)))
#;(display 777 out)
(newline out)

You can replace (open-output-string) with (open-output-string), but you can't replace newline with display. My guess is that newline doesn't understand custom ports.

@mflatt
Copy link
Member

mflatt commented Jun 4, 2019

Thanks for the report and for narrowing down the problem!

For future reference, when you suspect a bug in the Racket layer over Chez Scheme, it can help to try building that layer in safe mode. To do that, comment out --unsafe in racket/src/cs/Makefile, then go to racket/src/build/cs/c (or wherever your build directory is) and delete all ".so" files, make, and try ./racketcs.

Safe mode produces an error that confirms @gus-massa's suspicion: core-port-buffer: #<myport> is not of type #<struct-type>.

@mflatt mflatt closed this as completed in 0371075 Jun 4, 2019
@gus-massa
Copy link
Contributor

Now the test of racket-r7rs finish cleanly in HEAD and HEADCS https://travis-ci.org/gus-massa/racket-r7rs/builds/542031427

MarcKaufmann pushed a commit to MarcKaufmann/racket that referenced this issue Apr 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants