all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Daniel Colascione <dancol@dancol.org>
Cc: emacs-devel@gnu.org
Subject: Re: [PATCH 3/9] Implement cygw32
Date: Tue, 07 Aug 2012 21:02:00 +0300	[thread overview]
Message-ID: <83obmmfunb.fsf@gnu.org> (raw)
In-Reply-To: <fa5019b3a90b6cbe2cd431af3ff0e57c3331e796.1344326992.git.dancol@dancol.org>

> Date: Tue, 07 Aug 2012 01:19:27 -0700
> From: Daniel Colascione <dancol@dancol.org>
> 
> +(defun w32-using-nt ()
> +  "Return non-nil if running on a Windows NT descendant.
> +That includes all Windows systems except for 9X/Me."
> +  (getenv "SystemRoot"))

I don't like to rely on environment variables for system-type
detection.  It's all to easy to remove or add environment variables.
If there's no better way that is already there, I'd prefer a new
primitive that is based on os_subtype variable in C, or something
similar.

(Yes, I know the current code uses getenv as well, but we might as
well fix it while at that.)

> --- a/lisp/w32-fns.el
> +++ b/lisp/w32-fns.el
> @@ -26,34 +26,20 @@
>  
>  ;;; Code:
>  (require 'w32-vars)
> +(require 'w32-common-fns)

Why do we need this require?  loadup.el loads w32-common-fns before
w32-fns, so it's already loaded here.  If you need this for
compilation, won't eval-when-compile be better?

> +wchar_t*
> +to_unicode (Lisp_Object str, Lisp_Object* buf)

A minor style issue: please leave a blank between '*' and the
preceding token.

> +  *buf = code_convert_string_norecord (str, Qutf_16_le, 1);
> +  /* We need to make a another copy (in addition to the one made by
> +     code_convert_string_norecord) to ensure that the final string is
> +     _doubly_ zero terminated --- that is, that the string is
> +     terminated by two zero bytes and one utf-16le null character.
> +     Because strings are already terminated with a single zero byte,
> +     we just add one additional zero. */
> +  str = make_uninit_string (SBYTES (*buf) + 1);
> +  memcpy (SDATA (str), SDATA (*buf), SBYTES (*buf));
> +  SDATA (str) [SBYTES (*buf)] = '\0';
> +  *buf = str;

Can't you append a zero byte to the original str, before encoding it
with code_convert_string_norecord?  Copying it after encoding looks
inelegant.

> +DEFUN ("cygwin-convert-path-to-windows",
> +       Fcygwin_convert_path_to_windows, Scygwin_convert_path_to_windows,
> +       1, 2, 0,
> +       doc: /* Convert PATH to a Windows path.  If ABSOLUTE-P if
> +               non-nil, return an absolute path.*/)
> +  (Lisp_Object path, Lisp_Object absolute_p)
> +{
> +  return from_unicode (
> +    conv_filename_to_w32_unicode (path, absolute_p == Qnil ? 0 : 1));
> +}

This function is only used from C.  Do we really need its Lisp
binding?

> +DEFUN ("cygwin-convert-path-from-windows",
> +       Fcygwin_convert_path_from_windows, Scygwin_convert_path_from_windows,
> +       1, 2, 0,
> +       doc: /* Convert a Windows path to a Cygwin path.  If ABSOLUTE-P
> +               if non-nil, return an absolute path.*/)
> +  (Lisp_Object path, Lisp_Object absolute_p)
> +{
> +  return conv_filename_from_w32_unicode (to_unicode (path, &path),
> +                                         absolute_p == Qnil ? 0 : 1);
> +}

I wonder why this couldn't be implemented in Lisp.  Isn't it just
decoding from UTF-16 followed by mirroring the backslashes?  If
there's more to it than that, please reflect that in the doc string.

> +#ifndef CYGW32_H
> +#define CYGW32_H
> +#include <config.h>
> +#include <windef.h>
> +#include <sys/cygwin.h>
> +#include <wchar.h>
> +
> +#include <signal.h>
> +#include <stdio.h>
> +#include <limits.h>
> +#include <errno.h>
> +#include <math.h>
> +#include <setjmp.h>
> +
> +#include "lisp.h"
> +#include "coding.h"

I think it's a bad mojo for a header to include other Emacs headers.
Is it really needed?

> +/* Access the wide-character string stored in a Lisp string object.  */
> +#define WCSDATA(x) ((wchar_t*) SDATA (x))

This is IMO yucky, and I'd like to avoid this if possible.  Can you
explain why it is needed?

> +#if defined(CYGWIN) && defined(HAVE_NTGUI)
> +#define NTGUI_UNICODE /* Cygwin runs only on UNICODE-supporting systems */
> +#define _WIN32_WINNT 0x500 /* Win2k */
> +#endif /* CYGWIN && HAVE_NTGUI */

I'd like to make tests of NTGUI_UNICODE at run time rather than at
compile time.  That's because we are gradually moving Emacs to using
Unicode APIs when available, so making these tests at run time will
allow to share more code between the Cygwin and native Windows builds.

There's already a variable w32_console_unicode_input in w32inevt.c
that is used for a similar purpose, and I believe there will be soon
another for a GUI input.  Can you define a similar variable for menus
or whatever, and either initialize it on some file that is compiled
both in the native and the Cygwin builds, or just unconditionally set
it to non-zero in some Cygwin specific function?  Then test it
whenever you need a Unicode API.

> --- a/src/emacs.c
> +++ b/src/emacs.c
> @@ -37,9 +37,20 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
>  
>  #ifdef WINDOWSNT
>  #include <fcntl.h>
> -#include <windows.h> /* just for w32.h */

It looks like you are deleting the inclusion of windows.h.  Why?

> -#if defined (WINDOWSNT)
> +#if defined (HAVE_NTGUI)
>    LANGUAGE_CHANGE_EVENT,	/* A LANGUAGE_CHANGE_EVENT is
> -				   generated on WINDOWSNT or Mac OS
> +				   generated on HAVE_NTGUI or Mac OS

"On HAVE_NTGUI" does not sound right...

Thanks.



  parent reply	other threads:[~2012-08-07 18:02 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-07  8:19 [PATCH 0/9] Support Win32 GUI in Cygwin Emacs Daniel Colascione
2012-08-07  8:19 ` [PATCH 6/9] Rename `w32' local to `nt' for clarity Daniel Colascione
2012-08-07 10:49   ` Lennart Borgman
2012-08-07 15:45   ` Stefan Monnier
2012-08-07 16:31     ` Eli Zaretskii
2012-08-07 16:40       ` Drew Adams
2012-08-07 17:07         ` Daniel Colascione
2012-08-07 20:00       ` Stefan Monnier
2012-08-08  2:50         ` Eli Zaretskii
2012-08-07  8:19 ` [PATCH 2/9] Refactor window-system configuration Daniel Colascione
2012-08-07 17:20   ` Eli Zaretskii
2012-08-07 17:31     ` Daniel Colascione
2012-08-07 20:47     ` Stefan Monnier
2012-08-07  8:19 ` [PATCH 7/9] Add alt_display to emacsclient for w32, ns Daniel Colascione
2012-08-07 15:22   ` Stefan Monnier
2012-08-07  8:19 ` [PATCH 9/9] Detect window-system from display name Daniel Colascione
2012-08-07 15:50   ` Stefan Monnier
2012-08-07 17:09     ` Daniel Colascione
2012-08-07 20:01       ` Stefan Monnier
2012-08-07 20:19         ` Daniel Colascione
2012-08-07 22:52           ` Lennart Borgman
2012-08-07 22:54             ` Daniel Colascione
2012-08-07 23:02               ` Lennart Borgman
2012-08-07 18:18   ` Eli Zaretskii
2012-08-07 20:28     ` Daniel Colascione
2012-08-08 16:50   ` Eli Zaretskii
2012-08-07  8:19 ` [PATCH 5/9] Prevent crash if w32 used before it's initialized Daniel Colascione
2012-08-07 17:23   ` Eli Zaretskii
2012-08-07 17:28     ` Daniel Colascione
2012-08-07 18:11       ` Eli Zaretskii
2012-08-07  8:19 ` [PATCH 4/9] Fix emacsclient to work with cygw32 Daniel Colascione
2012-08-07 18:14   ` Eli Zaretskii
2012-08-07 20:16     ` Daniel Colascione
2012-08-08  2:55       ` Eli Zaretskii
2012-08-07  8:19 ` [PATCH 8/9] Generalize fork+exec logic, add DAEMON_MUST_EXEC Daniel Colascione
2012-08-07  8:19 ` [PATCH 1/9] Under Remote Desktop, NUMCOLORS is unreliable; workaround Daniel Colascione
2012-08-07 17:07   ` Eli Zaretskii
2012-08-07  8:19 ` [PATCH 3/9] Implement cygw32 Daniel Colascione
2012-08-07 15:40   ` Stefan Monnier
2012-08-07 18:02   ` Eli Zaretskii [this message]
2012-08-07 20:11     ` Daniel Colascione
2012-08-08 17:15       ` Eli Zaretskii
2012-08-07 17:22 ` [PATCH 0/9] Support Win32 GUI in Cygwin Emacs Eli Zaretskii
2012-08-07 17:29   ` Daniel Colascione
2012-08-07 18:10     ` Eli Zaretskii
2012-08-07 19:18       ` Eli Zaretskii
2012-08-07 20:15       ` Daniel Colascione
2012-08-07 20:24         ` Juanma Barranquero
2012-08-08  2:53         ` Eli Zaretskii
2012-08-08  2:33     ` Daniel Colascione
2012-08-08  3:03       ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83obmmfunb.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=dancol@dancol.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.