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.6 by root, Fri Mar 23 15:10:55 2007 UTC vs.
Revision 1.7 by root, Fri Mar 23 15:57:18 2007 UTC

52{ 52{
53 if (!(SvROK (sv) && SvOBJECT (SvRV (sv)) && SvSTASH (SvRV (sv)) == json_stash)) 53 if (!(SvROK (sv) && SvOBJECT (SvRV (sv)) && SvSTASH (SvRV (sv)) == json_stash))
54 croak ("object is not of type JSON::XS"); 54 croak ("object is not of type JSON::XS");
55 55
56 return &SvUVX (SvRV (sv)); 56 return &SvUVX (SvRV (sv));
57}
58
59static void
60shrink (SV *sv)
61{
62 sv_utf8_downgrade (sv, 1);
63#ifdef SvPV_shrink_to_cur
64 SvPV_shrink_to_cur (sv);
65#endif
57} 66}
58 67
59///////////////////////////////////////////////////////////////////////////// 68/////////////////////////////////////////////////////////////////////////////
60 69
61static void 70static void
167 } 176 }
168 while (--clen); 177 while (--clen);
169 } 178 }
170 else 179 else
171 { 180 {
172 need (enc, 10); // never more than 11 bytes needed 181 need (enc, len += 10); // never more than 11 bytes needed
173 enc->cur = uvuni_to_utf8_flags (enc->cur, uch, 0); 182 enc->cur = uvuni_to_utf8_flags (enc->cur, uch, 0);
174 ++str; 183 ++str;
175 } 184 }
176 } 185 }
177 } 186 }
425 if (!(flags & (F_ASCII | F_UTF8))) 434 if (!(flags & (F_ASCII | F_UTF8)))
426 SvUTF8_on (enc.sv); 435 SvUTF8_on (enc.sv);
427 436
428 SvCUR_set (enc.sv, enc.cur - SvPVX (enc.sv)); 437 SvCUR_set (enc.sv, enc.cur - SvPVX (enc.sv));
429 438
430#ifdef SvPV_shrink_to_cur
431 if (enc.flags & F_SHRINK) 439 if (enc.flags & F_SHRINK)
432 SvPV_shrink_to_cur (enc.sv); 440 shrink (enc.sv);
433#endif 441
434 return enc.sv; 442 return enc.sv;
435} 443}
436 444
437///////////////////////////////////////////////////////////////////////////// 445/////////////////////////////////////////////////////////////////////////////
438 446
576 else if (ch >= 0x80) 584 else if (ch >= 0x80)
577 { 585 {
578 STRLEN clen; 586 STRLEN clen;
579 UV uch = utf8n_to_uvuni (dec->cur, dec->end - dec->cur, &clen, UTF8_CHECK_ONLY); 587 UV uch = utf8n_to_uvuni (dec->cur, dec->end - dec->cur, &clen, UTF8_CHECK_ONLY);
580 if (clen == (STRLEN)-1) 588 if (clen == (STRLEN)-1)
581 ERR ("malformed UTF-8 character in string, cannot convert to JSON"); 589 ERR ("malformed UTF-8 character in JSON string");
582 590
583 APPEND_GROW (clen); 591 APPEND_GROW (clen);
584 do 592 do
585 { 593 {
586 *cur++ = *dec->cur++; 594 *cur++ = *dec->cur++;
603 *SvEND (sv) = 0; 611 *SvEND (sv) = 0;
604 612
605 if (utf8) 613 if (utf8)
606 SvUTF8_on (sv); 614 SvUTF8_on (sv);
607 615
608#ifdef SvPV_shrink_to_cur
609 if (dec->flags & F_SHRINK) 616 if (dec->flags & F_SHRINK)
610 SvPV_shrink_to_cur (sv); 617 shrink (sv);
611#endif
612 618
613 return sv; 619 return sv;
614 620
615fail: 621fail:
616 SvREFCNT_dec (sv); 622 SvREFCNT_dec (sv);
838 ERR ("'null' expected"); 844 ERR ("'null' expected");
839 845
840 break; 846 break;
841 847
842 default: 848 default:
843 ERR ("malformed json string"); 849 ERR ("malformed json string, neither array, object, number, string or atom");
844 break; 850 break;
845 } 851 }
846 852
847fail: 853fail:
848 return 0; 854 return 0;
868 874
869 sv = decode_sv (&dec); 875 sv = decode_sv (&dec);
870 876
871 if (!sv) 877 if (!sv)
872 { 878 {
879 IV offset = dec.flags & F_UTF8
880 ? dec.cur - SvPVX (string)
873 IV offset = utf8_distance (dec.cur, SvPVX (string)); 881 : utf8_distance (dec.cur, SvPVX (string));
874 SV *uni = sv_newmortal (); 882 SV *uni = sv_newmortal ();
875 // horrible hack to silence warning inside pv_uni_display 883 // horrible hack to silence warning inside pv_uni_display
876 COP cop; 884 COP cop;
877 memset (&cop, 0, sizeof (cop)); 885 memset (&cop, 0, sizeof (cop));
878 cop.cop_warnings = pWARN_NONE; 886 cop.cop_warnings = pWARN_NONE;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines