Changeset 35763 in project


Ignore:
Timestamp:
07/05/18 10:01:49 (5 months ago)
Author:
kon
Message:

idiom

Location:
release/4/blob-utils/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • release/4/blob-utils/trunk/blob-hexadecimal.scm

    r35230 r35763  
    11;;;; blob-hexadecimal.scm  -*- Hen -*-
    22;;;; Kon Lovett, Apr '11
     3
     4(declare
     5  (bound-to-procedure
     6    ##sys#signal-hook))
    37
    48(module blob-hexadecimal
     
    1115  (only to-hex blob_to_hex)
    1216  (only type-checks check-natural-fixnum check-blob))
    13 
    14 (declare
    15   (bound-to-procedure
    16     ##sys#signal-hook))
    1717
    1818;;
     
    2727    (unless (<= start end)
    2828      (##sys#signal-hook
    29         #:bounds-error 'blob->hex
    30         "illegal subvector specification" start end))
     29        #:bounds-error 'blob->hex "illegal subvector specification" start end))
    3130    (let ((len (fx- end start)))
    3231      (if (fx= 0 len)
  • release/4/blob-utils/trunk/blob-set-int.scm

    r35386 r35763  
    2828;
    2929(define *blob-set-u8!
    30   (foreign-lambda* void ((nonnull-scheme-pointer bv) (unsigned-integer32 u32) (int off))
    31     "((uint8_t *)bv)[off] = (uint8_t)(u32 & 0xff);\n"))
     30  (foreign-lambda* void ((nonnull-scheme-pointer bv) (unsigned-integer32 u32) (int off)) "
     31    ((uint8_t *)bv)[off] = (uint8_t)(u32 & 0xff);
     32    "))
    3233
    3334(: *blob-set-u16-le! ((or blob string) number fixnum -> void))
    3435;
    3536(define *blob-set-u16-le!
    36   (foreign-lambda* void ((nonnull-scheme-pointer bv) (unsigned-integer32 u32) (int off))
    37     "((uint8_t *)bv)[off]   = (uint8_t)(u32 & 0xff);
    38     ((uint8_t *)bv)[++off] = (uint8_t)((u32 >> 8) & 0xff);\n"))
     37  (foreign-lambda* void ((nonnull-scheme-pointer bv) (unsigned-integer32 u32) (int off)) "
     38    ((uint8_t *)bv)[off]   = (uint8_t)(u32 & 0xff);
     39    ((uint8_t *)bv)[++off] = (uint8_t)((u32 >> 8) & 0xff);
     40    "))
    3941
    4042(: *blob-set-u32-le! ((or blob string) number fixnum -> void))
    4143;
    4244(define *blob-set-u16-be!
    43   (foreign-lambda* void ((nonnull-scheme-pointer bv) (unsigned-integer32 u32) (int off))
    44     "((uint8_t *)bv)[off]   = (uint8_t)((u32 >> 8) & 0xff);
    45     ((uint8_t *)bv)[++off] = (uint8_t)(u32 & 0xff);\n"))
     45  (foreign-lambda* void ((nonnull-scheme-pointer bv) (unsigned-integer32 u32) (int off)) "
     46    ((uint8_t *)bv)[off]   = (uint8_t)((u32 >> 8) & 0xff);
     47    ((uint8_t *)bv)[++off] = (uint8_t)(u32 & 0xff);
     48    "))
    4649
    4750(: *blob-set-u64-le! ((or blob string) number fixnum -> void))
    4851;
    4952(define *blob-set-u32-le!
    50   (foreign-lambda* void ((nonnull-scheme-pointer bv) (unsigned-integer32 u32) (int off))
    51     "((uint8_t *)bv)[off]   = (uint8_t)(u32 & 0xff);
     53  (foreign-lambda* void ((nonnull-scheme-pointer bv) (unsigned-integer32 u32) (int off)) "
     54    ((uint8_t *)bv)[off]   = (uint8_t)(u32 & 0xff);
    5255    ((uint8_t *)bv)[++off] = (uint8_t)((u32 >> 8) & 0xff);
    5356    ((uint8_t *)bv)[++off] = (uint8_t)((u32 >> 16) & 0xff);
    54     ((uint8_t *)bv)[++off] = (uint8_t)((u32 >> 24) & 0xff);\n"))
     57    ((uint8_t *)bv)[++off] = (uint8_t)((u32 >> 24) & 0xff);
     58    "))
    5559
    5660(: *blob-set-u16-be! ((or blob string) number fixnum -> void))
    5761;
    5862(define *blob-set-u32-be!
    59   (foreign-lambda* void ((nonnull-scheme-pointer bv) (unsigned-integer32 u32) (int off))
    60     "((uint8_t *)bv)[off]   = (uint8_t)((u32 >> 24) & 0xff);
     63  (foreign-lambda* void ((nonnull-scheme-pointer bv) (unsigned-integer32 u32) (int off)) "
     64    ((uint8_t *)bv)[off]   = (uint8_t)((u32 >> 24) & 0xff);
    6165    ((uint8_t *)bv)[++off] = (uint8_t)((u32 >> 16) & 0xff);
    6266    ((uint8_t *)bv)[++off] = (uint8_t)((u32 >> 8) & 0xff);
    63     ((uint8_t *)bv)[++off] = (uint8_t)(u32 & 0xff);\n"))
     67    ((uint8_t *)bv)[++off] = (uint8_t)(u32 & 0xff);
     68    "))
    6469
    6570(: *blob-set-u32-be! ((or blob string) number fixnum -> void))
    6671;
    6772(define *blob-set-u64-le!
    68   (foreign-lambda* void ((nonnull-scheme-pointer bv) (unsigned-integer64 u64) (int off))
    69     "((uint8_t *)bv)[off]   = (uint8_t)(u64 & 0xff);
     73  (foreign-lambda* void ((nonnull-scheme-pointer bv) (unsigned-integer64 u64) (int off)) "
     74    ((uint8_t *)bv)[off]   = (uint8_t)(u64 & 0xff);
    7075    ((uint8_t *)bv)[++off] = (uint8_t)((u64 >> 8) & 0xff);
    7176    ((uint8_t *)bv)[++off] = (uint8_t)((u64 >> 16) & 0xff);
    7277    ((uint8_t *)bv)[++off] = (uint8_t)((u64 >> 24) & 0xff);
    73                 ((uint8_t *)bv)[++off] = (uint8_t)((u64 >> 32) & 0xff);
    74                 ((uint8_t *)bv)[++off] = (uint8_t)((u64 >> 40) & 0xff);
    75                 ((uint8_t *)bv)[++off] = (uint8_t)((u64 >> 48) & 0xff);
    76                 ((uint8_t *)bv)[++off] = (uint8_t)((u64 >> 56) & 0xff);\n"))
     78    ((uint8_t *)bv)[++off] = (uint8_t)((u64 >> 32) & 0xff);
     79    ((uint8_t *)bv)[++off] = (uint8_t)((u64 >> 40) & 0xff);
     80    ((uint8_t *)bv)[++off] = (uint8_t)((u64 >> 48) & 0xff);
     81    ((uint8_t *)bv)[++off] = (uint8_t)((u64 >> 56) & 0xff);
     82    "))
    7783
    7884(: *blob-set-u64-be! ((or blob string) number fixnum -> void))
    7985;
    8086(define *blob-set-u64-be!
    81   (foreign-lambda* void ((nonnull-scheme-pointer bv) (unsigned-integer64 u64) (int off))
    82     "((uint8_t *)bv)[off]   = (uint8_t)((u64 >> 56) & 0xff);
     87  (foreign-lambda* void ((nonnull-scheme-pointer bv) (unsigned-integer64 u64) (int off)) "
     88    ((uint8_t *)bv)[off]   = (uint8_t)((u64 >> 56) & 0xff);
    8389    ((uint8_t *)bv)[++off] = (uint8_t)((u64 >> 48) & 0xff);
    8490    ((uint8_t *)bv)[++off] = (uint8_t)((u64 >> 40) & 0xff);
     
    8793    ((uint8_t *)bv)[++off] = (uint8_t)((u64 >> 16) & 0xff);
    8894    ((uint8_t *)bv)[++off] = (uint8_t)((u64 >> 8) & 0xff);
    89     ((uint8_t *)bv)[++off] = (uint8_t)(u64 & 0xff);\n"))
     95    ((uint8_t *)bv)[++off] = (uint8_t)(u64 & 0xff);
     96    "))
    9097
    9198;;; Only Blob Bytevector
  • release/4/blob-utils/trunk/pack-integer.scm

    r35230 r35763  
    11;;;; pack-integer.scm
     2;;;; Kon Lovett, Apr '12
     3;;;; Kon Lovett, May '10 (message-digest.scm)
    24;;;; Kon Lovett, Jan '06 (message-digest.scm)
    3 ;;;; Kon Lovett, May '10 (message-digest.scm)
    4 ;;;; Kon Lovett, Apr '12
    55
    66;; Issues
     7
     8#>
     9/* start is not a general offset. bytes length <= size */
     10static void
     11pack_uint64( uint8_t *bytes, uint64_t n, int size, int direction, int start )
     12{
     13  int end;
     14
     15  if(size == 1) {                           /* 1 byte */
     16    bytes[start] = n;
     17  } else if(direction == -1) {           /* Big endian */
     18    end = start;
     19    bytes[start += size - 1] = n & 0xff;    /* 2 bytes */
     20    bytes[--start] = (n >> 8) & 0xff;
     21    if(start != end) {                      /* 4 bytes */
     22      bytes[--start] = (n >> 16) & 0xff;
     23      bytes[--start] = (n >> 24) & 0xff;
     24      if(start != end) {                    /* 8 bytes */
     25        bytes[--start] = (n >> 32) & 0xff;
     26        bytes[--start] = (n >> 40) & 0xff;
     27        bytes[--start] = (n >> 48) & 0xff;
     28        bytes[--start] = (n >> 56) & 0xff;
     29      }
     30    }
     31  } else {                              /* Little endian */
     32    end = start + size - 1;
     33    bytes[start] = n & 0xff;              /* 2 bytes */
     34    bytes[++start] = (n >> 8) & 0xff;
     35    if(start != end) {                    /* 4 bytes */
     36      bytes[++start] = (n >> 16) & 0xff;
     37      bytes[++start] = (n >> 24) & 0xff;
     38      if(start != end) {                  /* 8 bytes */
     39        bytes[++start] = (n >> 32) & 0xff;
     40        bytes[++start] = (n >> 40) & 0xff;
     41        bytes[++start] = (n >> 48) & 0xff;
     42        bytes[++start] = (n >> 56) & 0xff;
     43      }
     44    }
     45  }
     46}
     47<#
    748
    849(module pack-integer
     
    3071
    3172;;;
    32 
    33 #>
    34 /* start is not a general offset. bytes length <= size */
    35 static void
    36 pack_uint64( uint8_t *bytes, uint64_t n, int size, int direction, int start )
    37 {
    38   int end;
    39 
    40   if (size == 1) {                        /* 1 byte */
    41 
    42     bytes[start] = n;
    43 
    44   } else if (direction == -1) { /* Big endian */
    45 
    46     end = start;
    47 
    48     bytes[start += size - 1] = n & 0xff;  /* 2 bytes */
    49     bytes[--start] = (n >> 8) & 0xff;
    50 
    51     if (start != end) {                   /* 4 bytes */
    52 
    53       bytes[--start] = (n >> 16) & 0xff;
    54       bytes[--start] = (n >> 24) & 0xff;
    55 
    56       if (start != end) {                 /* 8 bytes */
    57 
    58         bytes[--start] = (n >> 32) & 0xff;
    59         bytes[--start] = (n >> 40) & 0xff;
    60         bytes[--start] = (n >> 48) & 0xff;
    61         bytes[--start] = (n >> 56) & 0xff;
    62       }
    63     }
    64 
    65   } else {                      /* Little endian */
    66 
    67     end = start + size - 1;
    68 
    69     bytes[start] = n & 0xff;              /* 2 bytes */
    70     bytes[++start] = (n >> 8) & 0xff;
    71 
    72     if (start != end) {                   /* 4 bytes */
    73 
    74       bytes[++start] = (n >> 16) & 0xff;
    75       bytes[++start] = (n >> 24) & 0xff;
    76 
    77       if (start != end) {                 /* 8 bytes */
    78 
    79         bytes[++start] = (n >> 32) & 0xff;
    80         bytes[++start] = (n >> 40) & 0xff;
    81         bytes[++start] = (n >> 48) & 0xff;
    82         bytes[++start] = (n >> 56) & 0xff;
    83       }
    84     }
    85   }
    86 }
    87 <#
    8873
    8974(define (fxzero? x)
Note: See TracChangeset for help on using the changeset viewer.