From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Atsuo Ohki Newsgroups: gmane.emacs.bugs Subject: bug#22815: 25.0.91; emacs-module.* Date: Fri, 26 Feb 2016 16:28:09 +0900 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1456471885 10124 80.91.229.3 (26 Feb 2016 07:31:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 26 Feb 2016 07:31:25 +0000 (UTC) To: 22815@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Feb 26 08:31:14 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aZCrn-0002oW-6t for geb-bug-gnu-emacs@m.gmane.org; Fri, 26 Feb 2016 08:31:11 +0100 Original-Received: from localhost ([::1]:47874 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aZCrm-0002qa-JU for geb-bug-gnu-emacs@m.gmane.org; Fri, 26 Feb 2016 02:31:10 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35811) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aZCrh-0002nu-Uc for bug-gnu-emacs@gnu.org; Fri, 26 Feb 2016 02:31:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aZCre-0007LB-Jh for bug-gnu-emacs@gnu.org; Fri, 26 Feb 2016 02:31:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:49628) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aZCre-0007L6-Fo for bug-gnu-emacs@gnu.org; Fri, 26 Feb 2016 02:31:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84) (envelope-from ) id 1aZCre-0008PL-C6 for bug-gnu-emacs@gnu.org; Fri, 26 Feb 2016 02:31:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Atsuo Ohki Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 26 Feb 2016 07:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 22815 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.145647184132280 (code B ref -1); Fri, 26 Feb 2016 07:31:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 26 Feb 2016 07:30:41 +0000 Original-Received: from localhost ([127.0.0.1]:46754 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aZCrJ-0008Oa-L9 for submit@debbugs.gnu.org; Fri, 26 Feb 2016 02:30:41 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:44580) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aZCrH-0008OI-3R for submit@debbugs.gnu.org; Fri, 26 Feb 2016 02:30:39 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aZCrA-0007Dk-Ll for submit@debbugs.gnu.org; Fri, 26 Feb 2016 02:30:33 -0500 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:55964) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aZCrA-0007De-IJ for submit@debbugs.gnu.org; Fri, 26 Feb 2016 02:30:32 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35530) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aZCr9-0002O9-0F for bug-gnu-emacs@gnu.org; Fri, 26 Feb 2016 02:30:32 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aZCr5-0007CQ-OJ for bug-gnu-emacs@gnu.org; Fri, 26 Feb 2016 02:30:30 -0500 Original-Received: from utogwpl.gssm.otsuka.tsukuba.ac.jp ([210.154.96.162]:52970) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1aZCr5-0007B4-4K for bug-gnu-emacs@gnu.org; Fri, 26 Feb 2016 02:30:27 -0500 Original-Received: (qmail 5854 invoked from network); 26 Feb 2016 07:30:20 -0000 Original-Received: from OneOfLocalMachines (HELO smr00) (10.2.1.1) by 10.1.1.1 with SMTP; 26 Feb 2016 07:30:20 -0000 X-detected-operating-system: by eggs.gnu.org: Mac OS X 10.x X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:113856 Archived-At: 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))