unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#22815: 25.0.91; emacs-module.*
@ 2016-02-26  7:28 Atsuo Ohki
  2016-02-26  9:10 ` Eli Zaretskii
  0 siblings, 1 reply; 9+ messages in thread
From: Atsuo Ohki @ 2016-02-26  7:28 UTC (permalink / raw)
  To: 22815


 This is not a bug report, but feature enhancemnt for emacs-module.*

 API of emacs-module has two Lisp string related functions,
 `copy_string_contents' and `make_string'.
 Those functions assume UTF-8 encoded strings,
 but it becomes flexible if a user can specify a specific encoding.

 I made a following patch for accepting encoding.


--- src/emacs-module.c-ORIG	2016-02-05 03:15:31.000000000 +0900
+++ src/emacs-module.c	2016-02-26 10:20:31.831515000 +0900
@@ -502,17 +502,22 @@
 
 static bool
 module_copy_string_contents (emacs_env *env, emacs_value value, char *buffer,
-			     ptrdiff_t *length)
+			     ptrdiff_t *length, emacs_value coding)
 {
   MODULE_FUNCTION_BEGIN (false);
   Lisp_Object lisp_str = value_to_lisp (value);
+  Lisp_Object lisp_coding;
   if (! STRINGP (lisp_str))
     {
       module_wrong_type (env, Qstringp, lisp_str);
       return false;
     }
 
-  Lisp_Object lisp_str_utf8 = ENCODE_UTF_8 (lisp_str);
+  if (coding == module_nil) lisp_coding = Qutf_8;
+  else if ((lisp_coding = value_to_lisp(coding)) == Qnil) lisp_coding = Qutf_8;
+
+  Lisp_Object lisp_str_utf8 =
+      code_convert_string_norecord (lisp_str, lisp_coding, false);
   ptrdiff_t raw_size = SBYTES (lisp_str_utf8);
   if (raw_size == PTRDIFF_MAX)
     {
@@ -545,16 +550,23 @@
 }
 
 static emacs_value
-module_make_string (emacs_env *env, const char *str, ptrdiff_t length)
+module_make_string (emacs_env *env, const char *str,	
+		    ptrdiff_t length, emacs_value coding)
 {
   MODULE_FUNCTION_BEGIN (module_nil);
+  Lisp_Object lisp_coding;
   if (length > STRING_BYTES_BOUND)
     {
       module_non_local_exit_signal_1 (env, Qoverflow_error, Qnil);
       return module_nil;
     }
   Lisp_Object lstr = make_unibyte_string (str, length);
-  return lisp_to_value (code_convert_string_norecord (lstr, Qutf_8, false));
+
+  if (coding == module_nil) lisp_coding = Qutf_8;
+  else if ((lisp_coding = value_to_lisp(coding)) == Qnil) lisp_coding = Qutf_8;
+
+  return lisp_to_value (
+	code_convert_string_norecord (lstr, lisp_coding, false));
 }
 
 static emacs_value
--- src/emacs-module.h-ORIG	2016-02-05 03:15:31.000000000 +0900
+++ src/emacs-module.h	2016-02-25 14:25:04.785587000 +0900
@@ -151,7 +151,7 @@
   emacs_value (*make_float) (emacs_env *env, double value);
 
   /* Copy the content of the Lisp string VALUE to BUFFER as an utf8
-     null-terminated string.
+     (or specified coding) null-terminated string.
 
      SIZE must point to the total size of the buffer.  If BUFFER is
      NULL or if SIZE is not big enough, write the required buffer size
@@ -165,11 +165,13 @@
   bool (*copy_string_contents) (emacs_env *env,
                                 emacs_value value,
                                 char *buffer,
-                                ptrdiff_t *size_inout);
+                                ptrdiff_t *size_inout,
+                                emacs_value coding);
 
-  /* Create a Lisp string from a utf8 encoded string.  */
+  /* Create a Lisp string from a utf8 (or specified) encoded string.  */
   emacs_value (*make_string) (emacs_env *env,
-			      const char *contents, ptrdiff_t length);
+			      const char *contents,
+			      ptrdiff_t length, emacs_value coding);
 
   /* Embedded pointer type.  */
   emacs_value (*make_user_ptr) (emacs_env *env,




#===========================================================================
In GNU Emacs 25.0.91.1 (x86_64-ibm-freebsd10.2, X toolkit, Xaw3d scroll bars)
 of 2016-02-26 built on smr00
Configured using:
 'configure x86_64-ibm-freebsd10.2
 --srcdir=/usr/src/local/GNU/emacs/emacs-25.0.91 --with-x
 --x-includes=/usr/local/include --x-libraries=/usr/local/lib
 --with-x-toolkit=lucid --without-xim --with-modules --without-pop
 --without-xpm --without-jpeg --without-tiff --without-gif --without-png
 --without-rsvg --without-imagemagick --without-gpm --without-dbus
 --without-gconf --without-gsettings --without-selinux --without-gnutls
 LDFLAGS=-L/usr/local/lib'

Configured features:
XAW3D SOUND NOTIFY ACL LIBXML2 FREETYPE XFT ZLIB TOOLKIT_SCROLL_BARS
LUCID X11 MODULES

Important settings:
  locale-coding-system: nil

Major mode: Fundamental

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent messages:
Loading /usr/local/share/emacs/site-lisp/site-start-25.x.el (source)...
Loading /usr/local/share/emacs/25.0.91/site-lisp/canna-leim.el (source)...
byte-code: Canna is not built into this Emacs
No docstring slot for setup-japanese-environment-internal

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message idna dired format-spec rfc822
mml mml-sec epg epg-config gnus-util mm-decode mm-bodies mm-encode
mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047
rfc2045 ietf-drums mm-util help-fns help-mode easymenu cl-loaddefs pcase
cl-lib mail-prsvr mail-utils time-date japan-util disp-table mule-util
tooltip eldoc electric uniquify ediff-hook vc-hooks lisp-float-type
mwheel x-win term/common-win x-dnd tool-bar dnd fontset image regexp-opt
fringe tabulated-list newcomment elisp-mode lisp-mode prog-mode register
page menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock
font-lock syntax facemenu font-core frame cl-generic cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese charscript case-table epa-hook
jka-cmpr-hook help simple abbrev minibuffer cl-preloaded nadvice
loaddefs button faces cus-face macroexp files text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote kqueue dynamic-setting
font-render-setting x-toolkit x multi-tty make-network-process emacs)

