1 %module
(directors
="1") xapian
3 /* python.i
: SWIG interface file for the Python bindings
5 * Copyright
(C
) 2011,2012,2013,2015 Olly Betts
7 * This program is free software
; you can redistribute it and
/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation
; either version
2 of the
10 * License
, or
(at your option
) any later version.
12 * This program is distributed in the hope that it will be useful
,
13 * but WITHOUT
ANY WARRANTY
; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program
; if not
, write to the Free Software
19 * Foundation
, Inc.
, 51 Franklin St
, Fifth Floor
, Boston
, MA
02110-1301
26 Xapian is a highly adaptable toolkit which allows developers to easily
27 add advanced indexing and search facilities to their own
28 applications. It supports the Probabilistic Information Retrieval
29 model and also supports a rich set of boolean query operators.
31 In addition to the doc strings provided by this python library, you
32 may wish to look at the library's overall documentation, either
33 installed along with the bindings or online at
34 <https://xapian.org/docs/bindings/python/>, as well as the library's
35 documentation, possibly installed with the library or with its
36 development files, or again online at <https://xapian.org/docs/>.
44 /* Override SWIG's standard GIL locking machinery
- we want to avoid the
45 * overhead of thread locking when the user's code isn't using threads
,
46 * and to handle the GIL in a way which also works in sub-interpreters.
48 #define SWIG_PYTHON_NO_USE_GIL
52 static THREAD_LOCAL PyThreadState
* swig_pythreadstate
= NULL;
54 inline void swig_pythreadstate_ensure_init
() { }
56 inline PyThreadState
* swig_pythreadstate_reset
() {
57 PyThreadState
* v
= swig_pythreadstate
;
58 if
(v
) swig_pythreadstate
= NULL;
62 inline PyThreadState
* swig_pythreadstate_set
(PyThreadState
* v
) {
63 PyThreadState
* old
= swig_pythreadstate
;
64 swig_pythreadstate
= v
;
72 static pthread_key_t swig_pythreadstate_key
;
73 static pthread_once_t swig_pythreadstate_key_once
= PTHREAD_ONCE_INIT
;
75 static void swig_pythreadstate_make_key
()
77 if
(pthread_key_create
(&swig_pythreadstate_key, NULL) != 0)
78 Py_FatalError
("pthread_key_create failed");
81 inline void swig_pythreadstate_ensure_init
() {
82 pthread_once
(&swig_pythreadstate_key_once, swig_pythreadstate_make_key);
85 inline PyThreadState
* swig_pythreadstate_reset
() {
86 PyThreadState
* v
= (PyThreadState
*)pthread_getspecific
(swig_pythreadstate_key
);
87 if
(v
) pthread_setspecific
(swig_pythreadstate_key
, NULL);
91 inline PyThreadState
* swig_pythreadstate_set
(PyThreadState
* v
) {
92 PyThreadState
* old
= (PyThreadState
*)pthread_getspecific
(swig_pythreadstate_key
);
93 pthread_setspecific
(swig_pythreadstate_key
, (void
*)v
);
99 class XapianSWIG_Python_Thread_Block
{
102 XapianSWIG_Python_Thread_Block
() : status
(false
) {
103 if
(PyEval_ThreadsInitialized
()) {
104 swig_pythreadstate_ensure_init
();
105 PyThreadState
* ts
= swig_pythreadstate_reset
();
108 PyEval_RestoreThread
(ts
);
114 if
(swig_pythreadstate_set
(PyEval_SaveThread
()))
115 Py_FatalError
("swig_pythreadstate set in XapianSWIG_Python_Thread_Block::end()");
119 ~XapianSWIG_Python_Thread_Block
() { end
(); }
122 class XapianSWIG_Python_Thread_Allow
{
125 XapianSWIG_Python_Thread_Allow
() : status
(PyEval_ThreadsInitialized
()) {
127 swig_pythreadstate_ensure_init
();
128 if
(swig_pythreadstate_set
(PyEval_SaveThread
()))
129 Py_FatalError
("swig_pythreadstate set in XapianSWIG_Python_Thread_Allow ctor");
134 PyThreadState
* ts
= swig_pythreadstate_reset
();
136 Py_FatalError
("swig_pythreadstate unset in XapianSWIG_Python_Thread_Block::end()");
137 PyEval_RestoreThread
(ts
);
141 ~XapianSWIG_Python_Thread_Allow
() { end
(); }
144 #define SWIG_PYTHON_THREAD_BEGIN_BLOCK XapianSWIG_Python_Thread_Block _xapian_swig_thread_block
145 #define SWIG_PYTHON_THREAD_END_BLOCK _xapian_swig_thread_block.end
()
146 #define SWIG_PYTHON_THREAD_BEGIN_ALLOW XapianSWIG_Python_Thread_Allow _xapian_swig_thread_allow
147 #define SWIG_PYTHON_THREAD_END_ALLOW _xapian_swig_thread_allow.end
()
150 // Use SWIG directors for Python wrappers.
151 #define XAPIAN_SWIG_DIRECTORS
154 %include ..
/xapian-head.i
156 // Doccomments from Doxgyen-generated XML from C
++ API docs.
157 %include doccomments.i
159 // Manually added exceptions for cases where the automatic comments aren't
160 // helpful
, or are missing.
161 %include extracomments.i
165 #define XAPIAN_MIXED_SUBQUERIES_BY_ITERATOR_TYPEMAP
167 // Don't release the GIL for this method since we use Python C API calls to do
169 %nothreadallow Xapian
::Query
::Query
(op op_
, XapianSWIGQueryItor qbegin
, XapianSWIGQueryItor qend
, Xapian
::termcount parameter
= 0);
171 %typemap
(typecheck
, precedence
=500) (XapianSWIGQueryItor qbegin
, XapianSWIGQueryItor qend
) {
172 // Checking for a sequence is enough to disambiguate currently.
173 $
1 = PySequence_Check
($input
);
177 class XapianSWIGQueryItor
{
178 mutable PyObject
* seq
;
182 /// str_obj must be a string object
(or bytes object for Python
3.x
).
183 Xapian
::Query str_obj_to_query
(PyObject
* str_obj
) const
{
186 #if PY_VERSION_HEX
>= 0x03000000
187 (void
)PyBytes_AsStringAndSize
(str_obj
, &p, &len);
189 (void
)PyString_AsStringAndSize
(str_obj
, &p, &len);
191 return Xapian
::Query
(string
(p
, len
));
195 typedef std
::random_access_iterator_tag iterator_category
;
196 typedef Xapian
::Query value_type
;
197 typedef Xapian
::termcount_diff difference_type
;
198 typedef Xapian
::Query
* pointer
;
199 typedef Xapian
::Query
& reference;
201 XapianSWIGQueryItor
() : seq
(NULL), i
(0) { }
203 void begin
(PyObject
* seq_
) {
207 void end
(PyObject
* seq_
) {
208 i
= PySequence_Fast_GET_SIZE
(seq_
);
215 XapianSWIGQueryItor
& operator++() {
220 Xapian
::Query operator
*() const
{
221 PyObject
* obj
= PySequence_Fast_GET_ITEM
(seq
, i
);
224 if
(PyUnicode_Check
(obj
)) {
225 PyObject
*s
= PyUnicode_EncodeUTF8
(PyUnicode_AS_UNICODE
(obj
),
226 PyUnicode_GET_SIZE
(obj
),
229 Xapian
::Query result
= str_obj_to_query
(s
);
235 #if PY_VERSION_HEX
>= 0x03000000
236 if
(PyBytes_Check
(obj
))
238 if
(PyString_Check
(obj
))
240 return str_obj_to_query
(obj
);
242 // xapian.Query object
(or unexpected object type
).
244 Xapian
::Query
* result_ptr
= Xapian
::get_py_query
(obj
);
245 if
(result_ptr
) return
*result_ptr
;
249 throw Xapian
::InvalidArgumentError
("Expected Query object or string");
252 bool operator
==(const XapianSWIGQueryItor
& o) {
256 bool operator
!=(const XapianSWIGQueryItor
& o) {
257 return
!(*this
== o
);
260 difference_type operator-
(const XapianSWIGQueryItor
&o) const {
267 %typemap
(in
) (XapianSWIGQueryItor qbegin
, XapianSWIGQueryItor qend
) {
269 seq
= PySequence_Fast
($input
,
270 "expected sequence of Query objects and/or strings");
276 %typemap
(freearg
) (XapianSWIGQueryItor qbegin
, XapianSWIGQueryItor qend
)
280 %include ..
/xapian-headers.i