1 // -*- Mode: C++; -*-
2 //                            Package   : omniORBpy
3 // omnipy_sysdep.h            Created on: 2000/03/07
4 //                            Author    : Duncan Grisby (dpg1)
5 //
6 //    Copyright (C) 2002-2014 Apasphere Ltd
7 //    Copyright (C) 2000 AT&T Laboratories Cambridge
8 //
9 //    This file is part of the omniORBpy library
10 //
11 //    The omniORBpy library is free software; you can redistribute it
12 //    and/or modify it under the terms of the GNU Lesser General
13 //    Public License as published by the Free Software Foundation;
14 //    either version 2.1 of the License, or (at your option) any later
15 //    version.
16 //
17 //    This library is distributed in the hope that it will be useful,
18 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
19 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 //    GNU Lesser General Public License for more details.
21 //
22 //    You should have received a copy of the GNU Lesser General Public
23 //    License along with this library. If not, see http://www.gnu.org/licenses/
24 //
25 //
26 // Description:
27 //    Additional system dependencies
28 
29 #ifndef _omnipy_sysdep_h_
30 #define _omnipy_sysdep_h_
31 
32 
33 //
34 // Python version dependencies
35 
36 #if (PY_VERSION_HEX < 0x03000000) // Python 2
37 
38 #  define String_Check(o)                  PyString_Check(o)
39 #  define String_AsString(o)               PyString_AsString(o)
40 #  define String_FromString(s)             PyString_FromString(s)
41 #  define String_FromStringAndSize(s,l)    PyString_FromStringAndSize(s,l)
42 #  define String_Format(f,a)               PyString_Format(f,a)
43 #  define String_GET_SIZE(o)               PyString_GET_SIZE(o)
44 #  define String_AS_STRING(o)              PyString_AS_STRING(o)
45 
46 #  define Unicode_GET_SIZE(o)              PyUnicode_GET_SIZE(o)
47 
48 static inline const char*
String_AS_STRING_AND_SIZE(PyObject * obj,CORBA::ULong & size)49 String_AS_STRING_AND_SIZE(PyObject* obj, CORBA::ULong& size)
50 {
51   size = PyString_GET_SIZE(obj);
52   return PyString_AS_STRING(obj);
53 }
54 
55 #  define RawString_Check(o)                PyString_Check(o)
56 #  define RawString_GET_SIZE(o)             PyString_GET_SIZE(o)
57 #  define RawString_AS_STRING(o)            PyString_AS_STRING(o)
58 #  define RawString_AS_STRING_AND_SIZE(o,s) String_AS_STRING_AND_SIZE(o,s)
59 #  define RawString_FromStringAndSize(o,s)  PyString_FromStringAndSize(o,s)
60 #  define RawString_FromString(s)           PyString_FromString(s)
61 
62 #  define Int_Check(o)                      PyInt_Check(o)
63 #  define Int_FromLong(l)                   PyInt_FromLong(l)
64 #  define Int_AS_LONG(o)                    PyInt_AS_LONG(o)
65 
66 #else // Python 3
67 
68 #  if (PY_VERSION_HEX >= 0x03030000) // Python 3.3
69 
70 #    define String_AsString(o)               PyUnicode_AsUTF8(o)
71 #    define String_GET_SIZE(o)               PyUnicode_GET_LENGTH(o)
72 #    define String_AS_STRING(o)              PyUnicode_AsUTF8(o)
73 
74 #    define Unicode_GET_SIZE(o)              PyUnicode_GET_LENGTH(o)
75 
76 static inline const char*
String_AS_STRING_AND_SIZE(PyObject * obj,CORBA::ULong & size)77 String_AS_STRING_AND_SIZE(PyObject* obj, CORBA::ULong& size)
78 {
79   Py_ssize_t ss;
80   const char* str = PyUnicode_AsUTF8AndSize(obj, &ss);
81   size = ss;
82   return str;
83 }
84 
85 #  else // Python 3.0, 3.1, 3.2
86 
String_AsString(PyObject * obj)87 static inline char* String_AsString(PyObject* obj)
88 {
89   char* str;
90   PyArg_Parse(obj, (char*)"s", &str);
91   return str;
92 }
93 
94 static inline const char*
String_AS_STRING_AND_SIZE(PyObject * obj,CORBA::ULong & size)95 String_AS_STRING_AND_SIZE(PyObject* obj, CORBA::ULong& size)
96 {
97   char*      str;
98   Py_ssize_t ss;
99 
100   PyArg_Parse(obj, (char*)"s#", &str, &ss);
101 
102   size = ss;
103   return str;
104 }
105 
106 #    define String_AS_STRING(o)            String_AsString(o)
107 #    define String_GET_SIZE(o)             PyUnicode_GetSize(o)
108 
109 #    define Unicode_GET_SIZE(o)            PyUnicode_GET_SIZE(o)
110 
111 #  endif
112 
113 static inline const char*
RawString_AS_STRING_AND_SIZE(PyObject * obj,CORBA::ULong & size)114 RawString_AS_STRING_AND_SIZE(PyObject* obj, CORBA::ULong& size)
115 {
116   size = PyBytes_GET_SIZE(obj);
117   return PyBytes_AS_STRING(obj);
118 }
119 
120 #  define String_Check(o)                  PyUnicode_Check(o)
121 #  define String_FromString(s)             PyUnicode_FromString(s)
122 #  define String_FromStringAndSize(s,l)    PyUnicode_FromStringAndSize(s,l)
123 #  define String_Format(f,a)               PyUnicode_Format(f,a)
124 
125 #  define RawString_Check(o)               PyBytes_Check(o)
126 #  define RawString_GET_SIZE(o)            PyBytes_GET_SIZE(o)
127 #  define RawString_AS_STRING(o)           PyBytes_AS_STRING(o)
128 #  define RawString_FromStringAndSize(o,s) PyBytes_FromStringAndSize(o,s)
129 #  define RawString_FromString(s)          PyBytes_FromString(s)
130 
131 #  define Int_Check(o)                     PyLong_Check(o)
132 #  define Int_FromLong(l)                  PyLong_FromLong(l)
133 #  define Int_AS_LONG(o)                   PyLong_AsLong(o)
134 
135 #endif
136 
137 
138 
139 //
140 // Compiler dependencies
141 
142 // Defaults for things we'd like to do
143 
144 #define PY_OMNISERVANT_BASE omniPy::Py_omniServant
145 
146 // Some compilers will do some flow analysis and might get tricked if
147 // a function always throws an exception.
148 
149 #ifdef NEED_DUMMY_RETURN
150 #  define NEED_DUMMY_THROW
151 #elif defined(__DECCXX)
152 #  define NEED_DUMMY_THROW
153 #endif
154 
155 // Things that are broken
156 
157 #if defined(_MSC_VER)
158 #  undef  PY_OMNISERVANT_BASE
159 #  define PY_OMNISERVANT_BASE Py_omniServant
160 
161 #endif
162 
163 #endif // _omnipy_sysdep_h_
164