Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PATCH] Encode: Remove XS functions _bytes_to_utf8() and _utf8_to_bytes() #16462

Closed
p5pRT opened this issue Mar 12, 2018 · 7 comments
Closed

[PATCH] Encode: Remove XS functions _bytes_to_utf8() and _utf8_to_bytes() #16462

p5pRT opened this issue Mar 12, 2018 · 7 comments

Comments

@p5pRT
Copy link

@p5pRT p5pRT commented Mar 12, 2018

Migrated from rt.perl.org#132967 (status was 'rejected')

Searchable as RT132967$

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Mar 12, 2018

From @pali

Those two functions are totally undocumented, not fully implemented, they
croak on some usage with "panic_unimplemented" error. They are not used by
any module on CPAN. Therefore it is good candidate for removal.

As Encode is a Perl Core module, I'm sending this patch to the Perl RT
tracker. If you would agree with this change for a Core module, I can then
create a official pull request to the maintainer of CPAN Encode module.

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Mar 12, 2018

From @pali

0001-Encode-Remove-XS-functions-_bytes_to_utf8-and-_utf8_.patch
From 5dfe202ef3005aaa88cf834662708f3bc9e3d093 Mon Sep 17 00:00:00 2001
From: Pali <pali@cpan.org>
Date: Mon, 12 Mar 2018 20:41:59 +0100
Subject: [PATCH] Encode: Remove XS functions _bytes_to_utf8() and
 _utf8_to_bytes()

Those two functions are totally undocumented, not fully implemented, they
croak on some usage with "panic_unimplemented" error. They are not used by
any module on CPAN. Therefore it is good candidate for removal.

---

As Encode is a Perl Core module, I'm sending this patch to the Perl RT
tracker. If you would agree with this change for a Core module, I can then
create a official pull request to the maintainer of CPAN Encode module.
---
 cpan/Encode/Encode.xs | 117 --------------------------------------------------
 1 file changed, 117 deletions(-)

diff --git a/cpan/Encode/Encode.xs b/cpan/Encode/Encode.xs
index bc4a77d6d2..3200398260 100644
--- a/cpan/Encode/Encode.xs
+++ b/cpan/Encode/Encode.xs
@@ -20,17 +20,6 @@
    encode_method().  1 is recommended. 2 restores NI-S original */
 #define ENCODE_XS_USEFP   1
 
-#define UNIMPLEMENTED(x,y) static y x (SV *sv, char *encoding) {	\
-			Perl_croak_nocontext("panic_unimplemented");	\
-                        PERL_UNUSED_VAR(sv); \
-                        PERL_UNUSED_VAR(encoding); \
-             return (y)0; /* fool picky compilers */ \
-                         }
-/**/
-
-UNIMPLEMENTED(_encoded_utf8_to_bytes, I32)
-UNIMPLEMENTED(_encoded_bytes_to_utf8, I32)
-
 #ifndef SvIV_nomg
 #define SvIV_nomg SvIV
 #endif
@@ -67,16 +56,6 @@ Encode_XSEncoding(pTHX_ encode_t * enc)
 }
 
 static void
