unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
Cc: emacs-devel@gnu.org
Subject: Re: x-display-pixel-width/height inconsistency
Date: Fri, 10 May 2013 10:06:18 +0300	[thread overview]
Message-ID: <837gj7co0l.fsf@gnu.org> (raw)
In-Reply-To: <wlfvxvidby.wl%mituharu@math.s.chiba-u.ac.jp>

> Date: Fri, 10 May 2013 15:00:33 +0900
> From: YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
> Cc: emacs-devel@gnu.org
> 
> > It makes me nervous to have consing inside a Win32 API callback.  Are
> > we even sure the callback gets called in the context of our main
> > tread?  If not, and if consing causes GC, we could blow up the stack.
> 
> If the callback can be called from the thread/context other than the
> one for EnumDisplayMonitors and that can cause memory synchronization
> issue, then API documentation should clearly say so, because such kind
> of problem can happen even with other data structures.

Well, we can sue MS, but that won't help us, I think.

Seriously: while debugging Emacs on Windows, I frequently see messages
from GDB about new threads being launched, which I know for sure Emacs
didn't do directly.  I have no idea why they are started.  For
example, calling GetOpenFileName certainly starts a new thread, but
the MSDN documentation says nothing about that.  (We've had problems
with the stack size of that thread, see bug #13065.)  We define a
callback for that API, and I suspect that callback is run in the
context of that additional thread.  I don't know if the API you are
using is different in this regard, but I prefer not to risk that, if
we can avoid that risk.

> And it is not Fcons but Feval that can cause GC.

Thank you for your lecture.

> > And actually, I don't see why you need the list of monitor HMONITOR
> > handles, you get them from MonitorFromWindow anyway.  All you need is
> > the count of the monitors, and then you can create the vector in
> > monitor_frames by simply inserting every monitor you get from
> > MonitorFromWindow, and leave the rest at nil.  Or am I missing
> > something?
> 
> > So could we please get rid of the consing inside the callback, and
> > just count them instead?
> 
> The display-monitor-function lists all the monitors regardless of the
> existence of Emacs frames in it.

I know that, but you end up with just nil in the list of frames for
those monitors that don't have frames, right?  So just use the
callback to count the monitors; then you don't need to cons a list
inside the callback, you only need to increment a counter.  The cells
for the monitors that don't have frames just need to be filled with
nil.

> >> +       if (FRAME_W32_P (f) && FRAME_W32_DISPLAY_INFO (f) == dpyinfo
> >> + 	  && !EQ (frame, tip_frame))
> 
> > The test against dpyinfo is redundant, it will always be true: there's
> > only one dpyinfo on Windows.  I would like to remove it, because it's
> > confusing.  (There's one more such test in another place in the
> > patch.)
> 
> I'm aware of that.  It's just for resemblance to X11 code.  I'd rather
> leave it to make it easier to compare with the code for X11 if it were
> for the Mac port, but I don't have a strong opinion for W32.

The w32 display doesn't support multiple display terminals, and
probably never will.  Even if it does some day support that, I doubt
that the infrastructure for that will be similar to X.

So please remove that.

> >> +       name = make_unibyte_string (mi.szDevice, strlen (mi.szDevice));
> 
> > Why make_unibyte_string?  Is szDevice documented to be an ASCII-only
> > string?
> 
> make_unibyte_string does not assume that the passed bytes are only of
> ASCII characters.

Any other string will get users in trouble, because this will produce
a unibyte string, something Lisp programs generally don't expect to
get when the string is supposed to be human-readable text.

> Of course, you can decode the string if its encoding is known (I'm not
> sure how it is encoded because I'm not familiar with W32).

You want DECODE_SYSTEM.  It knows about the encoding of strings in the
current session.

> But you should be careful because code conversions can involve GC in
> general unlike Fcons.

Then use GCPRO (although I don't think it's needed in this case).
It's not a big deal.

> Alternatively, as the `name' attribute is optional, you can remove
> it entirely if you don't like make_unibyte_string.

I see no reason to remove it due to such a minor and easily solvable
issue.

Thanks.



  parent reply	other threads:[~2013-05-10  7:06 UTC|newest]

Thread overview: 97+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-21  0:58 x-display-pixel-width/height inconsistency grischka
2013-03-21  1:05 ` YAMAMOTO Mitsuharu
2013-03-21  1:09   ` grischka
2013-03-21  1:44     ` YAMAMOTO Mitsuharu
2013-03-21 23:29       ` YAMAMOTO Mitsuharu
2013-03-22 10:33         ` Eli Zaretskii
2013-03-23  0:32           ` YAMAMOTO Mitsuharu
2013-03-23  6:15             ` Eli Zaretskii
2013-03-23 13:35               ` Jan Djärv
2013-03-23 23:58               ` YAMAMOTO Mitsuharu
2013-03-24  3:53                 ` Eli Zaretskii
2013-03-24  4:36                   ` YAMAMOTO Mitsuharu
2013-03-24 16:19                     ` Eli Zaretskii
2013-04-27  5:13                     ` YAMAMOTO Mitsuharu
2013-04-27  8:04                       ` Jan Djärv
2013-04-28  1:40                         ` YAMAMOTO Mitsuharu
2013-04-28 17:16                           ` Jan D.
2013-04-29  2:27                             ` YAMAMOTO Mitsuharu
2013-04-29  2:42                               ` YAMAMOTO Mitsuharu
2013-05-01  9:58                               ` Jan Djärv
2013-05-02  4:09                                 ` YAMAMOTO Mitsuharu
2013-05-06  1:04                                   ` YAMAMOTO Mitsuharu
2013-05-06  1:55                                     ` Stefan Monnier
2013-05-06  6:15                                       ` YAMAMOTO Mitsuharu
2013-05-06 13:37                                         ` Stefan Monnier
2013-05-08 10:46                                         ` YAMAMOTO Mitsuharu
2013-05-08 11:24                                           ` YAMAMOTO Mitsuharu
2013-05-08 17:41                                           ` Eli Zaretskii
2013-05-09  0:09                                             ` YAMAMOTO Mitsuharu
2013-05-09  1:52                                               ` Glenn Morris
2013-05-09  3:19                                                 ` YAMAMOTO Mitsuharu
2013-05-09  6:27                                                   ` Glenn Morris
2013-05-09  2:53                                               ` Eli Zaretskii
2013-05-09  8:14                                               ` Jan Djärv
2013-05-09  8:43                                                 ` YAMAMOTO Mitsuharu
2013-05-09 15:18                                                   ` Jan Djärv
2013-05-09 20:03                                               ` Eli Zaretskii
2013-05-09 21:28                                                 ` Stefan Monnier
2013-05-10  6:00                                                 ` YAMAMOTO Mitsuharu
2013-05-10  6:05                                                   ` YAMAMOTO Mitsuharu
2013-05-10  7:06                                                   ` Eli Zaretskii [this message]
2013-05-10  7:47                                                     ` YAMAMOTO Mitsuharu
2013-05-10  8:41                                                       ` Eli Zaretskii
2013-05-10  8:55                                                         ` YAMAMOTO Mitsuharu
2013-05-10  9:15                                                           ` Eli Zaretskii
2013-05-10  9:27                                                             ` YAMAMOTO Mitsuharu
2013-05-14 10:39                                                               ` YAMAMOTO Mitsuharu
2013-07-01  6:49                                                                 ` martin rudalics
2013-07-02  1:30                                                                   ` YAMAMOTO Mitsuharu
2013-07-02 10:38                                                                     ` martin rudalics
2013-07-02 10:53                                                                       ` Juanma Barranquero
2013-07-02 13:11                                                                         ` martin rudalics
2013-07-02 14:05                                                                           ` Juanma Barranquero
2013-07-03  9:27                                                                             ` martin rudalics
2013-07-03 10:49                                                                               ` Juanma Barranquero
2013-07-03 12:44                                                                                 ` martin rudalics
2013-07-03 13:43                                                                                   ` Juanma Barranquero
2013-07-04  9:34                                                                                     ` martin rudalics
     [not found]                                                                                       ` <5987E3>
2013-07-04 22:32                                                                                       ` Juanma Barranquero
2013-07-05  7:44                                                                                         ` martin rudalics
2013-07-05  9:32                                                                                           ` Juanma Barranquero
2013-07-05  9:34                                                                                         ` Jan Djärv
2013-07-05  9:41                                                                                           ` Juanma Barranquero
2013-07-05 11:25                                                                                             ` Jan Djärv
2013-07-05 11:56                                                                                               ` Juanma Barranquero
2013-07-05 12:12                                                                                                 ` Jan Djärv
2013-07-05 12:16                                                                                                   ` Juanma Barranquero
2013-07-05 15:30                                                                                                     ` Drew Adams
2013-07-05 15:53                                                                                                       ` Juanma Barranquero
2013-07-05 16:58                                                                                                         ` Drew Adams
2013-07-06 14:48                                                                                                           ` Juanma Barranquero
2013-07-06 19:25                                                                                                             ` Drew Adams
2013-07-05 15:27                                                                                                   ` Drew Adams
2013-07-04 10:28                                                                                     ` YAMAMOTO Mitsuharu
2013-05-10  7:44                                                   ` Jan Djärv
2013-04-28  1:48                       ` YAMAMOTO Mitsuharu
  -- strict thread matches above, loose matches on Subject: below --
2013-03-19  0:39 YAMAMOTO Mitsuharu
2013-03-19  1:34 ` Leo Liu
2013-03-19  4:54   ` Xue Fuqiao
2013-03-19 15:41     ` Drew Adams
2013-03-19 15:51       ` Leo Liu
2013-03-19 15:58         ` Drew Adams
2013-03-20  0:55           ` Leo Liu
2013-03-19 22:25 ` YAMAMOTO Mitsuharu
2013-03-19 23:15   ` Dmitry Gutov
2013-03-19 23:52     ` YAMAMOTO Mitsuharu
2013-03-20  0:12       ` Dmitry Gutov
2013-03-20  0:20         ` YAMAMOTO Mitsuharu
2013-03-20  1:41           ` Dmitry Gutov
2013-03-20  3:58             ` YAMAMOTO Mitsuharu
2013-03-20 14:05               ` Dmitry Gutov
2013-03-20 23:28                 ` YAMAMOTO Mitsuharu
2013-03-21  1:27                   ` Dmitry Gutov
2013-03-21  1:51                     ` YAMAMOTO Mitsuharu
2013-03-21  2:43                       ` Dmitry Gutov
2013-03-21  3:47                         ` YAMAMOTO Mitsuharu
2013-03-21  4:22                           ` YAMAMOTO Mitsuharu

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=837gj7co0l.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=mituharu@math.s.chiba-u.ac.jp \
    /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 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).