[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: user-ptr as image :data
From: |
Stefan Monnier |
Subject: |
Re: user-ptr as image :data |
Date: |
Fri, 15 Mar 2019 15:41:40 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
> I'm currently porting (https://github.com/zevlg/ffi-wand.el) nice wand-mode
> from SXEmacs to GNU Emacs and I miss feature to specify image `:data' as
> user-ptr object.
>
> There is also no possibility to create DATA string in emacs-module, without
> string interpretation, because there is only `make_string' method, which
> expects given `str' pointer to be null-terminated UTF-8 string.
Hmm... indeed we don't have any direct way to create a unibyte string.
Can you `M-x report-emacs-bug` to request this new feature?
> What is the best approach to create `:data` value for image using user-ptr?
AFAICT while the string needs to have a NUL byte after its end,
make_string should handle NUL bytes within the string, so the best
option until a new primitive is provided is probably:
1- use make-string on your non-utf-8 binary data.
2- call encode-coding-string on the result (with utf-8 coding system).
It's ugly, hackish, and inefficient, but our decoding+encoding functions
are supposed to always preserve binary contents when no changes took
place (using the chars in the eight-bit charset when needed), so 1+2
should give you a unibyte string which has the exact byte sequence from
which you started.
Stefan