-call_failure(SV * routine, U8 * done, U8 * dest, U8 * orig)
-{
-    /* Exists for breakpointing */
-    PERL_UNUSED_VAR(routine);
-    PERL_UNUSED_VAR(done);
-    PERL_UNUSED_VAR(dest);
-    PERL_UNUSED_VAR(orig);
-}
-
-static void
 utf8_safe_downgrade(pTHX_ SV ** src, U8 ** s, STRLEN * slen, bool modify)
 {
     if (!modify) {
@@ -988,102 +967,6 @@ MODULE = Encode         PACKAGE = Encode
 
 PROTOTYPES: ENABLE
 
-I32
-_bytes_to_utf8(sv, ...)
-SV *    sv
-PREINIT:
-    SV * encoding;
-INIT:
-    encoding = items == 2 ? ST(1) : Nullsv;
-CODE:
-    if (encoding)
-    RETVAL = _encoded_bytes_to_utf8(sv, SvPV_nolen(encoding));
-    else {
-    STRLEN len;
-    U8*    s = (U8*)SvPV(sv, len);
-    U8*    converted;
-
-    converted = bytes_to_utf8(s, &len); /* This allocs */
-    sv_setpvn(sv, (char *)converted, len);
-    SvUTF8_on(sv); /* XXX Should we? */
-    Safefree(converted);                /* ... so free it */
-    RETVAL = len;
-    }
-OUTPUT:
-    RETVAL
-
-I32
-_utf8_to_bytes(sv, ...)
-SV *    sv
-PREINIT:
-    SV * to;
-    SV * check;
-INIT:
-    to    = items > 1 ? ST(1) : Nullsv;
-    check = items > 2 ? ST(2) : Nullsv;
-CODE:
-    if (to) {
-    RETVAL = _encoded_utf8_to_bytes(sv, SvPV_nolen(to));
-    } else {
-    STRLEN len;
-    U8 *s = (U8*)SvPV(sv, len);
-
-    RETVAL = 0;
-    if (SvTRUE(check)) {
-        /* Must do things the slow way */
-        U8 *dest;
-            /* We need a copy to pass to check() */
-        U8 *src  = s;
-        U8 *send = s + len;
-        U8 *d0;
-
-        New(83, dest, len, U8); /* I think */
-        d0 = dest;
-
-        while (s < send) {
-                if (*s < 0x80){
-            *dest++ = *s++;
-                } else {
-            STRLEN ulen;
-            UV uv = *s++;
-
-            /* Have to do it all ourselves because of error routine,
-               aargh. */
-            if (!(uv & 0x40)){ goto failure; }
-            if      (!(uv & 0x20)) { ulen = 2;  uv &= 0x1f; }
-            else if (!(uv & 0x10)) { ulen = 3;  uv &= 0x0f; }
-            else if (!(uv & 0x08)) { ulen = 4;  uv &= 0x07; }
-            else if (!(uv & 0x04)) { ulen = 5;  uv &= 0x03; }
-            else if (!(uv & 0x02)) { ulen = 6;  uv &= 0x01; }
-            else if (!(uv & 0x01)) { ulen = 7;  uv = 0; }
-            else                   { ulen = 13; uv = 0; }
-        
-            /* Note change to utf8.c variable naming, for variety */
-            while (ulen--) {
-            if ((*s & 0xc0) != 0x80){
-                goto failure;
-            } else {
-                uv = (uv << 6) | (*s++ & 0x3f);
-            }
-          }
-          if (uv > 256) {
-          failure:
-              call_failure(check, s, dest, src);
-              /* Now what happens? */
-          }
-          *dest++ = (U8)uv;
-        }
-        }
-        RETVAL = dest - d0;
-        sv_usepvn(sv, (char *)dest, RETVAL);
-        SvUTF8_off(sv);
-    } else {
-        RETVAL = (utf8_to_bytes(s, &len) ? len : 0);
-    }
-    }
-OUTPUT:
-    RETVAL
-
 bool
 is_utf8(sv, check = 0)
 SV *	sv
-- 
2.11.0

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Mar 14, 2018

From @khwilliamson

On Mon, 12 Mar 2018 12​:53​:54 -0700, pali@​cpan.org wrote​:

Those two functions are totally undocumented, not fully implemented, they
croak on some usage with "panic_unimplemented" error. They are not used by
any module on CPAN. Therefore it is good candidate for removal.

As Encode is a Perl Core module, I'm sending this patch to the Perl RT
tracker. If you would agree with this change for a Core module, I can then
create a official pull request to the maintainer of CPAN Encode module.

I see no reason to keep these stubs
--
Karl Williamson

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Mar 14, 2018

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Mar 14, 2018

From @pali

On Wednesday 14 March 2018 09​:31​:16 Karl Williamson via RT wrote​:

I see no reason to keep these stubs

Ok, I created pull request to the Encode upstream project​:

dankogai/p5-encode#133

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Mar 16, 2018

From @khwilliamson

Since, this entirely an upstream Encode issue, and a ticket has been opened there, I'm closing this one
--
Karl Williamson

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Mar 16, 2018

@khwilliamson - Status changed from 'open' to 'rejected'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant