unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* user-ptr as image :data
@ 2019-03-15 19:14 Evgeny Zajcev
  2019-03-15 19:41 ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Evgeny Zajcev @ 2019-03-15 19:14 UTC (permalink / raw)
  To: emacs-devel

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

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.

What is the best approach to create `:data` value for image using user-ptr?

Thanks

-- 
lg

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

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

* Re: user-ptr as image :data
  2019-03-15 19:14 user-ptr as image :data Evgeny Zajcev
@ 2019-03-15 19:41 ` Stefan Monnier
  0 siblings, 0 replies; 3+ messages in thread
From: Stefan Monnier @ 2019-03-15 19:41 UTC (permalink / raw)
  To: emacs-devel

> 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




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

* Re: user-ptr as image :data
@ 2019-03-15 20:28 Evgeny Zajcev
  0 siblings, 0 replies; 3+ messages in thread
From: Evgeny Zajcev @ 2019-03-15 20:28 UTC (permalink / raw)
  To: monnier; +Cc: emacs-devel

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

> 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?
will do

> 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).

This works! very slow, but it works, I'll use this hack for now

thanks

-- 
lg

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

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

end of thread, other threads:[~2019-03-15 20:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-15 19:14 user-ptr as image :data Evgeny Zajcev
2019-03-15 19:41 ` Stefan Monnier
  -- strict thread matches above, loose matches on Subject: below --
2019-03-15 20:28 Evgeny Zajcev

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).