diff options
| author | YAMAMOTO Mitsuharu | 2006-09-10 05:51:29 +0000 |
|---|---|---|
| committer | YAMAMOTO Mitsuharu | 2006-09-10 05:51:29 +0000 |
| commit | 601b0df72f624df8fefbb7c66484e6d916986fb8 (patch) | |
| tree | 5a9c035d99c63764816a9b30c85674775bfc7933 /src/mac.c | |
| parent | dd3a63bf1a7b799d25c932fbb6a1bbced7470eee (diff) | |
| download | emacs-601b0df72f624df8fefbb7c66484e6d916986fb8.tar.gz emacs-601b0df72f624df8fefbb7c66484e6d916986fb8.zip | |
[MAC_OSX] (sys_select): Check argument `nfds' more
rigidly. Make variable `ofds' static. Remove variable `maxfd'.
Diffstat (limited to 'src/mac.c')
| -rw-r--r-- | src/mac.c | 29 |
1 files changed, 16 insertions, 13 deletions
| @@ -4910,7 +4910,7 @@ defined in the Carbon Event Manager. */) | |||
| 4910 | HICommand command; | 4910 | HICommand command; |
| 4911 | 4911 | ||
| 4912 | bzero (&command, sizeof (HICommand)); | 4912 | bzero (&command, sizeof (HICommand)); |
| 4913 | command.commandID = mac_get_code_from_arg (command_id , 0); | 4913 | command.commandID = mac_get_code_from_arg (command_id, 0); |
| 4914 | 4914 | ||
| 4915 | BLOCK_INPUT; | 4915 | BLOCK_INPUT; |
| 4916 | err = ProcessHICommand (&command); | 4916 | err = ProcessHICommand (&command); |
| @@ -5055,10 +5055,10 @@ sys_select (nfds, rfds, wfds, efds, timeout) | |||
| 5055 | OSStatus err = noErr; | 5055 | OSStatus err = noErr; |
| 5056 | int r; | 5056 | int r; |
| 5057 | EMACS_TIME select_timeout; | 5057 | EMACS_TIME select_timeout; |
| 5058 | SELECT_TYPE ofds[3]; | 5058 | static SELECT_TYPE ofds[3]; |
| 5059 | 5059 | ||
| 5060 | if (inhibit_window_system || noninteractive | 5060 | if (inhibit_window_system || noninteractive |
| 5061 | || rfds == NULL || !FD_ISSET (0, rfds)) | 5061 | || nfds < 1 || rfds == NULL || !FD_ISSET (0, rfds)) |
| 5062 | return select (nfds, rfds, wfds, efds, timeout); | 5062 | return select (nfds, rfds, wfds, efds, timeout); |
| 5063 | 5063 | ||
| 5064 | FD_CLR (0, rfds); | 5064 | FD_CLR (0, rfds); |
| @@ -5073,18 +5073,22 @@ sys_select (nfds, rfds, wfds, efds, timeout) | |||
| 5073 | ofds[2] = *efds; | 5073 | ofds[2] = *efds; |
| 5074 | else | 5074 | else |
| 5075 | { | 5075 | { |
| 5076 | int maxfd; | ||
| 5077 | EventTimeout timeoutval = | 5076 | EventTimeout timeoutval = |
| 5078 | (timeout | 5077 | (timeout |
| 5079 | ? (EMACS_SECS (*timeout) * kEventDurationSecond | 5078 | ? (EMACS_SECS (*timeout) * kEventDurationSecond |
| 5080 | + EMACS_USECS (*timeout) * kEventDurationMicrosecond) | 5079 | + EMACS_USECS (*timeout) * kEventDurationMicrosecond) |
| 5081 | : kEventDurationForever); | 5080 | : kEventDurationForever); |
| 5082 | 5081 | ||
| 5083 | for (maxfd = nfds - 1; maxfd > 0; maxfd--) | 5082 | FD_SET (0, rfds); /* sentinel */ |
| 5084 | if (FD_ISSET (maxfd, rfds) || (wfds && FD_ISSET (maxfd, wfds))) | 5083 | do |
| 5085 | break; | 5084 | { |
| 5085 | nfds--; | ||
| 5086 | } | ||
| 5087 | while (!(FD_ISSET (nfds, rfds) || (wfds && FD_ISSET (nfds, wfds)))); | ||
| 5088 | nfds++; | ||
| 5089 | FD_CLR (0, rfds); | ||
| 5086 | 5090 | ||
| 5087 | if (maxfd == 0) | 5091 | if (nfds == 1) |
| 5088 | return select_and_poll_event (nfds, rfds, wfds, efds, timeout); | 5092 | return select_and_poll_event (nfds, rfds, wfds, efds, timeout); |
| 5089 | 5093 | ||
| 5090 | /* Avoid initial overhead of RunLoop setup for the case that | 5094 | /* Avoid initial overhead of RunLoop setup for the case that |
| @@ -5111,20 +5115,19 @@ sys_select (nfds, rfds, wfds, efds, timeout) | |||
| 5111 | int minfd, fd; | 5115 | int minfd, fd; |
| 5112 | CFRunLoopRef runloop = | 5116 | CFRunLoopRef runloop = |
| 5113 | (CFRunLoopRef) GetCFRunLoopFromEventLoop (GetCurrentEventLoop ()); | 5117 | (CFRunLoopRef) GetCFRunLoopFromEventLoop (GetCurrentEventLoop ()); |
| 5114 | static CFSocketContext context; | 5118 | static CFSocketContext context = {0, &ofds, NULL, NULL, NULL}; |
| 5115 | static CFMutableDictionaryRef sources; | 5119 | static CFMutableDictionaryRef sources; |
| 5116 | 5120 | ||
| 5117 | context.info = ofds; | ||
| 5118 | if (sources == NULL) | 5121 | if (sources == NULL) |
| 5119 | sources = | 5122 | sources = |
| 5120 | CFDictionaryCreateMutable (NULL, 0, NULL, | 5123 | CFDictionaryCreateMutable (NULL, 0, NULL, |
| 5121 | &kCFTypeDictionaryValueCallBacks); | 5124 | &kCFTypeDictionaryValueCallBacks); |
| 5122 | 5125 | ||
| 5123 | for (minfd = 1; minfd < maxfd; minfd++) | 5126 | for (minfd = 1; ; minfd++) /* nfds-1 works as a sentinel. */ |
| 5124 | if (FD_ISSET (minfd, rfds) || (wfds && FD_ISSET (minfd, wfds))) | 5127 | if (FD_ISSET (minfd, rfds) || (wfds && FD_ISSET (minfd, wfds))) |
| 5125 | break; | 5128 | break; |
| 5126 | 5129 | ||
| 5127 | for (fd = minfd; fd <= maxfd; fd++) | 5130 | for (fd = minfd; fd < nfds; fd++) |
| 5128 | if (FD_ISSET (fd, rfds) || (wfds && FD_ISSET (fd, wfds))) | 5131 | if (FD_ISSET (fd, rfds) || (wfds && FD_ISSET (fd, wfds))) |
| 5129 | { | 5132 | { |
| 5130 | void *key = (void *) fd; | 5133 | void *key = (void *) fd; |
| @@ -5157,7 +5160,7 @@ sys_select (nfds, rfds, wfds, efds, timeout) | |||
| 5157 | err = ReceiveNextEvent (0, NULL, timeoutval, | 5160 | err = ReceiveNextEvent (0, NULL, timeoutval, |
| 5158 | kEventLeaveInQueue, NULL); | 5161 | kEventLeaveInQueue, NULL); |
| 5159 | 5162 | ||
| 5160 | for (fd = minfd; fd <= maxfd; fd++) | 5163 | for (fd = minfd; fd < nfds; fd++) |
| 5161 | if (FD_ISSET (fd, rfds) || (wfds && FD_ISSET (fd, wfds))) | 5164 | if (FD_ISSET (fd, rfds) || (wfds && FD_ISSET (fd, wfds))) |
| 5162 | { | 5165 | { |
| 5163 | void *key = (void *) fd; | 5166 | void *key = (void *) fd; |