nil_method.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* GNU Objective C Runtime nil receiver function
  2. Copyright (C) 1993-2015 Free Software Foundation, Inc.
  3. Contributed by Kresten Krab Thorup
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it under the
  6. terms of the GNU General Public License as published by the Free Software
  7. Foundation; either version 3, or (at your option) any later version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  11. details.
  12. Under Section 7 of GPL version 3, you are granted additional
  13. permissions described in the GCC Runtime Library Exception, version
  14. 3.1, as published by the Free Software Foundation.
  15. You should have received a copy of the GNU General Public License and
  16. a copy of the GCC Runtime Library Exception along with this program;
  17. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  18. <http://www.gnu.org/licenses/>. */
  19. /* This is the nil method, the function that is called when the receiver
  20. of a method is nil */
  21. #include "objc-private/common.h"
  22. #include "objc/objc.h"
  23. /* When the receiver of a method invocation is nil, the runtime
  24. returns nil_method() as the method implementation. This function
  25. will be casted to whatever function was supposed to be executed to
  26. execute that method (that function will take an id, followed by a
  27. SEL, followed by who knows what arguments, depends on the method),
  28. and executed.
  29. For this reason, nil_method() should be a function which can be
  30. called in place of any function taking an 'id' argument followed by
  31. a 'SEL' argument, followed by zero, or one, or any number of
  32. arguments (both a fixed number, or a variable number !).
  33. There is no "proper" implementation of such a nil_method function
  34. in C, however in all existing implementations it does not matter
  35. when extra arguments are present, so we can simply create a function
  36. taking a receiver and a selector, and all other arguments will be
  37. ignored. :-)
  38. */
  39. id
  40. nil_method (id receiver, SEL op __attribute__ ((__unused__)))
  41. {
  42. return receiver;
  43. }