unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Lisp_String to LPWSTR
@ 2009-10-02 21:59 Eugen Anghel
  2009-10-03  8:35 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Eugen Anghel @ 2009-10-02 21:59 UTC (permalink / raw)
  To: emacs-devel

Hi,

What would be the best way to convert from a Lisp_String* to an UTF-16
encoded string?

I've tried something like
code_convert_string_norecord(mystring, Qutf_16, 0)
but that doesn't seem to do what I want.

I'm trying to work on this (from etc/TODO):
** Switch the Windows port to using Unicode keyboard input (maybe).
and I need to convert strings before passing them to W-variant winapi functions.

Thanks, Eugen




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

* Re: Lisp_String to LPWSTR
  2009-10-02 21:59 Lisp_String to LPWSTR Eugen Anghel
@ 2009-10-03  8:35 ` Eli Zaretskii
  2009-10-03 10:50   ` Eugen Anghel
  0 siblings, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2009-10-03  8:35 UTC (permalink / raw)
  To: Eugen Anghel; +Cc: emacs-devel

> From: Eugen Anghel <eugen@syntactic.org>
> Date: Sat, 3 Oct 2009 00:59:39 +0300
> 
> What would be the best way to convert from a Lisp_String* to an UTF-16
> encoded string?
> 
> I've tried something like
> code_convert_string_norecord(mystring, Qutf_16, 0)
> but that doesn't seem to do what I want.
> 
> I'm trying to work on this (from etc/TODO):
> ** Switch the Windows port to using Unicode keyboard input (maybe).
> and I need to convert strings before passing them to W-variant winapi functions.

Like this (untested):

   code_convert_string_norecord (SDATA (mystring), Qutf_16, 1);

Note the two differences:

  . To get a C string from a Lisp string, use SDATA (btw, why do you
    manipulate Lisp strings here?)

  . Converting a Lisp string into UTF-16 (or any other encoding) is an
    _encode_ operation, so the last argument to
    code_convert_string_norecord should be non-zero




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

* Re: Lisp_String to LPWSTR
  2009-10-03  8:35 ` Eli Zaretskii
@ 2009-10-03 10:50   ` Eugen Anghel
  2009-10-03 11:23     ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Eugen Anghel @ 2009-10-03 10:50 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

2009/10/3 Eli Zaretskii <eliz@gnu.org>:
>> From: Eugen Anghel <eugen@syntactic.org>
>> Date: Sat, 3 Oct 2009 00:59:39 +0300
>>
>> What would be the best way to convert from a Lisp_String* to an UTF-16
>> encoded string?
>>
>> I've tried something like
>> code_convert_string_norecord(mystring, Qutf_16, 0)
>> but that doesn't seem to do what I want.
>>
>> I'm trying to work on this (from etc/TODO):
>> ** Switch the Windows port to using Unicode keyboard input (maybe).
>> and I need to convert strings before passing them to W-variant winapi functions.
>
> Like this (untested):
>
>   code_convert_string_norecord (SDATA (mystring), Qutf_16, 1);
>
> Note the two differences:
>
>  . To get a C string from a Lisp string, use SDATA (btw, why do you
>    manipulate Lisp strings here?)

code_convert_string_norecord is defined as
Lisp_Object code_convert_string_norecord P_ ((Lisp_Object, Lisp_Object, int));
so I don't think the SDATA is needed.

I need this, for example, to set the title of the window that contains
a frame. This is done by calling SetWindowTextW, which needs a LPWSTR
in UCS-2/UTF-16, but the name to be set is received as a Lisp_Object
(Lisp_String?).

The function I'm changing is x_set_name, in w32fns.c.

>
>  . Converting a Lisp string into UTF-16 (or any other encoding) is an
>    _encode_ operation, so the last argument to
>    code_convert_string_norecord should be non-zero

You're right, thanks.
>

The issue was that I was using Qutf_16, which I believe adds a BOM
(and is big endian?). If I use Qutf_16le instead (no BOM,
little-endian) it's working ok.

Are there any issues that I need to worry about if I just call this
function everywhere this conversion is needed? e.g memory-leaks?




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

* Re: Lisp_String to LPWSTR
  2009-10-03 10:50   ` Eugen Anghel
@ 2009-10-03 11:23     ` Eli Zaretskii
  0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2009-10-03 11:23 UTC (permalink / raw)
  To: Eugen Anghel; +Cc: emacs-devel

> From: Eugen Anghel <eugen@syntactic.org>
> Date: Sat, 3 Oct 2009 13:50:52 +0300
> Cc: emacs-devel@gnu.org
> 
> Are there any issues that I need to worry about if I just call this
> function everywhere this conversion is needed? e.g memory-leaks?

Lisp objects are GC'ed automagically.  You may need to GC protect some
of the C strings, though.  See the other uses of
code_convert_string_norecord in the sources, for examples.




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

end of thread, other threads:[~2009-10-03 11:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-02 21:59 Lisp_String to LPWSTR Eugen Anghel
2009-10-03  8:35 ` Eli Zaretskii
2009-10-03 10:50   ` Eugen Anghel
2009-10-03 11:23     ` Eli Zaretskii

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