ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/JSON-XS/XS.xs
(Generate patch)

Comparing JSON-XS/XS.xs (file contents):
Revision 1.52 by root, Mon Jul 2 02:57:11 2007 UTC vs.
Revision 1.53 by root, Tue Jul 10 15:45:34 2007 UTC

489 } 489 }
490#endif 490#endif
491 if (enc->json.flags & F_CONV_BLESSED) 491 if (enc->json.flags & F_CONV_BLESSED)
492 { 492 {
493 // we re-bless the reference to get overload and other niceties right 493 // we re-bless the reference to get overload and other niceties right
494 GV *to_json = gv_fetchmethod_autoload (SvSTASH (sv), "TO_JSON", 1); 494 GV *to_json = gv_fetchmethod_autoload (SvSTASH (sv), "TO_JSON", 0);
495 495
496 if (to_json) 496 if (to_json)
497 { 497 {
498 dSP;
499
498 dSP; ENTER; SAVETMPS; PUSHMARK (SP); 500 ENTER; SAVETMPS; PUSHMARK (SP);
499 XPUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), SvSTASH (sv))); 501 XPUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), SvSTASH (sv)));
500 502
501 // calling with G_SCALAR ensures that we always get a 1 reutrn value 503 // calling with G_SCALAR ensures that we always get a 1 return value
502 // check anyways. 504 // check anyways.
503 PUTBACK; 505 PUTBACK;
504 assert (1 == call_sv ((SV *)GvCV (to_json), G_SCALAR)); 506 assert (1 == call_sv ((SV *)GvCV (to_json), G_SCALAR));
505 SPAGAIN; 507 SPAGAIN;
506 508
509 // catch this surprisingly common error
510 if (SvROK (TOPs) && SvRV (TOPs) == sv)
511 croak ("%s::TO_JSON method returned same object as was passed instead of a new one", HvNAME (SvSTASH (sv)));
512
513 sv = POPs;
514 PUTBACK;
515
507 encode_sv (enc, POPs); 516 encode_sv (enc, sv);
508 517
509 FREETMPS; LEAVE; 518 FREETMPS; LEAVE;
510 } 519 }
511 else if (enc->json.flags & F_ALLOW_BLESSED) 520 else if (enc->json.flags & F_ALLOW_BLESSED)
512 encode_str (enc, "null", 4, 0); 521 encode_str (enc, "null", 4, 0);
1113 // might want to optimise this for common cases. 1122 // might want to optimise this for common cases.
1114 cb = hv_fetch_ent (dec->json.cb_sk_object, hv_iterkeysv (he), 0, 0); 1123 cb = hv_fetch_ent (dec->json.cb_sk_object, hv_iterkeysv (he), 0, 0);
1115 1124
1116 if (cb) 1125 if (cb)
1117 { 1126 {
1127 dSP;
1118 int count; 1128 int count;
1119 ENTER; SAVETMPS;
1120 1129
1121 dSP; PUSHMARK (SP); 1130 ENTER; SAVETMPS; PUSHMARK (SP);
1122 XPUSHs (HeVAL (he)); 1131 XPUSHs (HeVAL (he));
1123 1132
1124 PUTBACK; count = call_sv (HeVAL (cb), G_ARRAY); SPAGAIN; 1133 PUTBACK; count = call_sv (HeVAL (cb), G_ARRAY); SPAGAIN;
1125 1134
1126 if (count == 1) 1135 if (count == 1)
1134 } 1143 }
1135 } 1144 }
1136 1145
1137 if (dec->json.cb_object) 1146 if (dec->json.cb_object)
1138 { 1147 {
1148 dSP;
1139 int count; 1149 int count;
1140 ENTER; SAVETMPS;
1141 1150
1142 dSP; ENTER; SAVETMPS; PUSHMARK (SP); 1151 ENTER; SAVETMPS; PUSHMARK (SP);
1143 XPUSHs (sv_2mortal (sv)); 1152 XPUSHs (sv_2mortal (sv));
1144 1153
1145 PUTBACK; count = call_sv (dec->json.cb_object, G_ARRAY); SPAGAIN; 1154 PUTBACK; count = call_sv (dec->json.cb_object, G_ARRAY); SPAGAIN;
1146 1155
1147 if (count == 1) 1156 if (count == 1)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines