bin_utils 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,11 +12,13 @@ typedef unsigned __int32 uint32_t;
12
12
  typedef __int64 int64_t;
13
13
  typedef unsigned __int64 uint64_t;
14
14
  #else
15
+ #ifndef __int8_t_defined
15
16
  typedef char int8_t;
16
- typedef unsigned char uint8_t;
17
17
  typedef short int16_t;
18
- typedef unsigned short uint16_t;
19
18
  typedef int int32_t;
19
+ #endif
20
+ typedef unsigned char uint8_t;
21
+ typedef unsigned short uint16_t;
20
22
  typedef unsigned int uint32_t;
21
23
  #if SIZEOF_LONG==8
22
24
  typedef long int64_t;
@@ -1097,100 +1099,122 @@ append_ber(VALUE rstr, uint64_t ber)
1097
1099
  return 11-i;
1098
1100
  }
1099
1101
 
1102
+ typedef struct append_args {
1103
+ VALUE str;
1104
+ int argc;
1105
+ VALUE *argv;
1106
+ } append_args;
1107
+
1108
+ typedef struct append_args2 {
1109
+ VALUE str;
1110
+ int argc;
1111
+ VALUE *argv;
1112
+ VALUE int0;
1113
+ } append_args2;
1114
+
1100
1115
  static void
1101
- check_argc_append(int argc, int bits)
1116
+ check_argc_append(int argc, VALUE *argv, append_args *args, int bits)
1102
1117
  {
1103
1118
  if (argc < 1) {
1104
1119
  rb_raise(rb_eArgError, "accepts at least 1 argument: (string[, *int%ds])", bits);
1105
1120
  }
1121
+ args->str = RTEST(argv[0]) ? argv[0] : rb_str_new(0, 0);
1122
+ if (argc == 2 && TYPE(argv[1]) == T_ARRAY) {
1123
+ args->argc = RARRAY_LEN(argv[1]);
1124
+ args->argv = RARRAY_PTR(argv[1]);
1125
+ }
1126
+ else {
1127
+ args->argc = argc-1;
1128
+ args->argv = argv+1;
1129
+ }
1106
1130
  }
1107
1131
 
1108
1132
  static void
