<commit_before>;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
;;;
;;; --- Early definitions.
;;;

(in-package :iolib.syscalls)

;;;; Sizes of Standard Types

(defconstant size-of-char (foreign-type-size :char))
(defconstant size-of-int (foreign-type-size :int))
(defconstant size-of-long (foreign-type-size :long))
(defconstant size-of-long-long (foreign-type-size :long-long))
(defconstant size-of-pointer (foreign-type-size :pointer))
(defconstant size-of-short (foreign-type-size :short))



;;; Error predicate that always returns NIL.  Not actually used
;;; because the RETURN-WRAPPER optimizes this call away.
(defun never-fails (errcode)
  (declare (ignore errcode))
  nil)

;;; NOTE: This is a pretty neat type that probably deserves to be
;;; included in CFFI. --luis
;;;
;;; This type is used by DEFSYSCALL to automatically check for errors
;;; using the ERROR-PREDICATE function which is passed the foreign
;;; function's return value (after going through RETURN-FILTER).  If
;;; ERROR-PREDICATE returns true, ERROR-GENERATOR is invoked.  See the
;;; RETURN-WRAPPER parse method and type translation.
(define-foreign-type syscall-wrapper ()
  ((error-predicate :initarg :error-predicate :reader error-predicate-of)
   (error-location :initarg :error-location :reader error-location-of)
   (return-filter :initarg :return-filter :reader return-filter-of)
   (error-generator :initarg :error-generator :reader error-generator-of)
   (restart :initarg :restart :reader syscall-restart-p)
   (handle :initarg :handle :reader handle-of)
   (handle2 :initarg :handle2 :reader handle2-of)
   (base-type :initarg :base-type :reader base-type-of)))

(defun default-error-predicate (base-type)
  (case base-type
    (:string
     '(lambda (s) (not (stringp s))))
    (t
     (case (cffi::canonicalize-foreign-type base-type)
       (:pointer
        'null-pointer-p)
       ((:char :short :int :long :long-long)
        'minusp)<commit_msg>Test for type USTRING in SYSCALL-WRAPPER.<commit_after>;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
;;;
;;; --- Early definitions.
;;;

(in-package :iolib.syscalls)

;;;; Sizes of Standard Types

(defconstant size-of-char (foreign-type-size :char))
(defconstant size-of-int (foreign-type-size :int))
(defconstant size-of-long (foreign-type-size :long))
(defconstant size-of-long-long (foreign-type-size :long-long))
(defconstant size-of-pointer (foreign-type-size :pointer))
(defconstant size-of-short (foreign-type-size :short))



;;; Error predicate that always returns NIL.  Not actually used
;;; because the RETURN-WRAPPER optimizes this call away.
(defun never-fails (errcode)
  (declare (ignore errcode))
  nil)

;;; NOTE: This is a pretty neat type that probably deserves to be
;;; included in CFFI. --luis
;;;
;;; This type is used by DEFSYSCALL to automatically check for errors
;;; using the ERROR-PREDICATE function which is passed the foreign
;;; function's return value (after going through RETURN-FILTER).  If
;;; ERROR-PREDICATE returns true, ERROR-GENERATOR is invoked.  See the
;;; RETURN-WRAPPER parse method and type translation.
(define-foreign-type syscall-wrapper ()
  ((error-predicate :initarg :error-predicate :reader error-predicate-of)
   (error-location :initarg :error-location :reader error-location-of)
   (return-filter :initarg :return-filter :reader return-filter-of)
   (error-generator :initarg :error-generator :reader error-generator-of)
   (restart :initarg :restart :reader syscall-restart-p)
   (handle :initarg :handle :reader handle-of)
   (handle2 :initarg :handle2 :reader handle2-of)
   (base-type :initarg :base-type :reader base-type-of)))

(defun default-error-predicate (base-type)
  (case base-type
    (ustring
     '(lambda (s) (null s)))
    (:string
     '(lambda (s) (not (stringp s))))
    (t
     (case (cffi::canonicalize-foreign-type base-type)
       (:pointer
        'null-pointer-p)
       ((:char :short :int :long :long-long)
        'minusp)
{'fraction_non_alphanumeric': 0.1411088911088911, 'fraction_numerical': 0.0014985014985014985, 'mean_word_length': 4.095419847328245, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6924802', 'n_tokens_mistral': 1342, 'n_tokens_neox': 1291, 'n_words': 379}