Memory information:
((conses 16 87847 5715)
 (symbols 48 19548 0)
 (miscs 40 44 85)
 (strings 32 14122 4881)
 (string-bytes 1 406710)
 (vectors 16 9853)
 (vector-slots 8 453785 38367)
 (floats 8 162 258)
 (intervals 56 200 18)
 (buffers 976 11))





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#22815: 25.0.91; emacs-module.*
  2016-02-26  7:28 bug#22815: 25.0.91; emacs-module.* Atsuo Ohki
@ 2016-02-26  9:10 ` Eli Zaretskii
  2016-02-26  9:16   ` ohki
  0 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2016-02-26  9:10 UTC (permalink / raw)
  To: Atsuo Ohki; +Cc: 22815

> From: Atsuo Ohki <ohki@gssm.otsuka.tsukuba.ac.jp>
> Date: Fri, 26 Feb 2016 16:28:09 +0900
> 
>  This is not a bug report, but feature enhancemnt for emacs-module.*
> 
>  API of emacs-module has two Lisp string related functions,
>  `copy_string_contents' and `make_string'.
>  Those functions assume UTF-8 encoded strings,
>  but it becomes flexible if a user can specify a specific encoding.

Thanks.

But why cannot the module convert the string to UTF-8 before passing
it to Emacs?





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#22815: 25.0.91; emacs-module.*
  2016-02-26  9:10 ` Eli Zaretskii
@ 2016-02-26  9:16   ` ohki
  2016-02-26  9:46     ` Eli Zaretskii
  0 siblings, 1 reply; 9+ messages in thread
From: ohki @ 2016-02-26  9:16 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Atsuo Ohki, 22815

Eli Zaretskii writes:
> > From: Atsuo Ohki <ohki@gssm.otsuka.tsukuba.ac.jp>
> > Date: Fri, 26 Feb 2016 16:28:09 +0900
> > 
> >  This is not a bug report, but feature enhancemnt for emacs-module.*
> > 
> >  API of emacs-module has two Lisp string related functions,
> >  `copy_string_contents' and `make_string'.
> >  Those functions assume UTF-8 encoded strings,
> >  but it becomes flexible if a user can specify a specific encoding.
> 
> Thanks.
> 
> But why cannot the module convert the string to UTF-8 before passing
> it to Emacs?
> 

 Because, an external module could use a coding system other then UTF-8.
 I have used emacs-module capability to plugin CANNA server interface
 (CANNA server is a rather out of dated KANA-KANJI converter for japanese),
 and CANNA server uses euc-jp encoding for communication.





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#22815: 25.0.91; emacs-module.*
  2016-02-26  9:16   ` ohki
@ 2016-02-26  9:46     ` Eli Zaretskii
  2016-02-26 10:09       ` ohki
  0 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2016-02-26  9:46 UTC (permalink / raw)
  To: ohki; +Cc: 22815

> From: ohki@gssm.otsuka.tsukuba.ac.jp
> Cc: Atsuo Ohki <ohki@gssm.otsuka.tsukuba.ac.jp>, 22815@debbugs.gnu.org
> Date: Fri, 26 Feb 2016 18:16:05 +0900
> 
> > But why cannot the module convert the string to UTF-8 before passing
> > it to Emacs?
> 
>  Because, an external module could use a coding system other then UTF-8.
>  I have used emacs-module capability to plugin CANNA server interface
>  (CANNA server is a rather out of dated KANA-KANJI converter for japanese),
>  and CANNA server uses euc-jp encoding for communication.

I was asking why couldn't the plug-in do the conversion, e.g., by
using libiconv?  Emacs is not the only piece of software that knows
how to convert from one encoding to another.





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#22815: 25.0.91; emacs-module.*
  2016-02-26  9:46     ` Eli Zaretskii
