summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2026-04-15 10:02:55 +0900
committerNobuyoshi Nakada <nobu.nakada@gmail.com>2026-04-15 11:41:59 +0900
commitb21043f8ac1aa2aeaaadae4153f4e059aedaf988 (patch)
treeaaad336199ffed859e17f60ef0c18ca1273f9bf5
parent40189f8f951bd0f655baaf26a774ee83cb9a04a5 (diff)
Constify pack functions
-rw-r--r--pack.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/pack.c b/pack.c
index 7e17b016c7..94bb510e0d 100644
--- a/pack.c
+++ b/pack.c
@@ -62,7 +62,7 @@ is_bigendian(void)
{
static int init = 0;
static int endian_value;
- char *p;
+ const char *p;
if (init) return endian_value;
init = 1;
@@ -771,7 +771,7 @@ pack_pack(rb_execution_context_t *ec, VALUE ary, VALUE fmt, VALUE buffer)
/* FALL THROUGH */
case 'p': /* pointer to string */
while (len-- > 0) {
- char *t = 0;
+ const char *t = 0;
from = NEXTFROM;
if (!NIL_P(from)) {
STR_FROM(from);
@@ -1001,8 +1001,8 @@ static VALUE
pack_unpack_internal(VALUE str, VALUE fmt, enum unpack_mode mode, long offset)
{
#define hexdigits ruby_hexdigits
- char *s, *send;
- char *p, *pend;
+ const char *s, *send;
+ const char *p, *pend;
VALUE ary, associates = Qfalse;
long len;
AVOID_CC_BUG long tmp_len;
@@ -1076,7 +1076,7 @@ pack_unpack_internal(VALUE str, VALUE fmt, enum unpack_mode mode, long offset)
if (len > send - s) len = send - s;
{
long end = len;
- char *t = s + len - 1;
+ const char *t = s + len - 1;
while (t >= s) {
if (*t != ' ' && *t != '\0') break;
@@ -1089,7 +1089,7 @@ pack_unpack_internal(VALUE str, VALUE fmt, enum unpack_mode mode, long offset)
case 'Z':
{
- char *t = s;
+ const char *t = s;
if (len > send-s) len = send-s;
while (t < s+len && *t) t++;
@@ -1523,7 +1523,8 @@ pack_unpack_internal(VALUE str, VALUE fmt, enum unpack_mode mode, long offset)
case 'M':
{
VALUE buf = rb_str_new(0, send - s);
- char *ptr = RSTRING_PTR(buf), *ss = s;
+ char *ptr = RSTRING_PTR(buf);
+ const char *ss = s;
int csum = 0;
int c1, c2;
@@ -1578,7 +1579,7 @@ pack_unpack_internal(VALUE str, VALUE fmt, enum unpack_mode mode, long offset)
case 'P':
if (sizeof(char *) <= (size_t)(send - s)) {
VALUE tmp = Qnil;
- char *t;
+ const char *t;
UNPACK_FETCH(&t, char *);
if (t) {
@@ -1601,7 +1602,7 @@ pack_unpack_internal(VALUE str, VALUE fmt, enum unpack_mode mode, long offset)
break;
else {
VALUE tmp = Qnil;
- char *t;
+ const char *t;
UNPACK_FETCH(&t, char *);
if (t) {
@@ -1621,7 +1622,7 @@ pack_unpack_internal(VALUE str, VALUE fmt, enum unpack_mode mode, long offset)
if (type == 'r') {
pack_flags |= INTEGER_PACK_2COMP;
}
- char *s0 = s;
+ const char *s0 = s;
while (len > 0 && s < send) {
if (*s & 0x80) {
s++;
@@ -1648,7 +1649,7 @@ pack_unpack_internal(VALUE str, VALUE fmt, enum unpack_mode mode, long offset)
case 'w':
{
- char *s0 = s;
+ const char *s0 = s;
while (len > 0 && s < send) {
if (*s & 0x80) {
s++;