Tcl Source Code

Hex Artifact Content
Login

Artifact 9353a436964c440c54a83e2ccfff7c40c3ae439318ddd5f70683500921f83c19:

Attachment "test-signed-tcl.c" to ticket [26f1328a86] added by anonymous 2022-01-12 13:01:28. (unpublished)
0000: 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e  #include <stdio.
0010: 68 3e 0a 0a 23 64 65 66 69 6e 65 20 69 73 5f 75  h>..#define is_u
0020: 6e 73 69 67 6e 65 64 28 6e 29 20 28 28 6e 29 20  nsigned(n) ((n) 
0030: 3e 3d 20 30 20 26 26 20 28 28 6e 29 2d 28 6e 29  >= 0 && ((n)-(n)
0040: 2d 31 29 20 3e 3d 20 30 29 0a 0a 23 64 65 66 69  -1) >= 0)..#defi
0050: 6e 65 20 54 63 6c 47 65 74 55 49 6e 74 31 41 74  ne TclGetUInt1At
0060: 50 74 72 28 70 29 20 5c 0a 20 20 20 20 28 28 75  Ptr(p) \.    ((u
0070: 6e 73 69 67 6e 65 64 20 69 6e 74 29 20 2a 28 70  nsigned int) *(p
0080: 29 29 0a 0a 23 64 65 66 69 6e 65 20 54 63 6c 47  ))..#define TclG
0090: 65 74 49 6e 74 34 41 74 50 74 72 28 70 29 20 20  etInt4AtPtr(p)  
00a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
00b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
00c0: 20 20 20 20 20 20 20 20 20 20 20 20 5c 0a 20 20              \.  
00d0: 20 20 28 28 28 69 6e 74 29 20 28 54 63 6c 47 65    (((int) (TclGe
00e0: 74 55 49 6e 74 31 41 74 50 74 72 28 70 29 20 3c  tUInt1AtPtr(p) <
00f0: 3c 20 32 34 29 29 20 7c 09 09 09 09 5c 0a 09 09  < 24)) |....\...
0100: 20 20 20 20 20 28 2a 28 28 70 29 2b 31 29 20 3c       (*((p)+1) <
0110: 3c 20 31 36 29 20 7c 09 09 09 09 5c 0a 09 09 20  < 16) |....\... 
0120: 20 20 20 20 28 2a 28 28 70 29 2b 32 29 20 3c 3c      (*((p)+2) <<
0130: 20 20 38 29 20 7c 09 09 09 09 5c 0a 09 09 20 20    8) |....\...  
0140: 20 20 20 28 2a 28 28 70 29 2b 33 29 29 29 0a 0a     (*((p)+3)))..
0150: 69 6e 74 0a 6d 61 69 6e 20 28 76 6f 69 64 29 20  int.main (void) 
0160: 7b 0a 20 20 20 20 20 20 20 20 2f 2f 20 42 61 73  {.        // Bas
0170: 65 6c 69 6e 65 0a 20 20 20 20 20 20 20 20 70 72  eline.        pr
0180: 69 6e 74 66 28 22 31 32 20 2d 3e 20 55 3a 25 64  intf("12 -> U:%d
0190: 5c 6e 22 2c 20 69 73 5f 75 6e 73 69 67 6e 65 64  \n", is_unsigned
01a0: 28 31 32 29 29 3b 0a 20 20 20 20 20 20 20 20 70  (12));.        p
01b0: 72 69 6e 74 66 28 22 31 32 55 20 2d 3e 20 55 3a  rintf("12U -> U:
01c0: 25 64 5c 6e 22 2c 20 69 73 5f 75 6e 73 69 67 6e  %d\n", is_unsign
01d0: 65 64 28 31 32 55 29 29 3b 0a 20 20 20 20 20 20  ed(12U));.      
01e0: 20 20 70 72 69 6e 74 66 28 22 2d 31 32 20 2d 3e    printf("-12 ->
01f0: 20 55 3a 25 64 5c 6e 22 2c 20 69 73 5f 75 6e 73   U:%d\n", is_uns
0200: 69 67 6e 65 64 28 2d 31 32 29 29 3b 0a 0a 20 20  igned(-12));..  
0210: 20 20 20 20 20 20 75 6e 73 69 67 6e 65 64 20 63        unsigned c
0220: 68 61 72 20 2a 20 70 63 20 3d 20 28 75 6e 73 69  har * pc = (unsi
0230: 67 6e 65 64 20 63 68 61 72 2a 29 6d 61 69 6e 3b  gned char*)main;
0240: 0a 0a 20 20 20 20 20 20 20 20 75 6e 73 69 67 6e  ..        unsign
0250: 65 64 20 63 68 61 72 20 62 79 74 65 73 5b 5d 20  ed char bytes[] 
0260: 3d 20 7b 30 78 46 46 2c 30 78 46 46 2c 30 78 46  = {0xFF,0xFF,0xF
0270: 44 2c 30 78 42 43 7d 3b 0a 20 20 20 20 20 20 20  D,0xBC};.       
0280: 20 70 72 69 6e 74 66 28 22 69 6e 74 28 62 79 74   printf("int(byt
0290: 65 73 29 3a 20 25 64 20 55 3a 25 64 5c 6e 22 2c  es): %d U:%d\n",
02a0: 20 54 63 6c 47 65 74 49 6e 74 34 41 74 50 74 72   TclGetInt4AtPtr
02b0: 28 62 79 74 65 73 29 2c 0a 20 20 20 20 20 20 20  (bytes),.       
02c0: 20 20 20 20 20 20 20 20 69 73 5f 75 6e 73 69 67          is_unsig
02d0: 6e 65 64 28 54 63 6c 47 65 74 49 6e 74 34 41 74  ned(TclGetInt4At
02e0: 50 74 72 28 62 79 74 65 73 29 29 29 3b 0a 0a 20  Ptr(bytes)));.. 
02f0: 20 20 20 20 20 20 20 70 72 69 6e 74 66 28 22 70         printf("p
0300: 74 72 3a 20 25 70 20 2b 20 69 6e 74 28 62 79 74  tr: %p + int(byt
0310: 65 73 29 20 2d 3e 20 25 70 20 28 64 69 66 66 3a  es) -> %p (diff:
0320: 25 6c 6c 64 29 5c 6e 22 2c 0a 20 20 20 20 20 20  %lld)\n",.      
0330: 20 20 20 20 20 20 20 20 20 70 63 2c 20 70 63 20           pc, pc 
0340: 2b 20 54 63 6c 47 65 74 49 6e 74 34 41 74 50 74  + TclGetInt4AtPt
0350: 72 28 62 79 74 65 73 29 2c 0a 20 20 20 20 20 20  r(bytes),.      
0360: 20 20 20 20 20 20 20 20 20 28 6c 6f 6e 67 20 6c           (long l
0370: 6f 6e 67 29 20 28 28 70 63 20 2b 20 54 63 6c 47  ong) ((pc + TclG
0380: 65 74 49 6e 74 34 41 74 50 74 72 28 62 79 74 65  etInt4AtPtr(byte
0390: 73 29 29 20 2d 20 70 63 29 29 3b 0a 0a 20 20 20  s)) - pc));..   
03a0: 20 20 20 20 20 72 65 74 75 72 6e 20 30 3b 0a 7d       return 0;.}
03b0: 0a                                               .