1/*
2 * Copyright (c) 2006-2008, The RubyCocoa Project.
3 * Copyright (c) 2001-2006, FUJIMOTO Hisakuni.
4 * All Rights Reserved.
5 *
6 * RubyCocoa is free software, covered under either the Ruby's license or the
7 * LGPL. See the COPYRIGHT file for more information.
8 */
9
10#import <objc/objc-class.h>
11#import <stdarg.h>
12#import "osx_ruby.h"
13
14#if HAVE_LONG_LONG
15/* long long is missing from objc-class.h
16   _C_LLNG and _C_ULLNG are kept for historical reasons, but the official
17   constants are _C_LNG_LNG and _C_ULNG_LNG */
18# ifndef _C_LLNG
19#  define _C_LLNG 'q'
20# endif
21# ifndef _C_LNG_LNG
22#  define _C_LNG_LNG 'q'
23# endif
24# ifndef _C_ULLNG
25#  define _C_ULLNG 'Q'
26# endif
27# ifndef _C_ULNG_LNG
28#  define _C_ULNG_LNG 'Q'
29# endif
30/* NUM2ULL is missing from ruby.h */
31# ifndef NUM2ULL
32#  define NUM2ULL(x) (FIXNUM_P(x)?FIX2ULONG(x):rb_num2ull((VALUE)x))
33# endif
34#endif	/* HAVE_LONG_LONG */
35
36#if !defined(_C_BOOL)
37# define _C_BOOL 'B'
38#endif
39
40#if !defined(_C_CONST)
41# define _C_CONST 'r'
42#endif
43
44enum osxobjc_nsdata_type {
45  _PRIV_C_BOOL = 1024,
46  _PRIV_C_PTR,
47  _PRIV_C_ID_PTR,
48  _PRIV_C_FUNC_PTR
49};
50
51size_t  ocdata_alloc_size (const char* octype_str);
52size_t  ocdata_size       (const char* octype_str);
53void*   ocdata_malloc     (const char* octype_str);
54#define OCDATA_ALLOCA(s)  alloca(ocdata_alloc_size(s))
55
56const char *encoding_skip_to_first_type(const char *type);
57const char *encoding_skip_qualifiers(const char *type);
58BOOL is_id_ptr (const char *type);
59struct bsBoxed;
60BOOL is_boxed_ptr (const char *type, struct bsBoxed **boxed);
61
62SEL          rbobj_to_nssel    (VALUE obj);
63BOOL         rbobj_to_nsobj    (VALUE obj, id* nsobj);
64BOOL         rbobj_to_bool     (VALUE obj);
65id           rbstr_to_ocstr    (VALUE obj);
66
67VALUE    sel_to_rbobj (SEL val);
68VALUE    int_to_rbobj (int val);
69VALUE   uint_to_rbobj (unsigned int val);
70VALUE double_to_rbobj (double val);
71VALUE   bool_to_rbobj (BOOL val);
72VALUE   ocid_to_rbobj (VALUE context_obj, id ocid);
73VALUE  ocstr_to_rbstr (id ocstr);
74
75BOOL  ocdata_to_rbobj (VALUE context_obj,
76		       const char *octype, const void* ocdata, VALUE* result, BOOL from_libffi);
77BOOL  rbobj_to_ocdata (VALUE obj, const char *octype, void* ocdata, BOOL to_libffi);
78
79void init_rb2oc_cache(void);
80void init_oc2rb_cache(void);
81void remove_from_rb2oc_cache(VALUE rbobj);
82void remove_from_oc2rb_cache(id ocid);
83VALUE ocid_to_rbobj_cache_only(id ocid);
84
85@class NSMethodSignature;
86void decode_method_encoding(const char *encoding, NSMethodSignature *methodSignature, unsigned *argc, char **retval_type, char ***arg_types, BOOL strip_first_two_args);
87void set_octypes_for_format_str (char **octypes, unsigned len, char *format_str);
88