summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Djärv <jan.h.d@swipnet.se>2011-11-05 13:25:01 +0100
committerJan Djärv <jan.h.d@swipnet.se>2011-11-05 13:25:01 +0100
commita97f8f3f16c6370acb0076011588822e572fa589 (patch)
treef5c322496afd1a62b4f8b37090f35bf403b3dac6
parentc9e7db78eff4bd8cf9e6abe3d33eb83c7d6cbf00 (diff)
downloademacs-a97f8f3f16c6370acb0076011588822e572fa589.tar.gz
* nsfns.m: Declare image_cache_refcount if GLYPH_DEBUG.
(unwind_create_frame): New function. (Fx_create_frame): Restructure code to be more similar to the one in xfns.c. Call record_unwind_protect with unwind_create_frame (Bug#9943). Initialize image_cache_refcount if GLYPH_DEBUG (Bug#9943). Move terminal->reference_count++ just before making the frame official (Bug#9943). * nsterm.m (x_free_frame_resources): New function. (x_destroy_window): Move code to x_free_frame_resources.
-rw-r--r--src/ChangeLog11
-rw-r--r--src/nsfns.m208
-rw-r--r--src/nsterm.m21
3 files changed, 140 insertions, 100 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 2bad4e388d0..c66692ca7c7 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,16 @@
2011-11-05 Jan Djärv <jan.h.d@swipnet.se>
+ * nsfns.m: Declare image_cache_refcount if GLYPH_DEBUG.
+ (unwind_create_frame): New function (Bug#9943).
+ (Fx_create_frame): Restructure code to be more similar to the one in
+ xfns.c. Call record_unwind_protect with unwind_create_frame (Bug#9943).
+ Initialize image_cache_refcount if GLYPH_DEBUG (Bug#9943).
+ Move terminal->reference_count++ just before making the frame official
+ (Bug#9943).
+
+ * nsterm.m (x_free_frame_resources): New function.
+ (x_destroy_window): Move code to x_free_frame_resources.
+
* xfns.c (unwind_create_frame): Fix comment.
(Fx_create_frame, x_create_tip_frame): Move
terminal->reference_count++ just before making the frame
diff --git a/src/nsfns.m b/src/nsfns.m
index a09011d8461..23362433a39 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -101,6 +101,10 @@ extern BOOL ns_in_resize;
static Lisp_Object as_script, *as_result;
static int as_status;
+#if GLYPH_DEBUG
+static ptrdiff_t image_cache_refcount;
+#endif
+
/* ==========================================================================
Internal utility functions
@@ -1038,6 +1042,41 @@ frame_parm_handler ns_frame_parm_handlers[] =
};
+/* Handler for signals raised during x_create_frame.
+ FRAME is the frame which is partially constructed. */
+
+static Lisp_Object
+unwind_create_frame (Lisp_Object frame)
+{
+ struct frame *f = XFRAME (frame);
+
+ /* If frame is already dead, nothing to do. This can happen if the
+ display is disconnected after the frame has become official, but
+ before x_create_frame removes the unwind protect. */
+ if (!FRAME_LIVE_P (f))
+ return Qnil;
+
+ /* If frame is ``official'', nothing to do. */
+ if (!CONSP (Vframe_list) || !EQ (XCAR (Vframe_list), frame))
+ {
+#if GLYPH_DEBUG && XASSERTS
+ struct ns_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
+#endif
+
+ x_free_frame_resources (f);
+ free_glyphs (f);
+
+#if GLYPH_DEBUG
+ /* Check that reference counts are indeed correct. */
+ xassert (dpyinfo->terminal->image_cache->refcount == image_cache_refcount);
+#endif
+ return Qt;
+ }
+
+ return Qnil;
+}
+
+
/* ==========================================================================
@@ -1047,46 +1086,50 @@ frame_parm_handler ns_frame_parm_handlers[] =
DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
1, 1, 0,
- doc: /* Make a new Nextstep window, called a \"frame\" in Emacs terms.
+ doc: /* Make a new Nextstep window, called a "frame" in Emacs terms.
Return an Emacs frame object.
PARMS is an alist of frame parameters.
If the parameters specify that the frame should not have a minibuffer,
and do not specify a specific minibuffer window to use,
then `default-minibuffer-frame' must be a frame whose minibuffer can
-be shared by the new frame. */)
+be shared by the new frame.
+
+This function is an internal primitive--use `make-frame' instead. */)
(Lisp_Object parms)
{
- static int desc_ctr = 1;
struct frame *f;
- struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
Lisp_Object frame, tem;
Lisp_Object name;
int minibuffer_only = 0;
+ int window_prompting = 0;
+ int width, height;
int count = specpdl_ptr - specpdl;
+ struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
Lisp_Object display;
struct ns_display_info *dpyinfo = NULL;
Lisp_Object parent;
struct kboard *kb;
Lisp_Object tfont, tfontsize;
- int window_prompting = 0;
- int width, height;
+ static int desc_ctr = 1;
check_ns ();
- /* Seems a little strange, but other terms do it. Perhaps the code below
- is modifying something? */
+ /* x_get_arg modifies parms. */
parms = Fcopy_alist (parms);
+ /* Use this general default value to start with
+ until we know if this frame has a specified name. */
+ Vx_resource_name = Vinvocation_name;
+
display = x_get_arg (dpyinfo, parms, Qterminal, 0, 0, RES_TYPE_STRING);
if (EQ (display, Qunbound))
display = Qnil;
dpyinfo = check_ns_display_info (display);
+ kb = dpyinfo->terminal->kboard;
if (!dpyinfo->terminal->name)
error ("Terminal is not live, can't create new frames on it");
- kb = dpyinfo->terminal->kboard;
-
name = x_get_arg (dpyinfo, parms, Qname, 0, 0, RES_TYPE_STRING);
if (!STRINGP (name)
&& ! EQ (name, Qunbound)
@@ -1095,8 +1138,6 @@ be shared by the new frame. */)
if (STRINGP (name))
Vx_resource_name = name;
- else
- Vx_resource_name = Vinvocation_name;
parent = x_get_arg (dpyinfo, parms, Qparent_id, 0, 0, RES_TYPE_NUMBER);
if (EQ (parent, Qunbound))
@@ -1104,57 +1145,36 @@ be shared by the new frame. */)
if (! NILP (parent))
CHECK_NUMBER (parent);
+ /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
+ /* No need to protect DISPLAY because that's not used after passing
+ it to make_frame_without_minibuffer. */
frame = Qnil;
GCPRO4 (parms, parent, name, frame);
-
tem = x_get_arg (dpyinfo, parms, Qminibuffer, "minibuffer", "Minibuffer",
RES_TYPE_SYMBOL);
if (EQ (tem, Qnone) || NILP (tem))
- {
f = make_frame_without_minibuffer (Qnil, kb, display);
- }
else if (EQ (tem, Qonly))
{
f = make_minibuffer_frame ();
minibuffer_only = 1;
}
else if (WINDOWP (tem))
- {
f = make_frame_without_minibuffer (tem, kb, display);
- }
else
- {
f = make_frame (1);
- }
-
- /* Set the name; the functions to which we pass f expect the name to
- be set. */
- if (EQ (name, Qunbound) || NILP (name) || (XTYPE (name) != Lisp_String))
- {
- f->name = build_string ([ns_app_name UTF8String]);
- f->explicit_name =0;
- }
- else
- {
- f->name = name;
- f->explicit_name = 1;
- specbind (Qx_resource_name, name);
- }
XSETFRAME (frame, f);
FRAME_CAN_HAVE_SCROLL_BARS (f) = 1;
f->terminal = dpyinfo->terminal;
- f->terminal->reference_count++;
f->output_method = output_ns;
f->output_data.ns = (struct ns_output *)xmalloc (sizeof *(f->output_data.ns));
- memset (f->output_data.ns, 0, sizeof (*(f->output_data.ns)));
+ memset (f->output_data.ns, 0, sizeof *(f->output_data.ns));
FRAME_FONTSET (f) = -1;
- /* record_unwind_protect (unwind_create_frame, frame); safety; maybe later? */
-
f->icon_name = x_get_arg (dpyinfo, parms, Qicon_name, "iconName", "Title",
RES_TYPE_STRING);
if (! STRINGP (f->icon_name))
@@ -1162,6 +1182,9 @@ be shared by the new frame. */)
FRAME_NS_DISPLAY_INFO (f) = dpyinfo;
+ /* With FRAME_NS_DISPLAY_INFO set up, this unwind-protect is safe. */
+ record_unwind_protect (unwind_create_frame, frame);
+
f->output_data.ns->window_desc = desc_ctr++;
if (!NILP (parent))
{
@@ -1174,6 +1197,20 @@ be shared by the new frame. */)
f->output_data.ns->explicit_parent = 0;
}
+ /* Set the name; the functions to which we pass f expect the name to
+ be set. */
+ if (EQ (name, Qunbound) || NILP (name) || ! STRINGP (name))
+ {
+ f->name = build_string ([ns_app_name UTF8String]);
+ f->explicit_name = 0;
+ }
+ else
+ {
+ f->name = name;
+ f->explicit_name = 1;
+ specbind (Qx_resource_name, name);
+ }
+
f->resx = dpyinfo->resx;
f->resy = dpyinfo->resy;
@@ -1223,11 +1260,15 @@ be shared by the new frame. */)
"leftFringe", "LeftFringe", RES_TYPE_NUMBER);
x_default_parameter (f, parms, Qright_fringe, Qnil,
"rightFringe", "RightFringe", RES_TYPE_NUMBER);
- /* end PENDING */
- init_frame_faces (f);
+#if GLYPH_DEBUG
+ image_cache_refcount =
+ FRAME_IMAGE_CACHE (f) ? FRAME_IMAGE_CACHE (f)->refcount : 0;
+#endif
- /* The X resources controlling the menu-bar and tool-bar are
+ init_frame_faces (f);
+
+ /* The resources controlling the menu-bar and tool-bar are
processed specially at startup, and reflected in the mode
variables; ignore them here. */
x_default_parameter (f, parms, Qmenu_bar_lines,
@@ -1244,38 +1285,6 @@ be shared by the new frame. */)
x_default_parameter (f, parms, Qtitle, Qnil, "title", "Title",
RES_TYPE_STRING);
-/* TODO: other terms seem to get away w/o this complexity.. */
- if (NILP (Fassq (Qwidth, parms)))
- {
- Lisp_Object value
- = x_get_arg (dpyinfo, parms, Qwidth, "width", "Width",
- RES_TYPE_NUMBER);
- if (! EQ (value, Qunbound))
- parms = Fcons (Fcons (Qwidth, value), parms);
- }
- if (NILP (Fassq (Qheight, parms)))
- {
- Lisp_Object value
- = x_get_arg (dpyinfo, parms, Qheight, "height", "Height",
- RES_TYPE_NUMBER);
- if (! EQ (value, Qunbound))
- parms = Fcons (Fcons (Qheight, value), parms);
- }
- if (NILP (Fassq (Qleft, parms)))
- {
- Lisp_Object value
- = x_get_arg (dpyinfo, parms, Qleft, "left", "Left", RES_TYPE_NUMBER);
- if (! EQ (value, Qunbound))
- parms = Fcons (Fcons (Qleft, value), parms);
- }
- if (NILP (Fassq (Qtop, parms)))
- {
- Lisp_Object value
- = x_get_arg (dpyinfo, parms, Qtop, "top", "Top", RES_TYPE_NUMBER);
- if (! EQ (value, Qunbound))
- parms = Fcons (Fcons (Qtop, value), parms);
- }
-
window_prompting = x_figure_window_size (f, parms, 1);
tem = x_get_arg (dpyinfo, parms, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN);
@@ -1297,23 +1306,27 @@ be shared by the new frame. */)
x_icon (f, parms);
+ /* ns_display_info does not have a reference_count. */
+ f->terminal->reference_count++;
+
/* It is now ok to make the frame official even if we get an error below.
The frame needs to be on Vframe_list or making it visible won't work. */
Vframe_list = Fcons (frame, Vframe_list);
- /*FRAME_NS_DISPLAY_INFO (f)->reference_count++; */
-
- x_default_parameter (f, parms, Qicon_type, Qnil, "bitmapIcon", "BitmapIcon",
- RES_TYPE_SYMBOL);
- x_default_parameter (f, parms, Qauto_raise, Qnil, "autoRaise", "AutoRaiseLower",
- RES_TYPE_BOOLEAN);
- x_default_parameter (f, parms, Qauto_lower, Qnil, "autoLower", "AutoLower",
- RES_TYPE_BOOLEAN);
- x_default_parameter (f, parms, Qcursor_type, Qbox, "cursorType", "CursorType",
- RES_TYPE_SYMBOL);
- x_default_parameter (f, parms, Qscroll_bar_width, Qnil, "scrollBarWidth",
- "ScrollBarWidth", RES_TYPE_NUMBER);
- x_default_parameter (f, parms, Qalpha, Qnil, "alpha", "Alpha",
- RES_TYPE_NUMBER);
+
+ x_default_parameter (f, parms, Qicon_type, Qnil,
+ "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL);
+
+ x_default_parameter (f, parms, Qauto_raise, Qnil,
+ "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN);
+ x_default_parameter (f, parms, Qauto_lower, Qnil,
+ "autoLower", "AutoLower", RES_TYPE_BOOLEAN);
+ x_default_parameter (f, parms, Qcursor_type, Qbox,
+ "cursorType", "CursorType", RES_TYPE_SYMBOL);
+ x_default_parameter (f, parms, Qscroll_bar_width, Qnil,
+ "scrollBarWidth", "ScrollBarWidth",
+ RES_TYPE_NUMBER);
+ x_default_parameter (f, parms, Qalpha, Qnil,
+ "alpha", "Alpha", RES_TYPE_NUMBER);
width = FRAME_COLS (f);
height = FRAME_LINES (f);
@@ -1324,20 +1337,24 @@ be shared by the new frame. */)
if (! f->output_data.ns->explicit_parent)
{
- tem = x_get_arg (dpyinfo, parms, Qvisibility, 0, 0, RES_TYPE_SYMBOL);
- if (EQ (tem, Qunbound))
- tem = Qt;
- x_set_visibility (f, tem, Qnil);
- if (EQ (tem, Qicon))
+ Lisp_Object visibility;
+
+ visibility = x_get_arg (dpyinfo, parms, Qvisibility, 0, 0,
+ RES_TYPE_SYMBOL);
+ if (EQ (visibility, Qunbound))
+ visibility = Qt;
+
+ if (EQ (visibility, Qicon))
x_iconify_frame (f);
- else if (! NILP (tem))
+ else if (! NILP (visibility))
{
x_make_frame_visible (f);
- f->async_visible = 1;
[[FRAME_NS_VIEW (f) window] makeKeyWindow];
}
else
- f->async_visible = 0;
+ {
+ /* Must have been Qnil. */
+ }
}
if (FRAME_HAS_MINIBUF_P (f)
@@ -1352,6 +1369,9 @@ be shared by the new frame. */)
f->param_alist = Fcons (XCAR (tem), f->param_alist);
UNGCPRO;
+
+ /* Make sure windows on this frame appear in calls to next-window
+ and similar functions. */
Vwindow_list = Qnil;
return unbind_to (count, frame);
diff --git a/src/nsterm.m b/src/nsterm.m
index a2ae5e69512..3d3723fc28c 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -164,7 +164,7 @@ static Lisp_Object last_mouse_motion_frame;
static EmacsScroller *last_mouse_scroll_bar = nil;
static struct frame *ns_updating_frame;
static NSView *focus_view = NULL;
-static int ns_window_num =0;
+static int ns_window_num = 0;
static NSRect uRect;
static BOOL gsaved = NO;
BOOL ns_in_resize = NO;
@@ -1123,12 +1123,10 @@ x_iconify_frame (struct frame *f)
[[view window] miniaturize: NSApp];
}
+/* Free X resources of frame F. */
void
-x_destroy_window (struct frame *f)
-/* --------------------------------------------------------------------------
- External: Delete the window
- -------------------------------------------------------------------------- */
+x_free_frame_resources (struct frame *f)
{
NSView *view = FRAME_NS_VIEW (f);
struct ns_display_info *dpyinfo = FRAME_NS_DISPLAY_INFO (f);
@@ -1163,10 +1161,21 @@ x_destroy_window (struct frame *f)
[[view window] close];
[view release];
- ns_window_num--;
UNBLOCK_INPUT;
}
+void
+x_destroy_window (struct frame *f)
+/* --------------------------------------------------------------------------
+ External: Delete the window
+ -------------------------------------------------------------------------- */
+{
+ NSTRACE (x_destroy_window);
+ check_ns ();
+ x_free_frame_resources (f);
+ ns_window_num--;
+}
+
void
x_set_offset (struct frame *f, int xoff, int yoff, int change_grav)