~williewillus/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
3 2

[PATCH r16 v2] Display almost all results in sandbox context

eutro
Details
Message ID
<20210513204241.1612633-1-benedek.szilvasy@gmail.com>
DKIM signature
pass
Download raw message
Patch: +17 -18
---
 evaluator.rkt | 18 +++++++++++-------
 main.rkt      | 17 ++++++-----------
 2 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/evaluator.rkt b/evaluator.rkt
index 3b93002..c396d13 100644
--- a/evaluator.rkt
+++ b/evaluator.rkt
@@ -5,7 +5,7 @@
(provide
 definitions?
 (contract-out
  [run (string? definitions? . -> . any)]))
  [run (string? definitions? predicate/c . -> . any)]))

(define definitions? (cons/c (listof (cons/c symbol? any/c))
                             (listof module-path?)))
@@ -72,16 +72,20 @@
                 [sandbox-reader (language-morph-reader definitions)])
    (make-evaluator 'racket)))

(define (run code definitions)
(define (run code definitions pass-out?)
  (parameterize ([current-environment-variables (make-environment-variables)])
    (let* ((evaluator (init-evaluator definitions))
           (results (call-with-values
    (let* ([evaluator (init-evaluator definitions)]
           [results (call-with-values
                     (thunk
                      (with-handlers ([(const #t) identity])
                        (evaluator code)))
                     list))
           (stdout (get-output evaluator))
           (stderr (get-error-output evaluator)))
                     (lambda results
                       (for/list ([result (in-list results)])
                         (if (pass-out? result)
                             result
                             (call-in-sandbox-context evaluator (thunk (~a result)))))))]
           [stdout (get-output evaluator)]
           [stderr (get-error-output evaluator)])
      (kill-evaluator evaluator)
      (apply values
             `(,stdout
diff --git a/main.rkt b/main.rkt
index 314de4e..9a7d61d 100755
--- a/main.rkt
+++ b/main.rkt
@@ -107,7 +107,7 @@
(define (run-snippet client db message code)
  (let ([code (strip-backticks code)])
    (with-typing-indicator client message
      (thunk (ev:run code (evaluation-ctx #f client message db (context-id message) "" #f))))))
      (thunk (ev:run code (evaluation-ctx #f client message db (context-id message) "" #f) http:attachment?)))))

(define (register-trick client db message text)
  (check-trick-prereqs
@@ -139,7 +139,8 @@
                      db
                      context-id
                      (or body "")
                      #f)))))
                      #f)
                     http:attachment?))))
         (~a "Trick " name " doesn't exist!")))))

(define (update-trick client db message text)
@@ -423,14 +424,8 @@
          (format "~a... [~a more characters]" (substring str 0 slicepos) restsize))
        str)))

(define (empty-string? s)
  (and (string? s) (= (string-length s) 0)))

(define (create-message-with-contents client channel message . contents)
  (let* ([content (apply ~a #:separator "\n"
                         (~>> contents
                              (map (lambda (x) (if (custom-write? x) "#<redacted>" x)))
                              (filter-not (disjoin void? http:attachment? empty-string?))))]
(define ((create-message-with-contents client channel message) . contents)
  (let* ([content (apply ~a #:separator "\n" (filter string? contents))]
         [attachment (findf http:attachment? contents)]
         [content (if (or attachment (non-empty-string? content))
                      (truncate-string content char-cap)
@@ -449,7 +444,7 @@
      (match-let ([(cons func content) (parse-command content)])
        (when func
          (call-with-values (thunk (func client db message content))
                            (curry create-message-with-contents client channel message)))))))
                            (create-message-with-contents client channel message)))))))

(define (init-client folder token)
  (log-r16-info "Storing tricks in ~a" folder)
-- 
2.31.1

[r16/patches/linux_buildtest.yml] build success

builds.sr.ht
Details
Message ID
<CBCESYYV4TWO.2ZUZWDLSQG27P@cirno>
In-Reply-To
<20210513204241.1612633-1-benedek.szilvasy@gmail.com> (view parent)
DKIM signature
missing
Download raw message
r16/patches/linux_buildtest.yml: SUCCESS in 1m38s

[Display almost all results in sandbox context][0] v2 from [eutro][1]

[0]: https://lists.sr.ht/~williewillus/public-inbox/patches/22682
[1]: benedek.szilvasy@gmail.com

✓ #506173 SUCCESS r16/patches/linux_buildtest.yml https://builds.sr.ht/~williewillus/job/506173
Details
Message ID
<87cztut9sg.fsf@vincent-lee.net>
In-Reply-To
<20210513204241.1612633-1-benedek.szilvasy@gmail.com> (view parent)
DKIM signature
pass
Download raw message
eutro writes:

> ---
>  evaluator.rkt | 18 +++++++++++-------
>  main.rkt      | 17 ++++++-----------
>  2 files changed, 17 insertions(+), 18 deletions(-)
>
> diff --git a/evaluator.rkt b/evaluator.rkt
> index 3b93002..c396d13 100644
> --- a/evaluator.rkt
> +++ b/evaluator.rkt
> @@ -5,7 +5,7 @@
>  (provide
>   definitions?
>   (contract-out
> -  [run (string? definitions? . -> . any)]))
> +  [run (string? definitions? predicate/c . -> . any)]))
>  
>  (define definitions? (cons/c (listof (cons/c symbol? any/c))
>                               (listof module-path?)))
> @@ -72,16 +72,20 @@
>                   [sandbox-reader (language-morph-reader definitions)])
>      (make-evaluator 'racket)))
>  
> -(define (run code definitions)
> +(define (run code definitions pass-out?)
>    (parameterize ([current-environment-variables (make-environment-variables)])
> -    (let* ((evaluator (init-evaluator definitions))
> -           (results (call-with-values
> +    (let* ([evaluator (init-evaluator definitions)]
> +           [results (call-with-values
>                       (thunk
>                        (with-handlers ([(const #t) identity])
>                          (evaluator code)))
> -                     list))
> -           (stdout (get-output evaluator))
> -           (stderr (get-error-output evaluator)))
> +                     (lambda results
> +                       (for/list ([result (in-list results)])
> +                         (if (pass-out? result)
> +                             result
> +                             (call-in-sandbox-context evaluator (thunk (~a result)))))))]
Doesn't this still have the same problem as before? Namely, I can
produce as output a large list of custom objects. Each of those custom
objects will now get ~a called on it with a fresh set of resource
limits. Thus, I can consume `(max time limit) * (max number of those
objects I can produce within one time limit)` time with one invocation.
> +           [stdout (get-output evaluator)]
> +           [stderr (get-error-output evaluator)])
>        (kill-evaluator evaluator)
>        (apply values
>               `(,stdout
> diff --git a/main.rkt b/main.rkt
> index 314de4e..9a7d61d 100755
> --- a/main.rkt
> +++ b/main.rkt
> @@ -107,7 +107,7 @@
>  (define (run-snippet client db message code)
>    (let ([code (strip-backticks code)])
>      (with-typing-indicator client message
> -      (thunk (ev:run code (evaluation-ctx #f client message db (context-id message) "" #f))))))
> +      (thunk (ev:run code (evaluation-ctx #f client message db (context-id message) "" #f) http:attachment?)))))
>  
>  (define (register-trick client db message text)
>    (check-trick-prereqs
> @@ -139,7 +139,8 @@
>                        db
>                        context-id
>                        (or body "")
> -                      #f)))))
> +                      #f)
> +                     http:attachment?))))
>           (~a "Trick " name " doesn't exist!")))))
>  
>  (define (update-trick client db message text)
> @@ -423,14 +424,8 @@
>            (format "~a... [~a more characters]" (substring str 0 slicepos) restsize))
>          str)))
>  
> -(define (empty-string? s)
> -  (and (string? s) (= (string-length s) 0)))
> -
> -(define (create-message-with-contents client channel message . contents)
> -  (let* ([content (apply ~a #:separator "\n"
> -                         (~>> contents
> -                              (map (lambda (x) (if (custom-write? x) "#<redacted>" x)))
> -                              (filter-not (disjoin void? http:attachment? empty-string?))))]
> +(define ((create-message-with-contents client channel message) . contents)
> +  (let* ([content (apply ~a #:separator "\n" (filter string? contents))]
>           [attachment (findf http:attachment? contents)]
>           [content (if (or attachment (non-empty-string? content))
>                        (truncate-string content char-cap)
> @@ -449,7 +444,7 @@
>        (match-let ([(cons func content) (parse-command content)])
>          (when func
>            (call-with-values (thunk (func client db message content))
> -                            (curry create-message-with-contents client channel message)))))))
> +                            (create-message-with-contents client channel message)))))))
>  
>  (define (init-client folder token)
>    (log-r16-info "Storing tricks in ~a" folder)
Details
Message ID
<878s4it9nt.fsf@vincent-lee.net>
In-Reply-To
<87cztut9sg.fsf@vincent-lee.net> (view parent)
DKIM signature
pass
Download raw message
Vincent Lee writes:

Ignore this message, I didn't see your V3.

> eutro writes:
>
>> ---
>>  evaluator.rkt | 18 +++++++++++-------
>>  main.rkt      | 17 ++++++-----------
>>  2 files changed, 17 insertions(+), 18 deletions(-)
>>
>> diff --git a/evaluator.rkt b/evaluator.rkt
>> index 3b93002..c396d13 100644
>> --- a/evaluator.rkt
>> +++ b/evaluator.rkt
>> @@ -5,7 +5,7 @@
>>  (provide
>>   definitions?
>>   (contract-out
>> -  [run (string? definitions? . -> . any)]))
>> +  [run (string? definitions? predicate/c . -> . any)]))
>>  
>>  (define definitions? (cons/c (listof (cons/c symbol? any/c))
>>                               (listof module-path?)))
>> @@ -72,16 +72,20 @@
>>                   [sandbox-reader (language-morph-reader definitions)])
>>      (make-evaluator 'racket)))
>>  
>> -(define (run code definitions)
>> +(define (run code definitions pass-out?)
>>    (parameterize ([current-environment-variables (make-environment-variables)])
>> -    (let* ((evaluator (init-evaluator definitions))
>> -           (results (call-with-values
>> +    (let* ([evaluator (init-evaluator definitions)]
>> +           [results (call-with-values
>>                       (thunk
>>                        (with-handlers ([(const #t) identity])
>>                          (evaluator code)))
>> -                     list))
>> -           (stdout (get-output evaluator))
>> -           (stderr (get-error-output evaluator)))
>> +                     (lambda results
>> +                       (for/list ([result (in-list results)])
>> +                         (if (pass-out? result)
>> +                             result
>> +                             (call-in-sandbox-context evaluator (thunk (~a result)))))))]
> Doesn't this still have the same problem as before? Namely, I can
> produce as output a large list of custom objects. Each of those custom
> objects will now get ~a called on it with a fresh set of resource
> limits. Thus, I can consume `(max time limit) * (max number of those
> objects I can produce within one time limit)` time with one invocation.
>> +           [stdout (get-output evaluator)]
>> +           [stderr (get-error-output evaluator)])
>>        (kill-evaluator evaluator)
>>        (apply values
>>               `(,stdout
>> diff --git a/main.rkt b/main.rkt
>> index 314de4e..9a7d61d 100755
>> --- a/main.rkt
>> +++ b/main.rkt
>> @@ -107,7 +107,7 @@
>>  (define (run-snippet client db message code)
>>    (let ([code (strip-backticks code)])
>>      (with-typing-indicator client message
>> -      (thunk (ev:run code (evaluation-ctx #f client message db (context-id message) "" #f))))))
>> +      (thunk (ev:run code (evaluation-ctx #f client message db (context-id message) "" #f) http:attachment?)))))
>>  
>>  (define (register-trick client db message text)
>>    (check-trick-prereqs
>> @@ -139,7 +139,8 @@
>>                        db
>>                        context-id
>>                        (or body "")
>> -                      #f)))))
>> +                      #f)
>> +                     http:attachment?))))
>>           (~a "Trick " name " doesn't exist!")))))
>>  
>>  (define (update-trick client db message text)
>> @@ -423,14 +424,8 @@
>>            (format "~a... [~a more characters]" (substring str 0 slicepos) restsize))
>>          str)))
>>  
>> -(define (empty-string? s)
>> -  (and (string? s) (= (string-length s) 0)))
>> -
>> -(define (create-message-with-contents client channel message . contents)
>> -  (let* ([content (apply ~a #:separator "\n"
>> -                         (~>> contents
>> -                              (map (lambda (x) (if (custom-write? x) "#<redacted>" x)))
>> -                              (filter-not (disjoin void? http:attachment? empty-string?))))]
>> +(define ((create-message-with-contents client channel message) . contents)
>> +  (let* ([content (apply ~a #:separator "\n" (filter string? contents))]
>>           [attachment (findf http:attachment? contents)]
>>           [content (if (or attachment (non-empty-string? content))
>>                        (truncate-string content char-cap)
>> @@ -449,7 +444,7 @@
>>        (match-let ([(cons func content) (parse-command content)])
>>          (when func
>>            (call-with-values (thunk (func client db message content))
>> -                            (curry create-message-with-contents client channel message)))))))
>> +                            (create-message-with-contents client channel message)))))))
>>  
>>  (define (init-client folder token)
>>    (log-r16-info "Storing tricks in ~a" folder)
Reply to thread Export thread (mbox)