with-i/o procedures close their ports
* tekuti/util.scm (with-output-to-string*, with-input-from-string*): New hacky helpers, which close the port before returning the string or result. Hopefully reduce pressure on the GC. (shell:quote): * tekuti/git.scm (git-commit-reverse-operations, with-output-to-blob*) (with-input-from-blob*): * tekuti/filters.scm (wordpress->sxml): Use the string* procedures.
This commit is contained in:
parent
a4bad7a561
commit
26216a593a
3 changed files with 22 additions and 8 deletions
|
@ -1,5 +1,5 @@
|
||||||
;; Tekuti
|
;; Tekuti
|
||||||
;; Copyright (C) 2008, 2010 Andy Wingo <wingo at pobox dot com>
|
;; Copyright (C) 2008, 2010, 2011 Andy Wingo <wingo at pobox dot com>
|
||||||
|
|
||||||
;; This program is free software; you can redistribute it and/or
|
;; This program is free software; you can redistribute it and/or
|
||||||
;; modify it under the terms of the GNU General Public License as
|
;; modify it under the terms of the GNU General Public License as
|
||||||
|
@ -79,7 +79,7 @@
|
||||||
(cons (car in) (pclose p out))))))))
|
(cons (car in) (pclose p out))))))))
|
||||||
|
|
||||||
(define (wordpress->sxml text)
|
(define (wordpress->sxml text)
|
||||||
(let ((sxml (cadr (with-input-from-string (string-append "<div>" text "</div>")
|
(let ((sxml (cadr (with-input-from-string* (string-append "<div>" text "</div>")
|
||||||
xml->sxml))))
|
xml->sxml))))
|
||||||
(pre-post-order
|
(pre-post-order
|
||||||
sxml
|
sxml
|
||||||
|
|
|
@ -235,7 +235,7 @@
|
||||||
;; probably the best that we can do, given that git does not track
|
;; probably the best that we can do, given that git does not track
|
||||||
;; directory renames.
|
;; directory renames.
|
||||||
(define (git-commit-reverse-operations sha1)
|
(define (git-commit-reverse-operations sha1)
|
||||||
(with-input-from-string (git "diff-tree" "-R" "-r" sha1)
|
(with-input-from-string* (git "diff-tree" "-R" "-r" sha1)
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(read-line) ;; throw away the header
|
(read-line) ;; throw away the header
|
||||||
(let lp ((ops '()))
|
(let lp ((ops '()))
|
||||||
|
@ -339,7 +339,7 @@
|
||||||
(- ts (* (+ (* (quotient tz 100) 60) (remainder tz 100)) 60)))))
|
(- ts (* (+ (* (quotient tz 100) 60) (remainder tz 100)) 60)))))
|
||||||
|
|
||||||
(define (with-output-to-blob* thunk)
|
(define (with-output-to-blob* thunk)
|
||||||
(git-hash-object (with-output-to-string thunk)))
|
(git-hash-object (with-output-to-string* thunk)))
|
||||||
|
|
||||||
(define-syntax with-output-to-blob
|
(define-syntax with-output-to-blob
|
||||||
(syntax-rules ()
|
(syntax-rules ()
|
||||||
|
@ -347,7 +347,7 @@
|
||||||
(with-output-to-blob* (lambda () f f* ...)))))
|
(with-output-to-blob* (lambda () f f* ...)))))
|
||||||
|
|
||||||
(define (with-input-from-blob* sha1 thunk)
|
(define (with-input-from-blob* sha1 thunk)
|
||||||
(with-input-from-string (git "show" sha1) thunk))
|
(with-input-from-string* (git "show" sha1) thunk))
|
||||||
|
|
||||||
(define-syntax with-input-from-blob
|
(define-syntax with-input-from-blob
|
||||||
(syntax-rules ()
|
(syntax-rules ()
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
;; Tekuti
|
;; Tekuti
|
||||||
;; Copyright (C) 2008, 2010 Andy Wingo <wingo at pobox dot com>
|
;; Copyright (C) 2008, 2010, 2011 Andy Wingo <wingo at pobox dot com>
|
||||||
|
|
||||||
;; This program is free software; you can redistribute it and/or
|
;; This program is free software; you can redistribute it and/or
|
||||||
;; modify it under the terms of the GNU General Public License as
|
;; modify it under the terms of the GNU General Public License as
|
||||||
|
@ -28,7 +28,8 @@
|
||||||
#:use-module (tekuti match-bind)
|
#:use-module (tekuti match-bind)
|
||||||
#:use-module (srfi srfi-1)
|
#:use-module (srfi srfi-1)
|
||||||
#:use-module (srfi srfi-19)
|
#:use-module (srfi srfi-19)
|
||||||
#:export (expanduser match-lines dbg unwind-protect dsu-sort
|
#:export (with-output-to-string* with-input-from-string*
|
||||||
|
expanduser match-lines dbg unwind-protect dsu-sort
|
||||||
hash-push! list-has-length? list-head-match mapn filter-mapn
|
hash-push! list-has-length? list-head-match mapn filter-mapn
|
||||||
take-max read-hash write-hash shell:quote foldn
|
take-max read-hash write-hash shell:quote foldn
|
||||||
call-with-temp-file emailish? urlish?
|
call-with-temp-file emailish? urlish?
|
||||||
|
@ -37,6 +38,19 @@
|
||||||
date->timestamp timestamp->date string-split/trimming
|
date->timestamp timestamp->date string-split/trimming
|
||||||
list-intersperse with-time-debugging))
|
list-intersperse with-time-debugging))
|
||||||
|
|
||||||
|
(define (with-output-to-string* thunk)
|
||||||
|
(let ((port (open-output-string)))
|
||||||
|
(with-output-to-port port thunk)
|
||||||
|
(let ((str (get-output-string port)))
|
||||||
|
(close-port port)
|
||||||
|
str)))
|
||||||
|
|
||||||
|
(define (with-input-from-string* str thunk)
|
||||||
|
(let* ((port (open-input-string str))
|
||||||
|
(res (with-input-from-port port thunk)))
|
||||||
|
(close-port port)
|
||||||
|
res))
|
||||||
|
|
||||||
(define (emailish? x)
|
(define (emailish? x)
|
||||||
(match-bind "^([a-zA-Z0-9._+-]+)@([a-zA-Z0-9-]+\\.)+[a-zA-Z]+$"
|
(match-bind "^([a-zA-Z0-9._+-]+)@([a-zA-Z0-9-]+\\.)+[a-zA-Z]+$"
|
||||||
x (_ . args)
|
x (_ . args)
|
||||||
|
@ -75,7 +89,7 @@
|
||||||
(delete-file template))))
|
(delete-file template))))
|
||||||
|
|
||||||
(define (shell:quote str)
|
(define (shell:quote str)
|
||||||
(with-output-to-string
|
(with-output-to-string*
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(display #\')
|
(display #\')
|
||||||
(string-for-each (lambda (ch)
|
(string-for-each (lambda (ch)
|
||||||
|
|
Loading…
Reference in a new issue