Skip to content

Commit 2a1e3a5

Browse files
committed
mruby-pack/pack.c (read_tmpl): support J/j template in pack
J/j is available since Ruby 2.3.
1 parent 663f936 commit 2a1e3a5

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

mrbgems/mruby-pack/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ There is no dependency on other mrbgems.
2828
- h : hex string (low nibble first)
2929
- I : unsigned integer, native endian (`unsigned int` in C)
3030
- i : signed integer, native endian (`int` in C)
31+
- J : unsigned integer, native endian (`uintptr_t` in C)
32+
- j : signed integer, native endian (`intptr_t` in C)
3133
- L : 32-bit unsigned, native endian (`uint32_t`)
3234
- l : 32-bit signed, native endian (`int32_t`)
3335
- m : base64 encoded string (see RFC 2045, count is width)

mrbgems/mruby-pack/src/pack.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,22 @@ read_tmpl(mrb_state *mrb, struct tmpl *tmpl, enum pack_dir *dirp, enum pack_type
12191219
mrb_raisef(mrb, E_RUNTIME_ERROR, "mruby-pack does not support sizeof(int) == %d", (int)sizeof(int));
12201220
}
12211221
break;
1222+
case 'J':
1223+
switch (sizeof(intptr_t)) {
1224+
case 4: t = 'L'; goto alias;
1225+
case 8: t = 'Q'; goto alias;
1226+
default:
1227+
mrb_raisef(mrb, E_RUNTIME_ERROR, "mruby-pack does not support sizeof(uintptr_t) == %d", (int)sizeof(uintptr_t));
1228+
}
1229+
break;
1230+
case 'j':
1231+
switch (sizeof(intptr_t)) {
1232+
case 4: t = 'l'; goto alias;
1233+
case 8: t = 'q'; goto alias;
1234+
default:
1235+
mrb_raisef(mrb, E_RUNTIME_ERROR, "mruby-pack does not support sizeof(intptr_t) == %d", (int)sizeof(intptr_t));
1236+
}
1237+
break;
12221238
case 'L':
12231239
dir = PACK_DIR_LONG;
12241240
type = PACK_TYPE_INTEGER;

0 commit comments

Comments
 (0)