1109
- check_argc_append_2(int argc, int bits, int bits1)
1133
+ check_argc_append_2(int argc, VALUE *argv, append_args2 *args, int bits, int bits1)
1110
1134
  {
1111
- if (argc <= 1) {
1135
+ if (argc < 2) {
1112
1136
  rb_raise(rb_eArgError, "accepts at least 2 arguments: (string, int%d[, *int%ds])", bits, bits1);
1113
1137
  }
1138
+ args->str = RTEST(argv[0]) ? argv[0] : rb_str_new(0, 0);
1139
+ args->int0 = argv[1];
1140
+ if (argc == 3 && TYPE(argv[2]) == T_ARRAY) {
1141
+ args->argc = RARRAY_LEN(argv[2]);
1142
+ args->argv = RARRAY_PTR(argv[2]);
1143
+ }
1144
+ else {
1145
+ args->argc = argc-2;
1146
+ args->argv = argv+2;
1147
+ }
1114
1148
  }
1115
1149
 
1116
1150
  /*** 32BIT **/
1117
1151
  static VALUE
1118
- rb_append_int8(int argc, VALUE* argv, VALUE self)
1152
+ append_var_int8(int argc, VALUE* argv, VALUE str)
1119
1153
  {
1120
- VALUE str; int i;
1121
- check_argc_append(argc, 8);
1122
- str = argv[0];
1123
- for(i = 1; i < argc; i++) {
1154
+ int i;
1155
+ for(i = 0; i < argc; i++) {
1124
1156
  append_int8(str, NUM2INT(argv[i]));
1125
1157
  }
1126
1158
  return str;
1127
1159
  }
1160
+ #define append_var_int8_le append_var_int8
1161
+ #define append_var_int8_be append_var_int8
1128
1162
 
1129
1163
  static VALUE
1130
- rb_append_int16_le(int argc, VALUE* argv, VALUE self)
1164
+ append_var_int16_le(int argc, VALUE* argv, VALUE str)
1131
1165
  {
1132
- VALUE str; int i;
1133
- check_argc_append(argc, 16);
1134
- str = argv[0];
1135
- for(i = 1; i < argc; i++) {
1166
+ int i;
1167
+ for(i = 0; i < argc; i++) {
1136
1168
  append_int16_le(str, NUM2INT(argv[i]));
1137
1169
  }
1138
1170
  return str;
1139
1171
  }
1140
1172
 
1141
1173
  static VALUE
1142
- rb_append_int24_le(int argc, VALUE* argv, VALUE self)
1174
+ append_var_int24_le(int argc, VALUE* argv, VALUE str)
1143
1175
  {
1144
- VALUE str; int i;
1145
- check_argc_append(argc, 24);
1146
- str = argv[0];
1147
- for(i = 1; i < argc; i++) {
1176
+ int i;
1177
+ for(i = 0; i < argc; i++) {
1148
1178
  append_int24_le(str, NUM2INT(argv[i]));
1149
1179
  }
1150
1180
  return str;
1151
1181
  }
1152
1182
 
1153
1183
  static VALUE
1154
- rb_append_int32_le(int argc, VALUE* argv, VALUE self)
1184
+ append_var_int32_le(int argc, VALUE* argv, VALUE str)
1155
1185
  {
1156
- VALUE str = argv[0];
1157
1186
  int i;
1158
- for(i = 1; i < argc; i++) {
1187
+ for(i = 0; i < argc; i++) {
1159
1188
  append_int32_le(str, (int32_t)NUM2I64(argv[i]));
1160
1189
  }
1161
1190
  return str;
1162
1191
  }
1163
1192
 
1164
1193
  static VALUE
1165
- rb_append_int16_be(int argc, VALUE* argv, VALUE self)
1194
+ append_var_int16_be(int argc, VALUE* argv, VALUE str)
1166
1195
  {
1167
- VALUE str; int i;
1168
- check_argc_append(argc, 16);
1169
- str = argv[0];
1170
- for(i = 1; i < argc; i++) {
1196
+ int i;
1197
+ for(i = 0; i < argc; i++) {
1171
1198
  append_int16_be(str, NUM2INT(argv[i]));
1172
1199
  }
1173
1200
  return str;
1174
1201
  }
1175
1202
 
1176
1203
  static VALUE
1177
- rb_append_int24_be(int argc, VALUE* argv, VALUE self)
1204
+ append_var_int24_be(int argc, VALUE* argv, VALUE str)
1178
1205
  {
1179
- VALUE str; int i;
1180
- check_argc_append(argc, 24);
1181
- str = argv[0];
1182
- for(i = 1; i < argc; i++) {
1206
+ int i;
1207
+ for(i = 0; i < argc; i++) {
1183
1208
  append_int24_be(str, NUM2INT(argv[i]));
1184
1209
  }
1185
1210
  return str;
1186
1211
  }
1187
1212
 
1188
1213
  static VALUE
1189
- rb_append_int32_be(int argc, VALUE* argv, VALUE self)
1214
+ append_var_int32_be(int argc, VALUE* argv, VALUE str)
1190
1215
  {
1191
- VALUE str = argv[0];
1192
1216
  int i;
1193
- for(i = 1; i < argc; i++) {
1217
+ for(i = 0; i < argc; i++) {
1194
1218
  append_int32_be(str, (int32_t)NUM2I64(argv[i]));
1195
1219
  }
1196
1220
  return str;
@@ -1199,369 +1223,187 @@ rb_append_int32_be(int argc, VALUE* argv, VALUE self)
1199
1223
 
1200
1224
  /*** 64BIT ***/
1201
1225
  static VALUE
1202
- rb_append_int40_le(int argc, VALUE* argv, VALUE self)
1226
+ append_var_int40_le(int argc, VALUE* argv, VALUE str)
1203
1227
  {
1204
- VALUE str; int i;
1205
- check_argc_append(argc, 40);
1206
- str = argv[0];
1207
- for(i = 1; i < argc; i++) {
1228
+ int i;
1229
+ for(i = 0; i < argc; i++) {
1208
1230
  append_int40_le(str, NUM2I64(argv[i]));
1209
1231
  }
1210
1232
  return str;
1211
1233
  }
1212
1234
 
1213
1235
  static VALUE
1214
- rb_append_int48_le(int argc, VALUE* argv, VALUE self)
1236
+ append_var_int48_le(int argc, VALUE* argv, VALUE str)
1215
1237
  {
1216
- VALUE str; int i;
1217
- check_argc_append(argc, 48);
1218
- str = argv[0];
1219
- for(i = 1; i < argc; i++) {
1238
+ int i;
1239
+ for(i = 0; i < argc; i++) {
1220
1240
  append_int48_le(str, NUM2I64(argv[i]));
1221
1241
  }
1222
1242
  return str;
1223
1243
  }
1224
1244
 
1225
1245
  static VALUE
1226
- rb_append_int56_le(int argc, VALUE* argv, VALUE self)
1246
+ append_var_int56_le(int argc, VALUE* argv, VALUE str)
1227
1247
  {
1228
- VALUE str; int i;
1229
- check_argc_append(argc, 56);
1230
- str = argv[0];
1231
- for(i = 1; i < argc; i++) {
1248
+ int i;
1249
+ for(i = 0; i < argc; i++) {
1232
1250
  append_int56_le(str, NUM2I64(argv[i]));
1233
1251
  }
1234
1252
  return str;
1235
1253
  }
1236
1254
 
1237
1255
  static VALUE
1238
- rb_append_int64_le(int argc, VALUE* argv, VALUE self)
1256
+ append_var_int64_le(int argc, VALUE* argv, VALUE str)
1239
1257
  {
1240
- VALUE str; int i;
1241
- check_argc_append(argc, 64);
1242
- str = argv[0];
1243
- for(i = 1; i < argc; i++) {
1258
+ int i;
1259
+ for(i = 0; i < argc; i++) {
1244
1260
  append_int64_le(str, safe_int64_t(argv[i]));
1245
1261
  }
1246
1262
  return str;
1247
1263
  }
1248
1264
 
1249
1265
  static VALUE
1250
- rb_append_int40_be(int argc, VALUE* argv, VALUE self)
1266
+ append_var_int40_be(int argc, VALUE* argv, VALUE str)
1251
1267
  {
1252
- VALUE str; int i;
1253
- check_argc_append(argc, 40);
1254
- str = argv[0];
1255
- for(i = 1; i < argc; i++) {
1268
+ int i;
1269
+ for(i = 0; i < argc; i++) {
1256
1270
  append_int40_be(str, NUM2I64(argv[i]));
1257
1271
  }
1258
1272
  return str;
1259
1273
  }
1260
1274
 
1261
1275
  static VALUE
1262
- rb_append_int48_be(int argc, VALUE* argv, VALUE self)
1276
+ append_var_int48_be(int argc, VALUE* argv, VALUE str)
1263
1277
  {
1264
- VALUE str; int i;
1265
- check_argc_append(argc, 48);
1266
- str = argv[0];
1267
- for(i = 1; i < argc; i++) {
1278
+ int i;
1279
+ for(i = 0; i < argc; i++) {
1268
1280
  append_int48_be(str, NUM2I64(argv[i]));
1269
1281
  }
1270
1282
  return str;
1271
1283
  }
1272
1284
 
1273
1285
  static VALUE
1274
- rb_append_int56_be(int argc, VALUE* argv, VALUE self)
1286
+ append_var_int56_be(int argc, VALUE* argv, VALUE str)
1275
1287
  {
1276
- VALUE str; int i;
1277
- check_argc_append(argc, 56);
1278
- str = argv[0];
1279
- for(i = 1; i < argc; i++) {
1288
+ int i;
1289
+ for(i = 0; i < argc; i++) {
1280
1290
  append_int56_be(str, NUM2I64(argv[i]));
1281
1291
  }
1282
1292
  return str;
1283
1293
  }
1284
1294
 
1285
1295
  static VALUE
1286
- rb_append_int64_be(int argc, VALUE* argv, VALUE self)
1296
+ append_var_int64_be(int argc, VALUE* argv, VALUE str)
1287
1297
  {
1288
- VALUE str; int i;
1289
- check_argc_append(argc, 64);
1290
- str = argv[0];
1291
- for(i = 1; i < argc; i++) {
1298
+ int i;
1299
+ for(i = 0; i < argc; i++) {
1292
1300
  append_int64_be(str, safe_int64_t(argv[i]));
1293
1301
  }
1294
1302
  return str;
1295
1303
  }
1296
1304
  /*** 64BIT END **/
1297
1305
 
1298
- /** APPEND END **/
1299
-
1300
- /** APPEND BERSIZE **/
1301
- static VALUE
1302
- rb_append_bersize_int8(int argc, VALUE* argv, VALUE self)
1303
- {
1304
- check_argc_append(argc, 8);
1305
- append_ber(argv[0], (argc-1));
1306
- return rb_append_int8(argc, argv, self);
1307
- }
1308
-
1309
- static VALUE
1310
- rb_append_bersize_int16_le(int argc, VALUE* argv, VALUE self)
1311
- {
1312
- check_argc_append(argc, 16);
1313
- append_ber(argv[0], (argc-1)*2);
1314
- return rb_append_int16_le(argc, argv, self);
1315
- }
1316
-
1317
- static VALUE
1318
- rb_append_bersize_int24_le(int argc, VALUE* argv, VALUE self)
1319
- {
1320
- check_argc_append(argc, 24);
1321
- append_ber(argv[0], (argc-1)*3);
1322
- return rb_append_int24_le(argc, argv, self);
1323
- }
1324
-
1325
- static VALUE
1326
- rb_append_bersize_int32_le(int argc, VALUE* argv, VALUE self)
1327
- {
1328
- check_argc_append(argc, 32);
1329
- append_ber(argv[0], (argc-1)*4);
1330
- return rb_append_int32_le(argc, argv, self);
1331
- }
1332
-
1333
- static VALUE
1334
- rb_append_bersize_int40_le(int argc, VALUE* argv, VALUE self)
1335
- {
1336
- check_argc_append(argc, 40);
1337
- append_ber(argv[0], (argc-1)*5);
1338
- return rb_append_int40_le(argc, argv, self);
1339
- }
1340
-
1341
- static VALUE
1342
- rb_append_bersize_int48_le(int argc, VALUE* argv, VALUE self)
1343
- {
1344
- check_argc_append(argc, 48);
1345
- append_ber(argv[0], (argc-1)*6);
1346
- return rb_append_int48_le(argc, argv, self);
1347
- }
1348
-
1349
- static VALUE
1350
- rb_append_bersize_int56_le(int argc, VALUE* argv, VALUE self)
1351
- {
1352
- check_argc_append(argc, 56);
1353
- append_ber(argv[0], (argc-1)*7);
1354
- return rb_append_int56_le(argc, argv, self);
1355
- }
1356
-
1357
- static VALUE
1358
- rb_append_bersize_int64_le(int argc, VALUE* argv, VALUE self)
1359
- {
1360
- check_argc_append(argc, 64);
1361
- append_ber(argv[0], (argc-1)*8);
1362
- return rb_append_int64_le(argc, argv, self);
1363
- }
1364
-
1365
- static VALUE
1366
- rb_append_bersize_int16_be(int argc, VALUE* argv, VALUE self)
1367
- {
1368
- check_argc_append(argc, 16);
1369
- append_ber(argv[0], (argc-1)*2);
1370
- return rb_append_int16_be(argc, argv, self);
1371
- }
1372
-
1373
- static VALUE
1374
- rb_append_bersize_int24_be(int argc, VALUE* argv, VALUE self)
1375
- {
1376
- check_argc_append(argc, 24);
1377
- append_ber(argv[0], (argc-1)*3);
1378
- return rb_append_int24_be(argc, argv, self);
1379
- }
1380
-
1381
- static VALUE
1382
- rb_append_bersize_int32_be(int argc, VALUE* argv, VALUE self)
1383
- {
1384
- check_argc_append(argc, 32);
1385
- append_ber(argv[0], (argc-1)*4);
1386
- return rb_append_int32_be(argc, argv, self);
1387
- }
1388
-
1389
- static VALUE
1390
- rb_append_bersize_int40_be(int argc, VALUE* argv, VALUE self)
1391
- {
1392
- check_argc_append(argc, 40);
1393
- append_ber(argv[0], (argc-1)*5);
1394
- return rb_append_int40_be(argc, argv, self);
1395
- }
1396
-
1397
- static VALUE
1398
- rb_append_bersize_int48_be(int argc, VALUE* argv, VALUE self)
1399
- {
1400
- check_argc_append(argc, 48);
1401
- append_ber(argv[0], (argc-1)*6);
1402
- return rb_append_int48_be(argc, argv, self);
1403
- }
1404
-
1405
- static VALUE
1406
- rb_append_bersize_int56_be(int argc, VALUE* argv, VALUE self)
1407
- {
1408
- check_argc_append(argc, 56);
1409
- append_ber(argv[0], (argc-1)*7);
1410
- return rb_append_int56_be(argc, argv, self);
1411
- }
1412
-
1413
- static VALUE
1414
- rb_append_bersize_int64_be(int argc, VALUE* argv, VALUE self)
1415
- {
1416
- check_argc_append(argc, 64);
1417
- append_ber(argv[0], (argc-1)*8);
1418
- return rb_append_int64_be(argc, argv, self);
1419
- }
1420
- /** APPEND BERSIZE END **/
1421
-
1422
- /** APPEND INT32SIZE **/
1423
- static VALUE
1424
- rb_append_int32size_int8_le(int argc, VALUE* argv, VALUE self)
1425
- {
1426
- check_argc_append(argc, 8);
1427
- append_int32_le(argv[0], (argc-1));
1428
- return rb_append_int8(argc, argv, self);
1429
- }
1430
-
1431
- static VALUE
1432
- rb_append_int32size_int16_le(int argc, VALUE* argv, VALUE self)
1433
- {
1434
- check_argc_append(argc, 16);
1435
- append_int32_le(argv[0], (argc-1)*2);
1436
- return rb_append_int16_le(argc, argv, self);
1437
- }
1438
-
1439
- static VALUE
1440
- rb_append_int32size_int24_le(int argc, VALUE* argv, VALUE self)
1441
- {
1442
- check_argc_append(argc, 24);
1443
- append_int32_le(argv[0], (argc-1)*3);
1444
- return rb_append_int24_le(argc, argv, self);
1445
- }
1446
-
1447
- static VALUE
1448
- rb_append_int32size_int32_le(int argc, VALUE* argv, VALUE self)
1449
- {
1450
- check_argc_append(argc, 32);
1451
- append_int32_le(argv[0], (argc-1)*4);
1452
- return rb_append_int32_le(argc, argv, self);
1453
- }
1454
-
1455
- static VALUE
1456
- rb_append_int32size_int40_le(int argc, VALUE* argv, VALUE self)
1457
- {
1458
- check_argc_append(argc, 40);
1459
- append_int32_le(argv[0], (argc-1)*5);
1460
- return rb_append_int40_le(argc, argv, self);
1461
- }
1462
-
1463
- static VALUE
1464
- rb_append_int32size_int48_le(int argc, VALUE* argv, VALUE self)
1465
- {
1466
- check_argc_append(argc, 48);
1467
- append_int32_le(argv[0], (argc-1)*6);
1468
- return rb_append_int48_le(argc, argv, self);
1469
- }
1470
1306
 
1471
- static VALUE
1472
- rb_append_int32size_int56_le(int argc, VALUE* argv, VALUE self)
1473
- {
1474
- check_argc_append(argc, 56);
1475
- append_int32_le(argv[0], (argc-1)*7);
1476
- return rb_append_int56_le(argc, argv, self);
1477
- }
1307
+ #define append_func(type, bits) \
1308
+ static VALUE \
1309
+ rb_append_##type(int argc, VALUE* argv, VALUE self) \
1310
+ { \
1311
+ append_args args; \
1312
+ check_argc_append(argc, argv, &args, bits); \
1313
+ return append_var_##type(args.argc, args.argv, args.str);\
1314
+ }
1315
+
1316
+ append_func(int8, 8)
1317
+ append_func(int16_le, 16)
1318
+ append_func(int24_le, 24)
1319
+ append_func(int32_le, 32)
1320
+ append_func(int40_le, 40)
1321
+ append_func(int48_le, 48)
1322
+ append_func(int56_le, 56)
1323
+ append_func(int64_le, 64)
1324
+ append_func(int16_be, 16)
1325
+ append_func(int24_be, 24)
1326
+ append_func(int32_be, 32)
1327
+ append_func(int40_be, 40)
1328
+ append_func(int48_be, 48)
1329
+ append_func(int56_be, 56)
1330
+ append_func(int64_be, 64)
1478
1331
 
1479
- static VALUE
1480
- rb_append_int32size_int64_le(int argc, VALUE* argv, VALUE self)
1481
- {
1482
- check_argc_append(argc, 64);
1483
- append_int32_le(argv[0], (argc-1)*8);
1484
- return rb_append_int64_le(argc, argv, self);
1485
- }
1486
-
1487
- static VALUE
1488
- rb_append_int32size_int8_be(int argc, VALUE* argv, VALUE self)
1489
- {
1490
- check_argc_append(argc, 8);
1491
- append_int32_be(argv[0], (argc-1));
1492
- return rb_append_int8(argc, argv, self);
1493
- }
1494
-
1495
- static VALUE
1496
- rb_append_int32size_int16_be(int argc, VALUE* argv, VALUE self)
1497
- {
1498
- check_argc_append(argc, 16);
1499
- append_int32_be(argv[0], (argc-1)*2);
1500
- return rb_append_int16_be(argc, argv, self);
1501
- }
1502
-
1503
- static VALUE
1504
- rb_append_int32size_int24_be(int argc, VALUE* argv, VALUE self)
1505
- {
1506
- check_argc_append(argc, 24);
1507
- append_int32_be(argv[0], (argc-1)*3);
1508
- return rb_append_int24_be(argc, argv, self);
1509
- }
1510
-
1511
- static VALUE
1512
- rb_append_int32size_int32_be(int argc, VALUE* argv, VALUE self)
1513
- {
1514
- check_argc_append(argc, 32);
1515
- append_int32_be(argv[0], (argc-1)*4);
1516
- return rb_append_int32_be(argc, argv, self);
1517
- }
1518
-
1519
- static VALUE
1520
- rb_append_int32size_int40_be(int argc, VALUE* argv, VALUE self)
1521
- {
1522
- check_argc_append(argc, 40);
1523
- append_int32_be(argv[0], (argc-1)*5);
1524
- return rb_append_int40_be(argc, argv, self);
1525
- }
1526
-
1527
- static VALUE
1528
- rb_append_int32size_int48_be(int argc, VALUE* argv, VALUE self)
1529
- {
1530
- check_argc_append(argc, 48);
1531
- append_int32_be(argv[0], (argc-1)*6);
1532
- return rb_append_int48_be(argc, argv, self);
1533
- }
1332
+ /** APPEND END **/
1534
1333
 
1535
- static VALUE
1536
- rb_append_int32size_int56_be(int argc, VALUE* argv, VALUE self)
1537
- {
1538
- check_argc_append(argc, 56);
1539
- append_int32_be(argv[0], (argc-1)*7);
1540
- return rb_append_int56_be(argc, argv, self);
1541
- }
1334
+ /** APPEND BERSIZE **/
1335
+ #define append_bersize_func(type, bytes) \
1336
+ static VALUE \
1337
+ rb_append_bersize_##type(int argc, VALUE* argv, VALUE self) \
1338
+ { \
1339
+ append_args args; \
1340
+ check_argc_append(argc, argv, &args, bytes * 8); \
1341
+ append_ber(args.str, args.argc * bytes); \
1342
+ return append_var_##type(args.argc, args.argv, args.str);\
1343
+ }
1344
+
1345
+ append_bersize_func(int8, 1)
1346
+ append_bersize_func(int16_le, 2)
1347
+ append_bersize_func(int24_le, 3)
1348
+ append_bersize_func(int32_le, 4)
1349
+ append_bersize_func(int40_le, 5)
1350
+ append_bersize_func(int48_le, 6)
1351
+ append_bersize_func(int56_le, 7)
1352
+ append_bersize_func(int64_le, 8)
1353
+ append_bersize_func(int16_be, 2)
1354
+ append_bersize_func(int24_be, 3)
1355
+ append_bersize_func(int32_be, 4)
1356
+ append_bersize_func(int40_be, 5)
1357
+ append_bersize_func(int48_be, 6)
1358
+ append_bersize_func(int56_be, 7)
1359
+ append_bersize_func(int64_be, 8)
1360
+
1361
+ #define append_int32size_func(type, end, bytes) \
1362
+ static VALUE \
1363
+ rb_append_int32size_##type##_##end(int argc, VALUE* argv, VALUE self) \
1364
+ { \
1365
+ append_args args; \
1366
+ check_argc_append(argc, argv, &args, bytes * 8); \
1367
+ append_int32_##end(args.str, args.argc * bytes); \
1368
+ append_var_##type##_##end(args.argc, args.argv, args.str); \
1369
+ return args.str; \
1370
+ }
1371
+
1372
+ append_int32size_func(int8, le, 1)
1373
+ append_int32size_func(int16, le, 2)
1374
+ append_int32size_func(int24, le, 3)
1375
+ append_int32size_func(int32, le, 4)
1376
+ append_int32size_func(int40, le, 5)
1377
+ append_int32size_func(int48, le, 6)
1378
+ append_int32size_func(int56, le, 7)
1379
+ append_int32size_func(int64, le, 8)
1380
+ append_int32size_func(int8, be, 1)
1381
+ append_int32size_func(int16, be, 2)
1382
+ append_int32size_func(int24, be, 3)
1383
+ append_int32size_func(int32, be, 4)
1384
+ append_int32size_func(int40, be, 5)
1385
+ append_int32size_func(int48, be, 6)
1386
+ append_int32size_func(int56, be, 7)
1387
+ append_int32size_func(int64, be, 8)
1542
1388
 
1543
- static VALUE
1544
- rb_append_int32size_int64_be(int argc, VALUE* argv, VALUE self)
1389
+ /** APPEND BER **/
1390
+ static long
1391
+ append_var_ber(int argc, VALUE* argv, VALUE str)
1545
1392
  {
1546
- check_argc_append(argc, 64);
1547
- append_int32_be(argv[0], (argc-1)*8);
1548
- return rb_append_int64_be(argc, argv, self);
1393
+ long i, bs = 0;
1394
+ for(i = 0; i < argc; i++) {
1395
+ bs += append_ber(str, safe_int64_t(argv[i]));
1396
+ }
1397
+ return bs;
1549
1398
  }
1550
- /** APPEND BERSIZE END **/
1551
- /** APPEND INT32SIZE END **/
1552
-
1553
- /** APPEND BER **/
1554
1399
 
1555
1400
  static VALUE
1556
1401
  rb_append_ber(int argc, VALUE* argv, VALUE self)
1557
1402
  {
1558
- VALUE str; int i;
1559
- check_argc_append(argc, 0);
1560
- str = argv[0];
1561
- for(i = 1; i < argc; i++) {
1562
- append_ber(str, safe_int64_t(argv[i]));
1563
- }
1564
- return str;
1403
+ append_args args;
1404
+ check_argc_append(argc, argv, &args, 0);
1405
+ append_var_ber(args.argc, args.argv, args.str);
1406
+ return args.str;
1565
1407
  }
1566
1408
 
1567
1409
  static VALUE rb_append_bersize_string(VALUE self, VALUE str, VALUE add);
@@ -1570,57 +1412,47 @@ static const char zeros[4] = {0, 0, 0, 0};
1570
1412
  static VALUE
1571
1413
  rb_append_bersize_ber(int argc, VALUE* argv, VALUE self)
1572
1414
  {
1573
- VALUE str, add_str;
1574
- int i;
1575
- check_argc_append(argc, 0);
1576
- str = argv[0];
1577
- add_str = rb_str_tmp_new(0);
1578
- for(i = 1; i < argc; i++) {
1579
- append_ber(add_str, safe_int64_t(argv[i]));
1580
- }
1581
- return rb_append_bersize_string(self, str, add_str);
1415
+ append_args args;
1416
+ VALUE add_str = rb_str_new(0, 0);
1417
+ check_argc_append(argc, argv, &args, 0);
1418
+ append_var_ber(args.argc, args.argv, add_str);
1419
+ return rb_append_bersize_string(self, args.str, add_str);
1582
1420
  }
1583
1421
 
1584
1422
  static VALUE
1585
1423
  rb_append_int32size_ber_le(int argc, VALUE* argv, VALUE self)
1586
1424
  {
1587
- VALUE str;
1588
- int i, bs=0, ss;
1425
+ append_args args;
1426
+ long ss, bs;
1589
1427
  uint8_t *ptr;
1590
- check_argc_append(argc, 0);
1591
- str = argv[0];
1592
- rb_str_cat(str, zeros, 4);
1593
- ss = RSTRING_LEN(str) - 4;
1594
- for(i = 1; i < argc; i++) {
1595
- bs += append_ber(str, safe_int64_t(argv[i]));
1596
- }
1597
- ptr = ((uint8_t*)RSTRING_PTR(str)) + ss;
1428
+ check_argc_append(argc, argv, &args, 0);
1429
+ rb_str_cat(args.str, zeros, 4);
1430
+ ss = RSTRING_LEN(args.str) - 4;
1431
+ bs = append_var_ber(args.argc, args.argv, args.str);
1432
+ ptr = ((uint8_t*)RSTRING_PTR(args.str)) + ss;
1598
1433
  ptr[0] = bs & 255;
1599
1434
  ptr[1] = (bs >> 8) & 255;
1600
1435
  ptr[2] = (bs >> 16) & 255;
1601
1436
  ptr[3] = (bs >> 24) & 255;
1602
- return str;
1437
+ return args.str;
1603
1438
  }
1604
1439
 
1605
1440
  static VALUE
1606
1441
  rb_append_int32size_ber_be(int argc, VALUE* argv, VALUE self)
1607
1442
  {
1608
- VALUE str;
1609
- int i = 0, bs=0, ss;
1443
+ append_args args;
1444
+ long ss, bs;
1610
1445
  uint8_t *ptr;
1611
- check_argc_append(argc, 0);
1612
- str = argv[0];
1613
- rb_str_cat(str, zeros, 4);
1614
- ss = RSTRING_LEN(str) - 4;
1615
- for(i = 1; i < argc; i++) {
1616
- bs += append_ber(str, safe_int64_t(argv[i]));
1617
- }
1618
- ptr = ((uint8_t*)RSTRING_PTR(str)) + ss;
1446
+ check_argc_append(argc, argv, &args, 0);
1447
+ rb_str_cat(args.str, zeros, 4);
1448
+ ss = RSTRING_LEN(args.str) - 4;
1449
+ bs = append_var_ber(args.argc, args.argv, args.str);
1450
+ ptr = ((uint8_t*)RSTRING_PTR(args.str)) + ss;
1619
1451
  ptr[3] = bs & 255;
1620
1452
  ptr[2] = (bs >> 8) & 255;
1621
1453
  ptr[1] = (bs >> 16) & 255;
1622
1454
  ptr[0] = (bs >> 24) & 255;
1623
- return str;
1455
+ return args.str;
1624
1456
  }
1625
1457
  /** APPEND BER END **/
1626
1458
 
@@ -1628,6 +1460,7 @@ rb_append_int32size_ber_be(int argc, VALUE* argv, VALUE self)
1628
1460
  static VALUE
1629
1461
  rb_append_string(VALUE self, VALUE str, VALUE add)
1630
1462
  {
1463
+ if (!RTEST(str)) str = rb_str_new(0, 0);
1631
1464
  StringValue(add);
1632
1465
  rb_str_cat(str, RSTRING_PTR(add), RSTRING_LEN(add));
1633
1466
  RB_GC_GUARD(add);
@@ -1637,6 +1470,7 @@ rb_append_string(VALUE self, VALUE str, VALUE add)
1637
1470
  static VALUE
1638
1471
  rb_append_bersize_string(VALUE self, VALUE str, VALUE add)
1639
1472
  {
1473
+ if (!RTEST(str)) str = rb_str_new(0, 0);
1640
1474
  StringValue(add);
1641
1475
  append_ber(str, RSTRING_LEN(add));
1642
1476
  rb_str_cat(str, RSTRING_PTR(add), RSTRING_LEN(add));
@@ -1647,6 +1481,7 @@ rb_append_bersize_string(VALUE self, VALUE str, VALUE add)
1647
1481
  static VALUE
1648
1482
  rb_append_int32size_string_le(VALUE self, VALUE str, VALUE add)
1649
1483
  {
1484
+ if (!RTEST(str)) str = rb_str_new(0, 0);
1650
1485
  StringValue(add);
1651
1486
  append_int32_le(str, RSTRING_LEN(add));
1652
1487
  rb_str_cat(str, RSTRING_PTR(add), RSTRING_LEN(add));
@@ -1657,6 +1492,7 @@ rb_append_int32size_string_le(VALUE self, VALUE str, VALUE add)
1657
1492
  static VALUE
1658
1493
  rb_append_int32size_string_be(VALUE self, VALUE str, VALUE add)
1659
1494
  {
1495
+ if (!RTEST(str)) str = rb_str_new(0, 0);
1660
1496
  StringValue(add);
1661
1497
  append_int32_be(str, RSTRING_LEN(add));
1662
1498
  rb_str_cat(str, RSTRING_PTR(add), RSTRING_LEN(add));
@@ -1670,346 +1506,80 @@ rb_append_int32size_string_be(VALUE self, VALUE str, VALUE add)
1670
1506
  static VALUE
1671
1507
  rb_append_int8_ber(int argc, VALUE *argv, VALUE self)
1672
1508
  {
1673
- check_argc_append_2(argc, 8, 0);
1674
- rb_append_int8(2, argv, self);
1675
- argv[1] = argv[0];
1676
- return rb_append_ber(argc-1, argv+1, self);
1677
- }
1678
-
1679
- static VALUE
1680
- rb_append_int16_ber_le(int argc, VALUE *argv, VALUE self)
1681
- {
1682
- check_argc_append_2(argc, 16, 0);
1683
- rb_append_int16_le(2, argv, self);
1684
- argv[1] = argv[0];
1685
- return rb_append_ber(argc-1, argv+1, self);
1686
- }
1687
-
1688
- static VALUE
1689
- rb_append_int24_ber_le(int argc, VALUE *argv, VALUE self)
1690
- {
1691
- check_argc_append_2(argc, 24, 0);
1692
- rb_append_int24_le(2, argv, self);
1693
- argv[1] = argv[0];
1694
- return rb_append_ber(argc-1, argv+1, self);
1695
- }
1696
-
1697
- static VALUE
1698
- rb_append_int32_ber_le(int argc, VALUE *argv, VALUE self)
1699
- {
1700
- check_argc_append_2(argc, 32, 0);
1701
- rb_append_int32_le(2, argv, self);
1702
- argv[1] = argv[0];
1703
- return rb_append_ber(argc-1, argv+1, self);
1704
- }
1705
-
1706
- static VALUE
1707
- rb_append_int16_ber_be(int argc, VALUE *argv, VALUE self)
1708
- {
1709
- check_argc_append_2(argc, 16, 0);
1710
- rb_append_int16_be(2, argv, self);
1711
- argv[1] = argv[0];
1712
- return rb_append_ber(argc-1, argv+1, self);
1713
- }
1714
-
1715
- static VALUE
1716
- rb_append_int24_ber_be(int argc, VALUE *argv, VALUE self)
1717
- {
1718
- check_argc_append_2(argc, 24, 0);
1719
- rb_append_int24_be(2, argv, self);
1720
- argv[1] = argv[0];
1721
- return rb_append_ber(argc-1, argv+1, self);
1722
- }
1723
-
1724
- static VALUE
1725
- rb_append_int32_ber_be(int argc, VALUE *argv, VALUE self)
1726
- {
1727
- check_argc_append_2(argc, 32, 0);
1728
- rb_append_int32_be(2, argv, self);
1729
- argv[1] = argv[0];
1730
- return rb_append_ber(argc-1, argv+1, self);
1731
- }
1732
-
1733
- static VALUE
1734
- rb_append_int8_int16_le(int argc, VALUE *argv, VALUE self)
1735
- {
1736
- check_argc_append_2(argc, 8, 16);
1737
- rb_append_int8(2, argv, self);
1738
- argv[1] = argv[0];
1739
- return rb_append_int16_le(argc-1, argv+1, self);
1740
- }
1741
-
1742
- static VALUE
1743
- rb_append_int8_int24_le(int argc, VALUE *argv, VALUE self)
1744
- {
1745
- check_argc_append_2(argc, 8, 24);
1746
- rb_append_int8(2, argv, self);
1747
- argv[1] = argv[0];
1748
- return rb_append_int24_le(argc-1, argv+1, self);
1749
- }
1750
-
1751
- static VALUE
1752
- rb_append_int8_int32_le(int argc, VALUE *argv, VALUE self)
1753
- {
1754
- check_argc_append_2(argc, 8, 32);
1755
- rb_append_int8(2, argv, self);
1756
- argv[1] = argv[0];
1757
- return rb_append_int32_le(argc-1, argv+1, self);
1758
- }
1759
-
1760
- static VALUE
1761
- rb_append_int8_int16_be(int argc, VALUE *argv, VALUE self)
1762
- {
1763
- check_argc_append_2(argc, 8, 16);
1764
- rb_append_int8(2, argv, self);
1765
- argv[1] = argv[0];
1766
- return rb_append_int16_be(argc-1, argv+1, self);
1767
- }
1768
-
1769
- static VALUE
1770
- rb_append_int8_int24_be(int argc, VALUE *argv, VALUE self)
1771
- {
1772
- check_argc_append_2(argc, 8, 24);
1773
- rb_append_int8(2, argv, self);
1774
- argv[1] = argv[0];
1775
- return rb_append_int24_be(argc-1, argv+1, self);
1776
- }
1777
-
1778
- static VALUE
1779
- rb_append_int8_int32_be(int argc, VALUE *argv, VALUE self)
1780
- {
1781
- check_argc_append_2(argc, 8, 32);
1782
- rb_append_int8(2, argv, self);
1783
- argv[1] = argv[0];
1784
- return rb_append_int32_be(argc-1, argv+1, self);
1785
- }
1786
-
1787
- static VALUE
1788
- rb_append_int16_int8_le(int argc, VALUE *argv, VALUE self)
1789
- {
1790
- check_argc_append_2(argc, 16, 8);
1791
- rb_append_int16_le(2, argv, self);
1792
- argv[1] = argv[0];
1793
- return rb_append_int8(argc-1, argv+1, self);
1794
- }
1795
-
1796
- static VALUE
1797
- rb_append_int16_int24_le(int argc, VALUE *argv, VALUE self)
1798
- {
1799
- check_argc_append_2(argc, 16, 24);
1800
- rb_append_int16_le(2, argv, self);
1801
- argv[1] = argv[0];
1802
- return rb_append_int24_le(argc-1, argv+1, self);
1803
- }
1804
-
1805
- static VALUE
1806
- rb_append_int16_int32_le(int argc, VALUE *argv, VALUE self)
1807
- {
1808
- check_argc_append_2(argc, 16, 32);
1809
- rb_append_int16_le(2, argv, self);
1810
- argv[1] = argv[0];
1811
- return rb_append_int32_le(argc-1, argv+1, self);
1812
- }
1813
-
1814
- static VALUE
1815
- rb_append_int16_int8_be(int argc, VALUE *argv, VALUE self)
1816
- {
1817
- check_argc_append_2(argc, 16, 8);
1818
- rb_append_int16_be(2, argv, self);
1819
- argv[1] = argv[0];
1820
- return rb_append_int8(argc-1, argv+1, self);
1821
- }
1822
-
1823
- static VALUE
1824
- rb_append_int16_int24_be(int argc, VALUE *argv, VALUE self)
1825
- {
1826
- check_argc_append_2(argc, 16, 24);
1827
- rb_append_int16_be(2, argv, self);
1828
- argv[1] = argv[0];
1829
- return rb_append_int24_be(argc-1, argv+1, self);
1830
- }
1831
-
1832
- static VALUE
1833
- rb_append_int16_int32_be(int argc, VALUE *argv, VALUE self)
1834
- {
1835
- check_argc_append_2(argc, 16, 32);
1836
- rb_append_int16_be(2, argv, self);
1837
- argv[1] = argv[0];
1838
- return rb_append_int32_be(argc-1, argv+1, self);
1839
- }
1840
-
1841
- static VALUE
1842
- rb_append_int24_int16_le(int argc, VALUE *argv, VALUE self)
1843
- {
1844
- check_argc_append_2(argc, 24, 16);
1845
- rb_append_int24_le(2, argv, self);
1846
- argv[1] = argv[0];
1847
- return rb_append_int16_le(argc-1, argv+1, self);
1848
- }
1849
-
1850
- static VALUE
1851
- rb_append_int24_int8_le(int argc, VALUE *argv, VALUE self)
1852
- {
1853
- check_argc_append_2(argc, 24, 8);
1854
- rb_append_int24_le(2, argv, self);
1855
- argv[1] = argv[0];
1856
- return rb_append_int8(argc-1, argv+1, self);
1857
- }
1858
-
1859
- static VALUE
1860
- rb_append_int24_int32_le(int argc, VALUE *argv, VALUE self)
1861
- {
1862
- check_argc_append_2(argc, 24, 32);
1863
- rb_append_int24_le(2, argv, self);
1864
- argv[1] = argv[0];
1865
- return rb_append_int32_le(argc-1, argv+1, self);
1866
- }
1867
-
1868
- static VALUE
1869
- rb_append_int24_int16_be(int argc, VALUE *argv, VALUE self)
1870
- {
1871
- check_argc_append_2(argc, 24, 16);
1872
- rb_append_int24_be(2, argv, self);
1873
- argv[1] = argv[0];
1874
- return rb_append_int16_be(argc-1, argv+1, self);
1875
- }
1876
-
1877
- static VALUE
1878
- rb_append_int24_int8_be(int argc, VALUE *argv, VALUE self)
1879
- {
1880
- check_argc_append_2(argc, 24, 8);
1881
- rb_append_int24_be(2, argv, self);
1882
- argv[1] = argv[0];
1883
- return rb_append_int8(argc-1, argv+1, self);
1884
- }
1885
-
1886
- static VALUE
1887
- rb_append_int24_int32_be(int argc, VALUE *argv, VALUE self)
1888
- {
1889
- check_argc_append_2(argc, 24, 32);
1890
- rb_append_int24_be(2, argv, self);
1891
- argv[1] = argv[0];
1892
- return rb_append_int32_be(argc-1, argv+1, self);
1893
- }
1894
-
1895
- static VALUE
1896
- rb_append_int32_int16_le(int argc, VALUE *argv, VALUE self)
1897
- {
1898
- check_argc_append_2(argc, 32, 16);
1899
- rb_append_int32_le(2, argv, self);
1900
- argv[1] = argv[0];
1901
- return rb_append_int16_le(argc-1, argv+1, self);
1902
- }
1903
-
1904
- static VALUE
1905
- rb_append_int32_int24_le(int argc, VALUE *argv, VALUE self)
1906
- {
1907
- check_argc_append_2(argc, 32, 24);
1908
- rb_append_int32_le(2, argv, self);
1909
- argv[1] = argv[0];
1910
- return rb_append_int24_le(argc-1, argv+1, self);
1911
- }
1912
-
1913
- static VALUE
1914
- rb_append_int32_int8_le(int argc, VALUE *argv, VALUE self)
1915
- {
1916
- check_argc_append_2(argc, 32, 8);
1917
- rb_append_int32_le(2, argv, self);
1918
- argv[1] = argv[0];
1919
- return rb_append_int8(argc-1, argv+1, self);
1920
- }
1921
-
1922
- static VALUE
1923
- rb_append_int32_int16_be(int argc, VALUE *argv, VALUE self)
1924
- {
1925
- check_argc_append_2(argc, 32, 16);
1926
- rb_append_int32_be(2, argv, self);
1927
- argv[1] = argv[0];
1928
- return rb_append_int16_be(argc-1, argv+1, self);
1929
- }
1930
-
1931
- static VALUE
1932
- rb_append_int32_int24_be(int argc, VALUE *argv, VALUE self)
1933
- {
1934
- check_argc_append_2(argc, 32, 24);
1935
- rb_append_int32_be(2, argv, self);
1936
- argv[1] = argv[0];
1937
- return rb_append_int24_be(argc-1, argv+1, self);
1938
- }
1939
-
1940
- static VALUE
1941
- rb_append_int32_int8_be(int argc, VALUE *argv, VALUE self)
1942
- {
1943
- check_argc_append_2(argc, 32, 8);
1944
- rb_append_int32_be(2, argv, self);
1945
- argv[1] = argv[0];
1946
- return rb_append_int8(argc-1, argv+1, self);
1509
+ append_args2 args;
1510
+ check_argc_append_2(argc, argv, &args, 8, 0);
1511
+ append_var_int8(1, &args.int0, args.str);
1512
+ append_var_ber(args.argc, args.argv, args.str);
1513
+ return args.str;
1947
1514
  }
1948
1515
 
1949
1516
  static VALUE
1950
1517
  rb_append_ber_int8(int argc, VALUE *argv, VALUE self)
1951
1518
  {
1952
- check_argc_append_2(argc, 0, 8);
1953
- rb_append_ber(2, argv, self);
1954
- argv[1] = argv[0];
1955
- return rb_append_int8(argc-1, argv+1, self);
1956
- }
1957
-
1958
- static VALUE
1959
- rb_append_ber_int16_le(int argc, VALUE *argv, VALUE self)
1960
- {
1961
- check_argc_append_2(argc, 0, 16);
1962
- rb_append_ber(2, argv, self);
1963
- argv[1] = argv[0];
1964
- return rb_append_int16_le(argc-1, argv+1, self);
1965
- }
1966
-
1967
- static VALUE
1968
- rb_append_ber_int16_be(int argc, VALUE *argv, VALUE self)
1969
- {
1970
- check_argc_append_2(argc, 0, 16);
1971
- rb_append_ber(2, argv, self);
1972
- argv[1] = argv[0];
1973
- return rb_append_int16_be(argc-1, argv+1, self);
1974
- }
1975
-
1976
- static VALUE
1977
- rb_append_ber_int24_le(int argc, VALUE *argv, VALUE self)
1978
- {
1979
- check_argc_append_2(argc, 0, 24);
1980
- rb_append_ber(2, argv, self);
1981
- argv[1] = argv[0];
1982
- return rb_append_int24_le(argc-1, argv+1, self);
1983
- }
1984
-
1985
- static VALUE
1986
- rb_append_ber_int24_be(int argc, VALUE *argv, VALUE self)
1987
- {
1988
- check_argc_append_2(argc, 0, 24);
1989
- rb_append_ber(2, argv, self);
1990
- argv[1] = argv[0];
1991
- return rb_append_int24_be(argc-1, argv+1, self);
1992
- }
1993
-
1994
- static VALUE
1995
- rb_append_ber_int32_le(int argc, VALUE *argv, VALUE self)
1996
- {
1997
- check_argc_append_2(argc, 0, 32);
1998
- rb_append_ber(2, argv, self);
1999
- argv[1] = argv[0];
2000
- return rb_append_int32_le(argc-1, argv+1, self);
2001
- }
2002
-
2003
- static VALUE
2004
- rb_append_ber_int32_be(int argc, VALUE *argv, VALUE self)
2005
- {
2006
- check_argc_append_2(argc, 0, 32);
2007
- rb_append_ber(2, argv, self);
2008
- argv[1] = argv[0];
2009
- return rb_append_int32_be(argc-1, argv+1, self);
2010
- }
2011
-
2012
-
1519
+ append_args2 args;
1520
+ check_argc_append_2(argc, argv, &args, 8, 0);
1521
+ append_var_ber(1, &args.int0, args.str);
1522
+ return append_var_int8(args.argc, args.argv, args.str);
1523
+ }
1524
+
1525
+ #define append_int_ber(bits, end) \
1526
+ static VALUE \
1527
+ rb_append_int##bits##_ber_##end(int argc, VALUE *argv, VALUE self) \
1528
+ { \
1529
+ append_args2 args; \
1530
+ check_argc_append_2(argc, argv, &args, bits, 0); \
1531
+ append_var_int##bits##_##end(1, &args.int0, args.str); \
1532
+ append_var_ber(args.argc, args.argv, args.str); \
1533
+ return args.str; \
1534
+ } \
1535
+ static VALUE \
1536
+ rb_append_ber_int##bits##_##end(int argc, VALUE *argv, VALUE self) \
1537
+ { \
1538
+ append_args2 args; \
1539
+ check_argc_append_2(argc, argv, &args, 0, bits); \
1540
+ append_var_ber(1, &args.int0, args.str); \
1541
+ return append_var_int##bits##_##end(args.argc, args.argv, args.str); \
1542
+ }
1543
+ append_int_ber(16, le)
1544
+ append_int_ber(24, le)
1545
+ append_int_ber(32, le)
1546
+ append_int_ber(16, be)
1547
+ append_int_ber(24, be)
1548
+ append_int_ber(32, be)
1549
+
1550
+ #define append_int_int(bit1, bit2, end) \
1551
+ static VALUE \
1552
+ rb_append_int##bit1##_int##bit2##_##end(int argc, VALUE *argv, VALUE self) \
1553
+ { \
1554
+ append_args2 args; \
1555
+ check_argc_append_2(argc, argv, &args, bit1, bit2); \
1556
+ append_var_int##bit1##_##end(1, &args.int0, args.str); \
1557
+ return append_var_int##bit2##_##end(args.argc, args.argv, args.str); \
1558
+ }
1559
+ append_int_int(8, 16, le)
1560
+ append_int_int(8, 24, le)
1561
+ append_int_int(8, 32, le)
1562
+ append_int_int(16, 8, le)
1563
+ append_int_int(16, 24, le)
1564
+ append_int_int(16, 32, le)
1565
+ append_int_int(24, 8, le)
1566
+ append_int_int(24, 16, le)
1567
+ append_int_int(24, 32, le)
1568
+ append_int_int(32, 8, le)
1569
+ append_int_int(32, 16, le)
1570
+ append_int_int(32, 24, le)
1571
+ append_int_int(8, 16, be)
1572
+ append_int_int(8, 24, be)
1573
+ append_int_int(8, 32, be)
1574
+ append_int_int(16, 8, be)
1575
+ append_int_int(16, 24, be)
1576
+ append_int_int(16, 32, be)
1577
+ append_int_int(24, 8, be)
1578
+ append_int_int(24, 16, be)
1579
+ append_int_int(24, 32, be)
1580
+ append_int_int(32, 8, be)
1581
+ append_int_int(32, 16, be)
1582
+ append_int_int(32, 24, be)
2013
1583
  /** APPEND COMPLEX END **/
2014
1584
 
2015
1585
  void
@@ -2017,8 +1587,8 @@ Init_native_bin_utils()
2017
1587
  {
2018
1588
  VALUE mod_bin_utils = rb_define_module("BinUtils");
2019
1589
  VALUE mod_native = rb_define_module_under(mod_bin_utils, "Native");
2020
- CONST_ID(rshft, ">>");
2021
- CONST_ID(band, "&");
1590
+ rshft = rb_intern(">>");
1591
+ band = rb_intern("&");
2022
1592
 
2023
1593
  rb_define_method(mod_native, "get_ber", rb_get_ber, -1);
2024
1594
  rb_define_method(mod_native, "get_int8", rb_get_int8, -1);