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

Comparing Convert-BER-XS/XS.xs (file contents):
Revision 1.8 by root, Sat Apr 20 01:50:13 2019 UTC vs.
Revision 1.11 by root, Sat Apr 20 12:25:23 2019 UTC

92 92
93static profile_type *cur_profile, *default_profile; 93static profile_type *cur_profile, *default_profile;
94static SV *buf_sv; // encoding buffer 94static SV *buf_sv; // encoding buffer
95static U8 *buf, *cur, *end; // buffer start, current, end 95static U8 *buf, *cur, *end; // buffer start, current, end
96 96
97#if PERL_VERSION < 18
98# define utf8_to_uvchr_buf(s,e,l) utf8_to_uvchr (s, l)
99#endif
100
97#if __GNUC__ >= 3 101#if __GNUC__ >= 3
98# define expect(expr,value) __builtin_expect ((expr), (value)) 102# define expect(expr,value) __builtin_expect ((expr), (value))
99# define INLINE static inline 103# define INLINE static inline
100#else 104#else
101# define expect(expr,value) (expr) 105# define expect(expr,value) (expr)
155 return BER_TYPE_BYTES; 159 return BER_TYPE_BYTES;
156 160
157 return SvPVX (sv)[idx]; 161 return SvPVX (sv)[idx];
158} 162}
159 163
160static int 164static void
161profile_set (profile_type *profile, int klass, int tag, int type) 165profile_set (profile_type *profile, int klass, int tag, int type)
162{ 166{
163 SV *sv = (SV *)profile; 167 SV *sv = (SV *)profile;
164 U32 idx = (tag << 2) + klass; 168 U32 idx = (tag << 2) + klass;
165 STRLEN oldlen = SvCUR (sv); 169 STRLEN oldlen = SvCUR (sv);
195 { ASN_UNIVERSAL, ASN_UTF8_STRING , BER_TYPE_UTF8 }, 199 { ASN_UNIVERSAL, ASN_UTF8_STRING , BER_TYPE_UTF8 },
196 { ASN_UNIVERSAL, ASN_BMP_STRING , BER_TYPE_UCS2 }, 200 { ASN_UNIVERSAL, ASN_BMP_STRING , BER_TYPE_UCS2 },
197 { ASN_UNIVERSAL, ASN_UNIVERSAL_STRING , BER_TYPE_UCS4 }, 201 { ASN_UNIVERSAL, ASN_UNIVERSAL_STRING , BER_TYPE_UCS4 },
198 }; 202 };
199 203
200 for (celem = default_map + sizeof (default_map) / sizeof (default_map [0]); celem > default_map; celem--) 204 for (celem = default_map + sizeof (default_map) / sizeof (default_map [0]); celem-- > default_map; )
201 profile_set ((void *)sv, celem->klass, celem->tag, celem->type); 205 profile_set ((profile_type *)sv, celem->klass, celem->tag, celem->type);
202 206
203 return sv_bless (newRV_noinc (sv), profile_stash); 207 return sv_bless (newRV_noinc (sv), profile_stash);
204} 208}
205 209
206///////////////////////////////////////////////////////////////////////////// 210/////////////////////////////////////////////////////////////////////////////
339 u /= 10; 343 u /= 10;
340 } 344 }
341 while (u); 345 while (u);
342 346
343 // reverse digits 347 // reverse digits
344 for (char *ptr = buf; --ptr != beg; ++beg) 348 char *ptr = buf;
349 while (--ptr != beg)
345 { 350 {
346 char c = *ptr; 351 char c = *ptr;
347 *ptr = *beg; 352 *ptr = *beg;
348 *beg = c; 353 *beg = c;
354 ++beg;
349 } 355 }
350 } 356 }
351 357
352 return buf; 358 return buf;
353} 359}
553static void 559static void
554set_buf (SV *sv) 560set_buf (SV *sv)
555{ 561{
556 STRLEN len; 562 STRLEN len;
557 buf_sv = sv; 563 buf_sv = sv;
558 buf = SvPVbyte (buf_sv, len); 564 buf = (U8 *)SvPVbyte (buf_sv, len);
559 cur = buf; 565 cur = buf;
560 end = buf + len; 566 end = buf + len;
561} 567}
562 568
563/* similar to SvGROW, but somewhat safer and guarantees exponential realloc strategy */ 569/* similar to SvGROW, but somewhat safer and guarantees exponential realloc strategy */
577need (STRLEN len) 583need (STRLEN len)
578{ 584{
579 if (expect_false ((uintptr_t)(end - cur) < len)) 585 if (expect_false ((uintptr_t)(end - cur) < len))
580 { 586 {
581 STRLEN pos = cur - buf; 587 STRLEN pos = cur - buf;
582 buf = my_sv_grow (buf_sv, pos, len); 588 buf = (U8 *)my_sv_grow (buf_sv, pos, len);
583 cur = buf + pos; 589 cur = buf + pos;
584 end = buf + SvLEN (buf_sv) - 1; 590 end = buf + SvLEN (buf_sv) - 1;
585 } 591 }
586} 592}
587 593
813 put_length (uchars * chrsize); 819 put_length (uchars * chrsize);
814 820
815 while (uchars--) 821 while (uchars--)
816 { 822 {
817 STRLEN uclen; 823 STRLEN uclen;
818 UV uchr = utf8_to_uvchr_buf (ptr, ptr + len, &uclen); 824 UV uchr = utf8_to_uvchr_buf ((U8 *)ptr, (U8 *)ptr + len, &uclen);
819 825
820 ptr += uclen; 826 ptr += uclen;
821 len -= uclen; 827 len -= uclen;
822 828
823 if (chrsize == 4) 829 if (chrsize == 4)
864 int fill = AvFILL (av); 870 int fill = AvFILL (av);
865 871
866 if (expect_false (SvRMAGICAL (av))) 872 if (expect_false (SvRMAGICAL (av)))
867 croak ("BER constructed data must not be tied"); 873 croak ("BER constructed data must not be tied");
868 874
875 int i;
869 for (int i = 0; i <= fill; ++i) 876 for (i = 0; i <= fill; ++i)
870 encode_ber (AvARRAY (av)[i]); 877 encode_ber (AvARRAY (av)[i]);
871 878
872 len_fixup (mark); 879 len_fixup (mark);
873 } 880 }
874 else 881 else
1024ber_decode (SV *ber, SV *profile = &PL_sv_undef) 1031ber_decode (SV *ber, SV *profile = &PL_sv_undef)
1025 CODE: 1032 CODE:
1026{ 1033{
1027 cur_profile = SvPROFILE (profile); 1034 cur_profile = SvPROFILE (profile);
1028 STRLEN len; 1035 STRLEN len;
1029 buf = SvPVbyte (ber, len); 1036 buf = (U8 *)SvPVbyte (ber, len);
1030 cur = buf; 1037 cur = buf;
1031 end = buf + len; 1038 end = buf + len;
1032 1039
1033 RETVAL = decode_ber (); 1040 RETVAL = decode_ber ();
1034} 1041}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines