annotate src/os_macosx.m @ 32936:c517845bd10e v9.0.1776

patch 9.0.1776: No support for stable Python 3 ABI Commit: https://github.com/vim/vim/commit/c13b3d1350b60b94fe87f0761ea31c0e7fb6ebf3 Author: Yee Cheng Chin <ychin.git@gmail.com> Date: Sun Aug 20 21:18:38 2023 +0200 patch 9.0.1776: No support for stable Python 3 ABI Problem: No support for stable Python 3 ABI Solution: Support Python 3 stable ABI Commits: 1) Support Python 3 stable ABI to allow mixed version interoperatbility Vim currently supports embedding Python for use with plugins, and the "dynamic" linking option allows the user to specify a locally installed version of Python by setting `pythonthreedll`. However, one caveat is that the Python 3 libs are not binary compatible across minor versions, and mixing versions can potentially be dangerous (e.g. let's say Vim was linked against the Python 3.10 SDK, but the user sets `pythonthreedll` to a 3.11 lib). Usually, nothing bad happens, but in theory this could lead to crashes, memory corruption, and other unpredictable behaviors. It's also difficult for the user to tell something is wrong because Vim has no way of reporting what Python 3 version Vim was linked with. For Vim installed via a package manager, this usually isn't an issue because all the dependencies would already be figured out. For prebuilt Vim binaries like MacVim (my motivation for working on this), AppImage, and Win32 installer this could potentially be an issue as usually a single binary is distributed. This is more tricky when a new Python version is released, as there's a chicken-and-egg issue with deciding what Python version to build against and hard to keep in sync when a new Python version just drops and we have a mix of users of different Python versions, and a user just blindly upgrading to a new Python could lead to bad interactions with Vim. Python 3 does have a solution for this problem: stable ABI / limited API (see https://docs.python.org/3/c-api/stable.html). The C SDK limits the API to a set of functions that are promised to be stable across versions. This pull request adds an ifdef config that allows us to turn it on when building Vim. Vim binaries built with this option should be safe to freely link with any Python 3 libraies without having the constraint of having to use the same minor version. Note: Python 2 has no such concept and this doesn't change how Python 2 integration works (not that there is going to be a new version of Python 2 that would cause compatibility issues in the future anyway). --- Technical details: ====== The stable ABI can be accessed when we compile with the Python 3 limited API (by defining `Py_LIMITED_API`). The Python 3 code (in `if_python3.c` and `if_py_both.h`) would now handle this and switch to limited API mode. Without it set, Vim will still use the full API as before so this is an opt-in change. The main difference is that `PyType_Object` is now an opaque struct that we can't directly create "static types" out of, and we have to create type objects as "heap types" instead. This is because the struct is not stable and changes from version to version (e.g. 3.8 added a `tp_vectorcall` field to it). I had to change all the types to be allocated on the heap instead with just a pointer to them. Other functions are also simply missing in limited API, or they are introduced too late (e.g. `PyUnicode_AsUTF8AndSize` in 3.10) to it that we need some other ways to do the same thing, so I had to abstract a few things into macros, and sometimes re-implement functions like `PyObject_NEW`. One caveat is that in limited API, `OutputType` (used for replacing `sys.stdout`) no longer inherits from `PyStdPrinter_Type` which I don't think has any real issue other than minor differences in how they convert to a string and missing a couple functions like `mode()` and `fileno()`. Also fixed an existing bug where `tp_basicsize` was set incorrectly for `BufferObject`, `TabListObject, `WinListObject`. Technically, there could be a small performance drop, there is a little more indirection with accessing type objects, and some APIs like `PyUnicode_AsUTF8AndSize` are missing, but in practice I didn't see any difference, and any well-written Python plugin should try to avoid excessing callbacks to the `vim` module in Python anyway. I only tested limited API mode down to Python 3.7, which seemes to compile and work fine. I haven't tried earlier Python versions. 2) Fix PyIter_Check on older Python vers / type##Ptr unused warning For PyIter_Check, older versions exposed them as either macros (used in full API), or a function (for use in limited API). A previous change exposed PyIter_Check to the dynamic build because Python just moved it to function-only in 3.10 anyway. Because of that, just make sure we always grab the function in dynamic builds in earlier versions since that's what Python eventually did anyway. 3) Move Py_LIMITED_API define to configure script Can now use --with-python-stable-abi flag to customize what stable ABI version to target. Can also use an env var to do so as well. 4) Show +python/dyn-stable in :version, and allow has() feature query Not sure if the "/dyn-stable" suffix would break things, or whether we should do it another way. Or just don't show it in version and rely on has() feature checking. 5) Documentation first draft. Still need to implement v:python3_version 6) Fix PyIter_Check build breaks when compiling against Python 3.8 7) Add CI coverage stable ABI on Linux/Windows / make configurable on Windows This adds configurable options for Windows make files (both MinGW and MSVC). CI will also now exercise both traditional full API and stable ABI for Linux and Windows in the matrix for coverage. Also added a "dynamic" option to Linux matrix as a drive-by change to make other scripting languages like Ruby / Perl testable under both static and dynamic builds. 8) Fix inaccuracy in Windows docs Python's own docs are confusing but you don't actually want to use `python3.dll` for the dynamic linkage. 9) Add generated autoconf file 10) Add v:python3_version support This variable indicates the version of Python3 that Vim was built against (PY_VERSION_HEX), and will be useful to check whether the Python library you are loading in dynamically actually fits it. When built with stable ABI, it will be the limited ABI version instead (`Py_LIMITED_API`), which indicates the minimum version of Python 3 the user should have, rather than the exact match. When stable ABI is used, we won't be exposing PY_VERSION_HEX in this var because it just doesn't seem necessary to do so (the whole point of stable ABI is the promise that it will work across versions), and I don't want to confuse the user with too many variables. Also, cleaned up some documentation, and added help tags. 11) Fix Python 3.7 compat issues Fix a couple issues when using limited API < 3.8 - Crash on exit: In Python 3.7, if a heap-allocated type is destroyed before all instances are, it would cause a crash later. This happens when we destroyed `OptionsType` before calling `Py_Finalize` when using the limited API. To make it worse, later versions changed the semantics and now each instance has a strong reference to its own type and the recommendation has changed to have each instance de-ref its own type and have its type in GC traversal. To avoid dealing with these cross-version variations, we just don't free the heap type. They are static types in non-limited-API anyway and are designed to last through the entirety of the app, and we also don't restart the Python runtime and therefore do not need it to have absolutely 0 leaks. See: - https://docs.python.org/3/whatsnew/3.8.html#changes-in-the-c-api - https://docs.python.org/3/whatsnew/3.9.html#changes-in-the-c-api - PyIter_Check: This function is not provided in limited APIs older than 3.8. Previously I was trying to mock it out using manual PyType_GetSlot() but it was brittle and also does not actually work properly for static types (it will generate a Python error). Just return false. It does mean using limited API < 3.8 is not recommended as you lose the functionality to handle iterators, but from playing with plugins I couldn't find it to be an issue. - Fix loading of PyIter_Check so it will be done when limited API < 3.8. Otherwise loading a 3.7 Python lib will fail even if limited API was specified to use it. 12) Make sure to only load `PyUnicode_AsUTF8AndSize` in needed in limited API We don't use this function unless limited API >= 3.10, but we were loading it regardless. Usually it's ok in Unix-like systems where Python just has a single lib that we load from, but in Windows where there is a separate python3.dll this would not work as the symbol would not have been exposed in this more limited DLL file. This makes it much clearer under what condition is this function needed. closes: #12032 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
author Christian Brabandt <cb@256bit.org>
date Sun, 20 Aug 2023 21:30:04 +0200
parents ca4e81de477a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10042
4aead6a9b7a9 commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents: 7860
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 /*
12716
351cf7c67bbe patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
11 * os_macosx.m -- Mac specific things for Mac OS X.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13
13420
f80abb797a32 patch 8.0.1584: using C99 in Mac file gives compiler warning messages
Christian Brabandt <cb@256bit.org>
parents: 12877
diff changeset
14 /* Suppress compiler warnings to non-C89 code. */
f80abb797a32 patch 8.0.1584: using C99 in Mac file gives compiler warning messages
Christian Brabandt <cb@256bit.org>
parents: 12877
diff changeset
15 #if defined(__clang__) && defined(__STRICT_ANSI__)
f80abb797a32 patch 8.0.1584: using C99 in Mac file gives compiler warning messages
Christian Brabandt <cb@256bit.org>
parents: 12877
diff changeset
16 # pragma clang diagnostic push
f80abb797a32 patch 8.0.1584: using C99 in Mac file gives compiler warning messages
Christian Brabandt <cb@256bit.org>
parents: 12877
diff changeset
17 # pragma clang diagnostic ignored "-Wc99-extensions"
f80abb797a32 patch 8.0.1584: using C99 in Mac file gives compiler warning messages
Christian Brabandt <cb@256bit.org>
parents: 12877
diff changeset
18 # pragma clang diagnostic push
f80abb797a32 patch 8.0.1584: using C99 in Mac file gives compiler warning messages
Christian Brabandt <cb@256bit.org>
parents: 12877
diff changeset
19 # pragma clang diagnostic ignored "-Wdeclaration-after-statement"
f80abb797a32 patch 8.0.1584: using C99 in Mac file gives compiler warning messages
Christian Brabandt <cb@256bit.org>
parents: 12877
diff changeset
20 #endif
f80abb797a32 patch 8.0.1584: using C99 in Mac file gives compiler warning messages
Christian Brabandt <cb@256bit.org>
parents: 12877
diff changeset
21
2598
10ce04af8c5b updated for version 7.3.021
Bram Moolenaar <bram@vim.org>
parents: 2567
diff changeset
22 /* Avoid a conflict for the definition of Boolean between Mac header files and
10ce04af8c5b updated for version 7.3.021
Bram Moolenaar <bram@vim.org>
parents: 2567
diff changeset
23 * X11 header files. */
10ce04af8c5b updated for version 7.3.021
Bram Moolenaar <bram@vim.org>
parents: 2567
diff changeset
24 #define NO_X11_INCLUDES
10ce04af8c5b updated for version 7.3.021
Bram Moolenaar <bram@vim.org>
parents: 2567
diff changeset
25
29071
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
26 #include <stdbool.h>
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
27 #include <mach/boolean.h>
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
28 #include <sys/errno.h>
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
29 #include <stdlib.h>
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
30
29796
3f88a6d02354 patch 9.0.0237: Mac: cannot build if dispatch.h is not available
Bram Moolenaar <Bram@vim.org>
parents: 29228
diff changeset
31 #ifdef FEAT_RELTIME
29071
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
32 #include <dispatch/dispatch.h>
29796
3f88a6d02354 patch 9.0.0237: Mac: cannot build if dispatch.h is not available
Bram Moolenaar <Bram@vim.org>
parents: 29228
diff changeset
33 #endif
29071
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
34
2309
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
35 #include "vim.h"
12716
351cf7c67bbe patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
36 #import <AppKit/AppKit.h>
2309
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
37
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
38
2565
4b7929dad28a Fix building the Mac version with GUI.
Bram Moolenaar <bram@vim.org>
parents: 2315
diff changeset
39 /*
4b7929dad28a Fix building the Mac version with GUI.
Bram Moolenaar <bram@vim.org>
parents: 2315
diff changeset
40 * Clipboard support for the console.
4b7929dad28a Fix building the Mac version with GUI.
Bram Moolenaar <bram@vim.org>
parents: 2315
diff changeset
41 */
21785
c346db463a59 patch 8.2.1442: outdated references to the Mac Carbon GUI
Bram Moolenaar <Bram@vim.org>
parents: 21749
diff changeset
42 #if defined(FEAT_CLIPBOARD)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43
2315
2e6dbc2fccd4 Remove obsolete Mac code.
Bram Moolenaar <bram@vim.org>
parents: 2314
diff changeset
44 /* Used to identify clipboard data copied from Vim. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45
2315
2e6dbc2fccd4 Remove obsolete Mac code.
Bram Moolenaar <bram@vim.org>
parents: 2314
diff changeset
46 NSString *VimPboardType = @"VimPboardType";
2309
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
47
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
48 void
17067
d0438b4b0acf patch 8.1.1533: GUI build fails on Mac
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
49 clip_mch_lose_selection(Clipboard_T *cbd UNUSED)
2309
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
50 {
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
51 }
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
52
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
53
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
54 int
17067
d0438b4b0acf patch 8.1.1533: GUI build fails on Mac
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
55 clip_mch_own_selection(Clipboard_T *cbd UNUSED)
2309
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
56 {
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
57 /* This is called whenever there is a new selection and 'guioptions'
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
58 * contains the "a" flag (automatically copy selection). Return TRUE, else
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
59 * the "a" flag does nothing. Note that there is no concept of "ownership"
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
60 * of the clipboard in Mac OS X.
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
61 */
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
62 return TRUE;
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
63 }
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
64
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
65
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
66 void
17067
d0438b4b0acf patch 8.1.1533: GUI build fails on Mac
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
67 clip_mch_request_selection(Clipboard_T *cbd)
2309
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
68 {
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
69 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
70
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
71 NSPasteboard *pb = [NSPasteboard generalPasteboard];
14911
73162bc0b21f patch 8.1.0467: cannot build with Mac OS X 10.5
Bram Moolenaar <Bram@vim.org>
parents: 14091
diff changeset
72 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
14091
616dc84228b7 patch 8.1.0063: Mac: NSStringPboardType is deprecated
Christian Brabandt <cb@256bit.org>
parents: 13420
diff changeset
73 NSArray *supportedTypes = [NSArray arrayWithObjects:VimPboardType,
616dc84228b7 patch 8.1.0063: Mac: NSStringPboardType is deprecated
Christian Brabandt <cb@256bit.org>
parents: 13420
diff changeset
74 NSPasteboardTypeString, nil];
616dc84228b7 patch 8.1.0063: Mac: NSStringPboardType is deprecated
Christian Brabandt <cb@256bit.org>
parents: 13420
diff changeset
75 #else
2309
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
76 NSArray *supportedTypes = [NSArray arrayWithObjects:VimPboardType,
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
77 NSStringPboardType, nil];
14091
616dc84228b7 patch 8.1.0063: Mac: NSStringPboardType is deprecated
Christian Brabandt <cb@256bit.org>
parents: 13420
diff changeset
78 #endif
2309
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
79 NSString *bestType = [pb availableTypeFromArray:supportedTypes];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
80 if (!bestType) goto releasepool;
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
81
2909
b65a26a2aa09 updated for version 7.3.227
Bram Moolenaar <bram@vim.org>
parents: 2891
diff changeset
82 int motion_type = MAUTO;
2309
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
83 NSString *string = nil;
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
84
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
85 if ([bestType isEqual:VimPboardType])
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
86 {
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
87 /* This type should consist of an array with two objects:
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
88 * 1. motion type (NSNumber)
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
89 * 2. text (NSString)
14091
616dc84228b7 patch 8.1.0063: Mac: NSStringPboardType is deprecated
Christian Brabandt <cb@256bit.org>
parents: 13420
diff changeset
90 * If this is not the case we fall back on using NSPasteboardTypeString.
2309
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
91 */
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
92 id plist = [pb propertyListForType:VimPboardType];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
93 if ([plist isKindOfClass:[NSArray class]] && [plist count] == 2)
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
94 {
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
95 id obj = [plist objectAtIndex:1];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
96 if ([obj isKindOfClass:[NSString class]])
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
97 {
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
98 motion_type = [[plist objectAtIndex:0] intValue];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
99 string = obj;
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
100 }
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
101 }
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
102 }
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
103
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
104 if (!string)
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
105 {
14091
616dc84228b7 patch 8.1.0063: Mac: NSStringPboardType is deprecated
Christian Brabandt <cb@256bit.org>
parents: 13420
diff changeset
106 /* Use NSPasteboardTypeString. The motion type is detected automatically.
2309
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
107 */
14911
73162bc0b21f patch 8.1.0467: cannot build with Mac OS X 10.5
Bram Moolenaar <Bram@vim.org>
parents: 14091
diff changeset
108 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
14091
616dc84228b7 patch 8.1.0063: Mac: NSStringPboardType is deprecated
Christian Brabandt <cb@256bit.org>
parents: 13420
diff changeset
109 NSMutableString *mstring =
616dc84228b7 patch 8.1.0063: Mac: NSStringPboardType is deprecated
Christian Brabandt <cb@256bit.org>
parents: 13420
diff changeset
110 [[pb stringForType:NSPasteboardTypeString] mutableCopy];
616dc84228b7 patch 8.1.0063: Mac: NSStringPboardType is deprecated
Christian Brabandt <cb@256bit.org>
parents: 13420
diff changeset
111 #else
2309
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
112 NSMutableString *mstring =
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
113 [[pb stringForType:NSStringPboardType] mutableCopy];
14091
616dc84228b7 patch 8.1.0063: Mac: NSStringPboardType is deprecated
Christian Brabandt <cb@256bit.org>
parents: 13420
diff changeset
114 #endif
2309
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
115 if (!mstring) goto releasepool;
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
116
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
117 /* Replace unrecognized end-of-line sequences with \x0a (line feed). */
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
118 NSRange range = { 0, [mstring length] };
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
119 unsigned n = [mstring replaceOccurrencesOfString:@"\x0d\x0a"
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
120 withString:@"\x0a" options:0
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
121 range:range];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
122 if (0 == n)
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
123 {
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
124 n = [mstring replaceOccurrencesOfString:@"\x0d" withString:@"\x0a"
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
125 options:0 range:range];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
126 }
2310
3e4574a4b627 Fix a few compiler warnings.
Bram Moolenaar <bram@vim.org>
parents: 2309
diff changeset
127
2309
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
128 string = mstring;
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
129 }
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
130
2909
b65a26a2aa09 updated for version 7.3.227
Bram Moolenaar <bram@vim.org>
parents: 2891
diff changeset
131 /* Default to MAUTO, uses MCHAR or MLINE depending on trailing NL. */
2309
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
132 if (!(MCHAR == motion_type || MLINE == motion_type || MBLOCK == motion_type
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
133 || MAUTO == motion_type))
2909
b65a26a2aa09 updated for version 7.3.227
Bram Moolenaar <bram@vim.org>
parents: 2891
diff changeset
134 motion_type = MAUTO;
2309
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
135
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
136 char_u *str = (char_u*)[string UTF8String];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
137 int len = [string lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
138
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
139 if (input_conv.vc_type != CONV_NONE)
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
140 str = string_convert(&input_conv, str, &len);
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
141
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
142 if (str)
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
143 clip_yank_selection(motion_type, str, len, cbd);
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
144
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
145 if (input_conv.vc_type != CONV_NONE)
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
146 vim_free(str);
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
147
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
148 releasepool:
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
149 [pool release];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
150 }
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
151
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
152
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
153 /*
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
154 * Send the current selection to the clipboard.
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
155 */
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
156 void
17067
d0438b4b0acf patch 8.1.1533: GUI build fails on Mac
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
157 clip_mch_set_selection(Clipboard_T *cbd)
2309
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
158 {
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
159 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
160
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
161 /* If the '*' register isn't already filled in, fill it in now. */
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
162 cbd->owned = TRUE;
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
163 clip_get_selection(cbd);
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
164 cbd->owned = FALSE;
2310
3e4574a4b627 Fix a few compiler warnings.
Bram Moolenaar <bram@vim.org>
parents: 2309
diff changeset
165
2309
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
166 /* Get the text to put on the pasteboard. */
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
167 long_u llen = 0; char_u *str = 0;
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
168 int motion_type = clip_convert_selection(&str, &llen, cbd);
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
169 if (motion_type < 0)
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
170 goto releasepool;
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
171
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
172 /* TODO: Avoid overflow. */
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
173 int len = (int)llen;
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
174 if (output_conv.vc_type != CONV_NONE)
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
175 {
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
176 char_u *conv_str = string_convert(&output_conv, str, &len);
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
177 if (conv_str)
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
178 {
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
179 vim_free(str);
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
180 str = conv_str;
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
181 }
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
182 }
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
183
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
184 if (len > 0)
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
185 {
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
186 NSString *string = [[NSString alloc]
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
187 initWithBytes:str length:len encoding:NSUTF8StringEncoding];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
188
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
189 /* See clip_mch_request_selection() for info on pasteboard types. */
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
190 NSPasteboard *pb = [NSPasteboard generalPasteboard];
14911
73162bc0b21f patch 8.1.0467: cannot build with Mac OS X 10.5
Bram Moolenaar <Bram@vim.org>
parents: 14091
diff changeset
191 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
14091
616dc84228b7 patch 8.1.0063: Mac: NSStringPboardType is deprecated
Christian Brabandt <cb@256bit.org>
parents: 13420
diff changeset
192 NSArray *supportedTypes = [NSArray arrayWithObjects:VimPboardType,
616dc84228b7 patch 8.1.0063: Mac: NSStringPboardType is deprecated
Christian Brabandt <cb@256bit.org>
parents: 13420
diff changeset
193 NSPasteboardTypeString, nil];
616dc84228b7 patch 8.1.0063: Mac: NSStringPboardType is deprecated
Christian Brabandt <cb@256bit.org>
parents: 13420
diff changeset
194 #else
2309
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
195 NSArray *supportedTypes = [NSArray arrayWithObjects:VimPboardType,
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
196 NSStringPboardType, nil];
14091
616dc84228b7 patch 8.1.0063: Mac: NSStringPboardType is deprecated
Christian Brabandt <cb@256bit.org>
parents: 13420
diff changeset
197 #endif
2309
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
198 [pb declareTypes:supportedTypes owner:nil];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
199
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
200 NSNumber *motion = [NSNumber numberWithInt:motion_type];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
201 NSArray *plist = [NSArray arrayWithObjects:motion, string, nil];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
202 [pb setPropertyList:plist forType:VimPboardType];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
203
14911
73162bc0b21f patch 8.1.0467: cannot build with Mac OS X 10.5
Bram Moolenaar <Bram@vim.org>
parents: 14091
diff changeset
204 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
14091
616dc84228b7 patch 8.1.0063: Mac: NSStringPboardType is deprecated
Christian Brabandt <cb@256bit.org>
parents: 13420
diff changeset
205 [pb setString:string forType:NSPasteboardTypeString];
616dc84228b7 patch 8.1.0063: Mac: NSStringPboardType is deprecated
Christian Brabandt <cb@256bit.org>
parents: 13420
diff changeset
206 #else
2309
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
207 [pb setString:string forType:NSStringPboardType];
14091
616dc84228b7 patch 8.1.0063: Mac: NSStringPboardType is deprecated
Christian Brabandt <cb@256bit.org>
parents: 13420
diff changeset
208 #endif
2310
3e4574a4b627 Fix a few compiler warnings.
Bram Moolenaar <bram@vim.org>
parents: 2309
diff changeset
209
2309
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
210 [string release];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
211 }
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
212
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
213 vim_free(str);
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
214 releasepool:
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
215 [pool release];
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
216 }
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
217
543ea69d037f Add clipboard support in Mac console. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents: 2215
diff changeset
218 #endif /* FEAT_CLIPBOARD */
13420
f80abb797a32 patch 8.0.1584: using C99 in Mac file gives compiler warning messages
Christian Brabandt <cb@256bit.org>
parents: 12877
diff changeset
219
29071
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
220 #ifdef FEAT_RELTIME
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
221 /*
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
222 * The following timer code is based on a Gist by Jorgen Lundman:
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
223 *
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
224 * https://gist.github.com/lundman
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
225 */
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
226
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
227 typedef struct macos_timer macos_timer_T;
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
228
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
229 static void
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
230 _timer_cancel(void *arg UNUSED)
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
231 {
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
232 // This is not currently used, but it might be useful in the future and
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
233 // it is non-trivial enough to provide as usable implementation.
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
234 # if 0
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
235 macos_timer_T *timerid = (macos_timer_T *)arg;
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
236
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
237 dispatch_release(timerid->tim_timer);
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
238 dispatch_release(timerid->tim_queue);
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
239 timerid->tim_timer = NULL;
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
240 timerid->tim_queue = NULL;
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
241 free(timerid);
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
242 # endif
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
243 }
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
244
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
245 static void
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
246 _timer_handler(void *arg)
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
247 {
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
248 macos_timer_T *timerid = (macos_timer_T *)arg;
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
249 union sigval sv;
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
250
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
251 sv.sival_ptr = timerid->tim_arg;
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
252
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
253 if (timerid->tim_func != NULL)
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
254 timerid->tim_func(sv);
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
255 }
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
256
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
257 static uint64_t
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
258 itime_to_ns(const struct timespec *it)
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
259 {
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
260 time_t sec = it->tv_sec;
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
261 long nsec = it->tv_nsec;
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
262 uint64_t ns = NSEC_PER_SEC * sec + nsec;
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
263
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
264 return ns == 0 ? DISPATCH_TIME_FOREVER : ns;
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
265 }
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
266
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
267 /*
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
268 * A partial emulation of the POSIX timer_create function.
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
269 *
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
270 * The limitations and differences include:
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
271 *
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
272 * - Only CLOCK_REALTIME and CLOCK_MONOTONIC are supported as clockid
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
273 * values.
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
274 * - Even if CLOCK_REALTIME is specified, internally the mach_absolute_time
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
275 * source is used internally.
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
276 * - The only notification method supported is SIGEV_THREAD.
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
277 */
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
278 inline int
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
279 timer_create(clockid_t clockid, struct sigevent *sevp, timer_t *timerid)
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
280 {
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
281 macos_timer_T *timer = NULL;
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
282
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
283 // We only support real time and monotonic clocks; and SIGEV_THREAD
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
284 // notification. In practice, there is no difference between the two
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
285 // types of clocks on MacOS - we always use the mach_machine_time
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
286 // source.
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
287 if ( (clockid != CLOCK_REALTIME && clockid != CLOCK_MONOTONIC)
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
288 || sevp->sigev_notify != SIGEV_THREAD)
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
289 {
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
290 semsg("clockid: %d %d", clockid, CLOCK_REALTIME);
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
291 semsg("notify: %d %d", sevp->sigev_notify, SIGEV_THREAD);
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
292 errno = ENOTSUP;
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
293 return -1;
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
294 }
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
295
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
296 timer = (macos_timer_T *)malloc(sizeof(macos_timer_T));
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
297 if (timer == NULL)
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
298 {
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
299 errno = ENOMEM;
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
300 return -1;
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
301 }
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
302 *timerid = timer;
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
303
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
304 timer->tim_queue = dispatch_queue_create(
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
305 "org.vim.timerqueue", NULL);
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
306 if (timer->tim_queue == NULL)
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
307 {
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
308 errno = ENOMEM;
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
309 return -1;
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
310 }
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
311
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
312 timer->tim_timer = dispatch_source_create(
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
313 DISPATCH_SOURCE_TYPE_TIMER, 0, 0, timer->tim_queue);
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
314 if (timer->tim_timer == NULL)
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
315 {
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
316 errno = ENOMEM;
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
317 return -1;
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
318 }
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
319
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
320 timer->tim_func = sevp->sigev_notify_function;
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
321 timer->tim_arg = sevp->sigev_value.sival_ptr;
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
322
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
323 dispatch_set_context(timer->tim_timer, timer);
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
324 dispatch_source_set_event_handler_f(timer->tim_timer, _timer_handler);
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
325 dispatch_source_set_cancel_handler_f(timer->tim_timer, _timer_cancel);
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
326
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
327 dispatch_resume(timer->tim_timer);
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
328
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
329 return 0;
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
330 }
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
331
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
332 /*
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
333 * A partial emulation of the POSIX timer_settime function.
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
334 *
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
335 * The limitations and differences include:
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
336 *
30986
360f286b5869 patch 9.0.0828: various typos
Bram Moolenaar <Bram@vim.org>
parents: 30719
diff changeset
337 * - The flags argument is ignored. The supplied new_value is therefore
29071
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
338 * always treated as a relative time.
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
339 * - The old_value argument is ignored.
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
340 */
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
341 int
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
342 timer_settime(
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
343 timer_t timerid,
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
344 int unused_flags UNUSED,
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
345 const struct itimerspec *new_value,
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
346 struct itimerspec *old_value UNUSED)
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
347 {
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
348 uint64_t first_shot = itime_to_ns(&new_value->it_value);
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
349
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
350 if (timerid == NULL)
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
351 return 0;
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
352
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
353 if (first_shot == DISPATCH_TIME_FOREVER)
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
354 {
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
355 dispatch_source_set_timer(
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
356 timerid->tim_timer, first_shot, first_shot, 0);
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
357 }
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
358 else
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
359 {
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
360 uint64_t interval = itime_to_ns(&new_value->it_interval);
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
361
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
362 dispatch_time_t start = dispatch_time(DISPATCH_TIME_NOW, first_shot);
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
363 dispatch_source_set_timer(timerid->tim_timer, start, interval, 0);
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
364 }
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
365
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
366 return 0;
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
367 }
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
368
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
369 /*
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
370 * An emulation of the POSIX timer_delete function.
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
371 *
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
372 * Disabled because it is not currently used, but an implemented provided
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
373 * for completeness and possible future use.
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
374 */
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
375 int
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
376 timer_delete(timer_t timerid)
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
377 {
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
378 /* Calls _timer_cancel() */
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
379 if (timerid != NULL)
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
380 dispatch_source_cancel(timerid->tim_timer);
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
381
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
382 return 0;
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
383 }
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
384
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
385 #endif /* FEAT_RELTIME */
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 21785
diff changeset
386
30719
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
387 #ifdef FEAT_SOUND
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
388
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
389 static NSMutableDictionary<NSNumber*, NSSound*> *sounds_list = nil;
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
390
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
391 /// A delegate for handling when a sound has stopped playing, in
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
392 /// order to clean up the sound and to send a callback.
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
393 @interface SoundDelegate : NSObject<NSSoundDelegate>;
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
394
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
395 - (id) init:(long) sound_id callback:(soundcb_T*) callback;
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
396 - (void) sound:(NSSound *)sound didFinishPlaying:(BOOL)flag;
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
397
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
398 @property (readonly) long sound_id;
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
399 @property (readonly) soundcb_T *callback;
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
400
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
401 @end
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
402
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
403 @implementation SoundDelegate
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
404 - (id) init:(long) sound_id callback:(soundcb_T*) callback
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
405 {
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
406 if ([super init])
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
407 {
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
408 _sound_id = sound_id;
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
409 _callback = callback;
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
410 }
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
411 return self;
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
412 }
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
413
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
414 - (void) sound:(NSSound *)sound didFinishPlaying:(BOOL)flag
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
415 {
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
416 if (sounds_list != nil)
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
417 {
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
418 if (_callback)
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
419 {
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
420 call_sound_callback(_callback, _sound_id, flag ? 0 : 1);
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
421 delete_sound_callback(_callback);
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
422 _callback = NULL;
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
423 }
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
424 [sounds_list removeObjectForKey:[NSNumber numberWithLong:_sound_id]];
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
425 }
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
426 // Release itself. Do that here instead of earlier because NSSound only
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
427 // holds weak reference to this object.
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
428 [self release];
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
429 }
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
430 @end
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
431
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
432 void
32280
ca4e81de477a patch 9.0.1471: warnings for function declarations
Bram Moolenaar <Bram@vim.org>
parents: 30986
diff changeset
433 process_cfrunloop(void)
30719
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
434 {
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
435 if (sounds_list != nil && [sounds_list count] > 0)
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
436 {
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
437 // Continually drain the run loop of events. Currently, this
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
438 // is only used for processing sound callbacks, because
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
439 // NSSound relies of this runloop to call back to the
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
440 // delegate.
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
441 @autoreleasepool
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
442 {
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
443 while (CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true)
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
444 == kCFRunLoopRunHandledSource)
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
445 ; // do nothing
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
446 }
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
447 }
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
448 }
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
449
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
450 bool
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
451 sound_mch_play(const char_u* sound_name, long sound_id, soundcb_T *callback, bool playfile)
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
452 {
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
453 @autoreleasepool
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
454 {
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
455 NSString *sound_name_ns = [[[NSString alloc] initWithUTF8String:(const char*)sound_name] autorelease];
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
456 NSSound* sound = playfile ?
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
457 [[[NSSound alloc] initWithContentsOfFile:sound_name_ns byReference:YES] autorelease] :
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
458 [NSSound soundNamed:sound_name_ns];
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
459 if (!sound)
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
460 {
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
461 return false;
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
462 }
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
463
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
464 if (sounds_list == nil)
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
465 {
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
466 sounds_list = [[NSMutableDictionary<NSNumber*, NSSound*> alloc] init];
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
467 }
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
468 sounds_list[[NSNumber numberWithLong:sound_id]] = sound;
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
469
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
470 // Make a delegate to handle when the sound stops. No need to call
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
471 // autorelease because NSSound only holds a weak reference to it.
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
472 SoundDelegate *delegate = [[SoundDelegate alloc] init:sound_id callback:callback];
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
473
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
474 [sound setDelegate:delegate];
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
475 [sound play];
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
476 }
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
477 return true;
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
478 }
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
479
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
480 void
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
481 sound_mch_stop(long sound_id)
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
482 {
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
483 @autoreleasepool
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
484 {
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
485 NSSound *sound = sounds_list[[NSNumber numberWithLong:sound_id]];
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
486 if (sound != nil)
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
487 {
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
488 // Stop the sound. No need to release it because the delegate will do
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
489 // it for us.
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
490 [sound stop];
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
491 }
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
492 }
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
493 }
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
494
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
495 void
32280
ca4e81de477a patch 9.0.1471: warnings for function declarations
Bram Moolenaar <Bram@vim.org>
parents: 30986
diff changeset
496 sound_mch_clear(void)
30719
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
497 {
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
498 if (sounds_list != nil)
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
499 {
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
500 @autoreleasepool
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
501 {
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
502 for (NSSound *sound in [sounds_list allValues])
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
503 {
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
504 [sound stop];
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
505 }
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
506 [sounds_list release];
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
507 sounds_list = nil;
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
508 }
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
509 }
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
510 }
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
511
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
512 void
32280
ca4e81de477a patch 9.0.1471: warnings for function declarations
Bram Moolenaar <Bram@vim.org>
parents: 30986
diff changeset
513 sound_mch_free(void)
30719
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
514 {
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
515 sound_mch_clear();
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
516 }
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
517
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
518 #endif // FEAT_SOUND
71137f73c94d patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents: 29796
diff changeset
519
13420
f80abb797a32 patch 8.0.1584: using C99 in Mac file gives compiler warning messages
Christian Brabandt <cb@256bit.org>
parents: 12877
diff changeset
520 /* Lift the compiler warning suppression. */
f80abb797a32 patch 8.0.1584: using C99 in Mac file gives compiler warning messages
Christian Brabandt <cb@256bit.org>
parents: 12877
diff changeset
521 #if defined(__clang__) && defined(__STRICT_ANSI__)
f80abb797a32 patch 8.0.1584: using C99 in Mac file gives compiler warning messages
Christian Brabandt <cb@256bit.org>
parents: 12877
diff changeset
522 # pragma clang diagnostic pop
f80abb797a32 patch 8.0.1584: using C99 in Mac file gives compiler warning messages
Christian Brabandt <cb@256bit.org>
parents: 12877
diff changeset
523 # pragma clang diagnostic pop
f80abb797a32 patch 8.0.1584: using C99 in Mac file gives compiler warning messages
Christian Brabandt <cb@256bit.org>
parents: 12877
diff changeset
524 #endif