<commit_before>#lang racket/base

(require (for-syntax racket/base
                     racket/syntax)
         ffi/unsafe
         ffi/unsafe/define
         racket/function)

(module+ test (require rackunit))

;; ---------------------------------------------------------------------------
;; library loader

(define zmq-lib (ffi-lib "libzmq"))

(define-ffi-definer define-zmq zmq-lib)

(define-syntax-rule (define-zmq-alias (alias actual) def)
  (define alias (get-ffi-obj 'actual zmq-lib def)))

(define-syntax-rule (define-zmq-check name args ...)
  (define-zmq name
    (_efun args ...
           -> (rc : _fixnum)
           -> (if (= rc -1) (croak 'name) rc))))

;; ---------------------------------------------------------------------------
;; error handling

(define-syntax-rule (_efun args ...)
  (_fun #:save-errno 'posix args ...))

(define-zmq zmq_strerror (_fun _fixint -> _string))

(define (croak caller)
  (error caller (zmq_strerror (saved-errno))))

;; ---------------------------------------------------------------------------
;; version

(define-zmq zmq_version
  (_fun (_box _fixint) (_box _fixint) (_box _fixint) -> _void))

(provide zmq_version)

(module+ test
  (let ([major (box -1)]
        [minor (box -1)]
        [patch (box -1)])
    (check equal? (zmq_version major minor patch) (void))))

;; ---------------------------------------------------------------------------
;; context

(struct context (obj) #:property prop:cpointer 0)

(define _context (_cpointer 'context))

(define-zmq zmq_ctx_new
  (_efun -> (obj : _context)
         -> (if obj (context obj) (croak 'zmq_ctx_new))))

(define _ctx_get_option<commit_msg>add zmq_version output checks<commit_after>#lang racket/base

(require (for-syntax racket/base
                     racket/syntax)
         ffi/unsafe
         ffi/unsafe/define
         racket/function)

(module+ test (require rackunit))

;; ---------------------------------------------------------------------------
;; library loader

(define zmq-lib (ffi-lib "libzmq"))

(define-ffi-definer define-zmq zmq-lib)

(define-syntax-rule (define-zmq-alias (alias actual) def)
  (define alias (get-ffi-obj 'actual zmq-lib def)))

(define-syntax-rule (define-zmq-check name args ...)
  (define-zmq name
    (_efun args ...
           -> (rc : _fixnum)
           -> (if (= rc -1) (croak 'name) rc))))

;; ---------------------------------------------------------------------------
;; error handling

(define-syntax-rule (_efun args ...)
  (_fun #:save-errno 'posix args ...))

(define-zmq zmq_strerror (_fun _fixint -> _string))

(define (croak caller)
  (error caller (zmq_strerror (saved-errno))))

;; ---------------------------------------------------------------------------
;; version

(define-zmq zmq_version
  (_fun (_box _fixint) (_box _fixint) (_box _fixint) -> _void))

(provide zmq_version)

(module+ test
  (let ([major (box -1)]
        [minor (box -1)]
        [patch (box -1)])
    (check equal? (zmq_version major minor patch) (void))
    (check-true (> (unbox major) 0))
    (check-true (> (unbox minor) 0))
    (check-true (> (unbox patch) 0))
    ))

;; ---------------------------------------------------------------------------
;; context

(struct context (obj) #:property prop:cpointer 0)

(define _context (_cpointer 'context))

(define-zmq zmq_ctx_new
  (_efun -> (obj : _context)
         -> (if obj (context obj) (croak 'zmq_ctx_new))))

(define _ctx_get_option
{'fraction_non_alphanumeric': 0.3073341094295693, 'fraction_numerical': 0.0037834691501746217, 'mean_word_length': 1.597883597883598, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6757559', 'n_tokens_mistral': 1074, 'n_tokens_neox': 1033, 'n_words': 266}