@@ -611,6 +611,13 @@ static int serialize1(Ser *s, VALUE refs, VALUE v)
611611 return 0 ;
612612}
613613
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+
614621static struct timespec deadline_ms (int ms )
615622{
616623 static const int64_t ns_per_sec = 1000 * 1000 * 1000 ;
@@ -859,18 +866,11 @@ static void *rendezvous_callback(void *arg)
859866 goto fail ;
860867 }
861868 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
867870 c -> exception = rb_exc_new_cstr (internal_error , s .err );
868871 ser_reset (& s );
869872 goto fail ;
870873 }
871- if (!exc )
872- ser_undefined (& s );
873- ser_array_end (& s , 2 );
874874out :
875875 buf_move (& s .b , a -> req );
876876 return NULL ;
@@ -1202,25 +1202,21 @@ static VALUE context_stop(VALUE self)
12021202
12031203static VALUE context_call (int argc , VALUE * argv , VALUE self )
12041204{
1205- VALUE a , e , h ;
1205+ VALUE name , args ;
1206+ VALUE a , e ;
12061207 Context * c ;
1207- int i ;
12081208 Ser s ;
12091209
12101210 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 );
12131214 // request is (C)all, [name, args...] array
12141215 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 );
12221219 }
1223- ser_array_end (& s , argc );
12241220 // response is [result, err] array
12251221 a = rendezvous (c , & s .b ); // takes ownership of |s.b|
12261222 e = rb_ary_pop (a );
0 commit comments