seq_darwin.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2015 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. #ifndef __GO_SEQ_DARWIN_HDR__
  5. #define __GO_SEQ_DARWIN_HDR__
  6. #include <Foundation/Foundation.h>
  7. #include "ref.h"
  8. #include "Universe.objc.h"
  9. #ifdef DEBUG
  10. #define LOG_DEBUG(...) NSLog(__VA_ARGS__);
  11. #else
  12. #define LOG_DEBUG(...) ;
  13. #endif
  14. #define LOG_INFO(...) NSLog(__VA_ARGS__);
  15. #define LOG_FATAL(...) \
  16. { \
  17. NSLog(__VA_ARGS__); \
  18. @throw \
  19. [NSException exceptionWithName:NSInternalInconsistencyException \
  20. reason:[NSString stringWithFormat:__VA_ARGS__] \
  21. userInfo:NULL]; \
  22. }
  23. // Platform specific types
  24. typedef struct nstring {
  25. void *ptr;
  26. int len;
  27. } nstring;
  28. typedef struct nbyteslice {
  29. void *ptr;
  30. int len;
  31. } nbyteslice;
  32. typedef int nint;
  33. extern void init_seq();
  34. // go_seq_dec_ref decrements the reference count for the
  35. // specified refnum. It is called from Go from a finalizer.
  36. extern void go_seq_dec_ref(int32_t refnum);
  37. // go_seq_inc_ref increments the reference count for the
  38. // specified refnum. It is called from Go just before converting
  39. // a proxy to its refnum.
  40. extern void go_seq_inc_ref(int32_t refnum);
  41. extern int32_t go_seq_to_refnum(id obj);
  42. // go_seq_go_to_refnum is a special case of go_seq_to_refnum
  43. extern int32_t go_seq_go_to_refnum(GoSeqRef *ref);
  44. extern GoSeqRef *go_seq_from_refnum(int32_t refnum);
  45. // go_seq_objc_from_refnum is a special case of go_seq_from_refnum for
  46. // Objective-C objects that implement a Go interface.
  47. extern id go_seq_objc_from_refnum(int32_t refnum);
  48. extern nbyteslice go_seq_from_objc_bytearray(NSData *data, int copy);
  49. extern nstring go_seq_from_objc_string(NSString *s);
  50. extern NSData *go_seq_to_objc_bytearray(nbyteslice, int copy);
  51. extern NSString *go_seq_to_objc_string(nstring str);
  52. #endif // __GO_SEQ_DARWIN_HDR__