1/* Copyright (c) 1996,97,98 by Lele Gaifax.  All Rights Reserved
2 * Copyright (2) 2003 Ronald Oussoren
3 *
4 * This software may be used and distributed freely for any purpose
5 * provided that this notice is included unchanged on any and all
6 * copies. The author does not warrant or guarantee this software in
7 * any way.
8 *
9 * This file is part of the PyObjC package.
10 *
11 * RCSfile: objc_support.h,v
12 * Revision: 1.16
13 * Date: 1998/08/18 15:35:57
14 *
15 * Created Tue Sep 10 14:11:38 1996.
16 *
17 * TODO: the functions exported by this file should be changed, the names
18 * should start with 'PyObjC' and should be the same as the names used in
19 * pyobjc-api.h (where appropriate).
20 */
21
22#ifndef _objc_support_H
23#define _objc_support_H
24
25extern BOOL PyObjC_signatures_compatible(const char* type1, const char* type2);
26/* Returns True iff two typestrings are compatible:
27 * - elements have same size
28 * - 'id' is compatible with 'void*' and not with other types
29 * - 'float'/'double' are not compatible with integer types.
30 */
31
32/*#F Takes a C value pointed by @var{datum} with its type encoded in
33  @var{type}, that should be coming from an ObjC @encode directive,
34  and returns an equivalent Python object where C structures and
35  arrays are represented as tuples. */
36extern PyObject *pythonify_c_value (const char *type,
37				    void *datum);
38extern PyObject *pythonify_c_return_value (const char *type,
39				    void *datum);
40
41extern PyObject *pythonify_c_array_nullterminated(const char* type, void* datum, BOOL already_retained, BOOL already_cfretained);
42
43extern int depythonify_c_array_count(const char* type, Py_ssize_t count, BOOL strict, PyObject* value, void* datum, BOOL already_retained, BOOL already_cfretained);
44extern Py_ssize_t c_array_nullterminated_size(PyObject* object, PyObject** seq);
45extern int depythonify_c_array_nullterminated(const char* type, Py_ssize_t count, PyObject* value, void* datum, BOOL already_retained, BOOL already_cfretained);
46
47/*#F Takes a Python object @var{arg} and translate it into a C value
48  pointed by @var{datum} accordingly with the type specification
49  encoded in @var{type}, that should be coming from an ObjC @encode
50  directive.
51  Returns NULL on success, or a static error string describing the
52  error. */
53extern int depythonify_c_value (const char *type,
54					PyObject *arg,
55					void *datum);
56extern int depythonify_c_return_value (const char *type,
57					PyObject *arg,
58					void *datum);
59
60extern int depythonify_c_return_array_count(const char* rettype, Py_ssize_t count, PyObject* arg, void* resp, BOOL already_retained, BOOL already_cfretained);
61extern int depythonify_c_return_array_nullterminated(const char* rettype, PyObject* arg, void* resp, BOOL already_retained, BOOL already_cfretained);
62
63
64extern Py_ssize_t PyObjCRT_SizeOfReturnType(const char* type);
65extern Py_ssize_t PyObjCRT_SizeOfType(const char *type);
66extern Py_ssize_t PyObjCRT_AlignOfType(const char *type);
67extern const char *PyObjCRT_SkipTypeSpec (const char *type);
68extern const char* PyObjCRT_NextField(const char *type);
69extern const char* PyObjCRT_SkipTypeQualifiers (const char* type);
70extern Py_ssize_t PyObjCRT_AlignedSize (const char *type);
71
72
73extern const char* PyObjCRT_RemoveFieldNames(char* buf, const char* type);
74
75/*
76 * Compatibility with pyobjc-api.h
77 */
78static inline id PyObjC_PythonToId(PyObject* value)
79{
80	id res;
81	int r;
82
83	r = depythonify_c_value(@encode(id), value, &res);
84	if (r == -1) {
85		return NULL;
86	} else {
87		return res;
88	}
89}
90
91static inline PyObject* PyObjC_IdToPython(id value)
92{
93	PyObject* res;
94
95	res = pythonify_c_value(@encode(id), &value);
96	return res;
97}
98
99#endif /* _objc_support_H */
100