@ 2016-02-26 10:09       ` ohki
  2016-02-26 18:26         ` Eli Zaretskii
  0 siblings, 1 reply; 9+ messages in thread
From: ohki @ 2016-02-26 10:09 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: ohki, 22815

Eli Zaretskii writes:
> > From: ohki@gssm.otsuka.tsukuba.ac.jp
> > Cc: Atsuo Ohki <ohki@gssm.otsuka.tsukuba.ac.jp>, 22815@debbugs.gnu.org
> > Date: Fri, 26 Feb 2016 18:16:05 +0900
> > 
> > > But why cannot the module convert the string to UTF-8 before passing
> > > it to Emacs?
> > 
> >  Because, an external module could use a coding system other then UTF-8.
> >  I have used emacs-module capability to plugin CANNA server interface
> >  (CANNA server is a rather out of dated KANA-KANJI converter for japanese),
> >  and CANNA server uses euc-jp encoding for communication.
> 
> I was asking why couldn't the plug-in do the conversion, e.g., by
> using libiconv?  Emacs is not the only piece of software that knows
> how to convert from one encoding to another.

 I considered using libiconv once, but Emacs has the conversion
 capability, so why not use it.  It is simple to use Emacs itself for
 conversion, than using different conversion library, as long as a
 plugin runs as a part of Emacs process.





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#22815: 25.0.91; emacs-module.*
  2016-02-26 10:09       ` ohki
@ 2016-02-26 18:26         ` Eli Zaretskii
  2016-02-26 23:21           ` ohki
  0 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2016-02-26 18:26 UTC (permalink / raw)
  To: ohki; +Cc: 22815

> From: ohki@gssm.otsuka.tsukuba.ac.jp
> Cc: ohki@gssm.otsuka.tsukuba.ac.jp, 22815@debbugs.gnu.org
> Date: Fri, 26 Feb 2016 19:09:57 +0900
> 
> > I was asking why couldn't the plug-in do the conversion, e.g., by
> > using libiconv?  Emacs is not the only piece of software that knows
> > how to convert from one encoding to another.
> 
>  I considered using libiconv once, but Emacs has the conversion
>  capability, so why not use it.

Because it can signal an error, if the encoding you pass is not a
valid coding-system that Emacs recognizes?





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#22815: 25.0.91; emacs-module.*
  2016-02-26 18:26         ` Eli Zaretskii
@ 2016-02-26 23:21           ` ohki
  2016-02-27  8:19             ` Eli Zaretskii
  0 siblings, 1 reply; 9+ messages in thread
From: ohki @ 2016-02-26 23:21 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: ohki, 22815

Eli Zaretskii writes:
> > From: ohki@gssm.otsuka.tsukuba.ac.jp
> > Cc: ohki@gssm.otsuka.tsukuba.ac.jp, 22815@debbugs.gnu.org
> > Date: Fri, 26 Feb 2016 19:09:57 +0900
> > 
> > > I was asking why couldn't the plug-in do the conversion, e.g., by
> > > using libiconv?  Emacs is not the only piece of software that knows
> > > how to convert from one encoding to another.
> > 
> >  I considered using libiconv once, but Emacs has the conversion
> >  capability, so why not use it.
> 
> Because it can signal an error, if the encoding you pass is not a
> valid coding-system that Emacs recognizes?
> 

 Yes it does!
 In the course of developing my plugin,
 I encountered `Invalid coding system' message,  and Emacs keep working
 (no crash, no hangup).





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#22815: 25.0.91; emacs-module.*
  2016-02-26 23:21           ` ohki
