1/*
2 * The SIP module interface.
3 *
4 * Copyright (c) 2020 Riverbank Computing Limited <info@riverbankcomputing.com>
5 *
6 * This file is part of SIP.
7 *
8 * This copy of SIP is licensed for use under the terms of the SIP License
9 * Agreement.  See the file LICENSE for more details.
10 *
11 * This copy of SIP may also used under the terms of the GNU General Public
12 * License v2 or v3 as published by the Free Software Foundation which can be
13 * found in the files LICENSE-GPL2 and LICENSE-GPL3 included in this package.
14 *
15 * SIP is supplied WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 */
18
19
20#ifndef _SIP_H
21#define _SIP_H
22
23
24#include <Python.h>
25
26/* Sanity check on the Python version. */
27#if PY_VERSION_HEX < 0x03050000
28#error "This version of SIP requires Python v3.5 or later"
29#endif
30
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36
37/* The patch version of this implementation of the ABI. */
38#define SIP_MODULE_PATCH_VERSION    4
39
40
41/*
42 * The changes to this version of the ABI.
43 *
44 * Preserve any current exception in the wrapper tp_dealloc functions.
45 */
46
47
48/* The ABI version implemented. */
49#define SIP_ABI_MAJOR_VERSION       @SIP_ABI_MAJOR_VERSION@
50#define SIP_ABI_MINOR_VERSION       @SIP_ABI_MINOR_VERSION@
51
52/* The version of the code generator. */
53#define SIP_VERSION                 @_SIP_VERSION@
54#define SIP_VERSION_STR             "@_SIP_VERSION_STR@"
55
56/* These are all dependent on the user-specified name of the sip module. */
57#define _SIP_MODULE_FQ_NAME         "@_SIP_MODULE_FQ_NAME@"
58#define _SIP_MODULE_NAME            "@_SIP_MODULE_NAME@"
59#define _SIP_MODULE_SHARED          @_SIP_MODULE_SHARED@
60#define _SIP_MODULE_ENTRY           @_SIP_MODULE_ENTRY@
61#define _SIP_MODULE_LEGACY          @_SIP_MODULE_LEGACY@
62
63/* Support the historical names. */
64#define SIP_API_MAJOR_NR    SIP_ABI_MAJOR_VERSION
65#define SIP_API_MINOR_NR    SIP_ABI_MINOR_VERSION
66
67
68/*
69 * Qt includes this typedef and its meta-object system explicitly converts
70 * types to uint.  If these correspond to signal arguments then that conversion
71 * is exposed.  Therefore SIP generates code that uses it.  This definition is
72 * for the cases that SIP is generating non-Qt related bindings with compilers
73 * that don't include it themselves (i.e. MSVC).
74 */
75typedef unsigned int uint;
76
77
78/* Some C++ compatibility stuff. */
79#if defined(__cplusplus)
80
81/*
82 * Cast a PyCFunctionWithKeywords to a PyCFunction in such a way that it
83 * suppresses the GCC -Wcast-function-type warning.
84 */
85#define SIP_MLMETH_CAST(m)  reinterpret_cast<PyCFunction>(reinterpret_cast<void (*)(void)>(m))
86
87#if __cplusplus >= 201103L || defined(_MSVC_LANG)
88
89/* C++11 and later. */
90#define SIP_NULLPTR     nullptr
91#define SIP_OVERRIDE    override
92
93#else
94
95/* Earlier versions of C++. */
96#define SIP_NULLPTR     NULL
97#define SIP_OVERRIDE
98
99#endif
100
101#else
102
103/* Cast a PyCFunctionWithKeywords to a PyCFunction. */
104#define SIP_MLMETH_CAST(m)  ((PyCFunction)(m))
105
106/* C. */
107#define SIP_NULLPTR     NULL
108#define SIP_OVERRIDE
109
110#endif
111
112
113/* Remove in v5.1. */
114#define SIP_SSIZE_T             Py_ssize_t
115#define SIP_SSIZE_T_FORMAT      "%zd"
116#define SIP_USE_PYCAPSULE
117#define SIP_MODULE_RETURN(v)    return (v)
118
119/*
120 * Remove in v5.1.  These are undocumented and can be removed when PyQt5 drops
121 * support for Python v2.
122 */
123#define SIPLong_Check       PyLong_Check
124#define SIPLong_FromLong    PyLong_FromLong
125#define SIPLong_AsLong      PyLong_AsLong
126
127#define SIPBytes_Check      PyBytes_Check
128#define SIPBytes_FromString PyBytes_FromString
129#define SIPBytes_FromStringAndSize  PyBytes_FromStringAndSize
130#define SIPBytes_AsString   PyBytes_AsString
131#define SIPBytes_Size       PyBytes_Size
132#define SIPBytes_AS_STRING  PyBytes_AS_STRING
133#define SIPBytes_GET_SIZE   PyBytes_GET_SIZE
134
135
136/*
137 * The mask that can be passed to sipTrace().
138 */
139#define SIP_TRACE_CATCHERS  0x0001
140#define SIP_TRACE_CTORS     0x0002
141#define SIP_TRACE_DTORS     0x0004
142#define SIP_TRACE_INITS     0x0008
143#define SIP_TRACE_DEALLOCS  0x0010
144#define SIP_TRACE_METHODS   0x0020
145
146
147/*
148 * Hide some thread dependent stuff.
149 */
150#ifdef WITH_THREAD
151typedef PyGILState_STATE sip_gilstate_t;
152#define SIP_RELEASE_GIL(gs) PyGILState_Release(gs);
153#define SIP_BLOCK_THREADS   {PyGILState_STATE sipGIL = PyGILState_Ensure();
154#define SIP_UNBLOCK_THREADS PyGILState_Release(sipGIL);}
155#else
156typedef int sip_gilstate_t;
157#define SIP_RELEASE_GIL(gs)
158#define SIP_BLOCK_THREADS
159#define SIP_UNBLOCK_THREADS
160#endif
161
162
163/*
164 * Forward declarations of types.
165 */
166struct _sipBufferDef;
167typedef struct _sipBufferDef sipBufferDef;
168
169struct _sipBufferInfoDef;
170typedef struct _sipBufferInfoDef sipBufferInfoDef;
171
172struct _sipCFunctionDef;
173typedef struct _sipCFunctionDef sipCFunctionDef;
174
175struct _sipDateDef;
176typedef struct _sipDateDef sipDateDef;
177
178struct _sipEnumTypeObject;
179typedef struct _sipEnumTypeObject sipEnumTypeObject;
180
181struct _sipMethodDef;
182typedef struct _sipMethodDef sipMethodDef;
183
184struct _sipSimpleWrapper;
185typedef struct _sipSimpleWrapper sipSimpleWrapper;
186
187struct _sipTimeDef;
188typedef struct _sipTimeDef sipTimeDef;
189
190struct _sipTypeDef;
191typedef struct _sipTypeDef sipTypeDef;
192
193struct _sipWrapperType;
194typedef struct _sipWrapperType sipWrapperType;
195
196struct _sipWrapper;
197typedef struct _sipWrapper sipWrapper;
198
199
200/*
201 * The different events a handler can be registered for.
202 */
203typedef enum
204{
205    sipEventWrappedInstance,    /* After wrapping a C/C++ instance. */
206    sipEventCollectingWrapper,  /* When garbage collecting a wrapper object. */
207    sipEventNrEvents
208} sipEventType;
209
210/*
211 * The event handlers.
212 */
213typedef void (*sipWrappedInstanceEventHandler)(void *sipCpp);
214typedef void (*sipCollectingWrapperEventHandler)(sipSimpleWrapper *sipSelf);
215
216
217/*
218 * The operation an access function is being asked to perform.
219 */
220typedef enum
221{
222    UnguardedPointer,   /* Return the unguarded pointer. */
223    GuardedPointer,     /* Return the guarded pointer, ie. 0 if it has gone. */
224    ReleaseGuard        /* Release the guard, if any. */
225} AccessFuncOp;
226
227
228/*
229 * Some convenient function pointers.
230 */
231typedef void *(*sipInitFunc)(sipSimpleWrapper *, PyObject *, PyObject *,
232        PyObject **, PyObject **, PyObject **);
233typedef int (*sipFinalFunc)(PyObject *, void *, PyObject *, PyObject **);
234typedef void *(*sipAccessFunc)(sipSimpleWrapper *, AccessFuncOp);
235typedef int (*sipTraverseFunc)(void *, visitproc, void *);
236typedef int (*sipClearFunc)(void *);
237typedef int (*sipGetBufferFuncLimited)(PyObject *, void *, sipBufferDef *);
238typedef void (*sipReleaseBufferFuncLimited)(PyObject *, void *);
239#if !defined(Py_LIMITED_API)
240typedef int (*sipGetBufferFunc)(PyObject *, void *, Py_buffer *, int);
241typedef void (*sipReleaseBufferFunc)(PyObject *, void *, Py_buffer *);
242#endif
243typedef void (*sipDeallocFunc)(sipSimpleWrapper *);
244typedef void *(*sipCastFunc)(void *, const sipTypeDef *);
245typedef const sipTypeDef *(*sipSubClassConvertFunc)(void **);
246typedef int (*sipConvertToFunc)(PyObject *, void **, int *, PyObject *);
247typedef PyObject *(*sipConvertFromFunc)(void *, PyObject *);
248typedef void (*sipVirtErrorHandlerFunc)(sipSimpleWrapper *, sip_gilstate_t);
249typedef int (*sipVirtHandlerFunc)(sip_gilstate_t, sipVirtErrorHandlerFunc,
250        sipSimpleWrapper *, PyObject *, ...);
251typedef void (*sipAssignFunc)(void *, Py_ssize_t, void *);
252typedef void *(*sipArrayFunc)(Py_ssize_t);
253typedef void *(*sipCopyFunc)(const void *, Py_ssize_t);
254typedef void (*sipReleaseFunc)(void *, int);
255typedef PyObject *(*sipPickleFunc)(void *);
256typedef int (*sipAttrGetterFunc)(const sipTypeDef *, PyObject *);
257typedef PyObject *(*sipVariableGetterFunc)(void *, PyObject *, PyObject *);
258typedef int (*sipVariableSetterFunc)(void *, PyObject *, PyObject *);
259typedef void *(*sipProxyResolverFunc)(void *);
260typedef int (*sipNewUserTypeFunc)(sipWrapperType *);
261typedef void (*sipWrapperVisitorFunc)(sipSimpleWrapper *, void *);
262
263
264#if !defined(Py_LIMITED_API)
265/*
266 * The meta-type of a wrapper type.
267 */
268struct _sipWrapperType {
269    /*
270     * The super-metatype.  This must be first in the structure so that it can
271     * be cast to a PyTypeObject *.
272     */
273    PyHeapTypeObject super;
274
275    /* Set if the type is a user implemented Python sub-class. */
276    unsigned wt_user_type : 1;
277
278    /* Set if the type's dictionary contains all lazy attributes. */
279    unsigned wt_dict_complete : 1;
280
281    /* Unused and available for future use. */
282    unsigned wt_unused : 30;
283
284    /* The generated type structure. */
285    sipTypeDef *wt_td;
286
287    /* The list of init extenders. */
288    struct _sipInitExtenderDef *wt_iextend;
289
290    /* The handler called whenever a new user type has been created. */
291    sipNewUserTypeFunc wt_new_user_type_handler;
292
293    /*
294     * For the user to use.  Note that any data structure will leak if the
295     * type is garbage collected.
296     */
297    void *wt_user_data;
298};
299
300
301/*
302 * The type of a simple C/C++ wrapper object.
303 */
304struct _sipSimpleWrapper {
305    PyObject_HEAD
306
307    /*
308     * The data, initially a pointer to the C/C++ object, as interpreted by the
309     * access function.
310     */
311    void *data;
312
313    /* The optional access function. */
314    sipAccessFunc access_func;
315
316    /* Object flags. */
317    unsigned sw_flags;
318
319    /* The optional dictionary of extra references keyed by argument number. */
320    PyObject *extra_refs;
321
322    /* For the user to use. */
323    PyObject *user;
324
325    /* The instance dictionary. */
326    PyObject *dict;
327
328    /* The main instance if this is a mixin. */
329    PyObject *mixin_main;
330
331    /* Next object at this address. */
332    struct _sipSimpleWrapper *next;
333};
334
335
336/*
337 * The type of a C/C++ wrapper object that supports parent/child relationships.
338 */
339struct _sipWrapper {
340    /* The super-type. */
341    sipSimpleWrapper super;
342
343    /* First child object. */
344    struct _sipWrapper *first_child;
345
346    /* Next sibling. */
347    struct _sipWrapper *sibling_next;
348
349    /* Previous sibling. */
350    struct _sipWrapper *sibling_prev;
351
352    /* Owning object. */
353    struct _sipWrapper *parent;
354};
355
356
357/*
358 * Removed in v5.1.
359 * The meta-type of an enum type.  (This is exposed only to support the
360 * deprecated sipConvertFromNamedEnum() macro.)
361 */
362struct _sipEnumTypeObject {
363    /*
364     * The super-metatype.  This must be first in the structure so that it can
365     * be cast to a PyTypeObject *.
366     */
367    PyHeapTypeObject super;
368
369    /* The generated type structure. */
370    struct _sipTypeDef *type;
371};
372#endif
373
374
375/*
376 * The information describing an encoded type ID.
377 */
378typedef struct _sipEncodedTypeDef {
379    /* The type number. */
380    unsigned sc_type : 16;
381
382    /* The module number (255 for this one). */
383    unsigned sc_module : 8;
384
385    /* A context specific flag. */
386    unsigned sc_flag : 1;
387} sipEncodedTypeDef;
388
389
390/*
391 * The information describing an enum member.
392 */
393typedef struct _sipEnumMemberDef {
394    /* The member name. */
395    const char *em_name;
396
397    /* The member value. */
398    int em_val;
399
400    /* The member enum, -ve if anonymous. */
401    int em_enum;
402} sipEnumMemberDef;
403
404
405/*
406 * The information describing static instances.
407 */
408typedef struct _sipInstancesDef {
409    /* The types. */
410    struct _sipTypeInstanceDef *id_type;
411
412    /* The void *. */
413    struct _sipVoidPtrInstanceDef *id_voidp;
414
415    /* The chars. */
416    struct _sipCharInstanceDef *id_char;
417
418    /* The strings. */
419    struct _sipStringInstanceDef *id_string;
420
421    /* The ints. */
422    struct _sipIntInstanceDef *id_int;
423
424    /* The longs. */
425    struct _sipLongInstanceDef *id_long;
426
427    /* The unsigned longs. */
428    struct _sipUnsignedLongInstanceDef *id_ulong;
429
430    /* The long longs. */
431    struct _sipLongLongInstanceDef *id_llong;
432
433    /* The unsigned long longs. */
434    struct _sipUnsignedLongLongInstanceDef *id_ullong;
435
436    /* The doubles. */
437    struct _sipDoubleInstanceDef *id_double;
438} sipInstancesDef;
439
440
441/*
442 * The information describing a type initialiser extender.
443 */
444typedef struct _sipInitExtenderDef {
445    /* The API version range index. */
446    int ie_api_range;
447
448    /* The extender function. */
449    sipInitFunc ie_extender;
450
451    /* The class being extended. */
452    sipEncodedTypeDef ie_class;
453
454    /* The next extender for this class. */
455    struct _sipInitExtenderDef *ie_next;
456} sipInitExtenderDef;
457
458
459/*
460 * The information describing a sub-class convertor.
461 */
462typedef struct _sipSubClassConvertorDef {
463    /* The convertor. */
464    sipSubClassConvertFunc scc_convertor;
465
466    /* The encoded base type. */
467    sipEncodedTypeDef scc_base;
468
469    /* The base type. */
470    struct _sipTypeDef *scc_basetype;
471} sipSubClassConvertorDef;
472
473
474/*
475 * The structure populated by %BIGetBufferCode when the limited API is enabled.
476 */
477struct _sipBufferDef {
478    /* The address of the buffer. */
479    void *bd_buffer;
480
481    /* The length of the buffer. */
482    Py_ssize_t bd_length;
483
484    /* Set if the buffer is read-only. */
485    int bd_readonly;
486};
487
488
489/*
490 * The structure describing a Python buffer.
491 */
492struct _sipBufferInfoDef {
493    /* This is internal to sip. */
494    void *bi_internal;
495
496    /* The address of the buffer. */
497    void *bi_buf;
498
499    /* A reference to the object implementing the buffer interface. */
500    PyObject *bi_obj;
501
502    /* The length of the buffer in bytes. */
503    Py_ssize_t bi_len;
504
505    /* The number of dimensions. */
506    int bi_ndim;
507
508    /* The format of each element of the buffer. */
509    char *bi_format;
510};
511
512
513/*
514 * The structure describing a Python C function.
515 */
516struct _sipCFunctionDef {
517    /* The C function. */
518    PyMethodDef *cf_function;
519
520    /* The optional bound object. */
521    PyObject *cf_self;
522};
523
524
525/*
526 * The structure describing a Python method.
527 */
528struct _sipMethodDef {
529    /* The function that implements the method. */
530    PyObject *pm_function;
531
532    /* The bound object. */
533    PyObject *pm_self;
534};
535
536
537/*
538 * The structure describing a Python date.
539 */
540struct _sipDateDef {
541    /* The year. */
542    int pd_year;
543
544    /* The month (1-12). */
545    int pd_month;
546
547    /* The day (1-31). */
548    int pd_day;
549};
550
551
552/*
553 * The structure describing a Python time.
554 */
555struct _sipTimeDef {
556    /* The hour (0-23). */
557    int pt_hour;
558
559    /* The minute (0-59). */
560    int pt_minute;
561
562    /* The second (0-59). */
563    int pt_second;
564
565    /* The microsecond (0-999999). */
566    int pt_microsecond;
567};
568
569
570/*
571 * The different error states of handwritten code.
572 */
573typedef enum {
574    sipErrorNone,       /* There is no error. */
575    sipErrorFail,       /* The error is a failure. */
576    sipErrorContinue    /* It may not apply if a later operation succeeds. */
577} sipErrorState;
578
579
580/*
581 * The different Python slot types.  New slots must be added to the end,
582 * otherwise the major version of the internal ABI must be changed.
583 */
584typedef enum {
585    str_slot,           /* __str__ */
586    int_slot,           /* __int__ */
587    float_slot,         /* __float__ */
588    len_slot,           /* __len__ */
589    contains_slot,      /* __contains__ */
590    add_slot,           /* __add__ for number */
591    concat_slot,        /* __add__ for sequence types */
592    sub_slot,           /* __sub__ */
593    mul_slot,           /* __mul__ for number types */
594    repeat_slot,        /* __mul__ for sequence types */
595    div_slot,           /* __div__ */
596    mod_slot,           /* __mod__ */
597    floordiv_slot,      /* __floordiv__ */
598    truediv_slot,       /* __truediv__ */
599    and_slot,           /* __and__ */
600    or_slot,            /* __or__ */
601    xor_slot,           /* __xor__ */
602    lshift_slot,        /* __lshift__ */
603    rshift_slot,        /* __rshift__ */
604    iadd_slot,          /* __iadd__ for number types */
605    iconcat_slot,       /* __iadd__ for sequence types */
606    isub_slot,          /* __isub__ */
607    imul_slot,          /* __imul__ for number types */
608    irepeat_slot,       /* __imul__ for sequence types */
609    idiv_slot,          /* __idiv__ */
610    imod_slot,          /* __imod__ */
611    ifloordiv_slot,     /* __ifloordiv__ */
612    itruediv_slot,      /* __itruediv__ */
613    iand_slot,          /* __iand__ */
614    ior_slot,           /* __ior__ */
615    ixor_slot,          /* __ixor__ */
616    ilshift_slot,       /* __ilshift__ */
617    irshift_slot,       /* __irshift__ */
618    invert_slot,        /* __invert__ */
619    call_slot,          /* __call__ */
620    getitem_slot,       /* __getitem__ */
621    setitem_slot,       /* __setitem__ */
622    delitem_slot,       /* __delitem__ */
623    lt_slot,            /* __lt__ */
624    le_slot,            /* __le__ */
625    eq_slot,            /* __eq__ */
626    ne_slot,            /* __ne__ */
627    gt_slot,            /* __gt__ */
628    ge_slot,            /* __ge__ */
629    bool_slot,          /* __bool__, __nonzero__ */
630    neg_slot,           /* __neg__ */
631    repr_slot,          /* __repr__ */
632    hash_slot,          /* __hash__ */
633    pos_slot,           /* __pos__ */
634    abs_slot,           /* __abs__ */
635    index_slot,         /* __index__ */
636    iter_slot,          /* __iter__ */
637    next_slot,          /* __next__ */
638    setattr_slot,       /* __setattr__, __delattr__ */
639    matmul_slot,        /* __matmul__ (for Python v3.5 and later) */
640    imatmul_slot,       /* __imatmul__ (for Python v3.5 and later) */
641    await_slot,         /* __await__ (for Python v3.5 and later) */
642    aiter_slot,         /* __aiter__ (for Python v3.5 and later) */
643    anext_slot,         /* __anext__ (for Python v3.5 and later) */
644} sipPySlotType;
645
646
647/*
648 * The information describing a Python slot function.
649 */
650typedef struct _sipPySlotDef {
651    /* The function. */
652    void *psd_func;
653
654    /* The type. */
655    sipPySlotType psd_type;
656} sipPySlotDef;
657
658
659/*
660 * The information describing a Python slot extender.
661 */
662typedef struct _sipPySlotExtenderDef {
663    /* The function. */
664    void *pse_func;
665
666    /* The type. */
667    sipPySlotType pse_type;
668
669    /* The encoded class. */
670    sipEncodedTypeDef pse_class;
671} sipPySlotExtenderDef;
672
673
674/*
675 * The information describing a typedef.
676 */
677typedef struct _sipTypedefDef {
678    /* The typedef name. */
679    const char *tdd_name;
680
681    /* The typedef value. */
682    const char *tdd_type_name;
683} sipTypedefDef;
684
685
686/*
687 * The information describing a variable or property.
688 */
689
690typedef enum
691{
692    PropertyVariable,       /* A property. */
693    InstanceVariable,       /* An instance variable. */
694    ClassVariable           /* A class (i.e. static) variable. */
695} sipVariableType;
696
697typedef struct _sipVariableDef {
698    /* The type of variable. */
699    sipVariableType vd_type;
700
701    /* The name. */
702    const char *vd_name;
703
704    /*
705     * The getter.  If this is a variable (rather than a property) then the
706     * actual type is sipVariableGetterFunc.
707     */
708    PyMethodDef *vd_getter;
709
710    /*
711     * The setter.  If this is a variable (rather than a property) then the
712     * actual type is sipVariableSetterFunc.  It is NULL if the property cannot
713     * be set or the variable is const.
714     */
715    PyMethodDef *vd_setter;
716
717    /* The property deleter. */
718    PyMethodDef *vd_deleter;
719
720    /* The docstring. */
721    const char *vd_docstring;
722} sipVariableDef;
723
724
725/*
726 * The information describing a type, either a C++ class (or C struct), a C++
727 * namespace, a mapped type or a named enum.
728 */
729struct _sipTypeDef {
730    /* The version range index, -1 if the type isn't versioned. */
731    int td_version;
732
733    /* The next version of this type. */
734    struct _sipTypeDef *td_next_version;
735
736    /*
737     * The module, 0 if the type hasn't been initialised.
738     */
739    struct _sipExportedModuleDef *td_module;
740
741    /* Type flags, see the sipType*() macros. */
742    int td_flags;
743
744    /* The C/C++ name of the type. */
745    int td_cname;
746
747    /* The Python type object. */
748    PyTypeObject *td_py_type;
749
750    /* Any additional fixed data generated by a plugin. */
751    void *td_plugin_data;
752};
753
754
755/*
756 * The information describing a container (ie. a class, namespace or a mapped
757 * type).
758 */
759typedef struct _sipContainerDef {
760    /*
761     * The Python name of the type, -1 if this is a namespace extender (in the
762     * context of a class) or doesn't require a namespace (in the context of a
763     * mapped type). */
764    int cod_name;
765
766    /*
767     * The scoping type or the namespace this is extending if it is a namespace
768     * extender.
769     */
770    sipEncodedTypeDef cod_scope;
771
772    /* The number of lazy methods. */
773    int cod_nrmethods;
774
775    /* The table of lazy methods. */
776    PyMethodDef *cod_methods;
777
778    /* The number of lazy enum members. */
779    int cod_nrenummembers;
780
781    /* The table of lazy enum members. */
782    sipEnumMemberDef *cod_enummembers;
783
784    /* The number of variables. */
785    int cod_nrvariables;
786
787    /* The table of variables. */
788    sipVariableDef *cod_variables;
789
790    /* The static instances. */
791    sipInstancesDef cod_instances;
792} sipContainerDef;
793
794
795/*
796 * The information describing a C++ class (or C struct) or a C++ namespace.
797 */
798typedef struct _sipClassTypeDef {
799    /* The base type information. */
800    sipTypeDef ctd_base;
801
802    /* The container information. */
803    sipContainerDef ctd_container;
804
805    /* The docstring. */
806    const char *ctd_docstring;
807
808    /*
809     * The meta-type name, -1 to use the meta-type of the first super-type
810     * (normally sipWrapperType).
811     */
812    int ctd_metatype;
813
814    /* The super-type name, -1 to use sipWrapper. */
815    int ctd_supertype;
816
817    /* The super-types. */
818    sipEncodedTypeDef *ctd_supers;
819
820    /* The table of Python slots. */
821    sipPySlotDef *ctd_pyslots;
822
823    /* The initialisation function. */
824    sipInitFunc ctd_init;
825
826    /* The traverse function. */
827    sipTraverseFunc ctd_traverse;
828
829    /* The clear function. */
830    sipClearFunc ctd_clear;
831
832    /* The get buffer function. */
833#if defined(Py_LIMITED_API)
834    sipGetBufferFuncLimited ctd_getbuffer;
835#else
836    sipGetBufferFunc ctd_getbuffer;
837#endif
838
839    /* The release buffer function. */
840#if defined(Py_LIMITED_API)
841    sipReleaseBufferFuncLimited ctd_releasebuffer;
842#else
843    sipReleaseBufferFunc ctd_releasebuffer;
844#endif
845
846    /* The deallocation function. */
847    sipDeallocFunc ctd_dealloc;
848
849    /* The optional assignment function. */
850    sipAssignFunc ctd_assign;
851
852    /* The optional array allocation function. */
853    sipArrayFunc ctd_array;
854
855    /* The optional copy function. */
856    sipCopyFunc ctd_copy;
857
858    /* The release function, 0 if a C struct. */
859    sipReleaseFunc ctd_release;
860
861    /* The cast function, 0 if a C struct. */
862    sipCastFunc ctd_cast;
863
864    /* The optional convert to function. */
865    sipConvertToFunc ctd_cto;
866
867    /* The optional convert from function. */
868    sipConvertFromFunc ctd_cfrom;
869
870    /* The next namespace extender. */
871    struct _sipClassTypeDef *ctd_nsextender;
872
873    /* The pickle function. */
874    sipPickleFunc ctd_pickle;
875
876    /* The finalisation function. */
877    sipFinalFunc ctd_final;
878
879    /* The mixin initialisation function. */
880    initproc ctd_init_mixin;
881} sipClassTypeDef;
882
883
884/*
885 * The information describing a mapped type.
886 */
887typedef struct _sipMappedTypeDef {
888    /* The base type information. */
889    sipTypeDef mtd_base;
890
891    /* The container information. */
892    sipContainerDef mtd_container;
893
894    /* The optional assignment function. */
895    sipAssignFunc mtd_assign;
896
897    /* The optional array allocation function. */
898    sipArrayFunc mtd_array;
899
900    /* The optional copy function. */
901    sipCopyFunc mtd_copy;
902
903    /* The optional release function. */
904    sipReleaseFunc mtd_release;
905
906    /* The convert to function. */
907    sipConvertToFunc mtd_cto;
908
909    /* The convert from function. */
910    sipConvertFromFunc mtd_cfrom;
911} sipMappedTypeDef;
912
913
914/*
915 * The information describing a named enum.
916 */
917typedef struct _sipEnumTypeDef {
918    /* The base type information. */
919    sipTypeDef etd_base;
920
921    /* The Python name of the enum. */
922    int etd_name;
923
924    /* The scoping type, -1 if it is defined at the module level. */
925    int etd_scope;
926
927    /* The Python slots. */
928    struct _sipPySlotDef *etd_pyslots;
929} sipEnumTypeDef;
930
931
932/*
933 * The information describing an external type.
934 */
935typedef struct _sipExternalTypeDef {
936    /* The index into the type table. */
937    int et_nr;
938
939    /* The name of the type. */
940    const char *et_name;
941} sipExternalTypeDef;
942
943
944/*
945 * Remove in v5.1.
946 * The information describing a mapped class.  This (and anything that uses it)
947 * is deprecated.
948 */
949typedef sipTypeDef sipMappedType;
950
951
952/*
953 * Defines an entry in the module specific list of delayed dtor calls.
954 */
955typedef struct _sipDelayedDtor {
956    /* The C/C++ instance. */
957    void *dd_ptr;
958
959    /* The class name. */
960    const char *dd_name;
961
962    /* Non-zero if dd_ptr is a derived class instance. */
963    int dd_isderived;
964
965    /* Next in the list. */
966    struct _sipDelayedDtor *dd_next;
967} sipDelayedDtor;
968
969
970/*
971 * Defines an entry in the table of global functions all of whose overloads
972 * are versioned (so their names can't be automatically added to the module
973 * dictionary).
974 */
975typedef struct _sipVersionedFunctionDef {
976    /* The name, -1 marks the end of the table. */
977    int vf_name;
978
979    /* The function itself. */
980    PyCFunction vf_function;
981
982    /* The METH_* flags. */
983    int vf_flags;
984
985    /* The docstring. */
986    const char *vf_docstring;
987
988    /* The API version range index. */
989    int vf_api_range;
990} sipVersionedFunctionDef;
991
992
993/*
994 * Defines a virtual error handler.
995 */
996typedef struct _sipVirtErrorHandlerDef {
997    /* The name of the handler. */
998    const char *veh_name;
999
1000    /* The handler function. */
1001    sipVirtErrorHandlerFunc veh_handler;
1002} sipVirtErrorHandlerDef;
1003
1004
1005/*
1006 * Defines a type imported from another module.
1007 */
1008typedef union _sipImportedTypeDef {
1009    /* The type name before the module is imported. */
1010    const char *it_name;
1011
1012    /* The type after the module is imported. */
1013    sipTypeDef *it_td;
1014} sipImportedTypeDef;
1015
1016
1017/*
1018 * Defines a virtual error handler imported from another module.
1019 */
1020typedef union _sipImportedVirtErrorHandlerDef {
1021    /* The handler name before the module is imported. */
1022    const char *iveh_name;
1023
1024    /* The handler after the module is imported. */
1025    sipVirtErrorHandlerFunc iveh_handler;
1026} sipImportedVirtErrorHandlerDef;
1027
1028
1029/*
1030 * Defines an exception imported from another module.
1031 */
1032typedef union _sipImportedExceptionDef {
1033    /* The exception name before the module is imported. */
1034    const char *iexc_name;
1035
1036    /* The exception object after the module is imported. */
1037    PyObject *iexc_object;
1038} sipImportedExceptionDef;
1039
1040
1041/*
1042 * The information describing an imported module.
1043 */
1044typedef struct _sipImportedModuleDef {
1045    /* The module name. */
1046    const char *im_name;
1047
1048    /* The types imported from the module. */
1049    sipImportedTypeDef *im_imported_types;
1050
1051    /* The virtual error handlers imported from the module. */
1052    sipImportedVirtErrorHandlerDef *im_imported_veh;
1053
1054    /* The exceptions imported from the module. */
1055    sipImportedExceptionDef *im_imported_exceptions;
1056} sipImportedModuleDef;
1057
1058
1059/*
1060 * The main client module structure.
1061 */
1062typedef struct _sipExportedModuleDef {
1063    /* The next in the list. */
1064    struct _sipExportedModuleDef *em_next;
1065
1066    /* The SIP API minor version number. */
1067    unsigned em_api_minor;
1068
1069    /* The module name. */
1070    int em_name;
1071
1072    /* The module name as an object. */
1073    PyObject *em_nameobj;
1074
1075    /* The string pool. */
1076    const char *em_strings;
1077
1078    /* The imported modules. */
1079    sipImportedModuleDef *em_imports;
1080
1081    /* The optional Qt support API. */
1082    struct _sipQtAPI *em_qt_api;
1083
1084    /* The number of types. */
1085    int em_nrtypes;
1086
1087    /* The table of types. */
1088    sipTypeDef **em_types;
1089
1090    /* The table of external types. */
1091    sipExternalTypeDef *em_external;
1092
1093    /* The number of members in global enums. */
1094    int em_nrenummembers;
1095
1096    /* The table of members in global enums. */
1097    sipEnumMemberDef *em_enummembers;
1098
1099    /* The number of typedefs. */
1100    int em_nrtypedefs;
1101
1102    /* The table of typedefs. */
1103    sipTypedefDef *em_typedefs;
1104
1105    /* The table of virtual error handlers. */
1106    sipVirtErrorHandlerDef *em_virterrorhandlers;
1107
1108    /* The sub-class convertors. */
1109    sipSubClassConvertorDef *em_convertors;
1110
1111    /* The static instances. */
1112    sipInstancesDef em_instances;
1113
1114    /* The license. */
1115    struct _sipLicenseDef *em_license;
1116
1117    /* The table of exception types. */
1118    PyObject **em_exceptions;
1119
1120    /* The table of Python slot extenders. */
1121    sipPySlotExtenderDef *em_slotextend;
1122
1123    /* The table of initialiser extenders. */
1124    sipInitExtenderDef *em_initextend;
1125
1126    /* The delayed dtor handler. */
1127    void (*em_delayeddtors)(const sipDelayedDtor *);
1128
1129    /* The list of delayed dtors. */
1130    sipDelayedDtor *em_ddlist;
1131
1132    /*
1133     * The array of API version definitions.  Each definition takes up 3
1134     * elements.  If the third element of a 3-tuple is negative then the first
1135     * two elements define an API and its default version.  All such
1136     * definitions will appear at the end of the array.  If the first element
1137     * of a 3-tuple is negative then that is the last element of the array.
1138     */
1139    int *em_versions;
1140
1141    /* The optional table of versioned functions. */
1142    sipVersionedFunctionDef *em_versioned_functions;
1143} sipExportedModuleDef;
1144
1145
1146/*
1147 * The information describing a license to be added to a dictionary.
1148 */
1149typedef struct _sipLicenseDef {
1150    /* The type of license. */
1151    const char *lc_type;
1152
1153    /* The licensee. */
1154    const char *lc_licensee;
1155
1156    /* The timestamp. */
1157    const char *lc_timestamp;
1158
1159    /* The signature. */
1160    const char *lc_signature;
1161} sipLicenseDef;
1162
1163
1164/*
1165 * The information describing a void pointer instance to be added to a
1166 * dictionary.
1167 */
1168typedef struct _sipVoidPtrInstanceDef {
1169    /* The void pointer name. */
1170    const char *vi_name;
1171
1172    /* The void pointer value. */
1173    void *vi_val;
1174} sipVoidPtrInstanceDef;
1175
1176
1177/*
1178 * The information describing a char instance to be added to a dictionary.
1179 */
1180typedef struct _sipCharInstanceDef {
1181    /* The char name. */
1182    const char *ci_name;
1183
1184    /* The char value. */
1185    char ci_val;
1186
1187    /* The encoding used, either 'A', 'L', '8' or 'N'. */
1188    char ci_encoding;
1189} sipCharInstanceDef;
1190
1191
1192/*
1193 * The information describing a string instance to be added to a dictionary.
1194 * This is also used as a hack to add (or fix) other types rather than add a
1195 * new table type and so requiring a new major version of the API.
1196 */
1197typedef struct _sipStringInstanceDef {
1198    /* The string name. */
1199    const char *si_name;
1200
1201    /* The string value. */
1202    const char *si_val;
1203
1204    /*
1205     * The encoding used, either 'A', 'L', '8' or 'N'.  'w' and 'W' are also
1206     * used to support the fix for wchar_t.
1207     */
1208    char si_encoding;
1209} sipStringInstanceDef;
1210
1211
1212/*
1213 * The information describing an int instance to be added to a dictionary.
1214 */
1215typedef struct _sipIntInstanceDef {
1216    /* The int name. */
1217    const char *ii_name;
1218
1219    /* The int value. */
1220    int ii_val;
1221} sipIntInstanceDef;
1222
1223
1224/*
1225 * The information describing a long instance to be added to a dictionary.
1226 */
1227typedef struct _sipLongInstanceDef {
1228    /* The long name. */
1229    const char *li_name;
1230
1231    /* The long value. */
1232    long li_val;
1233} sipLongInstanceDef;
1234
1235
1236/*
1237 * The information describing an unsigned long instance to be added to a
1238 * dictionary.
1239 */
1240typedef struct _sipUnsignedLongInstanceDef {
1241    /* The unsigned long name. */
1242    const char *uli_name;
1243
1244    /* The unsigned long value. */
1245    unsigned long uli_val;
1246} sipUnsignedLongInstanceDef;
1247
1248
1249/*
1250 * The information describing a long long instance to be added to a dictionary.
1251 */
1252typedef struct _sipLongLongInstanceDef {
1253    /* The long long name. */
1254    const char *lli_name;
1255
1256    /* The long long value. */
1257#if defined(HAVE_LONG_LONG)
1258    PY_LONG_LONG lli_val;
1259#else
1260    long lli_val;
1261#endif
1262} sipLongLongInstanceDef;
1263
1264
1265/*
1266 * The information describing an unsigned long long instance to be added to a
1267 * dictionary.
1268 */
1269typedef struct _sipUnsignedLongLongInstanceDef {
1270    /* The unsigned long long name. */
1271    const char *ulli_name;
1272
1273    /* The unsigned long long value. */
1274#if defined(HAVE_LONG_LONG)
1275    unsigned PY_LONG_LONG ulli_val;
1276#else
1277    unsigned long ulli_val;
1278#endif
1279} sipUnsignedLongLongInstanceDef;
1280
1281
1282/*
1283 * The information describing a double instance to be added to a dictionary.
1284 */
1285typedef struct _sipDoubleInstanceDef {
1286    /* The double name. */
1287    const char *di_name;
1288
1289    /* The double value. */
1290    double di_val;
1291} sipDoubleInstanceDef;
1292
1293
1294/*
1295 * The information describing a class or enum instance to be added to a
1296 * dictionary.
1297 */
1298typedef struct _sipTypeInstanceDef {
1299    /* The type instance name. */
1300    const char *ti_name;
1301
1302    /* The actual instance. */
1303    void *ti_ptr;
1304
1305    /* A pointer to the generated type. */
1306    struct _sipTypeDef **ti_type;
1307
1308    /* The wrapping flags. */
1309    int ti_flags;
1310} sipTypeInstanceDef;
1311
1312
1313/*
1314 * Remove in v5.1.
1315 * Define a mapping between a wrapped type identified by a string and the
1316 * corresponding Python type.
1317 */
1318typedef struct _sipStringTypeClassMap {
1319    /* The type as a string. */
1320    const char *typeString;
1321
1322    /* A pointer to the Python type. */
1323    struct _sipWrapperType **pyType;
1324} sipStringTypeClassMap;
1325
1326
1327/*
1328 * Remove in v5.1.
1329 * Define a mapping between a wrapped type identified by an integer and the
1330 * corresponding Python type.
1331 */
1332typedef struct _sipIntTypeClassMap {
1333    /* The type as an integer. */
1334    int typeInt;
1335
1336    /* A pointer to the Python type. */
1337    struct _sipWrapperType **pyType;
1338} sipIntTypeClassMap;
1339
1340
1341/*
1342 * A Python method's component parts.  This allows us to re-create the method
1343 * without changing the reference counts of the components.
1344 */
1345typedef struct _sipPyMethod {
1346    /* The function. */
1347    PyObject *mfunc;
1348
1349    /* Self if it is a bound method. */
1350    PyObject *mself;
1351} sipPyMethod;
1352
1353
1354/*
1355 * A slot (in the Qt, rather than Python, sense).
1356 */
1357typedef struct _sipSlot {
1358    /* Name if a Qt or Python signal. */
1359    char *name;
1360
1361    /* Signal or Qt slot object. */
1362    PyObject *pyobj;
1363
1364    /* Python slot method, pyobj is NULL. */
1365    sipPyMethod meth;
1366
1367    /* A weak reference to the slot, Py_True if pyobj has an extra reference. */
1368    PyObject *weakSlot;
1369} sipSlot;
1370
1371
1372/*
1373 * The API exported by the SIP module, ie. pointers to all the data and
1374 * functions that can be used by generated code.
1375 */
1376typedef struct _sipAPIDef {
1377    /*
1378     * This must be the first entry and it's signature must not change so that
1379     * version number mismatches can be detected and reported.
1380     */
1381    int (*api_export_module)(sipExportedModuleDef *client, unsigned api_major,
1382            unsigned api_minor, void *unused);
1383
1384    /*
1385     * The following are part of the public API.
1386     */
1387    PyTypeObject *api_simplewrapper_type;
1388    PyTypeObject *api_wrapper_type;
1389    PyTypeObject *api_wrappertype_type;
1390    PyTypeObject *api_voidptr_type;
1391
1392    void (*api_bad_catcher_result)(PyObject *method);
1393    void (*api_bad_length_for_slice)(Py_ssize_t seqlen, Py_ssize_t slicelen);
1394    PyObject *(*api_build_result)(int *isErr, const char *fmt, ...);
1395    PyObject *(*api_call_method)(int *isErr, PyObject *method, const char *fmt,
1396            ...);
1397    void (*api_call_procedure_method)(sip_gilstate_t, sipVirtErrorHandlerFunc,
1398            sipSimpleWrapper *, PyObject *, const char *, ...);
1399    PyObject *(*api_connect_rx)(PyObject *txObj, const char *sig,
1400            PyObject *rxObj, const char *slot, int type);
1401    Py_ssize_t (*api_convert_from_sequence_index)(Py_ssize_t idx,
1402            Py_ssize_t len);
1403    int (*api_can_convert_to_type)(PyObject *pyObj, const sipTypeDef *td,
1404            int flags);
1405    void *(*api_convert_to_type)(PyObject *pyObj, const sipTypeDef *td,
1406            PyObject *transferObj, int flags, int *statep, int *iserrp);
1407    void *(*api_force_convert_to_type)(PyObject *pyObj, const sipTypeDef *td,
1408            PyObject *transferObj, int flags, int *statep, int *iserrp);
1409
1410    /*
1411     * The following are deprecated parts of the public API.
1412     */
1413    int (*api_can_convert_to_enum)(PyObject *pyObj, const sipTypeDef *td);
1414
1415    /*
1416     * The following are part of the public API.
1417     */
1418    void (*api_release_type)(void *cpp, const sipTypeDef *td, int state);
1419    PyObject *(*api_convert_from_type)(void *cpp, const sipTypeDef *td,
1420            PyObject *transferObj);
1421    PyObject *(*api_convert_from_new_type)(void *cpp, const sipTypeDef *td,
1422            PyObject *transferObj);
1423    PyObject *(*api_convert_from_enum)(int eval, const sipTypeDef *td);
1424    int (*api_get_state)(PyObject *transferObj);
1425    PyObject *(*api_disconnect_rx)(PyObject *txObj, const char *sig,
1426            PyObject *rxObj, const char *slot);
1427    void (*api_free)(void *mem);
1428    PyObject *(*api_get_pyobject)(void *cppPtr, const sipTypeDef *td);
1429    void *(*api_malloc)(size_t nbytes);
1430    int (*api_parse_result)(int *isErr, PyObject *method, PyObject *res,
1431            const char *fmt, ...);
1432    void (*api_trace)(unsigned mask, const char *fmt, ...);
1433    void (*api_transfer_back)(PyObject *self);
1434    void (*api_transfer_to)(PyObject *self, PyObject *owner);
1435    void (*api_transfer_break)(PyObject *self);
1436    unsigned long (*api_long_as_unsigned_long)(PyObject *o);
1437    PyObject *(*api_convert_from_void_ptr)(void *val);
1438    PyObject *(*api_convert_from_const_void_ptr)(const void *val);
1439    PyObject *(*api_convert_from_void_ptr_and_size)(void *val,
1440            Py_ssize_t size);
1441    PyObject *(*api_convert_from_const_void_ptr_and_size)(const void *val,
1442            Py_ssize_t size);
1443    void *(*api_convert_to_void_ptr)(PyObject *obj);
1444    int (*api_export_symbol)(const char *name, void *sym);
1445    void *(*api_import_symbol)(const char *name);
1446    const sipTypeDef *(*api_find_type)(const char *type);
1447    int (*api_register_py_type)(PyTypeObject *type);
1448    const sipTypeDef *(*api_type_from_py_type_object)(PyTypeObject *py_type);
1449    const sipTypeDef *(*api_type_scope)(const sipTypeDef *td);
1450    const char *(*api_resolve_typedef)(const char *name);
1451    int (*api_register_attribute_getter)(const sipTypeDef *td,
1452            sipAttrGetterFunc getter);
1453    int (*api_is_api_enabled)(const char *name, int from, int to);
1454    sipErrorState (*api_bad_callable_arg)(int arg_nr, PyObject *arg);
1455    void *(*api_get_address)(struct _sipSimpleWrapper *w);
1456    void (*api_set_destroy_on_exit)(int);
1457    int (*api_enable_autoconversion)(const sipTypeDef *td, int enable);
1458    void *(*api_get_mixin_address)(struct _sipSimpleWrapper *w,
1459            const sipTypeDef *td);
1460    PyObject *(*api_convert_from_new_pytype)(void *cpp, PyTypeObject *py_type,
1461            sipWrapper *owner, sipSimpleWrapper **selfp, const char *fmt, ...);
1462    PyObject *(*api_convert_to_typed_array)(void *data, const sipTypeDef *td,
1463            const char *format, size_t stride, Py_ssize_t len, int flags);
1464    PyObject *(*api_convert_to_array)(void *data, const char *format,
1465            Py_ssize_t len, int flags);
1466    int (*api_register_proxy_resolver)(const sipTypeDef *td,
1467            sipProxyResolverFunc resolver);
1468    PyInterpreterState *(*api_get_interpreter)(void);
1469    sipNewUserTypeFunc (*api_set_new_user_type_handler)(const sipTypeDef *,
1470            sipNewUserTypeFunc);
1471    void (*api_set_type_user_data)(sipWrapperType *, void *);
1472    void *(*api_get_type_user_data)(const sipWrapperType *);
1473    PyObject *(*api_py_type_dict)(const PyTypeObject *);
1474    const char *(*api_py_type_name)(const PyTypeObject *);
1475    int (*api_get_method)(PyObject *, sipMethodDef *);
1476    PyObject *(*api_from_method)(const sipMethodDef *);
1477    int (*api_get_c_function)(PyObject *, sipCFunctionDef *);
1478    int (*api_get_date)(PyObject *, sipDateDef *);
1479    PyObject *(*api_from_date)(const sipDateDef *);
1480    int (*api_get_datetime)(PyObject *, sipDateDef *, sipTimeDef *);
1481    PyObject *(*api_from_datetime)(const sipDateDef *, const sipTimeDef *);
1482    int (*api_get_time)(PyObject *, sipTimeDef *);
1483    PyObject *(*api_from_time)(const sipTimeDef *);
1484    int (*api_is_user_type)(const sipWrapperType *);
1485    struct _frame *(*api_get_frame)(int);
1486    int (*api_check_plugin_for_type)(const sipTypeDef *, const char *);
1487    PyObject *(*api_unicode_new)(Py_ssize_t, unsigned, int *, void **);
1488    void (*api_unicode_write)(int, void *, int, unsigned);
1489    void *(*api_unicode_data)(PyObject *, int *, Py_ssize_t *);
1490    int (*api_get_buffer_info)(PyObject *, sipBufferInfoDef *);
1491    void (*api_release_buffer_info)(sipBufferInfoDef *);
1492    PyObject *(*api_get_user_object)(const sipSimpleWrapper *);
1493    void (*api_set_user_object)(sipSimpleWrapper *, PyObject *);
1494
1495    /*
1496     * The following are not part of the public API.
1497     */
1498    int (*api_init_module)(sipExportedModuleDef *client, PyObject *mod_dict);
1499    int (*api_parse_args)(PyObject **parseErrp, PyObject *sipArgs,
1500            const char *fmt, ...);
1501    int (*api_parse_pair)(PyObject **parseErrp, PyObject *arg0, PyObject *arg1,
1502            const char *fmt, ...);
1503
1504    /*
1505     * The following are part of the public API.
1506     */
1507    void (*api_instance_destroyed)(sipSimpleWrapper *sipSelf);
1508
1509    /*
1510     * The following are not part of the public API.
1511     */
1512    void (*api_no_function)(PyObject *parseErr, const char *func,
1513            const char *doc);
1514    void (*api_no_method)(PyObject *parseErr, const char *scope,
1515            const char *method, const char *doc);
1516    void (*api_abstract_method)(const char *classname, const char *method);
1517    void (*api_bad_class)(const char *classname);
1518    void *(*api_get_cpp_ptr)(sipSimpleWrapper *w, const sipTypeDef *td);
1519    void *(*api_get_complex_cpp_ptr)(sipSimpleWrapper *w);
1520    PyObject *(*api_is_py_method)(sip_gilstate_t *gil, char *pymc,
1521            sipSimpleWrapper *sipSelf, const char *cname, const char *mname);
1522    void (*api_call_hook)(const char *hookname);
1523    void (*api_end_thread)(void);
1524    void (*api_raise_unknown_exception)(void);
1525    void (*api_raise_type_exception)(const sipTypeDef *td, void *ptr);
1526    int (*api_add_type_instance)(PyObject *dict, const char *name,
1527            void *cppPtr, const sipTypeDef *td);
1528    void (*api_bad_operator_arg)(PyObject *self, PyObject *arg,
1529            sipPySlotType st);
1530    PyObject *(*api_pyslot_extend)(sipExportedModuleDef *mod, sipPySlotType st,
1531            const sipTypeDef *type, PyObject *arg0, PyObject *arg1);
1532    void (*api_add_delayed_dtor)(sipSimpleWrapper *w);
1533    char (*api_bytes_as_char)(PyObject *obj);
1534    const char *(*api_bytes_as_string)(PyObject *obj);
1535    char (*api_string_as_ascii_char)(PyObject *obj);
1536    const char *(*api_string_as_ascii_string)(PyObject **obj);
1537    char (*api_string_as_latin1_char)(PyObject *obj);
1538    const char *(*api_string_as_latin1_string)(PyObject **obj);
1539    char (*api_string_as_utf8_char)(PyObject *obj);
1540    const char *(*api_string_as_utf8_string)(PyObject **obj);
1541#if defined(HAVE_WCHAR_H)
1542    wchar_t (*api_unicode_as_wchar)(PyObject *obj);
1543    wchar_t *(*api_unicode_as_wstring)(PyObject *obj);
1544#else
1545    int (*api_unicode_as_wchar)(PyObject *obj);
1546    int *(*api_unicode_as_wstring)(PyObject *obj);
1547#endif
1548    int (*api_deprecated)(const char *classname, const char *method);
1549    void (*api_keep_reference)(PyObject *self, int key, PyObject *obj);
1550    int (*api_parse_kwd_args)(PyObject **parseErrp, PyObject *sipArgs,
1551            PyObject *sipKwdArgs, const char **kwdlist, PyObject **unused,
1552            const char *fmt, ...);
1553    void (*api_add_exception)(sipErrorState es, PyObject **parseErrp);
1554    int (*api_parse_result_ex)(sip_gilstate_t, sipVirtErrorHandlerFunc,
1555            sipSimpleWrapper *, PyObject *method, PyObject *res,
1556            const char *fmt, ...);
1557    void (*api_call_error_handler)(sipVirtErrorHandlerFunc,
1558            sipSimpleWrapper *, sip_gilstate_t);
1559    int (*api_init_mixin)(PyObject *self, PyObject *args, PyObject *kwds,
1560            const sipClassTypeDef *ctd);
1561    PyObject *(*api_get_reference)(PyObject *self, int key);
1562
1563    /*
1564     * The following are part of the public API.
1565     */
1566    int (*api_is_owned_by_python)(sipSimpleWrapper *);
1567
1568    /*
1569     * The following are not part of the public API.
1570     */
1571    int (*api_is_derived_class)(sipSimpleWrapper *);
1572
1573    /*
1574     * The following may be used by Qt support code but no other handwritten
1575     * code.
1576     */
1577    void (*api_free_sipslot)(sipSlot *slot);
1578    int (*api_same_slot)(const sipSlot *sp, PyObject *rxObj, const char *slot);
1579    void *(*api_convert_rx)(sipWrapper *txSelf, const char *sigargs,
1580            PyObject *rxObj, const char *slot, const char **memberp,
1581            int flags);
1582    PyObject *(*api_invoke_slot)(const sipSlot *slot, PyObject *sigargs);
1583    PyObject *(*api_invoke_slot_ex)(const sipSlot *slot, PyObject *sigargs,
1584            int check_receiver);
1585    int (*api_save_slot)(sipSlot *sp, PyObject *rxObj, const char *slot);
1586    void (*api_clear_any_slot_reference)(sipSlot *slot);
1587    int (*api_visit_slot)(sipSlot *slot, visitproc visit, void *arg);
1588
1589    /*
1590     * The following are deprecated parts of the public API.
1591     */
1592    PyTypeObject *(*api_find_named_enum)(const char *type);
1593    const sipMappedType *(*api_find_mapped_type)(const char *type);
1594    sipWrapperType *(*api_find_class)(const char *type);
1595    sipWrapperType *(*api_map_int_to_class)(int typeInt,
1596            const sipIntTypeClassMap *map, int maplen);
1597    sipWrapperType *(*api_map_string_to_class)(const char *typeString,
1598            const sipStringTypeClassMap *map, int maplen);
1599
1600    /*
1601     * The following are part of the public API.
1602     */
1603    int (*api_enable_gc)(int enable);
1604    void (*api_print_object)(PyObject *o);
1605    int (*api_register_event_handler)(sipEventType type, const sipTypeDef *td,
1606            void *handler);
1607    int (*api_convert_to_enum)(PyObject *obj, const sipTypeDef *td);
1608    int (*api_convert_to_bool)(PyObject *obj);
1609    int (*api_enable_overflow_checking)(int enable);
1610    char (*api_long_as_char)(PyObject *o);
1611    signed char (*api_long_as_signed_char)(PyObject *o);
1612    unsigned char (*api_long_as_unsigned_char)(PyObject *o);
1613    short (*api_long_as_short)(PyObject *o);
1614    unsigned short (*api_long_as_unsigned_short)(PyObject *o);
1615    int (*api_long_as_int)(PyObject *o);
1616    unsigned int (*api_long_as_unsigned_int)(PyObject *o);
1617    long (*api_long_as_long)(PyObject *o);
1618#if defined(HAVE_LONG_LONG)
1619    PY_LONG_LONG (*api_long_as_long_long)(PyObject *o);
1620    unsigned PY_LONG_LONG (*api_long_as_unsigned_long_long)(PyObject *o);
1621#else
1622    void *api_long_as_long_long;
1623    void *api_long_as_unsigned_long_long;
1624#endif
1625
1626    /*
1627     * The following are not part of the public API.
1628     */
1629    void (*api_instance_destroyed_ex)(sipSimpleWrapper **sipSelfp);
1630
1631    /*
1632     * The following are part of the public API.
1633     */
1634    int (*api_convert_from_slice_object)(PyObject *slice, Py_ssize_t length,
1635            Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step,
1636            Py_ssize_t *slicelength);
1637    size_t (*api_long_as_size_t)(PyObject *o);
1638    void (*api_visit_wrappers)(sipWrapperVisitorFunc visitor, void *closure);
1639    int (*api_register_exit_notifier)(PyMethodDef *md);
1640} sipAPIDef;
1641
1642const sipAPIDef *sip_init_library(PyObject *mod_dict);
1643
1644
1645/*
1646 * The API implementing the optional Qt support.
1647 */
1648typedef struct _sipQtAPI {
1649    sipTypeDef **qt_qobject;
1650    void *(*qt_create_universal_signal)(void *, const char **);
1651    void *(*qt_find_universal_signal)(void *, const char **);
1652    void *(*qt_create_universal_slot)(struct _sipWrapper *, const char *,
1653            PyObject *, const char *, const char **, int);
1654    void (*qt_destroy_universal_slot)(void *);
1655    void *(*qt_find_slot)(void *, const char *, PyObject *, const char *,
1656            const char **);
1657    int (*qt_connect)(void *, const char *, void *, const char *, int);
1658    int (*qt_disconnect)(void *, const char *, void *, const char *);
1659    int (*qt_same_name)(const char *, const char *);
1660    sipSlot *(*qt_find_sipslot)(void *, void **);
1661    int (*qt_emit_signal)(PyObject *, const char *, PyObject *);
1662    int (*qt_connect_py_signal)(PyObject *, const char *, PyObject *,
1663            const char *);
1664    void (*qt_disconnect_py_signal)(PyObject *, const char *, PyObject *,
1665            const char *);
1666} sipQtAPI;
1667
1668
1669/*
1670 * These are flags that can be passed to sipCanConvertToType(),
1671 * sipConvertToType() and sipForceConvertToType().
1672 */
1673#define SIP_NOT_NONE        0x01    /* Disallow None. */
1674#define SIP_NO_CONVERTORS   0x02    /* Disable any type convertors. */
1675
1676
1677/*
1678 * These are flags that can be passed to sipConvertToArray().  These are held
1679 * in sw_flags.
1680 */
1681#define SIP_READ_ONLY       0x01    /* The array is read-only. */
1682#define SIP_OWNS_MEMORY     0x02    /* The array owns its memory. */
1683
1684
1685/*
1686 * These are the state flags returned by %ConvertToTypeCode.  Note that the
1687 * values share the same "flagspace" as the contents of sw_flags.
1688 */
1689#define SIP_TEMPORARY       0x01    /* A temporary instance. */
1690#define SIP_DERIVED_CLASS   0x02    /* The instance is derived. */
1691
1692
1693/*
1694 * These flags are specific to the Qt support API.
1695 */
1696#define SIP_SINGLE_SHOT     0x01    /* The connection is single shot. */
1697
1698
1699/*
1700 * Useful macros, not part of the public API.
1701 */
1702
1703/* These are held in sw_flags. */
1704#define SIP_INDIRECT        0x0004  /* If there is a level of indirection. */
1705#define SIP_ACCFUNC         0x0008  /* If there is an access function. */
1706#define SIP_NOT_IN_MAP      0x0010  /* If Python object is not in the map. */
1707
1708#if !defined(Py_LIMITED_API)
1709#define SIP_PY_OWNED        0x0020  /* If owned by Python. */
1710#define SIP_SHARE_MAP       0x0040  /* If the map slot might be occupied. */
1711#define SIP_CPP_HAS_REF     0x0080  /* If C/C++ has a reference. */
1712#define SIP_POSSIBLE_PROXY  0x0100  /* If there might be a proxy slot. */
1713#define SIP_ALIAS           0x0200  /* If it is an alias. */
1714#define SIP_CREATED         0x0400  /* If the C/C++ object has been created. */
1715
1716#define sipIsDerived(sw)    ((sw)->sw_flags & SIP_DERIVED_CLASS)
1717#define sipIsIndirect(sw)   ((sw)->sw_flags & SIP_INDIRECT)
1718#define sipIsAccessFunc(sw) ((sw)->sw_flags & SIP_ACCFUNC)
1719#define sipNotInMap(sw)     ((sw)->sw_flags & SIP_NOT_IN_MAP)
1720#define sipSetNotInMap(sw)  ((sw)->sw_flags |= SIP_NOT_IN_MAP)
1721#define sipIsPyOwned(sw)    ((sw)->sw_flags & SIP_PY_OWNED)
1722#define sipSetPyOwned(sw)   ((sw)->sw_flags |= SIP_PY_OWNED)
1723#define sipResetPyOwned(sw) ((sw)->sw_flags &= ~SIP_PY_OWNED)
1724#define sipCppHasRef(sw)    ((sw)->sw_flags & SIP_CPP_HAS_REF)
1725#define sipSetCppHasRef(sw) ((sw)->sw_flags |= SIP_CPP_HAS_REF)
1726#define sipResetCppHasRef(sw)   ((sw)->sw_flags &= ~SIP_CPP_HAS_REF)
1727#define sipPossibleProxy(sw)    ((sw)->sw_flags & SIP_POSSIBLE_PROXY)
1728#define sipSetPossibleProxy(sw) ((sw)->sw_flags |= SIP_POSSIBLE_PROXY)
1729#define sipIsAlias(sw)      ((sw)->sw_flags & SIP_ALIAS)
1730#define sipWasCreated(sw)   ((sw)->sw_flags & SIP_CREATED)
1731#endif
1732
1733#define SIP_TYPE_TYPE_MASK  0x0007  /* The type type mask. */
1734#define SIP_TYPE_CLASS      0x0000  /* If the type is a C++ class. */
1735#define SIP_TYPE_NAMESPACE  0x0001  /* If the type is a C++ namespace. */
1736#define SIP_TYPE_MAPPED     0x0002  /* If the type is a mapped type. */
1737#define SIP_TYPE_ENUM       0x0003  /* If the type is a named enum. */
1738#define SIP_TYPE_SCOPED_ENUM    0x0004  /* If the type is a scoped enum. */
1739#define SIP_TYPE_ABSTRACT   0x0008  /* If the type is abstract. */
1740#define SIP_TYPE_SCC        0x0010  /* If the type is subject to sub-class convertors. */
1741#define SIP_TYPE_ALLOW_NONE 0x0020  /* If the type can handle None. */
1742#define SIP_TYPE_STUB       0x0040  /* If the type is a stub. */
1743#define SIP_TYPE_NONLAZY    0x0080  /* If the type has a non-lazy method. */
1744#define SIP_TYPE_SUPER_INIT 0x0100  /* If the instance's super init should be called. */
1745#define SIP_TYPE_LIMITED_API    0x0200  /* Use the limited API.  If this is more generally required it may need to be moved to the module definition. */
1746
1747
1748/*
1749 * The following are part of the public API.
1750 */
1751#define sipTypeIsClass(td)  (((td)->td_flags & SIP_TYPE_TYPE_MASK) == SIP_TYPE_CLASS)
1752#define sipTypeIsNamespace(td)  (((td)->td_flags & SIP_TYPE_TYPE_MASK) == SIP_TYPE_NAMESPACE)
1753#define sipTypeIsMapped(td) (((td)->td_flags & SIP_TYPE_TYPE_MASK) == SIP_TYPE_MAPPED)
1754#define sipTypeIsEnum(td)   (((td)->td_flags & SIP_TYPE_TYPE_MASK) == SIP_TYPE_ENUM)
1755#define sipTypeIsScopedEnum(td) (((td)->td_flags & SIP_TYPE_TYPE_MASK) == SIP_TYPE_SCOPED_ENUM)
1756#define sipTypeAsPyTypeObject(td)   ((td)->td_py_type)
1757#define sipTypeName(td)     sipNameFromPool((td)->td_module, (td)->td_cname)
1758#define sipTypePluginData(td)   ((td)->td_plugin_data)
1759
1760
1761/*
1762 * Remove in v5.1.
1763 */
1764#define sipClassName(w)     PyString_FromString(Py_TYPE(w)->tp_name)
1765#define sipIsExactWrappedType(wt)   (sipTypeAsPyTypeObject((wt)->wt_td) == (PyTypeObject *)(wt))
1766
1767
1768/*
1769 * The following are not part of the public API.
1770 */
1771#define sipTypeIsAbstract(td)   ((td)->td_flags & SIP_TYPE_ABSTRACT)
1772#define sipTypeHasSCC(td)   ((td)->td_flags & SIP_TYPE_SCC)
1773#define sipTypeAllowNone(td)    ((td)->td_flags & SIP_TYPE_ALLOW_NONE)
1774#define sipTypeIsStub(td)   ((td)->td_flags & SIP_TYPE_STUB)
1775#define sipTypeSetStub(td)  ((td)->td_flags |= SIP_TYPE_STUB)
1776#define sipTypeHasNonlazyMethod(td) ((td)->td_flags & SIP_TYPE_NONLAZY)
1777#define sipTypeCallSuperInit(td)    ((td)->td_flags & SIP_TYPE_SUPER_INIT)
1778#define sipTypeUseLimitedAPI(td)    ((td)->td_flags & SIP_TYPE_LIMITED_API)
1779
1780/*
1781 * Get various names from the string pool for various data types.
1782 */
1783#define sipNameFromPool(em, mr) (&((em)->em_strings)[(mr)])
1784#define sipNameOfModule(em)     sipNameFromPool((em), (em)->em_name)
1785#define sipPyNameOfContainer(cod, td)   sipNameFromPool((td)->td_module, (cod)->cod_name)
1786#define sipPyNameOfEnum(etd)    sipNameFromPool((etd)->etd_base.td_module, (etd)->etd_name)
1787
1788
1789/*
1790 * The following are PyQt4-specific extensions.  In SIP v5 they will be pushed
1791 * out to a plugin supplied by PyQt4.
1792 */
1793
1794/*
1795 * The description of a Qt signal for PyQt4.
1796 */
1797typedef struct _pyqt4QtSignal {
1798    /* The C++ name and signature of the signal. */
1799    const char *signature;
1800
1801    /* The optional docstring. */
1802    const char *docstring;
1803
1804    /*
1805     * If the signal is an overload of regular methods then this points to the
1806     * code that implements those methods.
1807     */
1808    PyMethodDef *non_signals;
1809
1810    /*
1811     * The hack to apply when built against Qt5:
1812     *
1813     * 0 - no hack
1814     * 1 - add an optional None
1815     * 2 - add an optional []
1816     * 3 - add an optional False
1817     */
1818    int hack;
1819} pyqt4QtSignal;
1820
1821
1822/*
1823 * This is the PyQt4-specific extension to the generated class type structure.
1824 */
1825typedef struct _pyqt4ClassPluginDef {
1826    /* A pointer to the QObject sub-class's staticMetaObject class variable. */
1827    const void *static_metaobject;
1828
1829    /*
1830     * A set of flags.  At the moment only bit 0 is used to say if the type is
1831     * derived from QFlags.
1832     */
1833    unsigned flags;
1834
1835    /*
1836     * The table of signals emitted by the type.  These are grouped by signal
1837     * name.
1838     */
1839    const pyqt4QtSignal *qt_signals;
1840} pyqt4ClassPluginDef;
1841
1842
1843/*
1844 * The following are PyQt5-specific extensions.  In SIP v5 they will be pushed
1845 * out to a plugin supplied by PyQt5.
1846 */
1847
1848/*
1849 * The description of a Qt signal for PyQt5.
1850 */
1851typedef int (*pyqt5EmitFunc)(void *, PyObject *);
1852
1853typedef struct _pyqt5QtSignal {
1854    /* The normalised C++ name and signature of the signal. */
1855    const char *signature;
1856
1857    /* The optional docstring. */
1858    const char *docstring;
1859
1860    /*
1861     * If the signal is an overload of regular methods then this points to the
1862     * code that implements those methods.
1863     */
1864    PyMethodDef *non_signals;
1865
1866    /*
1867     * If the signal has optional arguments then this function will implement
1868     * emit() for the signal.
1869     */
1870    pyqt5EmitFunc emitter;
1871} pyqt5QtSignal;
1872
1873
1874/*
1875 * This is the PyQt5-specific extension to the generated class type structure.
1876 */
1877typedef struct _pyqt5ClassPluginDef {
1878    /* A pointer to the QObject sub-class's staticMetaObject class variable. */
1879    const void *static_metaobject;
1880
1881    /*
1882     * A set of flags.  At the moment only bit 0 is used to say if the type is
1883     * derived from QFlags.
1884     */
1885    unsigned flags;
1886
1887    /*
1888     * The table of signals emitted by the type.  These are grouped by signal
1889     * name.
1890     */
1891    const pyqt5QtSignal *qt_signals;
1892
1893    /* The name of the interface that the class defines. */
1894    const char *qt_interface;
1895} pyqt5ClassPluginDef;
1896
1897
1898#ifdef __cplusplus
1899}
1900#endif
1901
1902
1903#endif
1904