@@ -611,6 +611,13 @@ static int serialize1(Ser *s, VALUE refs, VALUE v)
611
611
return 0 ;
612
612
}
613
613
614
+ // don't mix with ser_array_begin/ser_object_begin because
615
+ // that will throw off the object reference count
616
+ static int serialize (Ser * s , VALUE v )
617
+ {
618
+ return serialize1 (s , rb_hash_new (), v );
619
+ }
620
+
614
621
static struct timespec deadline_ms (int ms )
615
622
{
616
623
static const int64_t ns_per_sec = 1000 * 1000 * 1000 ;
@@ -859,18 +866,11 @@ static void *rendezvous_callback(void *arg)
859
866
goto fail ;
860
867
}
861
868
ser_init1 (& s , 'c' ); // callback reply
862
- ser_array_begin (& s , 2 );
863
- // either [result, undefined] or [undefined, err]
864
- if (exc )
865
- ser_undefined (& s );
866
- if (serialize1 (& s , rb_hash_new (), r )) { // should not happen
869
+ if (serialize (& s , r )) { // should not happen
867
870
c -> exception = rb_exc_new_cstr (internal_error , s .err );
868
871
ser_reset (& s );
869
872
goto fail ;
870
873
}
871
- if (!exc )
872
- ser_undefined (& s );
873
- ser_array_end (& s , 2 );
874
874
out :
875
875
buf_move (& s .b , a -> req );
876
876
return NULL ;
@@ -1202,25 +1202,21 @@ static VALUE context_stop(VALUE self)
1202
1202
1203
1203
static VALUE context_call (int argc , VALUE * argv , VALUE self )
1204
1204
{
1205
- VALUE a , e , h ;
1205
+ VALUE name , args ;
1206
+ VALUE a , e ;
1206
1207
Context * c ;
1207
- int i ;
1208
1208
Ser s ;
1209
1209
1210
1210
TypedData_Get_Struct (self , Context , & context_type , c );
1211
- rb_scan_args (argc , argv , "1*" , & a , & e );
1212
- Check_Type (a , T_STRING );
1211
+ rb_scan_args (argc , argv , "1*" , & name , & args );
1212
+ Check_Type (name , T_STRING );
1213
+ rb_ary_unshift (args , name );
1213
1214
// request is (C)all, [name, args...] array
1214
1215
ser_init1 (& s , 'C' );
1215
- ser_array_begin (& s , argc );
1216
- h = rb_hash_new ();
1217
- for (i = 0 ; i < argc ; i ++ ) {
1218
- if (serialize1 (& s , h , argv [i ])) {
1219
- ser_reset (& s );
1220
- rb_raise (runtime_error , "Context.call: %s" , s .err );
1221
- }
1216
+ if (serialize (& s , args )) {
1217
+ ser_reset (& s );
1218
+ rb_raise (runtime_error , "Context.call: %s" , s .err );
1222
1219
}
1223
- ser_array_end (& s , argc );
1224
1220
// response is [result, err] array
1225
1221
a = rendezvous (c , & s .b ); // takes ownership of |s.b|
1226
1222
e = rb_ary_pop (a );
0 commit comments