@ 2016-02-27  8:19             ` Eli Zaretskii
  2016-03-29 10:05               ` Philipp Stephani
  0 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2016-02-27  8:19 UTC (permalink / raw)
  To: ohki, Daniel Colascione, John Wiegley; +Cc: 22815

> From: ohki@gssm.otsuka.tsukuba.ac.jp
> Cc: ohki@gssm.otsuka.tsukuba.ac.jp, 22815@debbugs.gnu.org
> Date: Sat, 27 Feb 2016 08:21:39 +0900
> 
> Eli Zaretskii writes:
> > > From: ohki@gssm.otsuka.tsukuba.ac.jp
> > > Cc: ohki@gssm.otsuka.tsukuba.ac.jp, 22815@debbugs.gnu.org
> > > Date: Fri, 26 Feb 2016 19:09:57 +0900
> > > 
> > > > I was asking why couldn't the plug-in do the conversion, e.g., by
> > > > using libiconv?  Emacs is not the only piece of software that knows
> > > > how to convert from one encoding to another.
> > > 
> > >  I considered using libiconv once, but Emacs has the conversion
> > >  capability, so why not use it.
> > 
> > Because it can signal an error, if the encoding you pass is not a
> > valid coding-system that Emacs recognizes?
> 
>  Yes it does!
>  In the course of developing my plugin,
>  I encountered `Invalid coding system' message,  and Emacs keep working
>  (no crash, no hangup).

It's all too easy to get that, since Emacs coding-systems have names
that are rarely used elsewhere.  And using libiconv is easy enough.

So I'm uneasy about this.  What do others think?





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#22815: 25.0.91; emacs-module.*
  2016-02-27  8:19             ` Eli Zaretskii
@ 2016-03-29 10:05               ` Philipp Stephani
  0 siblings, 0 replies; 9+ messages in thread
From: Philipp Stephani @ 2016-03-29 10:05 UTC (permalink / raw)
  To: Eli Zaretskii, ohki, Daniel Colascione, John Wiegley; +Cc: 22815

[-- Attachment #1: Type: text/plain, Size: 1450 bytes --]

Eli Zaretskii <eliz@gnu.org> schrieb am Sa., 27. Feb. 2016 um 09:21 Uhr:

> > From: ohki@gssm.otsuka.tsukuba.ac.jp
> > Cc: ohki@gssm.otsuka.tsukuba.ac.jp, 22815@debbugs.gnu.org
> > Date: Sat, 27 Feb 2016 08:21:39 +0900
> >
> > Eli Zaretskii writes:
> > > > From: ohki@gssm.otsuka.tsukuba.ac.jp
> > > > Cc: ohki@gssm.otsuka.tsukuba.ac.jp, 22815@debbugs.gnu.org
> > > > Date: Fri, 26 Feb 2016 19:09:57 +0900
> > > >
> > > > > I was asking why couldn't the plug-in do the conversion, e.g., by
> > > > > using libiconv?  Emacs is not the only piece of software that knows
> > > > > how to convert from one encoding to another.
> > > >
> > > >  I considered using libiconv once, but Emacs has the conversion
> > > >  capability, so why not use it.
> > >
> > > Because it can signal an error, if the encoding you pass is not a
> > > valid coding-system that Emacs recognizes?
> >
> >  Yes it does!
> >  In the course of developing my plugin,
> >  I encountered `Invalid coding system' message,  and Emacs keep working
> >  (no crash, no hangup).
>
> It's all too easy to get that, since Emacs coding-systems have names
> that are rarely used elsewhere.  And using libiconv is easy enough.
>
> So I'm uneasy about this.  What do others think?
>
>
>
>
I agree, this adds complexity without significant advantages.
I'd recommend to add a wrapper for make-unibyte-string instead, then users
can choose to use Emacs functions for decoding and encoding strings.

[-- Attachment #2: Type: text/html, Size: 2389 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-03-29 10:05 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-26  7:28 bug#22815: 25.0.91; emacs-module.* Atsuo Ohki
2016-02-26  9:10 ` Eli Zaretskii
2016-02-26  9:16   ` ohki
2016-02-26  9:46     ` Eli Zaretskii
2016-02-26 10:09       ` ohki
2016-02-26 18:26         ` Eli Zaretskii
2016-02-26 23:21           ` ohki
2016-02-27  8:19             ` Eli Zaretskii
2016-03-29 10:05               ` Philipp Stephani

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).