summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Huddleston Sequoia <jeremyhu@apple.com>2021-02-17 23:58:53 -0800
committerJeremy Huddleston Sequoia <jeremyhu@apple.com>2021-02-18 22:32:14 -0800
commit94e4e173486c2a94ddcfd2d0515e1ee6731f6656 (patch)
treed6debc69f69b22b5992e21ab9cf653af860e0d04
parentfba421f700498fa382089df47942df36a2d75ce6 (diff)
xquartz: Use objc_autoreleasePoolPush / objc_autoreleasePoolPop directly in QuartzBlockHandler
It violates @autoreleasepool best practices, and this helps collapse quartzCocoa.m into quartz.c Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
-rw-r--r--hw/xquartz/Makefile.am1
-rw-r--r--hw/xquartz/quartz.c33
-rw-r--r--hw/xquartz/quartzCocoa.m66
-rw-r--r--hw/xquartz/quartzCommon.h6
4 files changed, 33 insertions, 73 deletions
diff --git a/hw/xquartz/Makefile.am b/hw/xquartz/Makefile.am
index 85355a8ac..c238fe909 100644
--- a/hw/xquartz/Makefile.am
+++ b/hw/xquartz/Makefile.am
@@ -30,7 +30,6 @@ libXquartz_la_SOURCES = \
darwinXinput.c \
keysym2ucs.c \
quartz.c \
- quartzCocoa.m \
quartzKeyboard.c \
quartzStartup.c \
quartzRandR.c
diff --git a/hw/xquartz/quartz.c b/hw/xquartz/quartz.c
index 8a3c5a2d3..477a85f96 100644
--- a/hw/xquartz/quartz.c
+++ b/hw/xquartz/quartz.c
@@ -72,6 +72,15 @@
#include <rootlessCommon.h>
#include <Xplugin.h>
+// These are vended by the Objective-C runtime, but they are unfortunately
+// not available as API in the macOS SDK. We are following suit with swift
+// and clang in declaring them inline here. They canot be removed or changed
+// in the OS without major bincompat ramifications.
+//
+// These were added in macOS 10.7.
+void * _Nonnull objc_autoreleasePoolPush(void);
+void objc_autoreleasePoolPop(void * _Nonnull context);
+
DevPrivateKeyRec quartzScreenKeyRec;
int aquaMenuBarHeight = 0;
QuartzModeProcsPtr quartzProcs = NULL;
@@ -144,6 +153,30 @@ QuartzSetupScreen(int index,
}
/*
+ * QuartzBlockHandler
+ * Clean out any autoreleased objects.
+ */
+static void
+QuartzBlockHandler(void *blockData, void *pTimeout)
+{
+ static void *poolToken = NULL;
+
+ if (poolToken) {
+ objc_autoreleasePoolPop(poolToken);
+ }
+ poolToken = objc_autoreleasePoolPush();
+}
+
+/*
+ * QuartzWakeupHandler
+ */
+static void
+QuartzWakeupHandler(void *blockData, int result)
+{
+ /* nothing here */
+}
+
+/*
* QuartzInitOutput
* Quartz display initialization.
*/
diff --git a/hw/xquartz/quartzCocoa.m b/hw/xquartz/quartzCocoa.m
deleted file mode 100644
index ac6f67e2b..000000000
--- a/hw/xquartz/quartzCocoa.m
+++ /dev/null
@@ -1,66 +0,0 @@
-/**************************************************************
- *
- * Quartz-specific support for the Darwin X Server
- * that requires Cocoa and Objective-C.
- *
- * This file is separate from the parts of Quartz support
- * that use X include files to avoid symbol collisions.
- *
- * Copyright (c) 2001-2004 Torrey T. Lyons and Greg Parker.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Except as contained in this notice, the name(s) of the above copyright
- * holders shall not be used in advertising or otherwise to promote the sale,
- * use or other dealings in this Software without prior written authorization.
- */
-
-#include "sanitizedCocoa.h"
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include "quartzCommon.h"
-#include "inputstr.h"
-
-#include "darwin.h"
-
-/*
- * QuartzBlockHandler
- * Clean out any autoreleased objects.
- */
-void
-QuartzBlockHandler(void *blockData, void *pTimeout)
-{
- static NSAutoreleasePool *aPool = nil;
-
- [aPool release];
- aPool = [[NSAutoreleasePool alloc] init];
-}
-
-/*
- * QuartzWakeupHandler
- */
-void
-QuartzWakeupHandler(void *blockData, int result)
-{
- // nothing here
-}
diff --git a/hw/xquartz/quartzCommon.h b/hw/xquartz/quartzCommon.h
index 721886b87..13fbe55d8 100644
--- a/hw/xquartz/quartzCommon.h
+++ b/hw/xquartz/quartzCommon.h
@@ -46,10 +46,4 @@ extern int aquaMenuBarHeight;
// Name of GLX bundle for native OpenGL
extern const char *quartzOpenGLBundle;
-void
-QuartzBlockHandler(void *blockData, void *pTimeout);
-
-void
-QuartzWakeupHandler(void *blockData, int result);
-
#endif /* _QUARTZCOMMON_H */