Skip to content

Commit 1583016

Browse files
authored
Merge pull request #754 from larskanis/rb_len_t
Make use of new data type for lengths in ruby-4.1+
2 parents fcf40c5 + af41d2f commit 1583016

11 files changed

Lines changed: 27 additions & 22 deletions

‎ext/pg.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ typedef long suseconds_t;
8080
#define rb_hash_new_capa(x) rb_hash_new()
8181
#endif
8282

83+
#ifndef HAVE_RB_LEN_T
84+
typedef long rb_len_t;
85+
typedef unsigned long rb_ulen_t;
86+
#endif
87+
8388
#define pg_gc_location(x) x = rb_gc_location(x)
8489

8590
extern int ruby_native_thread_p(void);

‎ext/pg_binary_decoder.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,12 @@ pg_bin_dec_array(t_pg_coder *conv, const char *input_line, int len, int tuple, i
275275
}
276276

277277
if (cur_ptr < line_end_ptr)
278-
rb_raise( rb_eArgError, "trailing data after binary array data at position: %ld", (long)(cur_ptr - input_line) + 1 );
278+
rb_raise( rb_eArgError, "trailing data after binary array data at position: %lld", (long long)(cur_ptr - input_line) + 1 );
279279

280280
return arrays[0];
281281

282282
length_error:
283-
rb_raise( rb_eArgError, "premature end of binary array data at position: %ld", (long)(cur_ptr - input_line) + 1 );
283+
rb_raise( rb_eArgError, "premature end of binary array data at position: %lld", (long long)(cur_ptr - input_line) + 1 );
284284
}
285285

286286
#define PG_INT64_MIN (-0x7FFFFFFFFFFFFFFFL - 1)

‎ext/pg_copy_coder.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ pg_text_dec_copy_row(t_pg_coder *conv, const char *input_line, int len, int _tup
692692
}
693693

694694
if (!found_delim && cur_ptr < line_end_ptr)
695-
rb_raise( rb_eArgError, "trailing data after linefeed at position: %ld", (long)(cur_ptr - input_line) + 1 );
695+
rb_raise( rb_eArgError, "trailing data after linefeed at position: %lld", (long long)(cur_ptr - input_line) + 1 );
696696

697697

698698
/* Check whether raw input matched null marker */
@@ -881,13 +881,13 @@ pg_bin_dec_copy_row(t_pg_coder *conv, const char *input_line, int len, int _tupl
881881
}
882882

883883
if (cur_ptr < line_end_ptr)
884-
rb_raise( rb_eArgError, "trailing data after row data at position: %ld", (long)(cur_ptr - input_line) + 1 );
884+
rb_raise( rb_eArgError, "trailing data after row data at position: %lld", (long long)(cur_ptr - input_line) + 1 );
885885

886886
RB_GC_GUARD(rb_typemap);
887887
return array;
888888

889889
length_error:
890-
rb_raise( rb_eArgError, "premature end of COPY data at position: %ld", (long)(cur_ptr - input_line) + 1 );
890+
rb_raise( rb_eArgError, "premature end of COPY data at position: %lld", (long long)(cur_ptr - input_line) + 1 );
891891
}
892892

893893
void

‎ext/pg_record_coder.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ pg_text_enc_record(t_pg_coder *conv, VALUE value, char *out, VALUE *intermediate
198198
for( i=0; i<RARRAY_LEN(value); i++){
199199
char *ptr1;
200200
char *ptr2;
201-
long strlen;
201+
rb_len_t strlen;
202202
int backslashes;
203203
VALUE subint;
204204
VALUE entry;

‎ext/pg_text_decoder.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pg_text_dec_string(t_pg_coder *conv, const char *val, int len, int tuple, int fi
103103
static VALUE
104104
pg_text_dec_integer(t_pg_coder *conv, const char *val, int len, int tuple, int field, int enc_idx)
105105
{
106-
long i;
106+
rb_len_t i;
107107
int max_len;
108108

109109
if( sizeof(i) >= 8 && FIXNUM_MAX >= 1000000000000000000LL ){

‎ext/pg_text_encoder.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ pg_text_enc_bytea(t_pg_coder *conv, VALUE value, char *out, VALUE *intermediate,
430430
}
431431
return (int)(optr - out);
432432
}else{
433-
long size;
433+
rb_len_t size;
434434
*intermediate = rb_obj_as_string(value);
435435
size = RSTRING_LEN(*intermediate);
436436

@@ -653,8 +653,8 @@ quote_identifier( VALUE value, VALUE out_string, char *current_out ){
653653
static char *
654654
pg_text_enc_array_identifier(VALUE value, VALUE string, char *out, int enc_idx)
655655
{
656-
long i;
657-
long nr_elems;
656+
rb_len_t i;
657+
rb_len_t nr_elems;
658658

659659
Check_Type(value, T_ARRAY);
660660
nr_elems = RARRAY_LEN(value);

‎ext/pg_tuple.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ static VALUE
253253
pg_tuple_fetch(int argc, VALUE *argv, VALUE self)
254254
{
255255
VALUE key;
256-
long block_given;
256+
int block_given;
257257
VALUE index;
258258
int field_num;
259259
t_pg_tuple *this = pg_tuple_get_this(self);

‎ext/pg_type_map_by_class.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ typedef struct {
2727
* We use 8 Bits of the klass object id as index to a 256 entry cache.
2828
* This avoids full lookups in most cases.
2929
*/
30-
#define CACHE_LOOKUP(this, klass) ( &this->cache_row[(((unsigned long)klass) >> 8) & 0xff] )
30+
#define CACHE_LOOKUP(this, klass) ( &this->cache_row[(((unsigned int)klass) >> 8) & 0xff] )
3131

3232

3333
static t_pg_coder *

‎ext/pg_type_map_by_column.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ pg_tmbc_allocate(void)
263263
static VALUE
264264
pg_tmbc_init(VALUE self, VALUE conv_ary)
265265
{
266-
long i;
266+
int i;
267267
t_tmbc *this;
268268
int conv_ary_len;
269269

‎ext/pg_util.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ rbpg_base64_encode( char *out, const char *in, int len)
2222
int part_len = len % 3;
2323

2424
if( part_len > 0 ){
25-
long byte2 = 0;
26-
long byte1 = part_len > 1 ? *--in_ptr : 0;
27-
long byte0 = *--in_ptr;
28-
long triple = (byte0 << 16) + (byte1 << 8) + byte2;
25+
int byte2 = 0;
26+
int byte1 = part_len > 1 ? *--in_ptr : 0;
27+
int byte0 = *--in_ptr;
28+
int triple = (byte0 << 16) + (byte1 << 8) + byte2;
2929

3030
*--out_ptr = '=';
3131
*--out_ptr = part_len > 1 ? base64_encode_table[(triple >> 1 * 6) & 0x3F] : '=';
@@ -34,10 +34,10 @@ rbpg_base64_encode( char *out, const char *in, int len)
3434
}
3535

3636
while( out_ptr > out ){
37-
long byte2 = *--in_ptr;
38-
long byte1 = *--in_ptr;
39-
long byte0 = *--in_ptr;
40-
long triple = (byte0 << 16) + (byte1 << 8) + byte2;
37+
int byte2 = *--in_ptr;
38+
int byte1 = *--in_ptr;
39+
int byte0 = *--in_ptr;
40+
int triple = (byte0 << 16) + (byte1 << 8) + byte2;
4141

4242
*--out_ptr = base64_encode_table[(triple >> 0 * 6) & 0x3F];
4343
*--out_ptr = base64_encode_table[(triple >> 1 * 6) & 0x3F];

0 commit comments

Comments
 (0)