summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Guyomarc'h <jean.guyomarch@openwide.fr>2015-10-14 09:31:45 +0200
committerNicolas Aguirre <aguirre.nicolas@gmail.com>2015-11-10 08:32:49 +0100
commit8bbdb2511e150d3d1672de640d7565d9e21baa6d (patch)
treea417484b64eeb5ad581557c974c9b6a9447cebf2
parent226709745a8b46bf1c9fd3bfee14d4702ad0f014 (diff)
ecore_cocoa: add more safety checks
-rw-r--r--src/lib/ecore_cocoa/ecore_cocoa_window.m130
1 files changed, 67 insertions, 63 deletions
diff --git a/src/lib/ecore_cocoa/ecore_cocoa_window.m b/src/lib/ecore_cocoa/ecore_cocoa_window.m
index 68688971b4..cf04da456e 100644
--- a/src/lib/ecore_cocoa/ecore_cocoa_window.m
+++ b/src/lib/ecore_cocoa/ecore_cocoa_window.m
@@ -57,12 +57,11 @@ static NSCursor *_cursors[__ECORE_COCOA_CURSOR_LAST];
57 NSLog(@"window is going to be closed"); 57 NSLog(@"window is going to be closed");
58 Ecore_Cocoa_Event_Window *event; 58 Ecore_Cocoa_Event_Window *event;
59 59
60 event = malloc(sizeof(Ecore_Cocoa_Event_Window)); 60 event = malloc(sizeof(*event));
61 if (event == NULL) 61 if (EINA_UNLIKELY(event == NULL))
62 { 62 {
63 // FIXME Use Eina_Log 63 CRI("Failed to allocate Ecore_Cocoa_Event_Window");
64 printf("Failed to allocate Ecore_Cocoa_Event_Window_destroy\n"); 64 return;
65 return;
66 } 65 }
67 event->wid = [notification object]; 66 event->wid = [notification object];
68 ecore_event_add(ECORE_COCOA_EVENT_WINDOW_DESTROY, event, NULL, NULL); 67 ecore_event_add(ECORE_COCOA_EVENT_WINDOW_DESTROY, event, NULL, NULL);
@@ -73,10 +72,10 @@ static NSCursor *_cursors[__ECORE_COCOA_CURSOR_LAST];
73 Ecore_Cocoa_Event_Video_Resize *event; 72 Ecore_Cocoa_Event_Video_Resize *event;
74 NSSize size = self.frame.size; 73 NSSize size = self.frame.size;
75 74
76 event = malloc(sizeof(Ecore_Cocoa_Event_Video_Resize)); 75 event = malloc(sizeof(*event));
77 if (event == NULL) 76 if (EINA_UNLIKELY(event == NULL))
78 { 77 {
79 DBG("Failed to allocate Ecore_Cocoa_Event_Video_Resize\n"); 78 CRI("Failed to allocate Ecore_Cocoa_Event_Video_Resize");
80 return; 79 return;
81 } 80 }
82 event->w = size.width; 81 event->w = size.width;
@@ -90,11 +89,11 @@ static NSCursor *_cursors[__ECORE_COCOA_CURSOR_LAST];
90{ 89{
91 Ecore_Cocoa_Event_Window *e; 90 Ecore_Cocoa_Event_Window *e;
92 91
93 e = malloc(sizeof(Ecore_Cocoa_Event_Window)); 92 e = malloc(sizeof(*e));
94 if (!e) 93 if (EINA_UNLIKELY(e == NULL))
95 { 94 {
96 DBG("GOT_FOCUS: Failed to allocate Ecore_Cocoa_Event_Window\n"); 95 CRI("Failed to allocate Ecore_Cocoa_Event_Window");
97 return; 96 return;
98 } 97 }
99 e->wid = [notification object]; 98 e->wid = [notification object];
100 ecore_event_add(ECORE_COCOA_EVENT_GOT_FOCUS, e, NULL, NULL); 99 ecore_event_add(ECORE_COCOA_EVENT_GOT_FOCUS, e, NULL, NULL);
@@ -104,11 +103,11 @@ static NSCursor *_cursors[__ECORE_COCOA_CURSOR_LAST];
104{ 103{
105 Ecore_Cocoa_Event_Window *e; 104 Ecore_Cocoa_Event_Window *e;
106 105
107 e = malloc(sizeof(Ecore_Cocoa_Event_Window)); 106 e = malloc(sizeof(*e));
108 if (!e) 107 if (EINA_UNLIKELY(e == NULL))
109 { 108 {
110 DBG("LOST_FOCUS: Failed to allocate Ecore_Cocoa_Event_Window\n"); 109 CRI("Failed to allocate Ecore_Cocoa_Event_Window");
111 return; 110 return;
112 } 111 }
113 e->wid = [notification object]; 112 e->wid = [notification object];
114 ecore_event_add(ECORE_COCOA_EVENT_LOST_FOCUS, e, NULL, NULL); 113 ecore_event_add(ECORE_COCOA_EVENT_LOST_FOCUS, e, NULL, NULL);
@@ -133,7 +132,12 @@ static NSCursor *_cursors[__ECORE_COCOA_CURSOR_LAST];
133 } 132 }
134 133
135 Ecore_Event_Mouse_Button * ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)); 134 Ecore_Event_Mouse_Button * ev = calloc(1, sizeof(Ecore_Event_Mouse_Button));
136 if (!ev) return; 135
136 if (EINA_UNLIKELY(!ev))
137 {
138 CRI("Failed to allocate Ecore_Event_Mouse_Button");
139 return;
140 }
137 141
138 ev->x = x; 142 ev->x = x;
139 ev->y = y; 143 ev->y = y;
@@ -185,8 +189,12 @@ static NSCursor *_cursors[__ECORE_COCOA_CURSOR_LAST];
185 int x = pt.x; 189 int x = pt.x;
186 int y = h - pt.y; 190 int y = h - pt.y;
187 191
188 Ecore_Event_Mouse_Button * ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)); 192 Ecore_Event_Mouse_Button *ev = calloc(1, sizeof(*ev));
189 if (!ev) return; 193 if (EINA_UNLIKELY(!ev))
194 {
195 CRI("Failed to allocate Ecore_Event_Mouse_Button");
196 return;
197 }
190 198
191 ev->x = x; 199 ev->x = x;
192 ev->y = y; 200 ev->y = y;
@@ -229,8 +237,12 @@ static NSCursor *_cursors[__ECORE_COCOA_CURSOR_LAST];
229- (void) mouseMoved:(NSEvent*) event 237- (void) mouseMoved:(NSEvent*) event
230{ 238{
231 unsigned int time = (unsigned int)((unsigned long long)(ecore_time_get() * 1000.0) & 0xffffffff); 239 unsigned int time = (unsigned int)((unsigned long long)(ecore_time_get() * 1000.0) & 0xffffffff);
232 Ecore_Event_Mouse_Move * ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)); 240 Ecore_Event_Mouse_Move *ev = calloc(1, sizeof(*ev));
233 if (!ev) return; 241 if (EINA_UNLIKELY(!ev))
242 {
243 CRI("Failed to allocate Ecore_Event_Mouse_Move");
244 return;
245 }
234 246
235 NSView *view = [self contentView]; 247 NSView *view = [self contentView];
236 NSPoint event_location = [event locationInWindow]; 248 NSPoint event_location = [event locationInWindow];
@@ -271,8 +283,11 @@ ecore_cocoa_window_new(int x,
271 backing:NSBackingStoreBuffered 283 backing:NSBackingStoreBuffered
272 defer:NO]; 284 defer:NO];
273 285
274 if (!window) 286 if (EINA_UNLIKELY(!window))
275 return NULL; 287 {
288 CRI("Failed to create EcoreCocoaWindow");
289 return NULL;
290 }
276 291
277 //Set the process to be a foreground process, 292 //Set the process to be a foreground process,
278 //without that it prevents the window to become the key window and 293 //without that it prevents the window to become the key window and
@@ -282,8 +297,10 @@ ecore_cocoa_window_new(int x,
282 297
283 298
284 w = calloc(1, sizeof(Ecore_Cocoa_Window)); 299 w = calloc(1, sizeof(Ecore_Cocoa_Window));
285 if (w == NULL) 300 if (EINA_UNLIKELY(w == NULL))
286 { 301 {
302 CRI("Failed to allocate Ecore_Cocoa_Window");
303 [window release];
287 return NULL; 304 return NULL;
288 } 305 }
289 w->window = window; 306 w->window = window;
@@ -309,8 +326,8 @@ ecore_cocoa_window_size_min_set(Ecore_Cocoa_Window *window,
309 unsigned int w, 326 unsigned int w,
310 unsigned int h) 327 unsigned int h)
311{ 328{
312 if (!window) 329 EINA_SAFETY_ON_NULL_RETURN(window);
313 return; 330
314 NSSize size = {w,h}; 331 NSSize size = {w,h};
315 window->window.contentMinSize = size; 332 window->window.contentMinSize = size;
316} 333}
@@ -320,8 +337,8 @@ ecore_cocoa_window_size_max_set(Ecore_Cocoa_Window *window,
320 unsigned int w, 337 unsigned int w,
321 unsigned int h) 338 unsigned int h)
322{ 339{
323 if (!window) 340 EINA_SAFETY_ON_NULL_RETURN(window);
324 return; 341
325 NSSize size = {w,h}; 342 NSSize size = {w,h};
326 window->window.contentMaxSize = size; 343 window->window.contentMaxSize = size;
327} 344}
@@ -331,8 +348,8 @@ ecore_cocoa_window_size_step_set(Ecore_Cocoa_Window *window,
331 unsigned int w, 348 unsigned int w,
332 unsigned int h) 349 unsigned int h)
333{ 350{
334 if (!window) 351 EINA_SAFETY_ON_NULL_RETURN(window);
335 return; 352
336 NSSize size = {w,h}; 353 NSSize size = {w,h};
337 window->window.contentResizeIncrements = size; 354 window->window.contentResizeIncrements = size;
338} 355}
@@ -342,10 +359,9 @@ ecore_cocoa_window_move(Ecore_Cocoa_Window *window,
342 int x, 359 int x,
343 int y) 360 int y)
344{ 361{
345 NSRect win_frame; 362 EINA_SAFETY_ON_NULL_RETURN(window);
346 363
347 if (!window) 364 NSRect win_frame;
348 return;
349 365
350 win_frame = [window->window frame]; 366 win_frame = [window->window frame];
351 win_frame.origin.x = x; 367 win_frame.origin.x = x;
@@ -359,7 +375,7 @@ ecore_cocoa_window_resize(Ecore_Cocoa_Window *window,
359 int width, 375 int width,
360 int height) 376 int height)
361{ 377{
362 if (!window) return; 378 EINA_SAFETY_ON_NULL_RETURN(window);
363 379
364 NSRect win_frame; 380 NSRect win_frame;
365 381
@@ -378,7 +394,7 @@ ecore_cocoa_window_move_resize(Ecore_Cocoa_Window *window,
378 int width, 394 int width,
379 int height) 395 int height)
380{ 396{
381 if (!window) return; 397 EINA_SAFETY_ON_NULL_RETURN(window);
382 398
383 NSRect win_frame; 399 NSRect win_frame;
384 400
@@ -395,8 +411,8 @@ ecore_cocoa_window_move_resize(Ecore_Cocoa_Window *window,
395EAPI void 411EAPI void
396ecore_cocoa_window_title_set(Ecore_Cocoa_Window *window, const char *title) 412ecore_cocoa_window_title_set(Ecore_Cocoa_Window *window, const char *title)
397{ 413{
398 if (!window || !title) 414 EINA_SAFETY_ON_NULL_RETURN(window);
399 return; 415 EINA_SAFETY_ON_NULL_RETURN(title);
400 416
401 [window->window setTitle:[NSString stringWithUTF8String:title]]; 417 [window->window setTitle:[NSString stringWithUTF8String:title]];
402} 418}
@@ -404,48 +420,39 @@ ecore_cocoa_window_title_set(Ecore_Cocoa_Window *window, const char *title)
404EAPI void 420EAPI void
405ecore_cocoa_window_show(Ecore_Cocoa_Window *window) 421ecore_cocoa_window_show(Ecore_Cocoa_Window *window)
406{ 422{
407 if (!window || [window->window isVisible]) 423 EINA_SAFETY_ON_NULL_RETURN(window);
408 {
409 DBG("Window(%p) is not visible\n", window->window);
410 return;
411 }
412 424
413 [window->window makeKeyAndOrderFront:NSApp]; 425 if (![window->window isVisible])
426 [window->window makeKeyAndOrderFront:NSApp];
414} 427}
415 428
416EAPI void 429EAPI void
417ecore_cocoa_window_hide(Ecore_Cocoa_Window *window) 430ecore_cocoa_window_hide(Ecore_Cocoa_Window *window)
418{ 431{
419 if (!window || ![window->window isVisible]) 432 EINA_SAFETY_ON_NULL_RETURN(window);
420 return;
421 433
422 [window->window orderOut:NSApp]; 434 if (![window->window isVisible])
435 [window->window orderOut:NSApp];
423} 436}
424 437
425EAPI void 438EAPI void
426ecore_cocoa_window_raise(Ecore_Cocoa_Window *window) 439ecore_cocoa_window_raise(Ecore_Cocoa_Window *window)
427{ 440{
428 if (!window) 441 EINA_SAFETY_ON_NULL_RETURN(window);
429 return;
430
431 [window->window orderFront:nil]; 442 [window->window orderFront:nil];
432} 443}
433 444
434EAPI void 445EAPI void
435ecore_cocoa_window_lower(Ecore_Cocoa_Window *window) 446ecore_cocoa_window_lower(Ecore_Cocoa_Window *window)
436{ 447{
437 if (!window) 448 EINA_SAFETY_ON_NULL_RETURN(window);
438 return;
439
440 [window->window orderBack:nil]; 449 [window->window orderBack:nil];
441} 450}
442 451
443EAPI void 452EAPI void
444ecore_cocoa_window_activate(Ecore_Cocoa_Window *window) 453ecore_cocoa_window_activate(Ecore_Cocoa_Window *window)
445{ 454{
446 if (!window) 455 EINA_SAFETY_ON_NULL_RETURN(window);
447 return;
448
449 [window->window makeKeyAndOrderFront:nil]; 456 [window->window makeKeyAndOrderFront:nil];
450} 457}
451 458
@@ -453,8 +460,7 @@ EAPI void
453ecore_cocoa_window_iconified_set(Ecore_Cocoa_Window *window, 460ecore_cocoa_window_iconified_set(Ecore_Cocoa_Window *window,
454 int on) 461 int on)
455{ 462{
456 if (!window) 463 EINA_SAFETY_ON_NULL_RETURN(window);
457 return;
458 464
459 if (on) 465 if (on)
460 { 466 {
@@ -470,8 +476,7 @@ EAPI void
470ecore_cocoa_window_borderless_set(Ecore_Cocoa_Window *window, 476ecore_cocoa_window_borderless_set(Ecore_Cocoa_Window *window,
471 int on) 477 int on)
472{ 478{
473 if (!window) 479 EINA_SAFETY_ON_NULL_RETURN(window);
474 return;
475 480
476 if (on) 481 if (on)
477 [window->window setContentBorderThickness:0.0 482 [window->window setContentBorderThickness:0.0
@@ -482,8 +487,8 @@ EAPI void
482ecore_cocoa_window_view_set(Ecore_Cocoa_Window *window, 487ecore_cocoa_window_view_set(Ecore_Cocoa_Window *window,
483 void *view) 488 void *view)
484{ 489{
485 if (!window || !view) 490 EINA_SAFETY_ON_NULL_RETURN(window);
486 return; 491 EINA_SAFETY_ON_NULL_RETURN(view);
487 492
488 //[[window->window contentView] addSubview:view]; 493 //[[window->window contentView] addSubview:view];
489 NSView *v = view; 494 NSView *v = view;
@@ -503,8 +508,7 @@ ecore_cocoa_window_view_set(Ecore_Cocoa_Window *window,
503EAPI Ecore_Cocoa_Window_Id 508EAPI Ecore_Cocoa_Window_Id
504ecore_cocoa_window_get_window_id(const Ecore_Cocoa_Window *window) 509ecore_cocoa_window_get_window_id(const Ecore_Cocoa_Window *window)
505{ 510{
506 if (!window) 511 EINA_SAFETY_ON_NULL_RETURN_VAL(window, NULL);
507 return 0;
508 512
509 DBG("Return : %p", window->window); 513 DBG("Return : %p", window->window);
510 514