LCOV - code coverage report
Current view: top level - build-coverage/swig/python/extensions - gdal_array_wrap.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 1744 2788 62.6 %
Date: 2025-09-10 17:48:50 Functions: 70 114 61.4 %

          Line data    Source code
       1             : /* ----------------------------------------------------------------------------
       2             :  * This file was automatically generated by SWIG (http://www.swig.org).
       3             :  * Version 4.0.1
       4             :  *
       5             :  * This file is not intended to be easily readable and contains a number of
       6             :  * coding conventions designed to improve portability and efficiency. Do not make
       7             :  * changes to this file unless you know what you are doing--modify the SWIG
       8             :  * interface file instead.
       9             :  * ----------------------------------------------------------------------------- */
      10             : 
      11             : 
      12             : #ifndef SWIGPYTHON
      13             : #define SWIGPYTHON
      14             : #endif
      15             : 
      16             : #define SWIG_PYTHON_THREADS
      17             : #define SWIG_PYTHON_DIRECTOR_NO_VTABLE
      18             : 
      19             : 
      20             : #ifdef __cplusplus
      21             : /* SwigValueWrapper is described in swig.swg */
      22             : template<typename T> class SwigValueWrapper {
      23             :   struct SwigMovePointer {
      24             :     T *ptr;
      25             :     SwigMovePointer(T *p) : ptr(p) { }
      26             :     ~SwigMovePointer() { delete ptr; }
      27             :     SwigMovePointer& operator=(SwigMovePointer& rhs) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = rhs.ptr; rhs.ptr = 0; return *this; }
      28             :   } pointer;
      29             :   SwigValueWrapper& operator=(const SwigValueWrapper<T>& rhs);
      30             :   SwigValueWrapper(const SwigValueWrapper<T>& rhs);
      31             : public:
      32             :   SwigValueWrapper() : pointer(0) { }
      33             :   SwigValueWrapper& operator=(const T& t) { SwigMovePointer tmp(new T(t)); pointer = tmp; return *this; }
      34             :   operator T&() const { return *pointer.ptr; }
      35             :   T *operator&() { return pointer.ptr; }
      36             : };
      37             : 
      38             : template <typename T> T SwigValueInit() {
      39             :   return T();
      40             : }
      41             : #endif
      42             : 
      43             : /* -----------------------------------------------------------------------------
      44             :  *  This section contains generic SWIG labels for method/variable
      45             :  *  declarations/attributes, and other compiler dependent labels.
      46             :  * ----------------------------------------------------------------------------- */
      47             : 
      48             : /* template workaround for compilers that cannot correctly implement the C++ standard */
      49             : #ifndef SWIGTEMPLATEDISAMBIGUATOR
      50             : # if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560)
      51             : #  define SWIGTEMPLATEDISAMBIGUATOR template
      52             : # elif defined(__HP_aCC)
      53             : /* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */
      54             : /* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */
      55             : #  define SWIGTEMPLATEDISAMBIGUATOR template
      56             : # else
      57             : #  define SWIGTEMPLATEDISAMBIGUATOR
      58             : # endif
      59             : #endif
      60             : 
      61             : /* inline attribute */
      62             : #ifndef SWIGINLINE
      63             : # if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))
      64             : #   define SWIGINLINE inline
      65             : # else
      66             : #   define SWIGINLINE
      67             : # endif
      68             : #endif
      69             : 
      70             : /* attribute recognised by some compilers to avoid 'unused' warnings */
      71             : #ifndef SWIGUNUSED
      72             : # if defined(__GNUC__)
      73             : #   if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
      74             : #     define SWIGUNUSED __attribute__ ((__unused__))
      75             : #   else
      76             : #     define SWIGUNUSED
      77             : #   endif
      78             : # elif defined(__ICC)
      79             : #   define SWIGUNUSED __attribute__ ((__unused__))
      80             : # else
      81             : #   define SWIGUNUSED
      82             : # endif
      83             : #endif
      84             : 
      85             : #ifndef SWIG_MSC_UNSUPPRESS_4505
      86             : # if defined(_MSC_VER)
      87             : #   pragma warning(disable : 4505) /* unreferenced local function has been removed */
      88             : # endif
      89             : #endif
      90             : 
      91             : #ifndef SWIGUNUSEDPARM
      92             : # ifdef __cplusplus
      93             : #   define SWIGUNUSEDPARM(p)
      94             : # else
      95             : #   define SWIGUNUSEDPARM(p) p SWIGUNUSED
      96             : # endif
      97             : #endif
      98             : 
      99             : /* internal SWIG method */
     100             : #ifndef SWIGINTERN
     101             : # define SWIGINTERN static SWIGUNUSED
     102             : #endif
     103             : 
     104             : /* internal inline SWIG method */
     105             : #ifndef SWIGINTERNINLINE
     106             : # define SWIGINTERNINLINE SWIGINTERN SWIGINLINE
     107             : #endif
     108             : 
     109             : /* exporting methods */
     110             : #if defined(__GNUC__)
     111             : #  if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
     112             : #    ifndef GCC_HASCLASSVISIBILITY
     113             : #      define GCC_HASCLASSVISIBILITY
     114             : #    endif
     115             : #  endif
     116             : #endif
     117             : 
     118             : #ifndef SWIGEXPORT
     119             : # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
     120             : #   if defined(STATIC_LINKED)
     121             : #     define SWIGEXPORT
     122             : #   else
     123             : #     define SWIGEXPORT __declspec(dllexport)
     124             : #   endif
     125             : # else
     126             : #   if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
     127             : #     define SWIGEXPORT __attribute__ ((visibility("default")))
     128             : #   else
     129             : #     define SWIGEXPORT
     130             : #   endif
     131             : # endif
     132             : #endif
     133             : 
     134             : /* calling conventions for Windows */
     135             : #ifndef SWIGSTDCALL
     136             : # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
     137             : #   define SWIGSTDCALL __stdcall
     138             : # else
     139             : #   define SWIGSTDCALL
     140             : # endif
     141             : #endif
     142             : 
     143             : /* Deal with Microsoft's attempt at deprecating C standard runtime functions */
     144             : #if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
     145             : # define _CRT_SECURE_NO_DEPRECATE
     146             : #endif
     147             : 
     148             : /* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */
     149             : #if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE)
     150             : # define _SCL_SECURE_NO_DEPRECATE
     151             : #endif
     152             : 
     153             : /* Deal with Apple's deprecated 'AssertMacros.h' from Carbon-framework */
     154             : #if defined(__APPLE__) && !defined(__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES)
     155             : # define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0
     156             : #endif
     157             : 
     158             : /* Intel's compiler complains if a variable which was never initialised is
     159             :  * cast to void, which is a common idiom which we use to indicate that we
     160             :  * are aware a variable isn't used.  So we just silence that warning.
     161             :  * See: https://github.com/swig/swig/issues/192 for more discussion.
     162             :  */
     163             : #ifdef __INTEL_COMPILER
     164             : # pragma warning disable 592
     165             : #endif
     166             : 
     167             : 
     168             : #if defined(__GNUC__) && defined(_WIN32) && !defined(SWIG_PYTHON_NO_HYPOT_WORKAROUND)
     169             : /* Workaround for '::hypot' has not been declared', see https://bugs.python.org/issue11566 */
     170             : # include <math.h>
     171             : #endif
     172             : 
     173             : #if defined(_DEBUG) && defined(SWIG_PYTHON_INTERPRETER_NO_DEBUG)
     174             : /* Use debug wrappers with the Python release dll */
     175             : # undef _DEBUG
     176             : # include <Python.h>
     177             : # define _DEBUG 1
     178             : #else
     179             : # include <Python.h>
     180             : #endif
     181             : 
     182             : /* -----------------------------------------------------------------------------
     183             :  * swigrun.swg
     184             :  *
     185             :  * This file contains generic C API SWIG runtime support for pointer
     186             :  * type checking.
     187             :  * ----------------------------------------------------------------------------- */
     188             : 
     189             : /* This should only be incremented when either the layout of swig_type_info changes,
     190             :    or for whatever reason, the runtime changes incompatibly */
     191             : #define SWIG_RUNTIME_VERSION "4"
     192             : 
     193             : /* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */
     194             : #ifdef SWIG_TYPE_TABLE
     195             : # define SWIG_QUOTE_STRING(x) #x
     196             : # define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x)
     197             : # define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE)
     198             : #else
     199             : # define SWIG_TYPE_TABLE_NAME
     200             : #endif
     201             : 
     202             : /*
     203             :   You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for
     204             :   creating a static or dynamic library from the SWIG runtime code.
     205             :   In 99.9% of the cases, SWIG just needs to declare them as 'static'.
     206             : 
     207             :   But only do this if strictly necessary, ie, if you have problems
     208             :   with your compiler or suchlike.
     209             : */
     210             : 
     211             : #ifndef SWIGRUNTIME
     212             : # define SWIGRUNTIME SWIGINTERN
     213             : #endif
     214             : 
     215             : #ifndef SWIGRUNTIMEINLINE
     216             : # define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE
     217             : #endif
     218             : 
     219             : /*  Generic buffer size */
     220             : #ifndef SWIG_BUFFER_SIZE
     221             : # define SWIG_BUFFER_SIZE 1024
     222             : #endif
     223             : 
     224             : /* Flags for pointer conversions */
     225             : #define SWIG_POINTER_DISOWN        0x1
     226             : #define SWIG_CAST_NEW_MEMORY       0x2
     227             : #define SWIG_POINTER_NO_NULL       0x4
     228             : 
     229             : /* Flags for new pointer objects */
     230             : #define SWIG_POINTER_OWN           0x1
     231             : 
     232             : 
     233             : /*
     234             :    Flags/methods for returning states.
     235             : 
     236             :    The SWIG conversion methods, as ConvertPtr, return an integer
     237             :    that tells if the conversion was successful or not. And if not,
     238             :    an error code can be returned (see swigerrors.swg for the codes).
     239             : 
     240             :    Use the following macros/flags to set or process the returning
     241             :    states.
     242             : 
     243             :    In old versions of SWIG, code such as the following was usually written:
     244             : 
     245             :      if (SWIG_ConvertPtr(obj,vptr,ty.flags) != -1) {
     246             :        // success code
     247             :      } else {
     248             :        //fail code
     249             :      }
     250             : 
     251             :    Now you can be more explicit:
     252             : 
     253             :     int res = SWIG_ConvertPtr(obj,vptr,ty.flags);
     254             :     if (SWIG_IsOK(res)) {
     255             :       // success code
     256             :     } else {
     257             :       // fail code
     258             :     }
     259             : 
     260             :    which is the same really, but now you can also do
     261             : 
     262             :     Type *ptr;
     263             :     int res = SWIG_ConvertPtr(obj,(void **)(&ptr),ty.flags);
     264             :     if (SWIG_IsOK(res)) {
     265             :       // success code
     266             :       if (SWIG_IsNewObj(res) {
     267             :         ...
     268             :   delete *ptr;
     269             :       } else {
     270             :         ...
     271             :       }
     272             :     } else {
     273             :       // fail code
     274             :     }
     275             : 
     276             :    I.e., now SWIG_ConvertPtr can return new objects and you can
     277             :    identify the case and take care of the deallocation. Of course that
     278             :    also requires SWIG_ConvertPtr to return new result values, such as
     279             : 
     280             :       int SWIG_ConvertPtr(obj, ptr,...) {
     281             :         if (<obj is ok>) {
     282             :           if (<need new object>) {
     283             :             *ptr = <ptr to new allocated object>;
     284             :             return SWIG_NEWOBJ;
     285             :           } else {
     286             :             *ptr = <ptr to old object>;
     287             :             return SWIG_OLDOBJ;
     288             :           }
     289             :         } else {
     290             :           return SWIG_BADOBJ;
     291             :         }
     292             :       }
     293             : 
     294             :    Of course, returning the plain '0(success)/-1(fail)' still works, but you can be
     295             :    more explicit by returning SWIG_BADOBJ, SWIG_ERROR or any of the
     296             :    SWIG errors code.
     297             : 
     298             :    Finally, if the SWIG_CASTRANK_MODE is enabled, the result code
     299             :    allows to return the 'cast rank', for example, if you have this
     300             : 
     301             :        int food(double)
     302             :        int fooi(int);
     303             : 
     304             :    and you call
     305             : 
     306             :       food(1)   // cast rank '1'  (1 -> 1.0)
     307             :       fooi(1)   // cast rank '0'
     308             : 
     309             :    just use the SWIG_AddCast()/SWIG_CheckState()
     310             : */
     311             : 
     312             : #define SWIG_OK                    (0)
     313             : #define SWIG_ERROR                 (-1)
     314             : #define SWIG_IsOK(r)               (r >= 0)
     315             : #define SWIG_ArgError(r)           ((r != SWIG_ERROR) ? r : SWIG_TypeError)
     316             : 
     317             : /* The CastRankLimit says how many bits are used for the cast rank */
     318             : #define SWIG_CASTRANKLIMIT         (1 << 8)
     319             : /* The NewMask denotes the object was created (using new/malloc) */
     320             : #define SWIG_NEWOBJMASK            (SWIG_CASTRANKLIMIT  << 1)
     321             : /* The TmpMask is for in/out typemaps that use temporal objects */
     322             : #define SWIG_TMPOBJMASK            (SWIG_NEWOBJMASK << 1)
     323             : /* Simple returning values */
     324             : #define SWIG_BADOBJ                (SWIG_ERROR)
     325             : #define SWIG_OLDOBJ                (SWIG_OK)
     326             : #define SWIG_NEWOBJ                (SWIG_OK | SWIG_NEWOBJMASK)
     327             : #define SWIG_TMPOBJ                (SWIG_OK | SWIG_TMPOBJMASK)
     328             : /* Check, add and del mask methods */
     329             : #define SWIG_AddNewMask(r)         (SWIG_IsOK(r) ? (r | SWIG_NEWOBJMASK) : r)
     330             : #define SWIG_DelNewMask(r)         (SWIG_IsOK(r) ? (r & ~SWIG_NEWOBJMASK) : r)
     331             : #define SWIG_IsNewObj(r)           (SWIG_IsOK(r) && (r & SWIG_NEWOBJMASK))
     332             : #define SWIG_AddTmpMask(r)         (SWIG_IsOK(r) ? (r | SWIG_TMPOBJMASK) : r)
     333             : #define SWIG_DelTmpMask(r)         (SWIG_IsOK(r) ? (r & ~SWIG_TMPOBJMASK) : r)
     334             : #define SWIG_IsTmpObj(r)           (SWIG_IsOK(r) && (r & SWIG_TMPOBJMASK))
     335             : 
     336             : /* Cast-Rank Mode */
     337             : #if defined(SWIG_CASTRANK_MODE)
     338             : #  ifndef SWIG_TypeRank
     339             : #    define SWIG_TypeRank             unsigned long
     340             : #  endif
     341             : #  ifndef SWIG_MAXCASTRANK            /* Default cast allowed */
     342             : #    define SWIG_MAXCASTRANK          (2)
     343             : #  endif
     344             : #  define SWIG_CASTRANKMASK          ((SWIG_CASTRANKLIMIT) -1)
     345             : #  define SWIG_CastRank(r)           (r & SWIG_CASTRANKMASK)
     346             : SWIGINTERNINLINE int SWIG_AddCast(int r) {
     347             :   return SWIG_IsOK(r) ? ((SWIG_CastRank(r) < SWIG_MAXCASTRANK) ? (r + 1) : SWIG_ERROR) : r;
     348             : }
     349             : SWIGINTERNINLINE int SWIG_CheckState(int r) {
     350             :   return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0;
     351             : }
     352             : #else /* no cast-rank mode */
     353             : #  define SWIG_AddCast(r) (r)
     354             : #  define SWIG_CheckState(r) (SWIG_IsOK(r) ? 1 : 0)
     355             : #endif
     356             : 
     357             : 
     358             : #include <string.h>
     359             : 
     360             : #ifdef __cplusplus
     361             : extern "C" {
     362             : #endif
     363             : 
     364             : typedef void *(*swig_converter_func)(void *, int *);
     365             : typedef struct swig_type_info *(*swig_dycast_func)(void **);
     366             : 
     367             : /* Structure to store information on one type */
     368             : typedef struct swig_type_info {
     369             :   const char             *name;     /* mangled name of this type */
     370             :   const char             *str;      /* human readable name of this type */
     371             :   swig_dycast_func        dcast;    /* dynamic cast function down a hierarchy */
     372             :   struct swig_cast_info  *cast;     /* linked list of types that can cast into this type */
     373             :   void                   *clientdata;   /* language specific type data */
     374             :   int                    owndata;   /* flag if the structure owns the clientdata */
     375             : } swig_type_info;
     376             : 
     377             : /* Structure to store a type and conversion function used for casting */
     378             : typedef struct swig_cast_info {
     379             :   swig_type_info         *type;     /* pointer to type that is equivalent to this type */
     380             :   swig_converter_func     converter;    /* function to cast the void pointers */
     381             :   struct swig_cast_info  *next;     /* pointer to next cast in linked list */
     382             :   struct swig_cast_info  *prev;     /* pointer to the previous cast */
     383             : } swig_cast_info;
     384             : 
     385             : /* Structure used to store module information
     386             :  * Each module generates one structure like this, and the runtime collects
     387             :  * all of these structures and stores them in a circularly linked list.*/
     388             : typedef struct swig_module_info {
     389             :   swig_type_info         **types;   /* Array of pointers to swig_type_info structures that are in this module */
     390             :   size_t                 size;            /* Number of types in this module */
     391             :   struct swig_module_info *next;    /* Pointer to next element in circularly linked list */
     392             :   swig_type_info         **type_initial;  /* Array of initially generated type structures */
     393             :   swig_cast_info         **cast_initial;  /* Array of initially generated casting structures */
     394             :   void                    *clientdata;    /* Language specific module data */
     395             : } swig_module_info;
     396             : 
     397             : /*
     398             :   Compare two type names skipping the space characters, therefore
     399             :   "char*" == "char *" and "Class<int>" == "Class<int >", etc.
     400             : 
     401             :   Return 0 when the two name types are equivalent, as in
     402             :   strncmp, but skipping ' '.
     403             : */
     404             : SWIGRUNTIME int
     405           0 : SWIG_TypeNameComp(const char *f1, const char *l1,
     406             :       const char *f2, const char *l2) {
     407           0 :   for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) {
     408           0 :     while ((*f1 == ' ') && (f1 != l1)) ++f1;
     409           0 :     while ((*f2 == ' ') && (f2 != l2)) ++f2;
     410           0 :     if (*f1 != *f2) return (*f1 > *f2) ? 1 : -1;
     411             :   }
     412           0 :   return (int)((l1 - f1) - (l2 - f2));
     413             : }
     414             : 
     415             : /*
     416             :   Check type equivalence in a name list like <name1>|<name2>|...
     417             :   Return 0 if equal, -1 if nb < tb, 1 if nb > tb
     418             : */
     419             : SWIGRUNTIME int
     420           0 : SWIG_TypeCmp(const char *nb, const char *tb) {
     421           0 :   int equiv = 1;
     422           0 :   const char* te = tb + strlen(tb);
     423           0 :   const char* ne = nb;
     424           0 :   while (equiv != 0 && *ne) {
     425           0 :     for (nb = ne; *ne; ++ne) {
     426           0 :       if (*ne == '|') break;
     427             :     }
     428           0 :     equiv = SWIG_TypeNameComp(nb, ne, tb, te);
     429           0 :     if (*ne) ++ne;
     430             :   }
     431           0 :   return equiv;
     432             : }
     433             : 
     434             : /*
     435             :   Check type equivalence in a name list like <name1>|<name2>|...
     436             :   Return 0 if not equal, 1 if equal
     437             : */
     438             : SWIGRUNTIME int
     439           0 : SWIG_TypeEquiv(const char *nb, const char *tb) {
     440           0 :   return SWIG_TypeCmp(nb, tb) == 0 ? 1 : 0;
     441             : }
     442             : 
     443             : /*
     444             :   Check the typename
     445             : */
     446             : SWIGRUNTIME swig_cast_info *
     447        4050 : SWIG_TypeCheck(const char *c, swig_type_info *ty) {
     448        4050 :   if (ty) {
     449        4050 :     swig_cast_info *iter = ty->cast;
     450        4500 :     while (iter) {
     451        4500 :       if (strcmp(iter->type->name, c) == 0) {
     452        4050 :         if (iter == ty->cast)
     453             :           return iter;
     454             :         /* Move iter to the top of the linked list */
     455         450 :         iter->prev->next = iter->next;
     456         450 :         if (iter->next)
     457           0 :           iter->next->prev = iter->prev;
     458         450 :         iter->next = ty->cast;
     459         450 :         iter->prev = 0;
     460         450 :         if (ty->cast) ty->cast->prev = iter;
     461         450 :         ty->cast = iter;
     462         450 :         return iter;
     463             :       }
     464         450 :       iter = iter->next;
     465             :     }
     466             :   }
     467             :   return 0;
     468             : }
     469             : 
     470             : /*
     471             :   Identical to SWIG_TypeCheck, except strcmp is replaced with a pointer comparison
     472             : */
     473             : SWIGRUNTIME swig_cast_info *
     474             : SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *ty) {
     475             :   if (ty) {
     476             :     swig_cast_info *iter = ty->cast;
     477             :     while (iter) {
     478             :       if (iter->type == from) {
     479             :         if (iter == ty->cast)
     480             :           return iter;
     481             :         /* Move iter to the top of the linked list */
     482             :         iter->prev->next = iter->next;
     483             :         if (iter->next)
     484             :           iter->next->prev = iter->prev;
     485             :         iter->next = ty->cast;
     486             :         iter->prev = 0;
     487             :         if (ty->cast) ty->cast->prev = iter;
     488             :         ty->cast = iter;
     489             :         return iter;
     490             :       }
     491             :       iter = iter->next;
     492             :     }
     493             :   }
     494             :   return 0;
     495             : }
     496             : 
     497             : /*
     498             :   Cast a pointer up an inheritance hierarchy
     499             : */
     500             : SWIGRUNTIMEINLINE void *
     501           0 : SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) {
     502           0 :   return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory);
     503             : }
     504             : 
     505             : /*
     506             :    Dynamic pointer casting. Down an inheritance hierarchy
     507             : */
     508             : SWIGRUNTIME swig_type_info *
     509             : SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) {
     510             :   swig_type_info *lastty = ty;
     511             :   if (!ty || !ty->dcast) return ty;
     512             :   while (ty && (ty->dcast)) {
     513             :     ty = (*ty->dcast)(ptr);
     514             :     if (ty) lastty = ty;
     515             :   }
     516             :   return lastty;
     517             : }
     518             : 
     519             : /*
     520             :   Return the name associated with this type
     521             : */
     522             : SWIGRUNTIMEINLINE const char *
     523             : SWIG_TypeName(const swig_type_info *ty) {
     524             :   return ty->name;
     525             : }
     526             : 
     527             : /*
     528             :   Return the pretty name associated with this type,
     529             :   that is an unmangled type name in a form presentable to the user.
     530             : */
     531             : SWIGRUNTIME const char *
     532           0 : SWIG_TypePrettyName(const swig_type_info *type) {
     533             :   /* The "str" field contains the equivalent pretty names of the
     534             :      type, separated by vertical-bar characters.  We choose
     535             :      to print the last name, as it is often (?) the most
     536             :      specific. */
     537           0 :   if (!type) return NULL;
     538           0 :   if (type->str != NULL) {
     539             :     const char *last_name = type->str;
     540             :     const char *s;
     541           0 :     for (s = type->str; *s; s++)
     542           0 :       if (*s == '|') last_name = s+1;
     543             :     return last_name;
     544             :   }
     545             :   else
     546           0 :     return type->name;
     547             : }
     548             : 
     549             : /*
     550             :    Set the clientdata field for a type
     551             : */
     552             : SWIGRUNTIME void
     553             : SWIG_TypeClientData(swig_type_info *ti, void *clientdata) {
     554             :   swig_cast_info *cast = ti->cast;
     555             :   /* if (ti->clientdata == clientdata) return; */
     556             :   ti->clientdata = clientdata;
     557             : 
     558             :   while (cast) {
     559             :     if (!cast->converter) {
     560             :       swig_type_info *tc = cast->type;
     561             :       if (!tc->clientdata) {
     562             :   SWIG_TypeClientData(tc, clientdata);
     563             :       }
     564             :     }
     565             :     cast = cast->next;
     566             :   }
     567             : }
     568             : SWIGRUNTIME void
     569         225 : SWIG_TypeNewClientData(swig_type_info *ti, void *clientdata) {
     570         225 :   SWIG_TypeClientData(ti, clientdata);
     571         225 :   ti->owndata = 1;
     572             : }
     573             : 
     574             : /*
     575             :   Search for a swig_type_info structure only by mangled name
     576             :   Search is a O(log #types)
     577             : 
     578             :   We start searching at module start, and finish searching when start == end.
     579             :   Note: if start == end at the beginning of the function, we go all the way around
     580             :   the circular list.
     581             : */
     582             : SWIGRUNTIME swig_type_info *
     583        9675 : SWIG_MangledTypeQueryModule(swig_module_info *start,
     584             :                             swig_module_info *end,
     585             :                 const char *name) {
     586        9675 :   swig_module_info *iter = start;
     587       29700 :   do {
     588       29700 :     if (iter->size) {
     589       29700 :       size_t l = 0;
     590       29700 :       size_t r = iter->size - 1;
     591      116775 :       do {
     592             :   /* since l+r >= 0, we can (>> 1) instead (/ 2) */
     593      116775 :   size_t i = (l + r) >> 1;
     594      116775 :   const char *iname = iter->types[i]->name;
     595      116775 :   if (iname) {
     596      116775 :     int compare = strcmp(name, iname);
     597      116775 :     if (compare == 0) {
     598        7875 :       return iter->types[i];
     599      108900 :     } else if (compare < 0) {
     600       61200 :       if (i) {
     601       50850 :         r = i - 1;
     602             :       } else {
     603             :         break;
     604             :       }
     605       47700 :     } else if (compare > 0) {
     606       47700 :       l = i + 1;
     607             :     }
     608             :   } else {
     609             :     break; /* should never happen */
     610             :   }
     611       98550 :       } while (l <= r);
     612             :     }
     613       21825 :     iter = iter->next;
     614       21825 :   } while (iter != end);
     615             :   return 0;
     616             : }
     617             : 
     618             : /*
     619             :   Search for a swig_type_info structure for either a mangled name or a human readable name.
     620             :   It first searches the mangled names of the types, which is a O(log #types)
     621             :   If a type is not found it then searches the human readable names, which is O(#types).
     622             : 
     623             :   We start searching at module start, and finish searching when start == end.
     624             :   Note: if start == end at the beginning of the function, we go all the way around
     625             :   the circular list.
     626             : */
     627             : SWIGRUNTIME swig_type_info *
     628           0 : SWIG_TypeQueryModule(swig_module_info *start,
     629             :                      swig_module_info *end,
     630             :          const char *name) {
     631             :   /* STEP 1: Search the name field using binary search */
     632           0 :   swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name);
     633           0 :   if (ret) {
     634             :     return ret;
     635             :   } else {
     636             :     /* STEP 2: If the type hasn't been found, do a complete search
     637             :        of the str field (the human readable name) */
     638             :     swig_module_info *iter = start;
     639           0 :     do {
     640           0 :       size_t i = 0;
     641           0 :       for (; i < iter->size; ++i) {
     642           0 :   if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name)))
     643           0 :     return iter->types[i];
     644             :       }
     645           0 :       iter = iter->next;
     646           0 :     } while (iter != end);
     647             :   }
     648             : 
     649             :   /* neither found a match */
     650             :   return 0;
     651             : }
     652             : 
     653             : /*
     654             :    Pack binary data into a string
     655             : */
     656             : SWIGRUNTIME char *
     657           0 : SWIG_PackData(char *c, void *ptr, size_t sz) {
     658           0 :   static const char hex[17] = "0123456789abcdef";
     659           0 :   const unsigned char *u = (unsigned char *) ptr;
     660           0 :   const unsigned char *eu =  u + sz;
     661           0 :   for (; u != eu; ++u) {
     662           0 :     unsigned char uu = *u;
     663           0 :     *(c++) = hex[(uu & 0xf0) >> 4];
     664           0 :     *(c++) = hex[uu & 0xf];
     665             :   }
     666           0 :   return c;
     667             : }
     668             : 
     669             : /*
     670             :    Unpack binary data from a string
     671             : */
     672             : SWIGRUNTIME const char *
     673             : SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
     674             :   unsigned char *u = (unsigned char *) ptr;
     675             :   const unsigned char *eu = u + sz;
     676             :   for (; u != eu; ++u) {
     677             :     char d = *(c++);
     678             :     unsigned char uu;
     679             :     if ((d >= '0') && (d <= '9'))
     680             :       uu = (unsigned char)((d - '0') << 4);
     681             :     else if ((d >= 'a') && (d <= 'f'))
     682             :       uu = (unsigned char)((d - ('a'-10)) << 4);
     683             :     else
     684             :       return (char *) 0;
     685             :     d = *(c++);
     686             :     if ((d >= '0') && (d <= '9'))
     687             :       uu |= (unsigned char)(d - '0');
     688             :     else if ((d >= 'a') && (d <= 'f'))
     689             :       uu |= (unsigned char)(d - ('a'-10));
     690             :     else
     691             :       return (char *) 0;
     692             :     *u = uu;
     693             :   }
     694             :   return c;
     695             : }
     696             : 
     697             : /*
     698             :    Pack 'void *' into a string buffer.
     699             : */
     700             : SWIGRUNTIME char *
     701           0 : SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) {
     702           0 :   char *r = buff;
     703           0 :   if ((2*sizeof(void *) + 2) > bsz) return 0;
     704           0 :   *(r++) = '_';
     705           0 :   r = SWIG_PackData(r,&ptr,sizeof(void *));
     706           0 :   if (strlen(name) + 1 > (bsz - (r - buff))) return 0;
     707           0 :   strcpy(r,name);
     708           0 :   return buff;
     709             : }
     710             : 
     711             : SWIGRUNTIME const char *
     712             : SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) {
     713             :   if (*c != '_') {
     714             :     if (strcmp(c,"NULL") == 0) {
     715             :       *ptr = (void *) 0;
     716             :       return name;
     717             :     } else {
     718             :       return 0;
     719             :     }
     720             :   }
     721             :   return SWIG_UnpackData(++c,ptr,sizeof(void *));
     722             : }
     723             : 
     724             : SWIGRUNTIME char *
     725           0 : SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) {
     726           0 :   char *r = buff;
     727           0 :   size_t lname = (name ? strlen(name) : 0);
     728           0 :   if ((2*sz + 2 + lname) > bsz) return 0;
     729           0 :   *(r++) = '_';
     730           0 :   r = SWIG_PackData(r,ptr,sz);
     731           0 :   if (lname) {
     732           0 :     strncpy(r,name,lname+1);
     733             :   } else {
     734           0 :     *r = 0;
     735             :   }
     736             :   return buff;
     737             : }
     738             : 
     739             : SWIGRUNTIME const char *
     740             : SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) {
     741             :   if (*c != '_') {
     742             :     if (strcmp(c,"NULL") == 0) {
     743             :       memset(ptr,0,sz);
     744             :       return name;
     745             :     } else {
     746             :       return 0;
     747             :     }
     748             :   }
     749             :   return SWIG_UnpackData(++c,ptr,sz);
     750             : }
     751             : 
     752             : #ifdef __cplusplus
     753             : }
     754             : #endif
     755             : 
     756             : /*  Errors in SWIG */
     757             : #define  SWIG_UnknownError         -1
     758             : #define  SWIG_IOError            -2
     759             : #define  SWIG_RuntimeError       -3
     760             : #define  SWIG_IndexError         -4
     761             : #define  SWIG_TypeError          -5
     762             : #define  SWIG_DivisionByZero     -6
     763             : #define  SWIG_OverflowError      -7
     764             : #define  SWIG_SyntaxError        -8
     765             : #define  SWIG_ValueError         -9
     766             : #define  SWIG_SystemError        -10
     767             : #define  SWIG_AttributeError     -11
     768             : #define  SWIG_MemoryError        -12
     769             : #define  SWIG_NullReferenceError   -13
     770             : 
     771             : 
     772             : 
     773             : /* Compatibility macros for Python 3 */
     774             : #if PY_VERSION_HEX >= 0x03000000
     775             : 
     776             : #define PyClass_Check(obj) PyObject_IsInstance(obj, (PyObject *)&PyType_Type)
     777             : #define PyInt_Check(x) PyLong_Check(x)
     778             : #define PyInt_AsLong(x) PyLong_AsLong(x)
     779             : #define PyInt_FromLong(x) PyLong_FromLong(x)
     780             : #define PyInt_FromSize_t(x) PyLong_FromSize_t(x)
     781             : #define PyString_Check(name) PyBytes_Check(name)
     782             : #define PyString_FromString(x) PyUnicode_FromString(x)
     783             : #define PyString_Format(fmt, args)  PyUnicode_Format(fmt, args)
     784             : #define PyString_AsString(str) PyBytes_AsString(str)
     785             : #define PyString_Size(str) PyBytes_Size(str)  
     786             : #define PyString_InternFromString(key) PyUnicode_InternFromString(key)
     787             : #define Py_TPFLAGS_HAVE_CLASS Py_TPFLAGS_BASETYPE
     788             : #define PyString_AS_STRING(x) PyUnicode_AS_STRING(x)
     789             : #define _PyLong_FromSsize_t(x) PyLong_FromSsize_t(x)
     790             : 
     791             : #endif
     792             : 
     793             : #ifndef Py_TYPE
     794             : #  define Py_TYPE(op) ((op)->ob_type)
     795             : #endif
     796             : 
     797             : /* SWIG APIs for compatibility of both Python 2 & 3 */
     798             : 
     799             : #if PY_VERSION_HEX >= 0x03000000
     800             : #  define SWIG_Python_str_FromFormat PyUnicode_FromFormat
     801             : #else
     802             : #  define SWIG_Python_str_FromFormat PyString_FromFormat
     803             : #endif
     804             : 
     805             : 
     806             : /* Warning: This function will allocate a new string in Python 3,
     807             :  * so please call SWIG_Python_str_DelForPy3(x) to free the space.
     808             :  */
     809             : SWIGINTERN char*
     810             : SWIG_Python_str_AsChar(PyObject *str)
     811             : {
     812             : #if PY_VERSION_HEX >= 0x03000000
     813             :   char *newstr = 0;
     814             :   str = PyUnicode_AsUTF8String(str);
     815             :   if (str) {
     816             :     char *cstr;
     817             :     Py_ssize_t len;
     818             :     PyBytes_AsStringAndSize(str, &cstr, &len);
     819             :     newstr = (char *) malloc(len+1);
     820             :     memcpy(newstr, cstr, len+1);
     821             :     Py_XDECREF(str);
     822             :   }
     823             :   return newstr;
     824             : #else
     825             :   return PyString_AsString(str);
     826             : #endif
     827             : }
     828             : 
     829             : #if PY_VERSION_HEX >= 0x03000000
     830             : #  define SWIG_Python_str_DelForPy3(x) free( (void*) (x) )
     831             : #else
     832             : #  define SWIG_Python_str_DelForPy3(x) 
     833             : #endif
     834             : 
     835             : 
     836             : SWIGINTERN PyObject*
     837         225 : SWIG_Python_str_FromChar(const char *c)
     838             : {
     839             : #if PY_VERSION_HEX >= 0x03000000
     840         225 :   return PyUnicode_FromString(c); 
     841             : #else
     842             :   return PyString_FromString(c);
     843             : #endif
     844             : }
     845             : 
     846             : #ifndef PyObject_DEL
     847             : # define PyObject_DEL PyObject_Del
     848             : #endif
     849             : 
     850             : // SWIGPY_USE_CAPSULE is no longer used within SWIG itself, but some user
     851             : // interface files check for it.
     852             : # define SWIGPY_USE_CAPSULE
     853             : # define SWIGPY_CAPSULE_NAME ("swig_runtime_data" SWIG_RUNTIME_VERSION ".type_pointer_capsule" SWIG_TYPE_TABLE_NAME)
     854             : 
     855             : #if PY_VERSION_HEX < 0x03020000
     856             : #define PyDescr_TYPE(x) (((PyDescrObject *)(x))->d_type)
     857             : #define PyDescr_NAME(x) (((PyDescrObject *)(x))->d_name)
     858             : #define Py_hash_t long
     859             : #endif
     860             : 
     861             : /* -----------------------------------------------------------------------------
     862             :  * error manipulation
     863             :  * ----------------------------------------------------------------------------- */
     864             : 
     865             : SWIGRUNTIME PyObject*
     866          37 : SWIG_Python_ErrorType(int code) {
     867          37 :   PyObject* type = 0;
     868           2 :   switch(code) {
     869           0 :   case SWIG_MemoryError:
     870           0 :     type = PyExc_MemoryError;
     871           0 :     break;
     872           0 :   case SWIG_IOError:
     873           0 :     type = PyExc_IOError;
     874           0 :     break;
     875          31 :   case SWIG_RuntimeError:
     876          31 :     type = PyExc_RuntimeError;
     877           0 :     break;
     878           0 :   case SWIG_IndexError:
     879           0 :     type = PyExc_IndexError;
     880           0 :     break;
     881           2 :   case SWIG_TypeError:
     882           2 :     type = PyExc_TypeError;
     883           2 :     break;
     884           0 :   case SWIG_DivisionByZero:
     885           0 :     type = PyExc_ZeroDivisionError;
     886           0 :     break;
     887           0 :   case SWIG_OverflowError:
     888           0 :     type = PyExc_OverflowError;
     889           0 :     break;
     890           0 :   case SWIG_SyntaxError:
     891           0 :     type = PyExc_SyntaxError;
     892           0 :     break;
     893           4 :   case SWIG_ValueError:
     894           4 :     type = PyExc_ValueError;
     895           0 :     break;
     896           0 :   case SWIG_SystemError:
     897           0 :     type = PyExc_SystemError;
     898           0 :     break;
     899           0 :   case SWIG_AttributeError:
     900           0 :     type = PyExc_AttributeError;
     901           0 :     break;
     902           0 :   default:
     903           0 :     type = PyExc_RuntimeError;
     904             :   }
     905          37 :   return type;
     906             : }
     907             : 
     908             : 
     909             : SWIGRUNTIME void
     910             : SWIG_Python_AddErrorMsg(const char* mesg)
     911             : {
     912             :   PyObject *type = 0;
     913             :   PyObject *value = 0;
     914             :   PyObject *traceback = 0;
     915             : 
     916             :   if (PyErr_Occurred())
     917             :     PyErr_Fetch(&type, &value, &traceback);
     918             :   if (value) {
     919             :     PyObject *old_str = PyObject_Str(value);
     920             :     const char *tmp = SWIG_Python_str_AsChar(old_str);
     921             :     PyErr_Clear();
     922             :     Py_XINCREF(type);
     923             :     if (tmp)
     924             :       PyErr_Format(type, "%s %s", tmp, mesg);
     925             :     else
     926             :       PyErr_Format(type, "%s", mesg);
     927             :     SWIG_Python_str_DelForPy3(tmp);
     928             :     Py_DECREF(old_str);
     929             :     Py_DECREF(value);
     930             :   } else {
     931             :     PyErr_SetString(PyExc_RuntimeError, mesg);
     932             :   }
     933             : }
     934             : 
     935             : SWIGRUNTIME int
     936           0 : SWIG_Python_TypeErrorOccurred(PyObject *obj)
     937             : {
     938           0 :   PyObject *error;
     939           0 :   if (obj)
     940             :     return 0;
     941           0 :   error = PyErr_Occurred();
     942           0 :   return error && PyErr_GivenExceptionMatches(error, PyExc_TypeError);
     943             : }
     944             : 
     945             : SWIGRUNTIME void
     946           0 : SWIG_Python_RaiseOrModifyTypeError(const char *message)
     947             : {
     948           0 :   if (SWIG_Python_TypeErrorOccurred(NULL)) {
     949             :     /* Use existing TypeError to preserve stacktrace and enhance with given message */
     950           0 :     PyObject *newvalue;
     951           0 :     PyObject *type = NULL, *value = NULL, *traceback = NULL;
     952           0 :     PyErr_Fetch(&type, &value, &traceback);
     953             : #if PY_VERSION_HEX >= 0x03000000
     954           0 :     newvalue = PyUnicode_FromFormat("%S\nAdditional information:\n%s", value, message);
     955             : #else
     956             :     newvalue = PyString_FromFormat("%s\nAdditional information:\n%s", PyString_AsString(value), message);
     957             : #endif
     958           0 :     Py_XDECREF(value);
     959           0 :     PyErr_Restore(type, newvalue, traceback);
     960             :   } else {
     961             :     /* Raise TypeError using given message */
     962           0 :     PyErr_SetString(PyExc_TypeError, message);
     963             :   }
     964           0 : }
     965             : 
     966             : #if defined(SWIG_PYTHON_NO_THREADS)
     967             : #  if defined(SWIG_PYTHON_THREADS)
     968             : #    undef SWIG_PYTHON_THREADS
     969             : #  endif
     970             : #endif
     971             : #if defined(SWIG_PYTHON_THREADS) /* Threading support is enabled */
     972             : #  if !defined(SWIG_PYTHON_USE_GIL) && !defined(SWIG_PYTHON_NO_USE_GIL)
     973             : #    define SWIG_PYTHON_USE_GIL
     974             : #  endif
     975             : #  if defined(SWIG_PYTHON_USE_GIL) /* Use PyGILState threads calls */
     976             : #    ifndef SWIG_PYTHON_INITIALIZE_THREADS
     977             : #     define SWIG_PYTHON_INITIALIZE_THREADS  PyEval_InitThreads() 
     978             : #    endif
     979             : #    ifdef __cplusplus /* C++ code */
     980             :        class SWIG_Python_Thread_Block {
     981             :          bool status;
     982             :          PyGILState_STATE state;
     983             :        public:
     984         960 :          void end() { if (status) { PyGILState_Release(state); status = false;} }
     985         696 :          SWIG_Python_Thread_Block() : status(true), state(PyGILState_Ensure()) {}
     986         264 :          ~SWIG_Python_Thread_Block() { end(); }
     987             :        };
     988             :        class SWIG_Python_Thread_Allow {
     989             :          bool status;
     990             :          PyThreadState *save;
     991             :        public:
     992       84558 :          void end() { if (status) { PyEval_RestoreThread(save); status = false; }}
     993       84558 :          SWIG_Python_Thread_Allow() : status(true), save(PyEval_SaveThread()) {}
     994           0 :          ~SWIG_Python_Thread_Allow() { end(); }
     995             :        };
     996             : #      define SWIG_PYTHON_THREAD_BEGIN_BLOCK   SWIG_Python_Thread_Block _swig_thread_block
     997             : #      define SWIG_PYTHON_THREAD_END_BLOCK     _swig_thread_block.end()
     998             : #      define SWIG_PYTHON_THREAD_BEGIN_ALLOW   SWIG_Python_Thread_Allow _swig_thread_allow
     999             : #      define SWIG_PYTHON_THREAD_END_ALLOW     _swig_thread_allow.end()
    1000             : #    else /* C code */
    1001             : #      define SWIG_PYTHON_THREAD_BEGIN_BLOCK   PyGILState_STATE _swig_thread_block = PyGILState_Ensure()
    1002             : #      define SWIG_PYTHON_THREAD_END_BLOCK     PyGILState_Release(_swig_thread_block)
    1003             : #      define SWIG_PYTHON_THREAD_BEGIN_ALLOW   PyThreadState *_swig_thread_allow = PyEval_SaveThread()
    1004             : #      define SWIG_PYTHON_THREAD_END_ALLOW     PyEval_RestoreThread(_swig_thread_allow)
    1005             : #    endif
    1006             : #  else /* Old thread way, not implemented, user must provide it */
    1007             : #    if !defined(SWIG_PYTHON_INITIALIZE_THREADS)
    1008             : #      define SWIG_PYTHON_INITIALIZE_THREADS
    1009             : #    endif
    1010             : #    if !defined(SWIG_PYTHON_THREAD_BEGIN_BLOCK)
    1011             : #      define SWIG_PYTHON_THREAD_BEGIN_BLOCK
    1012             : #    endif
    1013             : #    if !defined(SWIG_PYTHON_THREAD_END_BLOCK)
    1014             : #      define SWIG_PYTHON_THREAD_END_BLOCK
    1015             : #    endif
    1016             : #    if !defined(SWIG_PYTHON_THREAD_BEGIN_ALLOW)
    1017             : #      define SWIG_PYTHON_THREAD_BEGIN_ALLOW
    1018             : #    endif
    1019             : #    if !defined(SWIG_PYTHON_THREAD_END_ALLOW)
    1020             : #      define SWIG_PYTHON_THREAD_END_ALLOW
    1021             : #    endif
    1022             : #  endif
    1023             : #else /* No thread support */
    1024             : #  define SWIG_PYTHON_INITIALIZE_THREADS
    1025             : #  define SWIG_PYTHON_THREAD_BEGIN_BLOCK
    1026             : #  define SWIG_PYTHON_THREAD_END_BLOCK
    1027             : #  define SWIG_PYTHON_THREAD_BEGIN_ALLOW
    1028             : #  define SWIG_PYTHON_THREAD_END_ALLOW
    1029             : #endif
    1030             : 
    1031             : /* -----------------------------------------------------------------------------
    1032             :  * Python API portion that goes into the runtime
    1033             :  * ----------------------------------------------------------------------------- */
    1034             : 
    1035             : #ifdef __cplusplus
    1036             : extern "C" {
    1037             : #endif
    1038             : 
    1039             : /* -----------------------------------------------------------------------------
    1040             :  * Constant declarations
    1041             :  * ----------------------------------------------------------------------------- */
    1042             : 
    1043             : /* Constant Types */
    1044             : #define SWIG_PY_POINTER 4
    1045             : #define SWIG_PY_BINARY  5
    1046             : 
    1047             : /* Constant information structure */
    1048             : typedef struct swig_const_info {
    1049             :   int type;
    1050             :   const char *name;
    1051             :   long lvalue;
    1052             :   double dvalue;
    1053             :   void   *pvalue;
    1054             :   swig_type_info **ptype;
    1055             : } swig_const_info;
    1056             : 
    1057             : #ifdef __cplusplus
    1058             : }
    1059             : #endif
    1060             : 
    1061             : 
    1062             : /* -----------------------------------------------------------------------------
    1063             :  * pyrun.swg
    1064             :  *
    1065             :  * This file contains the runtime support for Python modules
    1066             :  * and includes code for managing global variables and pointer
    1067             :  * type checking.
    1068             :  *
    1069             :  * ----------------------------------------------------------------------------- */
    1070             : 
    1071             : #if PY_VERSION_HEX < 0x02070000 /* 2.7.0 */
    1072             : # error "This version of SWIG only supports Python >= 2.7"
    1073             : #endif
    1074             : 
    1075             : #if PY_VERSION_HEX >= 0x03000000 && PY_VERSION_HEX < 0x03020000
    1076             : # error "This version of SWIG only supports Python 3 >= 3.2"
    1077             : #endif
    1078             : 
    1079             : /* Common SWIG API */
    1080             : 
    1081             : /* for raw pointers */
    1082             : #define SWIG_Python_ConvertPtr(obj, pptr, type, flags)  SWIG_Python_ConvertPtrAndOwn(obj, pptr, type, flags, 0)
    1083             : #define SWIG_ConvertPtr(obj, pptr, type, flags)         SWIG_Python_ConvertPtr(obj, pptr, type, flags)
    1084             : #define SWIG_ConvertPtrAndOwn(obj,pptr,type,flags,own)  SWIG_Python_ConvertPtrAndOwn(obj, pptr, type, flags, own)
    1085             : 
    1086             : #ifdef SWIGPYTHON_BUILTIN
    1087             : #define SWIG_NewPointerObj(ptr, type, flags)            SWIG_Python_NewPointerObj(self, ptr, type, flags)
    1088             : #else
    1089             : #define SWIG_NewPointerObj(ptr, type, flags)            SWIG_Python_NewPointerObj(NULL, ptr, type, flags)
    1090             : #endif
    1091             : 
    1092             : #define SWIG_InternalNewPointerObj(ptr, type, flags)  SWIG_Python_NewPointerObj(NULL, ptr, type, flags)
    1093             : 
    1094             : #define SWIG_CheckImplicit(ty)                          SWIG_Python_CheckImplicit(ty) 
    1095             : #define SWIG_AcquirePtr(ptr, src)                       SWIG_Python_AcquirePtr(ptr, src)
    1096             : #define swig_owntype                                    int
    1097             : 
    1098             : /* for raw packed data */
    1099             : #define SWIG_ConvertPacked(obj, ptr, sz, ty)            SWIG_Python_ConvertPacked(obj, ptr, sz, ty)
    1100             : #define SWIG_NewPackedObj(ptr, sz, type)                SWIG_Python_NewPackedObj(ptr, sz, type)
    1101             : 
    1102             : /* for class or struct pointers */
    1103             : #define SWIG_ConvertInstance(obj, pptr, type, flags)    SWIG_ConvertPtr(obj, pptr, type, flags)
    1104             : #define SWIG_NewInstanceObj(ptr, type, flags)           SWIG_NewPointerObj(ptr, type, flags)
    1105             : 
    1106             : /* for C or C++ function pointers */
    1107             : #define SWIG_ConvertFunctionPtr(obj, pptr, type)        SWIG_Python_ConvertFunctionPtr(obj, pptr, type)
    1108             : #define SWIG_NewFunctionPtrObj(ptr, type)               SWIG_Python_NewPointerObj(NULL, ptr, type, 0)
    1109             : 
    1110             : /* for C++ member pointers, ie, member methods */
    1111             : #define SWIG_ConvertMember(obj, ptr, sz, ty)            SWIG_Python_ConvertPacked(obj, ptr, sz, ty)
    1112             : #define SWIG_NewMemberObj(ptr, sz, type)                SWIG_Python_NewPackedObj(ptr, sz, type)
    1113             : 
    1114             : 
    1115             : /* Runtime API */
    1116             : 
    1117             : #define SWIG_GetModule(clientdata)                      SWIG_Python_GetModule(clientdata)
    1118             : #define SWIG_SetModule(clientdata, pointer)             SWIG_Python_SetModule(pointer)
    1119             : #define SWIG_NewClientData(obj)                         SwigPyClientData_New(obj)
    1120             : 
    1121             : #define SWIG_SetErrorObj                                SWIG_Python_SetErrorObj                            
    1122             : #define SWIG_SetErrorMsg                          SWIG_Python_SetErrorMsg          
    1123             : #define SWIG_ErrorType(code)                      SWIG_Python_ErrorType(code)                        
    1124             : #define SWIG_Error(code, msg)               SWIG_Python_SetErrorMsg(SWIG_ErrorType(code), msg) 
    1125             : #define SWIG_fail                           goto fail            
    1126             : 
    1127             : 
    1128             : /* Runtime API implementation */
    1129             : 
    1130             : /* Error manipulation */
    1131             : 
    1132             : SWIGINTERN void 
    1133             : SWIG_Python_SetErrorObj(PyObject *errtype, PyObject *obj) {
    1134             :   SWIG_PYTHON_THREAD_BEGIN_BLOCK; 
    1135             :   PyErr_SetObject(errtype, obj);
    1136             :   Py_DECREF(obj);
    1137             :   SWIG_PYTHON_THREAD_END_BLOCK;
    1138             : }
    1139             : 
    1140             : SWIGINTERN void 
    1141          37 : SWIG_Python_SetErrorMsg(PyObject *errtype, const char *msg) {
    1142          37 :   SWIG_PYTHON_THREAD_BEGIN_BLOCK;
    1143          37 :   PyErr_SetString(errtype, msg);
    1144          37 :   SWIG_PYTHON_THREAD_END_BLOCK;
    1145          37 : }
    1146             : 
    1147             : #define SWIG_Python_Raise(obj, type, desc)  SWIG_Python_SetErrorObj(SWIG_Python_ExceptionType(desc), obj)
    1148             : 
    1149             : /* Set a constant value */
    1150             : 
    1151             : #if defined(SWIGPYTHON_BUILTIN)
    1152             : 
    1153             : SWIGINTERN void
    1154             : SwigPyBuiltin_AddPublicSymbol(PyObject *seq, const char *key) {
    1155             :   PyObject *s = PyString_InternFromString(key);
    1156             :   PyList_Append(seq, s);
    1157             :   Py_DECREF(s);
    1158             : }
    1159             : 
    1160             : SWIGINTERN void
    1161             : SWIG_Python_SetConstant(PyObject *d, PyObject *public_interface, const char *name, PyObject *obj) {   
    1162             :   PyDict_SetItemString(d, name, obj);
    1163             :   Py_DECREF(obj);
    1164             :   if (public_interface)
    1165             :     SwigPyBuiltin_AddPublicSymbol(public_interface, name);
    1166             : }
    1167             : 
    1168             : #else
    1169             : 
    1170             : SWIGINTERN void
    1171             : SWIG_Python_SetConstant(PyObject *d, const char *name, PyObject *obj) {   
    1172             :   PyDict_SetItemString(d, name, obj);
    1173             :   Py_DECREF(obj);                            
    1174             : }
    1175             : 
    1176             : #endif
    1177             : 
    1178             : /* Append a value to the result obj */
    1179             : 
    1180             : SWIGINTERN PyObject*
    1181             : SWIG_Python_AppendOutput(PyObject* result, PyObject* obj) {
    1182             :   if (!result) {
    1183             :     result = obj;
    1184             :   } else if (result == Py_None) {
    1185             :     Py_DECREF(result);
    1186             :     result = obj;
    1187             :   } else {
    1188             :     if (!PyList_Check(result)) {
    1189             :       PyObject *o2 = result;
    1190             :       result = PyList_New(1);
    1191             :       PyList_SetItem(result, 0, o2);
    1192             :     }
    1193             :     PyList_Append(result,obj);
    1194             :     Py_DECREF(obj);
    1195             :   }
    1196             :   return result;
    1197             : }
    1198             : 
    1199             : /* Unpack the argument tuple */
    1200             : 
    1201             : SWIGINTERN Py_ssize_t
    1202         842 : SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t max, PyObject **objs)
    1203             : {
    1204         842 :   if (!args) {
    1205          34 :     if (!min && !max) {
    1206             :       return 1;
    1207             :     } else {
    1208           0 :       PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got none", 
    1209             :        name, (min == max ? "" : "at least "), (int)min);
    1210           0 :       return 0;
    1211             :     }
    1212             :   }  
    1213         808 :   if (!PyTuple_Check(args)) {
    1214         225 :     if (min <= 1 && max >= 1) {
    1215         225 :       Py_ssize_t i;
    1216         225 :       objs[0] = args;
    1217         225 :       for (i = 1; i < max; ++i) {
    1218           0 :   objs[i] = 0;
    1219             :       }
    1220             :       return 2;
    1221             :     }
    1222           0 :     PyErr_SetString(PyExc_SystemError, "UnpackTuple() argument list is not a tuple");
    1223           0 :     return 0;
    1224             :   } else {
    1225         583 :     Py_ssize_t l = PyTuple_GET_SIZE(args);
    1226         583 :     if (l < min) {
    1227           0 :       PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", 
    1228             :        name, (min == max ? "" : "at least "), (int)min, (int)l);
    1229           0 :       return 0;
    1230         583 :     } else if (l > max) {
    1231           0 :       PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", 
    1232             :        name, (min == max ? "" : "at most "), (int)max, (int)l);
    1233           0 :       return 0;
    1234             :     } else {
    1235             :       Py_ssize_t i;
    1236        2536 :       for (i = 0; i < l; ++i) {
    1237        1953 :   objs[i] = PyTuple_GET_ITEM(args, i);
    1238             :       }
    1239         583 :       for (; l < max; ++l) {
    1240           0 :   objs[l] = 0;
    1241             :       }
    1242         583 :       return i + 1;
    1243             :     }    
    1244             :   }
    1245             : }
    1246             : 
    1247             : /* A functor is a function object with one single object argument */
    1248             : #define SWIG_Python_CallFunctor(functor, obj)         PyObject_CallFunctionObjArgs(functor, obj, NULL);
    1249             : 
    1250             : /*
    1251             :   Helper for static pointer initialization for both C and C++ code, for example
    1252             :   static PyObject *SWIG_STATIC_POINTER(MyVar) = NewSomething(...);
    1253             : */
    1254             : #ifdef __cplusplus
    1255             : #define SWIG_STATIC_POINTER(var)  var
    1256             : #else
    1257             : #define SWIG_STATIC_POINTER(var)  var = 0; if (!var) var
    1258             : #endif
    1259             : 
    1260             : /* -----------------------------------------------------------------------------
    1261             :  * Pointer declarations
    1262             :  * ----------------------------------------------------------------------------- */
    1263             : 
    1264             : /* Flags for new pointer objects */
    1265             : #define SWIG_POINTER_NOSHADOW       (SWIG_POINTER_OWN      << 1)
    1266             : #define SWIG_POINTER_NEW            (SWIG_POINTER_NOSHADOW | SWIG_POINTER_OWN)
    1267             : 
    1268             : #define SWIG_POINTER_IMPLICIT_CONV  (SWIG_POINTER_DISOWN   << 1)
    1269             : 
    1270             : #define SWIG_BUILTIN_TP_INIT      (SWIG_POINTER_OWN << 2)
    1271             : #define SWIG_BUILTIN_INIT     (SWIG_BUILTIN_TP_INIT | SWIG_POINTER_OWN)
    1272             : 
    1273             : #ifdef __cplusplus
    1274             : extern "C" {
    1275             : #endif
    1276             : 
    1277             : /* The python void return value */
    1278             : 
    1279             : SWIGRUNTIMEINLINE PyObject * 
    1280       23098 : SWIG_Py_Void(void)
    1281             : {
    1282       23098 :   PyObject *none = Py_None;
    1283           0 :   Py_INCREF(none);
    1284         228 :   return none;
    1285             : }
    1286             : 
    1287             : /* SwigPyClientData */
    1288             : 
    1289             : typedef struct {
    1290             :   PyObject *klass;
    1291             :   PyObject *newraw;
    1292             :   PyObject *newargs;
    1293             :   PyObject *destroy;
    1294             :   int delargs;
    1295             :   int implicitconv;
    1296             :   PyTypeObject *pytype;
    1297             : } SwigPyClientData;
    1298             : 
    1299             : SWIGRUNTIMEINLINE int 
    1300             : SWIG_Python_CheckImplicit(swig_type_info *ty)
    1301             : {
    1302             :   SwigPyClientData *data = (SwigPyClientData *)ty->clientdata;
    1303             :   int fail = data ? data->implicitconv : 0;
    1304             :   if (fail)
    1305             :     PyErr_SetString(PyExc_TypeError, "Implicit conversion is prohibited for explicit constructors.");
    1306             :   return fail;
    1307             : }
    1308             : 
    1309             : SWIGRUNTIMEINLINE PyObject *
    1310             : SWIG_Python_ExceptionType(swig_type_info *desc) {
    1311             :   SwigPyClientData *data = desc ? (SwigPyClientData *) desc->clientdata : 0;
    1312             :   PyObject *klass = data ? data->klass : 0;
    1313             :   return (klass ? klass : PyExc_RuntimeError);
    1314             : }
    1315             : 
    1316             : 
    1317             : SWIGRUNTIME SwigPyClientData * 
    1318         225 : SwigPyClientData_New(PyObject* obj)
    1319             : {
    1320         225 :   if (!obj) {
    1321             :     return 0;
    1322             :   } else {
    1323         225 :     SwigPyClientData *data = (SwigPyClientData *)malloc(sizeof(SwigPyClientData));
    1324             :     /* the klass element */
    1325         225 :     data->klass = obj;
    1326         225 :     Py_INCREF(data->klass);
    1327             :     /* the newraw method and newargs arguments used to create a new raw instance */
    1328         225 :     if (PyClass_Check(obj)) {
    1329         225 :       data->newraw = 0;
    1330         225 :       data->newargs = obj;
    1331         225 :       Py_INCREF(obj);
    1332             :     } else {
    1333           0 :       data->newraw = PyObject_GetAttrString(data->klass, "__new__");
    1334           0 :       if (data->newraw) {
    1335           0 :   Py_INCREF(data->newraw);
    1336           0 :   data->newargs = PyTuple_New(1);
    1337           0 :   PyTuple_SetItem(data->newargs, 0, obj);
    1338             :       } else {
    1339           0 :   data->newargs = obj;
    1340             :       }
    1341           0 :       Py_INCREF(data->newargs);
    1342             :     }
    1343             :     /* the destroy method, aka as the C++ delete method */
    1344         225 :     data->destroy = PyObject_GetAttrString(data->klass, "__swig_destroy__");
    1345         225 :     if (PyErr_Occurred()) {
    1346           0 :       PyErr_Clear();
    1347           0 :       data->destroy = 0;
    1348             :     }
    1349         225 :     if (data->destroy) {
    1350         225 :       int flags;
    1351         225 :       Py_INCREF(data->destroy);
    1352         225 :       flags = PyCFunction_GET_FLAGS(data->destroy);
    1353         225 :       data->delargs = !(flags & (METH_O));
    1354             :     } else {
    1355           0 :       data->delargs = 0;
    1356             :     }
    1357         225 :     data->implicitconv = 0;
    1358         225 :     data->pytype = 0;
    1359         225 :     return data;
    1360             :   }
    1361             : }
    1362             : 
    1363             : SWIGRUNTIME void 
    1364           0 : SwigPyClientData_Del(SwigPyClientData *data) {
    1365           0 :   Py_XDECREF(data->newraw);
    1366           0 :   Py_XDECREF(data->newargs);
    1367           0 :   Py_XDECREF(data->destroy);
    1368           0 : }
    1369             : 
    1370             : /* =============== SwigPyObject =====================*/
    1371             : 
    1372             : typedef struct {
    1373             :   PyObject_HEAD
    1374             :   void *ptr;
    1375             :   swig_type_info *ty;
    1376             :   int own;
    1377             :   PyObject *next;
    1378             : #ifdef SWIGPYTHON_BUILTIN
    1379             :   PyObject *dict;
    1380             : #endif
    1381             : } SwigPyObject;
    1382             : 
    1383             : 
    1384             : #ifdef SWIGPYTHON_BUILTIN
    1385             : 
    1386             : SWIGRUNTIME PyObject *
    1387             : SwigPyObject_get___dict__(PyObject *v, PyObject *SWIGUNUSEDPARM(args))
    1388             : {
    1389             :   SwigPyObject *sobj = (SwigPyObject *)v;
    1390             : 
    1391             :   if (!sobj->dict)
    1392             :     sobj->dict = PyDict_New();
    1393             : 
    1394             :   Py_INCREF(sobj->dict);
    1395             :   return sobj->dict;
    1396             : }
    1397             : 
    1398             : #endif
    1399             : 
    1400             : SWIGRUNTIME PyObject *
    1401           0 : SwigPyObject_long(SwigPyObject *v)
    1402             : {
    1403           0 :   return PyLong_FromVoidPtr(v->ptr);
    1404             : }
    1405             : 
    1406             : SWIGRUNTIME PyObject *
    1407             : SwigPyObject_format(const char* fmt, SwigPyObject *v)
    1408             : {
    1409             :   PyObject *res = NULL;
    1410             :   PyObject *args = PyTuple_New(1);
    1411             :   if (args) {
    1412             :     if (PyTuple_SetItem(args, 0, SwigPyObject_long(v)) == 0) {
    1413             :       PyObject *ofmt = SWIG_Python_str_FromChar(fmt);
    1414             :       if (ofmt) {
    1415             : #if PY_VERSION_HEX >= 0x03000000
    1416             :   res = PyUnicode_Format(ofmt,args);
    1417             : #else
    1418             :   res = PyString_Format(ofmt,args);
    1419             : #endif
    1420             :   Py_DECREF(ofmt);
    1421             :       }
    1422             :       Py_DECREF(args);
    1423             :     }
    1424             :   }
    1425             :   return res;
    1426             : }
    1427             : 
    1428             : SWIGRUNTIME PyObject *
    1429             : SwigPyObject_oct(SwigPyObject *v)
    1430             : {
    1431             :   return SwigPyObject_format("%o",v);
    1432             : }
    1433             : 
    1434             : SWIGRUNTIME PyObject *
    1435             : SwigPyObject_hex(SwigPyObject *v)
    1436             : {
    1437             :   return SwigPyObject_format("%x",v);
    1438             : }
    1439             : 
    1440             : SWIGRUNTIME PyObject *
    1441           0 : SwigPyObject_repr(SwigPyObject *v)
    1442             : {
    1443           0 :   const char *name = SWIG_TypePrettyName(v->ty);
    1444           0 :   PyObject *repr = SWIG_Python_str_FromFormat("<Swig Object of type '%s' at %p>", (name ? name : "unknown"), (void *)v);
    1445           0 :   if (v->next) {
    1446           0 :     PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next);
    1447             : # if PY_VERSION_HEX >= 0x03000000
    1448           0 :     PyObject *joined = PyUnicode_Concat(repr, nrep);
    1449           0 :     Py_DecRef(repr);
    1450           0 :     Py_DecRef(nrep);
    1451           0 :     repr = joined;
    1452             : # else
    1453             :     PyString_ConcatAndDel(&repr,nrep);
    1454             : # endif
    1455             :   }
    1456           0 :   return repr;  
    1457             : }
    1458             : 
    1459             : /* We need a version taking two PyObject* parameters so it's a valid
    1460             :  * PyCFunction to use in swigobject_methods[]. */
    1461             : SWIGRUNTIME PyObject *
    1462           0 : SwigPyObject_repr2(PyObject *v, PyObject *SWIGUNUSEDPARM(args))
    1463             : {
    1464           0 :   return SwigPyObject_repr((SwigPyObject*)v);
    1465             : }
    1466             : 
    1467             : SWIGRUNTIME int
    1468           0 : SwigPyObject_compare(SwigPyObject *v, SwigPyObject *w)
    1469             : {
    1470           0 :   void *i = v->ptr;
    1471           0 :   void *j = w->ptr;
    1472           0 :   return (i < j) ? -1 : ((i > j) ? 1 : 0);
    1473             : }
    1474             : 
    1475             : /* Added for Python 3.x, would it also be useful for Python 2.x? */
    1476             : SWIGRUNTIME PyObject*
    1477           0 : SwigPyObject_richcompare(SwigPyObject *v, SwigPyObject *w, int op)
    1478             : {
    1479           0 :   PyObject* res;
    1480           0 :   if( op != Py_EQ && op != Py_NE ) {
    1481           0 :     Py_INCREF(Py_NotImplemented);
    1482           0 :     return Py_NotImplemented;
    1483             :   }
    1484           0 :   res = PyBool_FromLong( (SwigPyObject_compare(v, w)==0) == (op == Py_EQ) ? 1 : 0);
    1485           0 :   return res;  
    1486             : }
    1487             : 
    1488             : 
    1489             : SWIGRUNTIME PyTypeObject* SwigPyObject_TypeOnce(void);
    1490             : 
    1491             : #ifdef SWIGPYTHON_BUILTIN
    1492             : static swig_type_info *SwigPyObject_stype = 0;
    1493             : SWIGRUNTIME PyTypeObject*
    1494             : SwigPyObject_type(void) {
    1495             :     SwigPyClientData *cd;
    1496             :     assert(SwigPyObject_stype);
    1497             :     cd = (SwigPyClientData*) SwigPyObject_stype->clientdata;
    1498             :     assert(cd);
    1499             :     assert(cd->pytype);
    1500             :     return cd->pytype;
    1501             : }
    1502             : #else
    1503             : SWIGRUNTIME PyTypeObject*
    1504       40030 : SwigPyObject_type(void) {
    1505       40030 :   static PyTypeObject *SWIG_STATIC_POINTER(type) = SwigPyObject_TypeOnce();
    1506       40030 :   return type;
    1507             : }
    1508             : #endif
    1509             : 
    1510             : SWIGRUNTIMEINLINE int
    1511             : SwigPyObject_Check(PyObject *op) {
    1512             : #ifdef SWIGPYTHON_BUILTIN
    1513             :   PyTypeObject *target_tp = SwigPyObject_type();
    1514             :   if (PyType_IsSubtype(op->ob_type, target_tp))
    1515             :     return 1;
    1516             :   return (strcmp(op->ob_type->tp_name, "SwigPyObject") == 0);
    1517             : #else
    1518             :   return (Py_TYPE(op) == SwigPyObject_type())
    1519             :     || (strcmp(Py_TYPE(op)->tp_name,"SwigPyObject") == 0);
    1520             : #endif
    1521             : }
    1522             : 
    1523             : SWIGRUNTIME PyObject *
    1524             : SwigPyObject_New(void *ptr, swig_type_info *ty, int own);
    1525             : 
    1526             : SWIGRUNTIME void
    1527          47 : SwigPyObject_dealloc(PyObject *v)
    1528             : {
    1529          47 :   SwigPyObject *sobj = (SwigPyObject *) v;
    1530          47 :   PyObject *next = sobj->next;
    1531          47 :   if (sobj->own == SWIG_POINTER_OWN) {
    1532          46 :     swig_type_info *ty = sobj->ty;
    1533          46 :     SwigPyClientData *data = ty ? (SwigPyClientData *) ty->clientdata : 0;
    1534          46 :     PyObject *destroy = data ? data->destroy : 0;
    1535          46 :     if (destroy) {
    1536             :       /* destroy is always a VARARGS method */
    1537          46 :       PyObject *res;
    1538             : 
    1539             :       /* PyObject_CallFunction() has the potential to silently drop
    1540             :          the active exception.  In cases of unnamed temporary
    1541             :          variable or where we just finished iterating over a generator
    1542             :          StopIteration will be active right now, and this needs to
    1543             :          remain true upon return from SwigPyObject_dealloc.  So save
    1544             :          and restore. */
    1545             :       
    1546          46 :       PyObject *type = NULL, *value = NULL, *traceback = NULL;
    1547          46 :       PyErr_Fetch(&type, &value, &traceback);
    1548             : 
    1549          46 :       if (data->delargs) {
    1550             :         /* we need to create a temporary object to carry the destroy operation */
    1551           0 :         PyObject *tmp = SwigPyObject_New(sobj->ptr, ty, 0);
    1552           0 :         res = SWIG_Python_CallFunctor(destroy, tmp);
    1553           0 :         Py_DECREF(tmp);
    1554             :       } else {
    1555          46 :         PyCFunction meth = PyCFunction_GET_FUNCTION(destroy);
    1556          46 :         PyObject *mself = PyCFunction_GET_SELF(destroy);
    1557          46 :         res = ((*meth)(mself, v));
    1558             :       }
    1559          46 :       if (!res)
    1560           0 :         PyErr_WriteUnraisable(destroy);
    1561             : 
    1562          46 :       PyErr_Restore(type, value, traceback);
    1563             : 
    1564          92 :       Py_XDECREF(res);
    1565             :     } 
    1566             : #if !defined(SWIG_PYTHON_SILENT_MEMLEAK)
    1567             :     else {
    1568             :       const char *name = SWIG_TypePrettyName(ty);
    1569             :       printf("swig/python detected a memory leak of type '%s', no destructor found.\n", (name ? name : "unknown"));
    1570             :     }
    1571             : #endif
    1572             :   } 
    1573          47 :   Py_XDECREF(next);
    1574          47 :   PyObject_DEL(v);
    1575          47 : }
    1576             : 
    1577             : SWIGRUNTIME PyObject* 
    1578           0 : SwigPyObject_append(PyObject* v, PyObject* next)
    1579             : {
    1580           0 :   SwigPyObject *sobj = (SwigPyObject *) v;
    1581           0 :   if (!SwigPyObject_Check(next)) {
    1582           0 :     PyErr_SetString(PyExc_TypeError, "Attempt to append a non SwigPyObject");
    1583           0 :     return NULL;
    1584             :   }
    1585           0 :   sobj->next = next;
    1586           0 :   Py_INCREF(next);
    1587           0 :   return SWIG_Py_Void();
    1588             : }
    1589             : 
    1590             : SWIGRUNTIME PyObject* 
    1591           0 : SwigPyObject_next(PyObject* v, PyObject *SWIGUNUSEDPARM(args))
    1592             : {
    1593           0 :   SwigPyObject *sobj = (SwigPyObject *) v;
    1594           0 :   if (sobj->next) {    
    1595           0 :     Py_INCREF(sobj->next);
    1596           0 :     return sobj->next;
    1597             :   } else {
    1598           0 :     return SWIG_Py_Void();
    1599             :   }
    1600             : }
    1601             : 
    1602             : SWIGINTERN PyObject*
    1603           0 : SwigPyObject_disown(PyObject* v, PyObject *SWIGUNUSEDPARM(args))
    1604             : {
    1605           0 :   SwigPyObject *sobj = (SwigPyObject *)v;
    1606           0 :   sobj->own = 0;
    1607           0 :   return SWIG_Py_Void();
    1608             : }
    1609             : 
    1610             : SWIGINTERN PyObject*
    1611           0 : SwigPyObject_acquire(PyObject* v, PyObject *SWIGUNUSEDPARM(args))
    1612             : {
    1613           0 :   SwigPyObject *sobj = (SwigPyObject *)v;
    1614           0 :   sobj->own = SWIG_POINTER_OWN;
    1615           0 :   return SWIG_Py_Void();
    1616             : }
    1617             : 
    1618             : SWIGINTERN PyObject*
    1619           0 : SwigPyObject_own(PyObject *v, PyObject *args)
    1620             : {
    1621           0 :   PyObject *val = 0;
    1622           0 :   if (!PyArg_UnpackTuple(args, "own", 0, 1, &val)) {
    1623             :     return NULL;
    1624             :   } else {
    1625           0 :     SwigPyObject *sobj = (SwigPyObject *)v;
    1626           0 :     PyObject *obj = PyBool_FromLong(sobj->own);
    1627           0 :     if (val) {
    1628           0 :       if (PyObject_IsTrue(val)) {
    1629           0 :         SwigPyObject_acquire(v,args);
    1630             :       } else {
    1631           0 :         SwigPyObject_disown(v,args);
    1632             :       }
    1633             :     } 
    1634           0 :     return obj;
    1635             :   }
    1636             : }
    1637             : 
    1638             : static PyMethodDef
    1639             : swigobject_methods[] = {
    1640             :   {"disown",  SwigPyObject_disown,  METH_NOARGS,  "releases ownership of the pointer"},
    1641             :   {"acquire", SwigPyObject_acquire, METH_NOARGS,  "acquires ownership of the pointer"},
    1642             :   {"own",     SwigPyObject_own,     METH_VARARGS, "returns/sets ownership of the pointer"},
    1643             :   {"append",  SwigPyObject_append,  METH_O,       "appends another 'this' object"},
    1644             :   {"next",    SwigPyObject_next,    METH_NOARGS,  "returns the next 'this' object"},
    1645             :   {"__repr__",SwigPyObject_repr2,   METH_NOARGS,  "returns object representation"},
    1646             :   {0, 0, 0, 0}  
    1647             : };
    1648             : 
    1649             : SWIGRUNTIME PyTypeObject*
    1650         225 : SwigPyObject_TypeOnce(void) {
    1651         225 :   static char swigobject_doc[] = "Swig object carries a C/C++ instance pointer";
    1652             : 
    1653         225 :   static PyNumberMethods SwigPyObject_as_number = {
    1654             :     (binaryfunc)0, /*nb_add*/
    1655             :     (binaryfunc)0, /*nb_subtract*/
    1656             :     (binaryfunc)0, /*nb_multiply*/
    1657             :     /* nb_divide removed in Python 3 */
    1658             : #if PY_VERSION_HEX < 0x03000000
    1659             :     (binaryfunc)0, /*nb_divide*/
    1660             : #endif
    1661             :     (binaryfunc)0, /*nb_remainder*/
    1662             :     (binaryfunc)0, /*nb_divmod*/
    1663             :     (ternaryfunc)0,/*nb_power*/
    1664             :     (unaryfunc)0,  /*nb_negative*/
    1665             :     (unaryfunc)0,  /*nb_positive*/
    1666             :     (unaryfunc)0,  /*nb_absolute*/
    1667             :     (inquiry)0,    /*nb_nonzero*/
    1668             :     0,       /*nb_invert*/
    1669             :     0,       /*nb_lshift*/
    1670             :     0,       /*nb_rshift*/
    1671             :     0,       /*nb_and*/
    1672             :     0,       /*nb_xor*/
    1673             :     0,       /*nb_or*/
    1674             : #if PY_VERSION_HEX < 0x03000000
    1675             :     0,   /*nb_coerce*/
    1676             : #endif
    1677             :     (unaryfunc)SwigPyObject_long, /*nb_int*/
    1678             : #if PY_VERSION_HEX < 0x03000000
    1679             :     (unaryfunc)SwigPyObject_long, /*nb_long*/
    1680             : #else
    1681             :     0, /*nb_reserved*/
    1682             : #endif
    1683             :     (unaryfunc)0,                 /*nb_float*/
    1684             : #if PY_VERSION_HEX < 0x03000000
    1685             :     (unaryfunc)SwigPyObject_oct,  /*nb_oct*/
    1686             :     (unaryfunc)SwigPyObject_hex,  /*nb_hex*/
    1687             : #endif
    1688             : #if PY_VERSION_HEX >= 0x03050000 /* 3.5 */
    1689             :     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_matrix_multiply */
    1690             : #elif PY_VERSION_HEX >= 0x03000000 /* 3.0 */
    1691             :     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_index, nb_inplace_divide removed */
    1692             : #else
    1693             :     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_index */
    1694             : #endif
    1695             :   };
    1696             : 
    1697         225 :   static PyTypeObject swigpyobject_type;
    1698         225 :   static int type_init = 0;
    1699         225 :   if (!type_init) {
    1700         225 :     const PyTypeObject tmp = {
    1701             : #if PY_VERSION_HEX >= 0x03000000
    1702             :       PyVarObject_HEAD_INIT(NULL, 0)
    1703             : #else
    1704             :       PyObject_HEAD_INIT(NULL)
    1705             :       0,                                    /* ob_size */
    1706             : #endif
    1707             :       "SwigPyObject",                       /* tp_name */
    1708             :       sizeof(SwigPyObject),                 /* tp_basicsize */
    1709             :       0,                                    /* tp_itemsize */
    1710             :       (destructor)SwigPyObject_dealloc,     /* tp_dealloc */
    1711             :       0,                                    /* tp_print */
    1712             :       (getattrfunc)0,                       /* tp_getattr */
    1713             :       (setattrfunc)0,                       /* tp_setattr */
    1714             : #if PY_VERSION_HEX >= 0x03000000
    1715             :       0, /* tp_reserved in 3.0.1, tp_compare in 3.0.0 but not used */
    1716             : #else
    1717             :       (cmpfunc)SwigPyObject_compare,        /* tp_compare */
    1718             : #endif
    1719             :       (reprfunc)SwigPyObject_repr,          /* tp_repr */
    1720             :       &SwigPyObject_as_number,              /* tp_as_number */
    1721             :       0,                                    /* tp_as_sequence */
    1722             :       0,                                    /* tp_as_mapping */
    1723             :       (hashfunc)0,                          /* tp_hash */
    1724             :       (ternaryfunc)0,                       /* tp_call */
    1725             :       0,                                    /* tp_str */
    1726             :       PyObject_GenericGetAttr,              /* tp_getattro */
    1727             :       0,                                    /* tp_setattro */
    1728             :       0,                                    /* tp_as_buffer */
    1729             :       Py_TPFLAGS_DEFAULT,                   /* tp_flags */
    1730             :       swigobject_doc,                       /* tp_doc */
    1731             :       0,                                    /* tp_traverse */
    1732             :       0,                                    /* tp_clear */
    1733             :       (richcmpfunc)SwigPyObject_richcompare,/* tp_richcompare */
    1734             :       0,                                    /* tp_weaklistoffset */
    1735             :       0,                                    /* tp_iter */
    1736             :       0,                                    /* tp_iternext */
    1737             :       swigobject_methods,                   /* tp_methods */
    1738             :       0,                                    /* tp_members */
    1739             :       0,                                    /* tp_getset */
    1740             :       0,                                    /* tp_base */
    1741             :       0,                                    /* tp_dict */
    1742             :       0,                                    /* tp_descr_get */
    1743             :       0,                                    /* tp_descr_set */
    1744             :       0,                                    /* tp_dictoffset */
    1745             :       0,                                    /* tp_init */
    1746             :       0,                                    /* tp_alloc */
    1747             :       0,                                    /* tp_new */
    1748             :       0,                                    /* tp_free */
    1749             :       0,                                    /* tp_is_gc */
    1750             :       0,                                    /* tp_bases */
    1751             :       0,                                    /* tp_mro */
    1752             :       0,                                    /* tp_cache */
    1753             :       0,                                    /* tp_subclasses */
    1754             :       0,                                    /* tp_weaklist */
    1755             :       0,                                    /* tp_del */
    1756             :       0,                                    /* tp_version_tag */
    1757             : #if PY_VERSION_HEX >= 0x03040000
    1758             :       0,                                    /* tp_finalize */
    1759             : #endif
    1760             : #ifdef COUNT_ALLOCS
    1761             :       0,                                    /* tp_allocs */
    1762             :       0,                                    /* tp_frees */
    1763             :       0,                                    /* tp_maxalloc */
    1764             :       0,                                    /* tp_prev */
    1765             :       0                                     /* tp_next */
    1766             : #endif
    1767             :     };
    1768         225 :     swigpyobject_type = tmp;
    1769         225 :     type_init = 1;
    1770         225 :     if (PyType_Ready(&swigpyobject_type) < 0)
    1771           0 :       return NULL;
    1772             :   }
    1773             :   return &swigpyobject_type;
    1774             : }
    1775             : 
    1776             : SWIGRUNTIME PyObject *
    1777         271 : SwigPyObject_New(void *ptr, swig_type_info *ty, int own)
    1778             : {
    1779         271 :   SwigPyObject *sobj = PyObject_NEW(SwigPyObject, SwigPyObject_type());
    1780         271 :   if (sobj) {
    1781         271 :     sobj->ptr  = ptr;
    1782         271 :     sobj->ty   = ty;
    1783         271 :     sobj->own  = own;
    1784         271 :     sobj->next = 0;
    1785             :   }
    1786         271 :   return (PyObject *)sobj;
    1787             : }
    1788             : 
    1789             : /* -----------------------------------------------------------------------------
    1790             :  * Implements a simple Swig Packed type, and use it instead of string
    1791             :  * ----------------------------------------------------------------------------- */
    1792             : 
    1793             : typedef struct {
    1794             :   PyObject_HEAD
    1795             :   void *pack;
    1796             :   swig_type_info *ty;
    1797             :   size_t size;
    1798             : } SwigPyPacked;
    1799             : 
    1800             : SWIGRUNTIME PyObject *
    1801           0 : SwigPyPacked_repr(SwigPyPacked *v)
    1802             : {
    1803           0 :   char result[SWIG_BUFFER_SIZE];
    1804           0 :   if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) {
    1805           0 :     return SWIG_Python_str_FromFormat("<Swig Packed at %s%s>", result, v->ty->name);
    1806             :   } else {
    1807           0 :     return SWIG_Python_str_FromFormat("<Swig Packed %s>", v->ty->name);
    1808             :   }  
    1809             : }
    1810             : 
    1811             : SWIGRUNTIME PyObject *
    1812           0 : SwigPyPacked_str(SwigPyPacked *v)
    1813             : {
    1814           0 :   char result[SWIG_BUFFER_SIZE];
    1815           0 :   if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))){
    1816           0 :     return SWIG_Python_str_FromFormat("%s%s", result, v->ty->name);
    1817             :   } else {
    1818           0 :     return SWIG_Python_str_FromChar(v->ty->name);
    1819             :   }  
    1820             : }
    1821             : 
    1822             : SWIGRUNTIME int
    1823             : SwigPyPacked_compare(SwigPyPacked *v, SwigPyPacked *w)
    1824             : {
    1825             :   size_t i = v->size;
    1826             :   size_t j = w->size;
    1827             :   int s = (i < j) ? -1 : ((i > j) ? 1 : 0);
    1828             :   return s ? s : strncmp((const char *)v->pack, (const char *)w->pack, 2*v->size);
    1829             : }
    1830             : 
    1831             : SWIGRUNTIME PyTypeObject* SwigPyPacked_TypeOnce(void);
    1832             : 
    1833             : SWIGRUNTIME PyTypeObject*
    1834         225 : SwigPyPacked_type(void) {
    1835         225 :   static PyTypeObject *SWIG_STATIC_POINTER(type) = SwigPyPacked_TypeOnce();
    1836         225 :   return type;
    1837             : }
    1838             : 
    1839             : SWIGRUNTIMEINLINE int
    1840             : SwigPyPacked_Check(PyObject *op) {
    1841             :   return ((op)->ob_type == SwigPyPacked_TypeOnce()) 
    1842             :     || (strcmp((op)->ob_type->tp_name,"SwigPyPacked") == 0);
    1843             : }
    1844             : 
    1845             : SWIGRUNTIME void
    1846           0 : SwigPyPacked_dealloc(PyObject *v)
    1847             : {
    1848           0 :   if (SwigPyPacked_Check(v)) {
    1849           0 :     SwigPyPacked *sobj = (SwigPyPacked *) v;
    1850           0 :     free(sobj->pack);
    1851             :   }
    1852           0 :   PyObject_DEL(v);
    1853           0 : }
    1854             : 
    1855             : SWIGRUNTIME PyTypeObject*
    1856         225 : SwigPyPacked_TypeOnce(void) {
    1857         225 :   static char swigpacked_doc[] = "Swig object carries a C/C++ instance pointer";
    1858         225 :   static PyTypeObject swigpypacked_type;
    1859         225 :   static int type_init = 0;
    1860         225 :   if (!type_init) {
    1861         225 :     const PyTypeObject tmp = {
    1862             : #if PY_VERSION_HEX>=0x03000000
    1863             :       PyVarObject_HEAD_INIT(NULL, 0)
    1864             : #else
    1865             :       PyObject_HEAD_INIT(NULL)
    1866             :       0,                                    /* ob_size */
    1867             : #endif
    1868             :       "SwigPyPacked",                       /* tp_name */
    1869             :       sizeof(SwigPyPacked),                 /* tp_basicsize */
    1870             :       0,                                    /* tp_itemsize */
    1871             :       (destructor)SwigPyPacked_dealloc,     /* tp_dealloc */
    1872             :       0,                                    /* tp_print */
    1873             :       (getattrfunc)0,                       /* tp_getattr */
    1874             :       (setattrfunc)0,                       /* tp_setattr */
    1875             : #if PY_VERSION_HEX>=0x03000000
    1876             :       0, /* tp_reserved in 3.0.1 */
    1877             : #else
    1878             :       (cmpfunc)SwigPyPacked_compare,        /* tp_compare */
    1879             : #endif
    1880             :       (reprfunc)SwigPyPacked_repr,          /* tp_repr */
    1881             :       0,                                    /* tp_as_number */
    1882             :       0,                                    /* tp_as_sequence */
    1883             :       0,                                    /* tp_as_mapping */
    1884             :       (hashfunc)0,                          /* tp_hash */
    1885             :       (ternaryfunc)0,                       /* tp_call */
    1886             :       (reprfunc)SwigPyPacked_str,           /* tp_str */
    1887             :       PyObject_GenericGetAttr,              /* tp_getattro */
    1888             :       0,                                    /* tp_setattro */
    1889             :       0,                                    /* tp_as_buffer */
    1890             :       Py_TPFLAGS_DEFAULT,                   /* tp_flags */
    1891             :       swigpacked_doc,                       /* tp_doc */
    1892             :       0,                                    /* tp_traverse */
    1893             :       0,                                    /* tp_clear */
    1894             :       0,                                    /* tp_richcompare */
    1895             :       0,                                    /* tp_weaklistoffset */
    1896             :       0,                                    /* tp_iter */
    1897             :       0,                                    /* tp_iternext */
    1898             :       0,                                    /* tp_methods */
    1899             :       0,                                    /* tp_members */
    1900             :       0,                                    /* tp_getset */
    1901             :       0,                                    /* tp_base */
    1902             :       0,                                    /* tp_dict */
    1903             :       0,                                    /* tp_descr_get */
    1904             :       0,                                    /* tp_descr_set */
    1905             :       0,                                    /* tp_dictoffset */
    1906             :       0,                                    /* tp_init */
    1907             :       0,                                    /* tp_alloc */
    1908             :       0,                                    /* tp_new */
    1909             :       0,                                    /* tp_free */
    1910             :       0,                                    /* tp_is_gc */
    1911             :       0,                                    /* tp_bases */
    1912             :       0,                                    /* tp_mro */
    1913             :       0,                                    /* tp_cache */
    1914             :       0,                                    /* tp_subclasses */
    1915             :       0,                                    /* tp_weaklist */
    1916             :       0,                                    /* tp_del */
    1917             :       0,                                    /* tp_version_tag */
    1918             : #if PY_VERSION_HEX >= 0x03040000
    1919             :       0,                                    /* tp_finalize */
    1920             : #endif
    1921             : #ifdef COUNT_ALLOCS
    1922             :       0,                                    /* tp_allocs */
    1923             :       0,                                    /* tp_frees */
    1924             :       0,                                    /* tp_maxalloc */
    1925             :       0,                                    /* tp_prev */
    1926             :       0                                     /* tp_next */
    1927             : #endif
    1928             :     };
    1929         225 :     swigpypacked_type = tmp;
    1930         225 :     type_init = 1;
    1931         225 :     if (PyType_Ready(&swigpypacked_type) < 0)
    1932           0 :       return NULL;
    1933             :   }
    1934             :   return &swigpypacked_type;
    1935             : }
    1936             : 
    1937             : SWIGRUNTIME PyObject *
    1938           0 : SwigPyPacked_New(void *ptr, size_t size, swig_type_info *ty)
    1939             : {
    1940           0 :   SwigPyPacked *sobj = PyObject_NEW(SwigPyPacked, SwigPyPacked_type());
    1941           0 :   if (sobj) {
    1942           0 :     void *pack = malloc(size);
    1943           0 :     if (pack) {
    1944           0 :       memcpy(pack, ptr, size);
    1945           0 :       sobj->pack = pack;
    1946           0 :       sobj->ty   = ty;
    1947           0 :       sobj->size = size;
    1948             :     } else {
    1949           0 :       PyObject_DEL((PyObject *) sobj);
    1950           0 :       sobj = 0;
    1951             :     }
    1952             :   }
    1953           0 :   return (PyObject *) sobj;
    1954             : }
    1955             : 
    1956             : SWIGRUNTIME swig_type_info *
    1957             : SwigPyPacked_UnpackData(PyObject *obj, void *ptr, size_t size)
    1958             : {
    1959             :   if (SwigPyPacked_Check(obj)) {
    1960             :     SwigPyPacked *sobj = (SwigPyPacked *)obj;
    1961             :     if (sobj->size != size) return 0;
    1962             :     memcpy(ptr, sobj->pack, size);
    1963             :     return sobj->ty;
    1964             :   } else {
    1965             :     return 0;
    1966             :   }
    1967             : }
    1968             : 
    1969             : /* -----------------------------------------------------------------------------
    1970             :  * pointers/data manipulation
    1971             :  * ----------------------------------------------------------------------------- */
    1972             : 
    1973             : static PyObject *Swig_This_global = NULL;
    1974             : 
    1975             : SWIGRUNTIME PyObject *
    1976       19846 : SWIG_This(void)
    1977             : {
    1978       19846 :   if (Swig_This_global == NULL)
    1979         225 :     Swig_This_global = SWIG_Python_str_FromChar("this");
    1980       19846 :   return Swig_This_global;
    1981             : }
    1982             : 
    1983             : /* #define SWIG_PYTHON_SLOW_GETSET_THIS */
    1984             : 
    1985             : /* TODO: I don't know how to implement the fast getset in Python 3 right now */
    1986             : #if PY_VERSION_HEX>=0x03000000
    1987             : #define SWIG_PYTHON_SLOW_GETSET_THIS 
    1988             : #endif
    1989             : 
    1990             : SWIGRUNTIME SwigPyObject *
    1991       19649 : SWIG_Python_GetSwigThis(PyObject *pyobj) 
    1992             : {
    1993       19649 :   PyObject *obj;
    1994             : 
    1995       19649 :   if (SwigPyObject_Check(pyobj))
    1996             :     return (SwigPyObject *) pyobj;
    1997             : 
    1998             : #ifdef SWIGPYTHON_BUILTIN
    1999             :   (void)obj;
    2000             : # ifdef PyWeakref_CheckProxy
    2001             :   if (PyWeakref_CheckProxy(pyobj)) {
    2002             :     pyobj = PyWeakref_GET_OBJECT(pyobj);
    2003             :     if (pyobj && SwigPyObject_Check(pyobj))
    2004             :       return (SwigPyObject*) pyobj;
    2005             :   }
    2006             : # endif
    2007             :   return NULL;
    2008             : #else
    2009             : 
    2010       19621 :   obj = 0;
    2011             : 
    2012             : #if !defined(SWIG_PYTHON_SLOW_GETSET_THIS)
    2013             :   if (PyInstance_Check(pyobj)) {
    2014             :     obj = _PyInstance_Lookup(pyobj, SWIG_This());      
    2015             :   } else {
    2016             :     PyObject **dictptr = _PyObject_GetDictPtr(pyobj);
    2017             :     if (dictptr != NULL) {
    2018             :       PyObject *dict = *dictptr;
    2019             :       obj = dict ? PyDict_GetItem(dict, SWIG_This()) : 0;
    2020             :     } else {
    2021             : #ifdef PyWeakref_CheckProxy
    2022             :       if (PyWeakref_CheckProxy(pyobj)) {
    2023             :   PyObject *wobj = PyWeakref_GET_OBJECT(pyobj);
    2024             :   return wobj ? SWIG_Python_GetSwigThis(wobj) : 0;
    2025             :       }
    2026             : #endif
    2027             :       obj = PyObject_GetAttr(pyobj,SWIG_This());
    2028             :       if (obj) {
    2029             :   Py_DECREF(obj);
    2030             :       } else {
    2031             :   if (PyErr_Occurred()) PyErr_Clear();
    2032             :   return 0;
    2033             :       }
    2034             :     }
    2035             :   }
    2036             : #else
    2037       19621 :   obj = PyObject_GetAttr(pyobj,SWIG_This());
    2038       19621 :   if (obj) {
    2039       19614 :     Py_DECREF(obj);
    2040             :   } else {
    2041           7 :     if (PyErr_Occurred()) PyErr_Clear();
    2042           7 :     return 0;
    2043             :   }
    2044             : #endif
    2045       19614 :   if (obj && !SwigPyObject_Check(obj)) {
    2046             :     /* a PyObject is called 'this', try to get the 'real this'
    2047             :        SwigPyObject from it */ 
    2048             :     return SWIG_Python_GetSwigThis(obj);
    2049             :   }
    2050             :   return (SwigPyObject *)obj;
    2051             : #endif
    2052             : }
    2053             : 
    2054             : /* Acquire a pointer value */
    2055             : 
    2056             : SWIGRUNTIME int
    2057             : SWIG_Python_AcquirePtr(PyObject *obj, int own) {
    2058             :   if (own == SWIG_POINTER_OWN) {
    2059             :     SwigPyObject *sobj = SWIG_Python_GetSwigThis(obj);
    2060             :     if (sobj) {
    2061             :       int oldown = sobj->own;
    2062             :       sobj->own = own;
    2063             :       return oldown;
    2064             :     }
    2065             :   }
    2066             :   return 0;
    2067             : }
    2068             : 
    2069             : /* Convert a pointer value */
    2070             : 
    2071             : SWIGRUNTIME int
    2072       19649 : SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int flags, int *own) {
    2073       19649 :   int res;
    2074       19649 :   SwigPyObject *sobj;
    2075       19649 :   int implicit_conv = (flags & SWIG_POINTER_IMPLICIT_CONV) != 0;
    2076             : 
    2077       19649 :   if (!obj)
    2078             :     return SWIG_ERROR;
    2079       19649 :   if (obj == Py_None && !implicit_conv) {
    2080           0 :     if (ptr)
    2081           0 :       *ptr = 0;
    2082           0 :     return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK;
    2083             :   }
    2084             : 
    2085       19649 :   res = SWIG_ERROR;
    2086             : 
    2087       19649 :   sobj = SWIG_Python_GetSwigThis(obj);
    2088       19649 :   if (own)
    2089           0 :     *own = 0;
    2090       19649 :   while (sobj) {
    2091       19642 :     void *vptr = sobj->ptr;
    2092       19642 :     if (ty) {
    2093       19642 :       swig_type_info *to = sobj->ty;
    2094       19642 :       if (to == ty) {
    2095             :         /* no type cast needed */
    2096       19642 :         if (ptr) *ptr = vptr;
    2097             :         break;
    2098             :       } else {
    2099           0 :         swig_cast_info *tc = SWIG_TypeCheck(to->name,ty);
    2100           0 :         if (!tc) {
    2101           0 :           sobj = (SwigPyObject *)sobj->next;
    2102             :         } else {
    2103           0 :           if (ptr) {
    2104           0 :             int newmemory = 0;
    2105           0 :             *ptr = SWIG_TypeCast(tc,vptr,&newmemory);
    2106           0 :             if (newmemory == SWIG_CAST_NEW_MEMORY) {
    2107           0 :               assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */
    2108           0 :               if (own)
    2109           0 :                 *own = *own | SWIG_CAST_NEW_MEMORY;
    2110             :             }
    2111             :           }
    2112             :           break;
    2113             :         }
    2114             :       }
    2115             :     } else {
    2116           0 :       if (ptr) *ptr = vptr;
    2117             :       break;
    2118             :     }
    2119             :   }
    2120       19649 :   if (sobj) {
    2121       19642 :     if (own)
    2122           0 :       *own = *own | sobj->own;
    2123       19642 :     if (flags & SWIG_POINTER_DISOWN) {
    2124          28 :       sobj->own = 0;
    2125             :     }
    2126             :     res = SWIG_OK;
    2127             :   } else {
    2128           7 :     if (implicit_conv) {
    2129           0 :       SwigPyClientData *data = ty ? (SwigPyClientData *) ty->clientdata : 0;
    2130           0 :       if (data && !data->implicitconv) {
    2131           0 :         PyObject *klass = data->klass;
    2132           0 :         if (klass) {
    2133           0 :           PyObject *impconv;
    2134           0 :           data->implicitconv = 1; /* avoid recursion and call 'explicit' constructors*/
    2135           0 :           impconv = SWIG_Python_CallFunctor(klass, obj);
    2136           0 :           data->implicitconv = 0;
    2137           0 :           if (PyErr_Occurred()) {
    2138           0 :             PyErr_Clear();
    2139           0 :             impconv = 0;
    2140             :           }
    2141           0 :           if (impconv) {
    2142           0 :             SwigPyObject *iobj = SWIG_Python_GetSwigThis(impconv);
    2143           0 :             if (iobj) {
    2144           0 :               void *vptr;
    2145           0 :               res = SWIG_Python_ConvertPtrAndOwn((PyObject*)iobj, &vptr, ty, 0, 0);
    2146           0 :               if (SWIG_IsOK(res)) {
    2147           0 :                 if (ptr) {
    2148           0 :                   *ptr = vptr;
    2149             :                   /* transfer the ownership to 'ptr' */
    2150           0 :                   iobj->own = 0;
    2151           0 :                   res = SWIG_AddCast(res);
    2152           0 :                   res = SWIG_AddNewMask(res);
    2153             :                 } else {
    2154             :                   res = SWIG_AddCast(res);        
    2155             :                 }
    2156             :               }
    2157             :             }
    2158           0 :             Py_DECREF(impconv);
    2159             :           }
    2160             :         }
    2161             :       }
    2162           0 :       if (!SWIG_IsOK(res) && obj == Py_None) {
    2163           0 :         if (ptr)
    2164           0 :           *ptr = 0;
    2165           0 :         if (PyErr_Occurred())
    2166           0 :           PyErr_Clear();
    2167             :         res = SWIG_OK;
    2168             :       }
    2169             :     }
    2170             :   }
    2171             :   return res;
    2172             : }
    2173             : 
    2174             : /* Convert a function ptr value */
    2175             : 
    2176             : SWIGRUNTIME int
    2177             : SWIG_Python_ConvertFunctionPtr(PyObject *obj, void **ptr, swig_type_info *ty) {
    2178             :   if (!PyCFunction_Check(obj)) {
    2179             :     return SWIG_ConvertPtr(obj, ptr, ty, 0);
    2180             :   } else {
    2181             :     void *vptr = 0;
    2182             :     swig_cast_info *tc;
    2183             : 
    2184             :     /* here we get the method pointer for callbacks */
    2185             :     const char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc);
    2186             :     const char *desc = doc ? strstr(doc, "swig_ptr: ") : 0;
    2187             :     if (desc)
    2188             :       desc = ty ? SWIG_UnpackVoidPtr(desc + 10, &vptr, ty->name) : 0;
    2189             :     if (!desc)
    2190             :       return SWIG_ERROR;
    2191             :     tc = SWIG_TypeCheck(desc,ty);
    2192             :     if (tc) {
    2193             :       int newmemory = 0;
    2194             :       *ptr = SWIG_TypeCast(tc,vptr,&newmemory);
    2195             :       assert(!newmemory); /* newmemory handling not yet implemented */
    2196             :     } else {
    2197             :       return SWIG_ERROR;
    2198             :     }
    2199             :     return SWIG_OK;
    2200             :   }
    2201             : }
    2202             : 
    2203             : /* Convert a packed pointer value */
    2204             : 
    2205             : SWIGRUNTIME int
    2206             : SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *ty) {
    2207             :   swig_type_info *to = SwigPyPacked_UnpackData(obj, ptr, sz);
    2208             :   if (!to) return SWIG_ERROR;
    2209             :   if (ty) {
    2210             :     if (to != ty) {
    2211             :       /* check type cast? */
    2212             :       swig_cast_info *tc = SWIG_TypeCheck(to->name,ty);
    2213             :       if (!tc) return SWIG_ERROR;
    2214             :     }
    2215             :   }
    2216             :   return SWIG_OK;
    2217             : }  
    2218             : 
    2219             : /* -----------------------------------------------------------------------------
    2220             :  * Create a new pointer object
    2221             :  * ----------------------------------------------------------------------------- */
    2222             : 
    2223             : /*
    2224             :   Create a new instance object, without calling __init__, and set the
    2225             :   'this' attribute.
    2226             : */
    2227             : 
    2228             : SWIGRUNTIME PyObject* 
    2229             : SWIG_Python_NewShadowInstance(SwigPyClientData *data, PyObject *swig_this)
    2230             : {
    2231             :   PyObject *inst = 0;
    2232             :   PyObject *newraw = data->newraw;
    2233             :   if (newraw) {
    2234             :     inst = PyObject_Call(newraw, data->newargs, NULL);
    2235             :     if (inst) {
    2236             : #if !defined(SWIG_PYTHON_SLOW_GETSET_THIS)
    2237             :       PyObject **dictptr = _PyObject_GetDictPtr(inst);
    2238             :       if (dictptr != NULL) {
    2239             :   PyObject *dict = *dictptr;
    2240             :   if (dict == NULL) {
    2241             :     dict = PyDict_New();
    2242             :     *dictptr = dict;
    2243             :     PyDict_SetItem(dict, SWIG_This(), swig_this);
    2244             :   }
    2245             :       }
    2246             : #else
    2247             :       PyObject *key = SWIG_This();
    2248             :       PyObject_SetAttr(inst, key, swig_this);
    2249             : #endif
    2250             :     }
    2251             :   } else {
    2252             : #if PY_VERSION_HEX >= 0x03000000
    2253             :     PyObject *empty_args = PyTuple_New(0);
    2254             :     if (empty_args) {
    2255             :       PyObject *empty_kwargs = PyDict_New();
    2256             :       if (empty_kwargs) {
    2257             :         inst = ((PyTypeObject *)data->newargs)->tp_new((PyTypeObject *)data->newargs, empty_args, empty_kwargs);
    2258             :         Py_DECREF(empty_kwargs);
    2259             :         if (inst) {
    2260             :           PyObject_SetAttr(inst, SWIG_This(), swig_this);
    2261             :           Py_TYPE(inst)->tp_flags &= ~Py_TPFLAGS_VALID_VERSION_TAG;
    2262             :         }
    2263             :       }
    2264             :       Py_DECREF(empty_args);
    2265             :     }
    2266             : #else
    2267             :     PyObject *dict = PyDict_New();
    2268             :     if (dict) {
    2269             :       PyDict_SetItem(dict, SWIG_This(), swig_this);
    2270             :       inst = PyInstance_NewRaw(data->newargs, dict);
    2271             :       Py_DECREF(dict);
    2272             :     }
    2273             : #endif
    2274             :   }
    2275             :   return inst;
    2276             : }
    2277             : 
    2278             : SWIGRUNTIME void
    2279             : SWIG_Python_SetSwigThis(PyObject *inst, PyObject *swig_this)
    2280             : {
    2281             :  PyObject *dict;
    2282             : #if !defined(SWIG_PYTHON_SLOW_GETSET_THIS)
    2283             :  PyObject **dictptr = _PyObject_GetDictPtr(inst);
    2284             :  if (dictptr != NULL) {
    2285             :    dict = *dictptr;
    2286             :    if (dict == NULL) {
    2287             :      dict = PyDict_New();
    2288             :      *dictptr = dict;
    2289             :    }
    2290             :    PyDict_SetItem(dict, SWIG_This(), swig_this);
    2291             :    return;
    2292             :  }
    2293             : #endif
    2294             :  dict = PyObject_GetAttrString(inst, "__dict__");
    2295             :  PyDict_SetItem(dict, SWIG_This(), swig_this);
    2296             :  Py_DECREF(dict);
    2297             : } 
    2298             : 
    2299             : 
    2300             : SWIGINTERN PyObject *
    2301             : SWIG_Python_InitShadowInstance(PyObject *args) {
    2302             :   PyObject *obj[2];
    2303             :   if (!SWIG_Python_UnpackTuple(args, "swiginit", 2, 2, obj)) {
    2304             :     return NULL;
    2305             :   } else {
    2306             :     SwigPyObject *sthis = SWIG_Python_GetSwigThis(obj[0]);
    2307             :     if (sthis) {
    2308             :       SwigPyObject_append((PyObject*) sthis, obj[1]);
    2309             :     } else {
    2310             :       SWIG_Python_SetSwigThis(obj[0], obj[1]);
    2311             :     }
    2312             :     return SWIG_Py_Void();
    2313             :   }
    2314             : }
    2315             : 
    2316             : /* Create a new pointer object */
    2317             : 
    2318             : SWIGRUNTIME PyObject *
    2319         274 : SWIG_Python_NewPointerObj(PyObject *self, void *ptr, swig_type_info *type, int flags) {
    2320         274 :   SwigPyClientData *clientdata;
    2321         274 :   PyObject * robj;
    2322         274 :   int own;
    2323             : 
    2324         274 :   if (!ptr)
    2325           3 :     return SWIG_Py_Void();
    2326             : 
    2327         271 :   clientdata = type ? (SwigPyClientData *)(type->clientdata) : 0;
    2328         271 :   own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0;
    2329         271 :   if (clientdata && clientdata->pytype) {
    2330           0 :     SwigPyObject *newobj;
    2331           0 :     if (flags & SWIG_BUILTIN_TP_INIT) {
    2332           0 :       newobj = (SwigPyObject*) self;
    2333           0 :       if (newobj->ptr) {
    2334           0 :         PyObject *next_self = clientdata->pytype->tp_alloc(clientdata->pytype, 0);
    2335           0 :         while (newobj->next)
    2336             :     newobj = (SwigPyObject *) newobj->next;
    2337           0 :         newobj->next = next_self;
    2338           0 :         newobj = (SwigPyObject *)next_self;
    2339             : #ifdef SWIGPYTHON_BUILTIN
    2340             :         newobj->dict = 0;
    2341             : #endif
    2342             :       }
    2343             :     } else {
    2344           0 :       newobj = PyObject_New(SwigPyObject, clientdata->pytype);
    2345             : #ifdef SWIGPYTHON_BUILTIN
    2346             :       newobj->dict = 0;
    2347             : #endif
    2348             :     }
    2349           0 :     if (newobj) {
    2350           0 :       newobj->ptr = ptr;
    2351           0 :       newobj->ty = type;
    2352           0 :       newobj->own = own;
    2353           0 :       newobj->next = 0;
    2354           0 :       return (PyObject*) newobj;
    2355             :     }
    2356           0 :     return SWIG_Py_Void();
    2357             :   }
    2358             : 
    2359         271 :   assert(!(flags & SWIG_BUILTIN_TP_INIT));
    2360             : 
    2361         271 :   robj = SwigPyObject_New(ptr, type, own);
    2362         271 :   if (robj && clientdata && !(flags & SWIG_POINTER_NOSHADOW)) {
    2363          46 :     PyObject *inst = SWIG_Python_NewShadowInstance(clientdata, robj);
    2364          46 :     Py_DECREF(robj);
    2365             :     robj = inst;
    2366             :   }
    2367             :   return robj;
    2368             : }
    2369             : 
    2370             : /* Create a new packed object */
    2371             : 
    2372             : SWIGRUNTIMEINLINE PyObject *
    2373           0 : SWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) {
    2374           0 :   return ptr ? SwigPyPacked_New((void *) ptr, sz, type) : SWIG_Py_Void();
    2375             : }
    2376             : 
    2377             : /* -----------------------------------------------------------------------------*
    2378             :  *  Get type list 
    2379             :  * -----------------------------------------------------------------------------*/
    2380             : 
    2381             : #ifdef SWIG_LINK_RUNTIME
    2382             : void *SWIG_ReturnGlobalTypeList(void *);
    2383             : #endif
    2384             : 
    2385             : SWIGRUNTIME swig_module_info *
    2386             : SWIG_Python_GetModule(void *SWIGUNUSEDPARM(clientdata)) {
    2387             :   static void *type_pointer = (void *)0;
    2388             :   /* first check if module already created */
    2389             :   if (!type_pointer) {
    2390             : #ifdef SWIG_LINK_RUNTIME
    2391             :     type_pointer = SWIG_ReturnGlobalTypeList((void *)0);
    2392             : #else
    2393             :     type_pointer = PyCapsule_Import(SWIGPY_CAPSULE_NAME, 0);
    2394             :     if (PyErr_Occurred()) {
    2395             :       PyErr_Clear();
    2396             :       type_pointer = (void *)0;
    2397             :     }
    2398             : #endif
    2399             :   }
    2400             :   return (swig_module_info *) type_pointer;
    2401             : }
    2402             : 
    2403             : SWIGRUNTIME void
    2404           0 : SWIG_Python_DestroyModule(PyObject *obj)
    2405             : {
    2406           0 :   swig_module_info *swig_module = (swig_module_info *) PyCapsule_GetPointer(obj, SWIGPY_CAPSULE_NAME);
    2407           0 :   swig_type_info **types = swig_module->types;
    2408           0 :   size_t i;
    2409           0 :   for (i =0; i < swig_module->size; ++i) {
    2410           0 :     swig_type_info *ty = types[i];
    2411           0 :     if (ty->owndata) {
    2412           0 :       SwigPyClientData *data = (SwigPyClientData *) ty->clientdata;
    2413           0 :       if (data) SwigPyClientData_Del(data);
    2414             :     }
    2415             :   }
    2416           0 :   Py_DECREF(SWIG_This());
    2417           0 :   Swig_This_global = NULL;
    2418           0 : }
    2419             : 
    2420             : SWIGRUNTIME void
    2421           0 : SWIG_Python_SetModule(swig_module_info *swig_module) {
    2422             : #if PY_VERSION_HEX >= 0x03000000
    2423             :  /* Add a dummy module object into sys.modules */
    2424           0 :   PyObject *module = PyImport_AddModule("swig_runtime_data" SWIG_RUNTIME_VERSION);
    2425             : #else
    2426             :   static PyMethodDef swig_empty_runtime_method_table[] = { {NULL, NULL, 0, NULL} }; /* Sentinel */
    2427             :   PyObject *module = Py_InitModule("swig_runtime_data" SWIG_RUNTIME_VERSION, swig_empty_runtime_method_table);
    2428             : #endif
    2429           0 :   PyObject *pointer = PyCapsule_New((void *) swig_module, SWIGPY_CAPSULE_NAME, SWIG_Python_DestroyModule);
    2430           0 :   if (pointer && module) {
    2431           0 :     PyModule_AddObject(module, "type_pointer_capsule" SWIG_TYPE_TABLE_NAME, pointer);
    2432             :   } else {
    2433           0 :     Py_XDECREF(pointer);
    2434             :   }
    2435           0 : }
    2436             : 
    2437             : /* The python cached type query */
    2438             : SWIGRUNTIME PyObject *
    2439         225 : SWIG_Python_TypeCache(void) {
    2440         225 :   static PyObject *SWIG_STATIC_POINTER(cache) = PyDict_New();
    2441         225 :   return cache;
    2442             : }
    2443             : 
    2444             : SWIGRUNTIME swig_type_info *
    2445           0 : SWIG_Python_TypeQuery(const char *type)
    2446             : {
    2447           0 :   PyObject *cache = SWIG_Python_TypeCache();
    2448           0 :   PyObject *key = SWIG_Python_str_FromChar(type); 
    2449           0 :   PyObject *obj = PyDict_GetItem(cache, key);
    2450           0 :   swig_type_info *descriptor;
    2451           0 :   if (obj) {
    2452           0 :     descriptor = (swig_type_info *) PyCapsule_GetPointer(obj, NULL);
    2453             :   } else {
    2454           0 :     swig_module_info *swig_module = SWIG_GetModule(0);
    2455           0 :     descriptor = SWIG_TypeQueryModule(swig_module, swig_module, type);
    2456           0 :     if (descriptor) {
    2457           0 :       obj = PyCapsule_New((void*) descriptor, NULL, NULL);
    2458           0 :       PyDict_SetItem(cache, key, obj);
    2459           0 :       Py_DECREF(obj);
    2460             :     }
    2461             :   }
    2462           0 :   Py_DECREF(key);
    2463           0 :   return descriptor;
    2464             : }
    2465             : 
    2466             : /* 
    2467             :    For backward compatibility only
    2468             : */
    2469             : #define SWIG_POINTER_EXCEPTION  0
    2470             : #define SWIG_arg_fail(arg)      SWIG_Python_ArgFail(arg)
    2471             : #define SWIG_MustGetPtr(p, type, argnum, flags)  SWIG_Python_MustGetPtr(p, type, argnum, flags)
    2472             : 
    2473             : SWIGRUNTIME int
    2474             : SWIG_Python_AddErrMesg(const char* mesg, int infront)
    2475             : {  
    2476             :   if (PyErr_Occurred()) {
    2477             :     PyObject *type = 0;
    2478             :     PyObject *value = 0;
    2479             :     PyObject *traceback = 0;
    2480             :     PyErr_Fetch(&type, &value, &traceback);
    2481             :     if (value) {
    2482             :       PyObject *old_str = PyObject_Str(value);
    2483             :       const char *tmp = SWIG_Python_str_AsChar(old_str);
    2484             :       const char *errmesg = tmp ? tmp : "Invalid error message";
    2485             :       Py_XINCREF(type);
    2486             :       PyErr_Clear();
    2487             :       if (infront) {
    2488             :   PyErr_Format(type, "%s %s", mesg, errmesg);
    2489             :       } else {
    2490             :   PyErr_Format(type, "%s %s", errmesg, mesg);
    2491             :       }
    2492             :       SWIG_Python_str_DelForPy3(tmp);
    2493             :       Py_DECREF(old_str);
    2494             :     }
    2495             :     return 1;
    2496             :   } else {
    2497             :     return 0;
    2498             :   }
    2499             : }
    2500             :   
    2501             : SWIGRUNTIME int
    2502             : SWIG_Python_ArgFail(int argnum)
    2503             : {
    2504             :   if (PyErr_Occurred()) {
    2505             :     /* add information about failing argument */
    2506             :     char mesg[256];
    2507             :     PyOS_snprintf(mesg, sizeof(mesg), "argument number %d:", argnum);
    2508             :     return SWIG_Python_AddErrMesg(mesg, 1);
    2509             :   } else {
    2510             :     return 0;
    2511             :   }
    2512             : }
    2513             : 
    2514             : SWIGRUNTIMEINLINE const char *
    2515             : SwigPyObject_GetDesc(PyObject *self)
    2516             : {
    2517             :   SwigPyObject *v = (SwigPyObject *)self;
    2518             :   swig_type_info *ty = v ? v->ty : 0;
    2519             :   return ty ? ty->str : "";
    2520             : }
    2521             : 
    2522             : SWIGRUNTIME void
    2523             : SWIG_Python_TypeError(const char *type, PyObject *obj)
    2524             : {
    2525             :   if (type) {
    2526             : #if defined(SWIG_COBJECT_TYPES)
    2527             :     if (obj && SwigPyObject_Check(obj)) {
    2528             :       const char *otype = (const char *) SwigPyObject_GetDesc(obj);
    2529             :       if (otype) {
    2530             :   PyErr_Format(PyExc_TypeError, "a '%s' is expected, 'SwigPyObject(%s)' is received",
    2531             :          type, otype);
    2532             :   return;
    2533             :       }
    2534             :     } else 
    2535             : #endif      
    2536             :     {
    2537             :       const char *otype = (obj ? obj->ob_type->tp_name : 0); 
    2538             :       if (otype) {
    2539             :   PyObject *str = PyObject_Str(obj);
    2540             :   const char *cstr = str ? SWIG_Python_str_AsChar(str) : 0;
    2541             :   if (cstr) {
    2542             :     PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s(%s)' is received",
    2543             :            type, otype, cstr);
    2544             :           SWIG_Python_str_DelForPy3(cstr);
    2545             :   } else {
    2546             :     PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s' is received",
    2547             :            type, otype);
    2548             :   }
    2549             :   Py_XDECREF(str);
    2550             :   return;
    2551             :       }
    2552             :     }   
    2553             :     PyErr_Format(PyExc_TypeError, "a '%s' is expected", type);
    2554             :   } else {
    2555             :     PyErr_Format(PyExc_TypeError, "unexpected type is received");
    2556             :   }
    2557             : }
    2558             : 
    2559             : 
    2560             : /* Convert a pointer value, signal an exception on a type mismatch */
    2561             : SWIGRUNTIME void *
    2562             : SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int SWIGUNUSEDPARM(argnum), int flags) {
    2563             :   void *result;
    2564             :   if (SWIG_Python_ConvertPtr(obj, &result, ty, flags) == -1) {
    2565             :     PyErr_Clear();
    2566             : #if SWIG_POINTER_EXCEPTION
    2567             :     if (flags) {
    2568             :       SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj);
    2569             :       SWIG_Python_ArgFail(argnum);
    2570             :     }
    2571             : #endif
    2572             :   }
    2573             :   return result;
    2574             : }
    2575             : 
    2576             : #ifdef SWIGPYTHON_BUILTIN
    2577             : SWIGRUNTIME int
    2578             : SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) {
    2579             :   PyTypeObject *tp = obj->ob_type;
    2580             :   PyObject *descr;
    2581             :   PyObject *encoded_name;
    2582             :   descrsetfunc f;
    2583             :   int res = -1;
    2584             : 
    2585             : # ifdef Py_USING_UNICODE
    2586             :   if (PyString_Check(name)) {
    2587             :     name = PyUnicode_Decode(PyString_AsString(name), PyString_Size(name), NULL, NULL);
    2588             :     if (!name)
    2589             :       return -1;
    2590             :   } else if (!PyUnicode_Check(name))
    2591             : # else
    2592             :   if (!PyString_Check(name))
    2593             : # endif
    2594             :   {
    2595             :     PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", name->ob_type->tp_name);
    2596             :     return -1;
    2597             :   } else {
    2598             :     Py_INCREF(name);
    2599             :   }
    2600             : 
    2601             :   if (!tp->tp_dict) {
    2602             :     if (PyType_Ready(tp) < 0)
    2603             :       goto done;
    2604             :   }
    2605             : 
    2606             :   descr = _PyType_Lookup(tp, name);
    2607             :   f = NULL;
    2608             :   if (descr != NULL)
    2609             :     f = descr->ob_type->tp_descr_set;
    2610             :   if (!f) {
    2611             :     if (PyString_Check(name)) {
    2612             :       encoded_name = name;
    2613             :       Py_INCREF(name);
    2614             :     } else {
    2615             :       encoded_name = PyUnicode_AsUTF8String(name);
    2616             :       if (!encoded_name)
    2617             :         return -1;
    2618             :     }
    2619             :     PyErr_Format(PyExc_AttributeError, "'%.100s' object has no attribute '%.200s'", tp->tp_name, PyString_AsString(encoded_name));
    2620             :     Py_DECREF(encoded_name);
    2621             :   } else {
    2622             :     res = f(descr, obj, value);
    2623             :   }
    2624             :   
    2625             :   done:
    2626             :   Py_DECREF(name);
    2627             :   return res;
    2628             : }
    2629             : #endif
    2630             : 
    2631             : 
    2632             : #ifdef __cplusplus
    2633             : }
    2634             : #endif
    2635             : 
    2636             : 
    2637             : 
    2638             : #define SWIG_exception_fail(code, msg) do { SWIG_Error(code, msg); SWIG_fail; } while(0) 
    2639             : 
    2640             : #define SWIG_contract_assert(expr, msg) if (!(expr)) { SWIG_Error(SWIG_RuntimeError, msg); SWIG_fail; } else 
    2641             : 
    2642             : 
    2643             : 
    2644             : #ifdef __cplusplus
    2645             : extern "C" {
    2646             : #endif
    2647             : 
    2648             : /* Method creation and docstring support functions */
    2649             : 
    2650             : SWIGINTERN PyMethodDef *SWIG_PythonGetProxyDoc(const char *name);
    2651             : SWIGINTERN PyObject *SWIG_PyInstanceMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *func);
    2652             : SWIGINTERN PyObject *SWIG_PyStaticMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *func);
    2653             : 
    2654             : #ifdef __cplusplus
    2655             : }
    2656             : #endif
    2657             : 
    2658             : 
    2659             :   #define SWIG_exception(code, msg) do { SWIG_Error(code, msg); SWIG_fail;; } while(0) 
    2660             : 
    2661             : 
    2662             : /* -------- TYPES TABLE (BEGIN) -------- */
    2663             : 
    2664             : #define SWIGTYPE_p_ArrowArray swig_types[0]
    2665             : #define SWIGTYPE_p_ArrowSchema swig_types[1]
    2666             : #define SWIGTYPE_p_CPLVirtualMemShadow swig_types[2]
    2667             : #define SWIGTYPE_p_GDALComputedRasterBandShadow swig_types[3]
    2668             : #define SWIGTYPE_p_GDALDataType swig_types[4]
    2669             : #define SWIGTYPE_p_GDALDatasetShadow swig_types[5]
    2670             : #define SWIGTYPE_p_GDALExtendedDataTypeHS swig_types[6]
    2671             : #define SWIGTYPE_p_GDALMDArrayHS swig_types[7]
    2672             : #define SWIGTYPE_p_GDALProgressFunc swig_types[8]
    2673             : #define SWIGTYPE_p_GDALRasterAttributeTableShadow swig_types[9]
    2674             : #define SWIGTYPE_p_GDALRasterBandShadow swig_types[10]
    2675             : #define SWIGTYPE_p_GIntBig swig_types[11]
    2676             : #define SWIGTYPE_p_GUIntBig swig_types[12]
    2677             : #define SWIGTYPE_p_PyArrayObject swig_types[13]
    2678             : #define SWIGTYPE_p_char swig_types[14]
    2679             : #define SWIGTYPE_p_f_double_p_q_const__char_p_void__int swig_types[15]
    2680             : #define SWIGTYPE_p_int swig_types[16]
    2681             : #define SWIGTYPE_p_p_CPLVirtualMemShadow swig_types[17]
    2682             : #define SWIGTYPE_p_p_void swig_types[18]
    2683             : #define SWIGTYPE_p_size_t swig_types[19]
    2684             : #define SWIGTYPE_p_std__string swig_types[20]
    2685             : static swig_type_info *swig_types[22];
    2686             : static swig_module_info swig_module = {swig_types, 21, 0, 0, 0, 0};
    2687             : #define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name)
    2688             : #define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name)
    2689             : 
    2690             : /* -------- TYPES TABLE (END) -------- */
    2691             : 
    2692             : #ifdef SWIG_TypeQuery
    2693             : # undef SWIG_TypeQuery
    2694             : #endif
    2695             : #define SWIG_TypeQuery SWIG_Python_TypeQuery
    2696             : 
    2697             : /*-----------------------------------------------
    2698             :               @(target):= _gdal_array.so
    2699             :   ------------------------------------------------*/
    2700             : #if PY_VERSION_HEX >= 0x03000000
    2701             : #  define SWIG_init    PyInit__gdal_array
    2702             : 
    2703             : #else
    2704             : #  define SWIG_init    init_gdal_array
    2705             : 
    2706             : #endif
    2707             : #define SWIG_name    "_gdal_array"
    2708             : 
    2709             : #define SWIGVERSION 0x040001 
    2710             : #define SWIG_VERSION SWIGVERSION
    2711             : 
    2712             : 
    2713             : #define SWIG_as_voidptr(a) const_cast< void * >(static_cast< const void * >(a)) 
    2714             : #define SWIG_as_voidptrptr(a) ((void)SWIG_as_voidptr(*a),reinterpret_cast< void** >(a)) 
    2715             : 
    2716             : 
    2717             : #include <stdexcept>
    2718             : 
    2719             : 
    2720             : namespace swig {
    2721             :   class SwigPtr_PyObject {
    2722             :   protected:
    2723             :     PyObject *_obj;
    2724             : 
    2725             :   public:
    2726             :     SwigPtr_PyObject() :_obj(0)
    2727             :     {
    2728             :     }
    2729             : 
    2730             :     SwigPtr_PyObject(const SwigPtr_PyObject& item) : _obj(item._obj)
    2731             :     {
    2732             :       SWIG_PYTHON_THREAD_BEGIN_BLOCK;
    2733             :       Py_XINCREF(_obj);      
    2734             :       SWIG_PYTHON_THREAD_END_BLOCK;
    2735             :     }
    2736             :     
    2737             :     SwigPtr_PyObject(PyObject *obj, bool initial_ref = true) :_obj(obj)
    2738             :     {
    2739             :       if (initial_ref) {
    2740             :         SWIG_PYTHON_THREAD_BEGIN_BLOCK;
    2741             :         Py_XINCREF(_obj);
    2742             :         SWIG_PYTHON_THREAD_END_BLOCK;
    2743             :       }
    2744             :     }
    2745             :     
    2746             :     SwigPtr_PyObject & operator=(const SwigPtr_PyObject& item) 
    2747             :     {
    2748             :       SWIG_PYTHON_THREAD_BEGIN_BLOCK;
    2749             :       Py_XINCREF(item._obj);
    2750             :       Py_XDECREF(_obj);
    2751             :       _obj = item._obj;
    2752             :       SWIG_PYTHON_THREAD_END_BLOCK;
    2753             :       return *this;      
    2754             :     }
    2755             :     
    2756             :     ~SwigPtr_PyObject() 
    2757             :     {
    2758             :       SWIG_PYTHON_THREAD_BEGIN_BLOCK;
    2759             :       Py_XDECREF(_obj);
    2760             :       SWIG_PYTHON_THREAD_END_BLOCK;
    2761             :     }
    2762             :     
    2763             :     operator PyObject *() const
    2764             :     {
    2765             :       return _obj;
    2766             :     }
    2767             : 
    2768             :     PyObject *operator->() const
    2769             :     {
    2770             :       return _obj;
    2771             :     }
    2772             :   };
    2773             : }
    2774             : 
    2775             : 
    2776             : namespace swig {
    2777             :   struct SwigVar_PyObject : SwigPtr_PyObject {
    2778             :     SwigVar_PyObject(PyObject* obj = 0) : SwigPtr_PyObject(obj, false) { }
    2779             :     
    2780             :     SwigVar_PyObject & operator = (PyObject* obj)
    2781             :     {
    2782             :       Py_XDECREF(_obj);
    2783             :       _obj = obj;
    2784             :       return *this;      
    2785             :     }
    2786             :   };
    2787             : }
    2788             : 
    2789             : 
    2790             : #include "gdal.h"
    2791             : 
    2792             : typedef struct
    2793             : {
    2794             :     CPLVirtualMem *vmem;
    2795             :     int            bAuto;
    2796             :     GDALDataType   eBufType;
    2797             :     int            bIsBandSequential;
    2798             :     int            bReadOnly;
    2799             :     int            nBufXSize;
    2800             :     int            nBufYSize;
    2801             :     int            nBandCount;
    2802             :     GDALTileOrganization eTileOrganization;
    2803             :     int                  nTileXSize;
    2804             :     int                  nTileYSize;
    2805             :     int            nPixelSpace; /* if bAuto == TRUE */
    2806             :     GIntBig        nLineSpace; /* if bAuto == TRUE */
    2807             : } CPLVirtualMemShadow;
    2808             : 
    2809             : 
    2810          28 : SWIGINTERN void delete_CPLVirtualMemShadow(CPLVirtualMemShadow *self){
    2811          28 :         CPLVirtualMemFree( self->vmem );
    2812          28 :         free(self);
    2813             :     }
    2814           0 : SWIGINTERN void CPLVirtualMemShadow_GetAddr(CPLVirtualMemShadow *self,void **pptr,size_t *pnsize,GDALDataType *pdatatype,int *preadonly){
    2815           0 :         *pptr = CPLVirtualMemGetAddr( self->vmem );
    2816           0 :         *pnsize = CPLVirtualMemGetSize( self->vmem );
    2817           0 :         *pdatatype = self->eBufType;
    2818           0 :         *preadonly = self->bReadOnly;
    2819             :     }
    2820             : 
    2821             : SWIGINTERN int
    2822       77460 : SWIG_AsVal_double (PyObject *obj, double *val)
    2823             : {
    2824       77460 :   int res = SWIG_TypeError;
    2825       77460 :   if (PyFloat_Check(obj)) {
    2826         278 :     if (val) *val = PyFloat_AsDouble(obj);
    2827         278 :     return SWIG_OK;
    2828             : #if PY_VERSION_HEX < 0x03000000
    2829             :   } else if (PyInt_Check(obj)) {
    2830             :     if (val) *val = (double) PyInt_AsLong(obj);
    2831             :     return SWIG_OK;
    2832             : #endif
    2833       77182 :   } else if (PyLong_Check(obj)) {
    2834       77182 :     double v = PyLong_AsDouble(obj);
    2835       77182 :     if (!PyErr_Occurred()) {
    2836       77182 :       if (val) *val = v;
    2837       77182 :       return SWIG_OK;
    2838             :     } else {
    2839           0 :       PyErr_Clear();
    2840             :     }
    2841             :   }
    2842             : #ifdef SWIG_PYTHON_CAST_MODE
    2843             :   {
    2844             :     int dispatch = 0;
    2845             :     double d = PyFloat_AsDouble(obj);
    2846             :     if (!PyErr_Occurred()) {
    2847             :       if (val) *val = d;
    2848             :       return SWIG_AddCast(SWIG_OK);
    2849             :     } else {
    2850             :       PyErr_Clear();
    2851             :     }
    2852             :     if (!dispatch) {
    2853             :       long v = PyLong_AsLong(obj);
    2854             :       if (!PyErr_Occurred()) {
    2855             :   if (val) *val = v;
    2856             :   return SWIG_AddCast(SWIG_AddCast(SWIG_OK));
    2857             :       } else {
    2858             :   PyErr_Clear();
    2859             :       }
    2860             :     }
    2861             :   }
    2862             : #endif
    2863             :   return res;
    2864             : }
    2865             : 
    2866             : 
    2867             : #include <float.h>
    2868             : 
    2869             : 
    2870             : #include <math.h>
    2871             : 
    2872             : 
    2873             : SWIGINTERNINLINE int
    2874             : SWIG_CanCastAsInteger(double *d, double min, double max) {
    2875             :   double x = *d;
    2876             :   if ((min <= x && x <= max)) {
    2877             :    double fx = floor(x);
    2878             :    double cx = ceil(x);
    2879             :    double rd =  ((x - fx) < 0.5) ? fx : cx; /* simple rint */
    2880             :    if ((errno == EDOM) || (errno == ERANGE)) {
    2881             :      errno = 0;
    2882             :    } else {
    2883             :      double summ, reps, diff;
    2884             :      if (rd < x) {
    2885             :        diff = x - rd;
    2886             :      } else if (rd > x) {
    2887             :        diff = rd - x;
    2888             :      } else {
    2889             :        return 1;
    2890             :      }
    2891             :      summ = rd + x;
    2892             :      reps = diff/summ;
    2893             :      if (reps < 8*DBL_EPSILON) {
    2894             :        *d = rd;
    2895             :        return 1;
    2896             :      }
    2897             :    }
    2898             :   }
    2899             :   return 0;
    2900             : }
    2901             : 
    2902             : 
    2903             : SWIGINTERN int
    2904           0 : SWIG_AsVal_unsigned_SS_long (PyObject *obj, unsigned long *val) 
    2905             : {
    2906             : #if PY_VERSION_HEX < 0x03000000
    2907             :   if (PyInt_Check(obj)) {
    2908             :     long v = PyInt_AsLong(obj);
    2909             :     if (v >= 0) {
    2910             :       if (val) *val = v;
    2911             :       return SWIG_OK;
    2912             :     } else {
    2913             :       return SWIG_OverflowError;
    2914             :     }
    2915             :   } else
    2916             : #endif
    2917           0 :   if (PyLong_Check(obj)) {
    2918           0 :     unsigned long v = PyLong_AsUnsignedLong(obj);
    2919           0 :     if (!PyErr_Occurred()) {
    2920           0 :       if (val) *val = v;
    2921           0 :       return SWIG_OK;
    2922             :     } else {
    2923           0 :       PyErr_Clear();
    2924           0 :       return SWIG_OverflowError;
    2925             :     }
    2926             :   }
    2927             : #ifdef SWIG_PYTHON_CAST_MODE
    2928             :   {
    2929             :     int dispatch = 0;
    2930             :     unsigned long v = PyLong_AsUnsignedLong(obj);
    2931             :     if (!PyErr_Occurred()) {
    2932             :       if (val) *val = v;
    2933             :       return SWIG_AddCast(SWIG_OK);
    2934             :     } else {
    2935             :       PyErr_Clear();
    2936             :     }
    2937             :     if (!dispatch) {
    2938             :       double d;
    2939             :       int res = SWIG_AddCast(SWIG_AsVal_double (obj,&d));
    2940             :       if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, 0, ULONG_MAX)) {
    2941             :   if (val) *val = (unsigned long)(d);
    2942             :   return res;
    2943             :       }
    2944             :     }
    2945             :   }
    2946             : #endif
    2947             :   return SWIG_TypeError;
    2948             : }
    2949             : 
    2950             : 
    2951             : #include <limits.h>
    2952             : #if !defined(SWIG_NO_LLONG_MAX)
    2953             : # if !defined(LLONG_MAX) && defined(__GNUC__) && defined (__LONG_LONG_MAX__)
    2954             : #   define LLONG_MAX __LONG_LONG_MAX__
    2955             : #   define LLONG_MIN (-LLONG_MAX - 1LL)
    2956             : #   define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL)
    2957             : # endif
    2958             : #endif
    2959             : 
    2960             : 
    2961             : #if defined(LLONG_MAX) && !defined(SWIG_LONG_LONG_AVAILABLE)
    2962             : #  define SWIG_LONG_LONG_AVAILABLE
    2963             : #endif
    2964             : 
    2965             : 
    2966             : #ifdef SWIG_LONG_LONG_AVAILABLE
    2967             : SWIGINTERN int
    2968             : SWIG_AsVal_unsigned_SS_long_SS_long (PyObject *obj, unsigned long long *val)
    2969             : {
    2970             :   int res = SWIG_TypeError;
    2971             :   if (PyLong_Check(obj)) {
    2972             :     unsigned long long v = PyLong_AsUnsignedLongLong(obj);
    2973             :     if (!PyErr_Occurred()) {
    2974             :       if (val) *val = v;
    2975             :       return SWIG_OK;
    2976             :     } else {
    2977             :       PyErr_Clear();
    2978             :       res = SWIG_OverflowError;
    2979             :     }
    2980             :   } else {
    2981             :     unsigned long v;
    2982             :     res = SWIG_AsVal_unsigned_SS_long (obj,&v);
    2983             :     if (SWIG_IsOK(res)) {
    2984             :       if (val) *val = v;
    2985             :       return res;
    2986             :     }
    2987             :   }
    2988             : #ifdef SWIG_PYTHON_CAST_MODE
    2989             :   {
    2990             :     const double mant_max = 1LL << DBL_MANT_DIG;
    2991             :     double d;
    2992             :     res = SWIG_AsVal_double (obj,&d);
    2993             :     if (SWIG_IsOK(res) && !SWIG_CanCastAsInteger(&d, 0, mant_max))
    2994             :       return SWIG_OverflowError;
    2995             :     if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, 0, mant_max)) {
    2996             :       if (val) *val = (unsigned long long)(d);
    2997             :       return SWIG_AddCast(res);
    2998             :     }
    2999             :     res = SWIG_TypeError;
    3000             :   }
    3001             : #endif
    3002             :   return res;
    3003             : }
    3004             : #endif
    3005             : 
    3006             : 
    3007             : SWIGINTERNINLINE int
    3008           0 : SWIG_AsVal_size_t (PyObject * obj, size_t *val)
    3009             : {
    3010           0 :   int res = SWIG_TypeError;
    3011             : #ifdef SWIG_LONG_LONG_AVAILABLE
    3012           0 :   if (sizeof(size_t) <= sizeof(unsigned long)) {
    3013             : #endif
    3014           0 :     unsigned long v;
    3015           0 :     res = SWIG_AsVal_unsigned_SS_long (obj, val ? &v : 0);
    3016           0 :     if (SWIG_IsOK(res) && val) *val = static_cast< size_t >(v);
    3017             : #ifdef SWIG_LONG_LONG_AVAILABLE
    3018             :   } else if (sizeof(size_t) <= sizeof(unsigned long long)) {
    3019             :     unsigned long long v;
    3020             :     res = SWIG_AsVal_unsigned_SS_long_SS_long (obj, val ? &v : 0);
    3021             :     if (SWIG_IsOK(res) && val) *val = static_cast< size_t >(v);
    3022             :   }
    3023             : #endif
    3024           0 :   return res;
    3025             : }
    3026             : 
    3027             : 
    3028             : SWIGINTERN int
    3029       81057 : SWIG_AsVal_long (PyObject *obj, long* val)
    3030             : {
    3031             : #if PY_VERSION_HEX < 0x03000000
    3032             :   if (PyInt_Check(obj)) {
    3033             :     if (val) *val = PyInt_AsLong(obj);
    3034             :     return SWIG_OK;
    3035             :   } else
    3036             : #endif
    3037       81057 :   if (PyLong_Check(obj)) {
    3038       81055 :     long v = PyLong_AsLong(obj);
    3039       81055 :     if (!PyErr_Occurred()) {
    3040       81055 :       if (val) *val = v;
    3041       81055 :       return SWIG_OK;
    3042             :     } else {
    3043           0 :       PyErr_Clear();
    3044           0 :       return SWIG_OverflowError;
    3045             :     }
    3046             :   }
    3047             : #ifdef SWIG_PYTHON_CAST_MODE
    3048             :   {
    3049             :     int dispatch = 0;
    3050             :     long v = PyInt_AsLong(obj);
    3051             :     if (!PyErr_Occurred()) {
    3052             :       if (val) *val = v;
    3053             :       return SWIG_AddCast(SWIG_OK);
    3054             :     } else {
    3055             :       PyErr_Clear();
    3056             :     }
    3057             :     if (!dispatch) {
    3058             :       double d;
    3059             :       int res = SWIG_AddCast(SWIG_AsVal_double (obj,&d));
    3060             :       if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, LONG_MIN, LONG_MAX)) {
    3061             :   if (val) *val = (long)(d);
    3062             :   return res;
    3063             :       }
    3064             :     }
    3065             :   }
    3066             : #endif
    3067             :   return SWIG_TypeError;
    3068             : }
    3069             : 
    3070             : 
    3071             : SWIGINTERN int
    3072       81057 : SWIG_AsVal_int (PyObject * obj, int *val)
    3073             : {
    3074       81057 :   long v;
    3075      162114 :   int res = SWIG_AsVal_long (obj, &v);
    3076       81057 :   if (SWIG_IsOK(res)) {
    3077       81055 :     if ((v < INT_MIN || v > INT_MAX)) {
    3078             :       return SWIG_OverflowError;
    3079             :     } else {
    3080       81055 :       if (val) *val = static_cast< int >(v);
    3081             :     }
    3082             :   }  
    3083             :   return res;
    3084             : }
    3085             : 
    3086             : SWIGINTERN void CPLVirtualMemShadow_Pin__SWIG_0(CPLVirtualMemShadow *self,size_t start_offset=0,size_t nsize=0,int bWriteOp=0){
    3087             :         if( nsize == 0 || start_offset + nsize >= CPLVirtualMemGetSize( self->vmem ) )
    3088             :             nsize = CPLVirtualMemGetSize( self->vmem ) - start_offset;
    3089             :         char* start_addr = (char*)CPLVirtualMemGetAddr( self->vmem ) + start_offset;
    3090             :         CPLVirtualMemPin(self->vmem, start_addr, nsize, bWriteOp);
    3091             :     }
    3092             : 
    3093             : #include "cpl_string.h"
    3094             : #include "cpl_conv.h"
    3095             : 
    3096             : static int bUseExceptions=0;
    3097             : static int bUserHasSpecifiedIfUsingExceptions = FALSE;
    3098             : static thread_local int bUseExceptionsLocal = -1;
    3099             : 
    3100       16712 : struct PythonBindingErrorHandlerContext
    3101             : {
    3102             :     std::string     osInitialMsg{};
    3103             :     std::string     osFailureMsg{};
    3104             :     CPLErrorNum     nLastCode = CPLE_None;
    3105             :     bool            bMemoryError = false;
    3106             : };
    3107             : 
    3108             : static void CPL_STDCALL
    3109         350 : PythonBindingErrorHandler(CPLErr eclass, CPLErrorNum err_no, const char *msg )
    3110             : {
    3111         350 :   PythonBindingErrorHandlerContext* ctxt = static_cast<
    3112         350 :       PythonBindingErrorHandlerContext*>(CPLGetErrorHandlerUserData());
    3113             : 
    3114             :   /*
    3115             :   ** Generally we want to suppress error reporting if we have exceptions
    3116             :   ** enabled as the error message will be in the exception thrown in
    3117             :   ** Python.
    3118             :   */
    3119             : 
    3120             :   /* If the error class is CE_Fatal, we want to have a message issued
    3121             :      because the CPL support code does an abort() before any exception
    3122             :      can be generated */
    3123         350 :   if (eclass == CE_Fatal ) {
    3124           0 :     CPLCallPreviousHandler(eclass, err_no, msg );
    3125             :   }
    3126             : 
    3127             :   /*
    3128             :   ** We do not want to interfere with non-failure messages since
    3129             :   ** they won't be translated into exceptions.
    3130             :   */
    3131         350 :   else if (eclass != CE_Failure ) {
    3132         302 :     CPLCallPreviousHandler(eclass, err_no, msg );
    3133             :   }
    3134             :   else {
    3135          48 :     ctxt->nLastCode = err_no;
    3136          48 :     try
    3137             :     {
    3138          48 :         if( ctxt->osFailureMsg.empty() ) {
    3139          31 :           ctxt->osFailureMsg = msg;
    3140          31 :           ctxt->osInitialMsg = ctxt->osFailureMsg;
    3141             :         } else {
    3142          17 :           if( ctxt->osFailureMsg.size() < 10000 ) {
    3143          34 :             std::string osTmp(msg);
    3144          17 :             osTmp += "\nMay be caused by: ";
    3145          17 :             osTmp += ctxt->osFailureMsg;
    3146          17 :             ctxt->osFailureMsg = std::move(osTmp);
    3147          17 :             ctxt->osInitialMsg = ctxt->osFailureMsg;
    3148             :           }
    3149             :           else
    3150             :           {
    3151           0 :             std::string osTmp(msg);
    3152           0 :             osTmp += "\n[...]\nMay be caused by: ";
    3153           0 :             osTmp += ctxt->osInitialMsg;
    3154           0 :             ctxt->osFailureMsg = std::move(osTmp);
    3155             :           }
    3156             :         }
    3157             :     }
    3158           0 :     catch( const std::exception& )
    3159             :     {
    3160           0 :         ctxt->bMemoryError = true;
    3161             :     }
    3162             :   }
    3163         350 : }
    3164             : 
    3165             : 
    3166             : 
    3167             : 
    3168             : static
    3169       20058 : int GetUseExceptions() {
    3170        1366 :   return bUseExceptionsLocal >= 0 ? bUseExceptionsLocal : bUseExceptions;
    3171             : }
    3172             : 
    3173           0 : static int _GetExceptionsLocal()
    3174             : {
    3175           0 :   return bUseExceptionsLocal;
    3176             : }
    3177             : 
    3178       22780 : static void _SetExceptionsLocal(int bVal)
    3179             : {
    3180       22780 :   bUseExceptionsLocal = bVal;
    3181             : }
    3182             : 
    3183             : static
    3184          29 : void _UseExceptions() {
    3185          29 :   CPLErrorReset();
    3186          29 :   bUserHasSpecifiedIfUsingExceptions = TRUE;
    3187          29 :   if( !bUseExceptions )
    3188             :   {
    3189          26 :     bUseExceptions = 1;
    3190             :   }
    3191             : }
    3192             : 
    3193             : static
    3194           5 : void _DontUseExceptions() {
    3195           5 :   CPLErrorReset();
    3196           5 :   bUserHasSpecifiedIfUsingExceptions = TRUE;
    3197           5 :   if( bUseExceptions )
    3198             :   {
    3199           0 :     bUseExceptions = 0;
    3200             :   }
    3201             : }
    3202             : 
    3203           0 : static int _UserHasSpecifiedIfUsingExceptions()
    3204             : {
    3205           0 :     return bUserHasSpecifiedIfUsingExceptions || bUseExceptionsLocal >= 0;
    3206             : }
    3207             : 
    3208             : 
    3209             : 
    3210             : SWIGINTERNINLINE PyObject*
    3211       19426 :   SWIG_From_int  (int value)
    3212             : {
    3213       19426 :   return PyInt_FromLong((long) value);
    3214             : }
    3215             : 
    3216             : 
    3217             : /* Completely unrelated: just to avoid Coverity warnings */
    3218             : 
    3219             : static int bReturnSame = 1;
    3220             : 
    3221           0 : void NeverCallMePlease() {
    3222           0 :     bReturnSame = 0;
    3223           0 : }
    3224             : 
    3225             : /* Some SWIG code generates dead code, which Coverity warns about */
    3226             : template<class T> static T ReturnSame(T x)
    3227             : {
    3228             :     if( bReturnSame )
    3229             :         return x;
    3230             :     return 0;
    3231             : }
    3232             : 
    3233       16712 : static void pushErrorHandler()
    3234             : {
    3235       16712 :     CPLErrorReset();
    3236       16712 :     PythonBindingErrorHandlerContext* ctxt = new PythonBindingErrorHandlerContext();
    3237       16712 :     CPLPushErrorHandlerEx(PythonBindingErrorHandler, ctxt);
    3238       16712 : }
    3239             : 
    3240       16712 : static void popErrorHandler()
    3241             : {
    3242       16712 :     PythonBindingErrorHandlerContext* ctxt = static_cast<
    3243       16712 :       PythonBindingErrorHandlerContext*>(CPLGetErrorHandlerUserData());
    3244       16712 :     CPLPopErrorHandler();
    3245       16712 :     if( ctxt->bMemoryError )
    3246             :     {
    3247           0 :         CPLErrorSetState(
    3248             :           CE_Failure, CPLE_OutOfMemory, "Out of memory");
    3249             :     }
    3250       16712 :     else if( !ctxt->osFailureMsg.empty() )
    3251             :     {
    3252          31 :       CPLErrorSetState(
    3253          31 :           CPLGetLastErrorType() == CE_Failure ? CE_Failure: CE_Warning,
    3254             :           ctxt->nLastCode, ctxt->osFailureMsg.c_str());
    3255             :     }
    3256       16712 :     delete ctxt;
    3257       16712 : }
    3258             : 
    3259             : 
    3260             : 
    3261             : 
    3262             : /* Return a PyObject* from a NULL terminated C String */
    3263             : static PyObject* GDALPythonObjectFromCStr(const char *pszStr) CPL_UNUSED;
    3264           2 : static PyObject* GDALPythonObjectFromCStr(const char *pszStr)
    3265             : {
    3266           2 :   const unsigned char* pszIter = (const unsigned char*) pszStr;
    3267          46 :   while(*pszIter != 0)
    3268             :   {
    3269          44 :     if (*pszIter > 127)
    3270             :     {
    3271           0 :         PyObject* pyObj = PyUnicode_DecodeUTF8(pszStr, strlen(pszStr), "strict");
    3272           0 :         if (pyObj != NULL && !PyErr_Occurred())
    3273             :             return pyObj;
    3274           0 :         PyErr_Clear();
    3275           0 :         return PyBytes_FromString(pszStr);
    3276             :     }
    3277          44 :     pszIter ++;
    3278             :   }
    3279           2 :   return PyUnicode_FromString(pszStr);
    3280             : }
    3281             : 
    3282             : /* Return a NULL terminated c String from a PyObject */
    3283             : /* Result must be freed with GDALPythonFreeCStr */
    3284             : static char* GDALPythonObjectToCStr(PyObject* pyObject, int* pbToFree) CPL_UNUSED;
    3285             : static char* GDALPythonObjectToCStr(PyObject* pyObject, int* pbToFree)
    3286             : {
    3287             :   *pbToFree = 0;
    3288             :   if (PyUnicode_Check(pyObject))
    3289             :   {
    3290             :       char *pszStr;
    3291             :       char *pszNewStr;
    3292             :       Py_ssize_t nLen;
    3293             :       PyObject* pyUTF8Str = PyUnicode_AsUTF8String(pyObject);
    3294             :       if( pyUTF8Str == NULL )
    3295             :         return NULL;
    3296             :       PyBytes_AsStringAndSize(pyUTF8Str, &pszStr, &nLen);
    3297             :       pszNewStr = (char *) malloc(nLen+1);
    3298             :       if( pszNewStr == NULL )
    3299             :       {
    3300             :           CPLError(CE_Failure, CPLE_OutOfMemory, "Failed to allocate %llu bytes",
    3301             :                    (unsigned long long)(nLen + 1));
    3302             :           Py_XDECREF(pyUTF8Str);
    3303             :           return NULL;
    3304             :       }
    3305             :       memcpy(pszNewStr, pszStr, nLen+1);
    3306             :       Py_XDECREF(pyUTF8Str);
    3307             :       *pbToFree = 1;
    3308             :       return pszNewStr;
    3309             :   }
    3310             :   else if( PyBytes_Check(pyObject) )
    3311             :   {
    3312             :       char* ret = PyBytes_AsString(pyObject);
    3313             : 
    3314             :       // Check if there are \0 bytes inside the string
    3315             :       const Py_ssize_t size = PyBytes_Size(pyObject);
    3316             :       for( Py_ssize_t i = 0; i < size; i++ )
    3317             :       {
    3318             :           if( ret[i] == 0 )
    3319             :           {
    3320             :               CPLError(CE_Failure, CPLE_AppDefined,
    3321             :                        "bytes object cast as string contains a zero-byte.");
    3322             :               return NULL;
    3323             :           }
    3324             :       }
    3325             : 
    3326             :       return ret;
    3327             :   }
    3328             :   else
    3329             :   {
    3330             :       CPLError(CE_Failure, CPLE_AppDefined,
    3331             :                "Passed object is neither of type string nor bytes");
    3332             :       return NULL;
    3333             :   }
    3334             : }
    3335             : 
    3336             : static char * GDALPythonPathToCStr(PyObject* pyObject, int* pbToFree) CPL_UNUSED;
    3337             : static char * GDALPythonPathToCStr(PyObject* pyObject, int* pbToFree)
    3338             : {
    3339             :     PyObject* os = PyImport_ImportModule("os");
    3340             :     if (os == NULL)
    3341             :     {
    3342             :         return NULL;
    3343             :     }
    3344             : 
    3345             :     PyObject* pathLike = PyObject_GetAttrString(os, "PathLike");
    3346             :     if (pathLike == NULL)
    3347             :     {
    3348             :         Py_DECREF(os);
    3349             :         return NULL;
    3350             :     }
    3351             : 
    3352             :     if (!PyObject_IsInstance(pyObject, pathLike))
    3353             :     {
    3354             :         Py_DECREF(pathLike);
    3355             :         Py_DECREF(os);
    3356             :         return NULL;
    3357             :     }
    3358             : 
    3359             :     PyObject* str = PyObject_Str(pyObject);
    3360             :     char* ret = NULL;
    3361             :     if (str != NULL)
    3362             :     {
    3363             :         ret = GDALPythonObjectToCStr(str, pbToFree);
    3364             :         Py_DECREF(str);
    3365             :     }
    3366             : 
    3367             :     Py_DECREF(pathLike);
    3368             :     Py_DECREF(os);
    3369             : 
    3370             :     return ret;
    3371             : }
    3372             : 
    3373             : 
    3374             : static void GDALPythonFreeCStr(void* ptr, int bToFree) CPL_UNUSED;
    3375             : static void GDALPythonFreeCStr(void* ptr, int bToFree)
    3376             : {
    3377             :    if (bToFree)
    3378             :        free(ptr);
    3379             : }
    3380             : 
    3381             : 
    3382             : 
    3383             : #include <vector>
    3384             : #include "gdal_priv.h"
    3385             : #include "ogr_recordbatch.h"
    3386             : 
    3387             : #ifdef _DEBUG
    3388             : #undef _DEBUG
    3389             : #include "Python.h"
    3390             : #include "datetime.h"
    3391             : #define _DEBUG
    3392             : #else
    3393             : #include "Python.h"
    3394             : #include "datetime.h"
    3395             : #endif
    3396             : #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
    3397             : #include "numpy/arrayobject.h"
    3398             : 
    3399             : #ifdef DEBUG
    3400             : typedef struct GDALRasterBandHS GDALRasterBandShadow;
    3401             : typedef struct GDALDatasetHS GDALDatasetShadow;
    3402             : typedef struct RasterAttributeTableHS GDALRasterAttributeTableShadow;
    3403             : #else
    3404             : typedef void GDALRasterBandShadow;
    3405             : typedef void GDALDatasetShadow;
    3406             : typedef void GDALRasterAttributeTableShadow;
    3407             : #endif
    3408             : typedef void GDALComputedRasterBandShadow;
    3409             : 
    3410             : // Declaration from memmultidim.h
    3411             : std::shared_ptr<GDALMDArray> CPL_DLL MEMGroupCreateMDArray(GDALGroup* poGroup,
    3412             :                                                    const std::string& osName,
    3413             :                                                    const std::vector<std::shared_ptr<GDALDimension>>& aoDimensions,
    3414             :                                                    const GDALExtendedDataType& oDataType,
    3415             :                                                    void* pData,
    3416             :                                                    CSLConstList papszOptions);
    3417             : 
    3418             : 
    3419             : CPL_C_START
    3420             : 
    3421             : GDALRasterBandH CPL_DLL MEMCreateRasterBandEx( GDALDataset *, int, GByte *,
    3422             :                                                GDALDataType, GSpacing, GSpacing, int );
    3423             : CPL_C_END
    3424             : 
    3425             : typedef char retStringAndCPLFree;
    3426             : 
    3427             : class NUMPYDataset : public GDALDataset
    3428             : {
    3429             :     PyArrayObject *psArray = nullptr;
    3430             : 
    3431             :     bool             bValidGeoTransform = false;
    3432             :     GDALGeoTransform m_gt{};
    3433             :     OGRSpatialReference m_oSRS{};
    3434             : 
    3435             :     int           nGCPCount = 0;
    3436             :     GDAL_GCP      *pasGCPList = nullptr;
    3437             :     OGRSpatialReference m_oGCPSRS{};
    3438             : 
    3439             :   public:
    3440          27 :                  NUMPYDataset() = default;
    3441             :                  ~NUMPYDataset();
    3442             : 
    3443             :     const OGRSpatialReference* GetSpatialRef() const override;
    3444             :     CPLErr SetSpatialRef(const OGRSpatialReference* poSRS) override;
    3445             : 
    3446             :     virtual CPLErr GetGeoTransform( GDALGeoTransform& gt ) const override;
    3447             :     virtual CPLErr SetGeoTransform( const GDALGeoTransform& gt ) override;
    3448             : 
    3449             :     virtual int    GetGCPCount() override;
    3450             :     const OGRSpatialReference* GetGCPSpatialRef() const override;
    3451             :     virtual const GDAL_GCP *GetGCPs() override;
    3452             :     CPLErr SetGCPs( int nGCPCount, const GDAL_GCP *pasGCPList,
    3453             :                     const OGRSpatialReference* poSRS ) override;
    3454             : 
    3455             :     static GDALDataset *Open( PyArrayObject *psArray, bool binterleave = true );
    3456             :     static GDALDataset *Open( GDALOpenInfo * );
    3457             : };
    3458             : 
    3459             : 
    3460             : /************************************************************************/
    3461             : /*                          GDALRegister_NUMPY()                        */
    3462             : /************************************************************************/
    3463             : 
    3464         227 : static void GDALRegister_NUMPY(void)
    3465             : 
    3466             : {
    3467         227 :     GDALDriver  *poDriver;
    3468         227 :     if (! GDAL_CHECK_VERSION("NUMPY driver"))
    3469             :         return;
    3470         227 :     if( GDALGetDriverByName( "NUMPY" ) == NULL )
    3471             :     {
    3472         225 :         poDriver = static_cast<GDALDriver*>(GDALCreateDriver());
    3473             : 
    3474         225 :         poDriver->SetDescription( "NUMPY" );
    3475         225 :         poDriver->SetMetadataItem( GDAL_DMD_LONGNAME,
    3476         225 :                                    "Numeric Python Array" );
    3477         225 :         poDriver->SetMetadataItem( GDAL_DCAP_RASTER, "YES" );
    3478             : 
    3479         225 :         poDriver->pfnOpen = NUMPYDataset::Open;
    3480             : 
    3481         225 :         GetGDALDriverManager()->RegisterDriver( poDriver );
    3482             : 
    3483             :     }
    3484             : }
    3485             : 
    3486             : /************************************************************************/
    3487             : /*                            ~NUMPYDataset()                            */
    3488             : /************************************************************************/
    3489             : 
    3490          54 : NUMPYDataset::~NUMPYDataset()
    3491             : 
    3492             : {
    3493          27 :     if( nGCPCount > 0 )
    3494             :     {
    3495           0 :         GDALDeinitGCPs( nGCPCount, pasGCPList );
    3496           0 :         CPLFree( pasGCPList );
    3497             :     }
    3498             : 
    3499          27 :     FlushCache(true);
    3500             : 
    3501             :     // Although the module has thread disabled, we go here from GDALClose()
    3502          27 :     SWIG_PYTHON_THREAD_BEGIN_BLOCK;
    3503             : 
    3504          27 :     Py_DECREF( psArray );
    3505             : 
    3506          27 :     SWIG_PYTHON_THREAD_END_BLOCK;
    3507          54 : }
    3508             : 
    3509             : /************************************************************************/
    3510             : /*                          GetSpatialRef()                             */
    3511             : /************************************************************************/
    3512             : 
    3513           0 : const OGRSpatialReference *NUMPYDataset::GetSpatialRef() const
    3514             : 
    3515             : {
    3516           0 :     return m_oSRS.IsEmpty() ? nullptr:  &m_oSRS;
    3517             : }
    3518             : 
    3519             : /************************************************************************/
    3520             : /*                           SetSpatialRef()                            */
    3521             : /************************************************************************/
    3522             : 
    3523           0 : CPLErr NUMPYDataset::SetSpatialRef( const OGRSpatialReference* poSRS )
    3524             : 
    3525             : {
    3526           0 :     m_oSRS.Clear();
    3527           0 :     if( poSRS )
    3528           0 :         m_oSRS = *poSRS;
    3529             : 
    3530           0 :     return CE_None;
    3531             : }
    3532             : 
    3533             : /************************************************************************/
    3534             : /*                          GetGeoTransform()                           */
    3535             : /************************************************************************/
    3536             : 
    3537           2 : CPLErr NUMPYDataset::GetGeoTransform(GDALGeoTransform &gt) const
    3538             : 
    3539             : {
    3540           2 :     gt = m_gt;
    3541           2 :     if( bValidGeoTransform )
    3542             :         return CE_None;
    3543             :     else
    3544           1 :         return CE_Failure;
    3545             : }
    3546             : 
    3547             : /************************************************************************/
    3548             : /*                          SetGeoTransform()                           */
    3549             : /************************************************************************/
    3550             : 
    3551           1 : CPLErr NUMPYDataset::SetGeoTransform(const GDALGeoTransform& gt)
    3552             : 
    3553             : {
    3554           1 :     bValidGeoTransform = true;
    3555           1 :     m_gt = gt;
    3556           1 :     return( CE_None );
    3557             : }
    3558             : 
    3559             : /************************************************************************/
    3560             : /*                            GetGCPCount()                             */
    3561             : /************************************************************************/
    3562             : 
    3563           0 : int NUMPYDataset::GetGCPCount()
    3564             : 
    3565             : {
    3566           0 :     return nGCPCount;
    3567             : }
    3568             : 
    3569             : /************************************************************************/
    3570             : /*                          GetGCPSpatialRef()                          */
    3571             : /************************************************************************/
    3572             : 
    3573           0 : const OGRSpatialReference *NUMPYDataset::GetGCPSpatialRef() const
    3574             : 
    3575             : {
    3576           0 :     return m_oGCPSRS.IsEmpty() ? nullptr:  &m_oGCPSRS;
    3577             : }
    3578             : 
    3579             : /************************************************************************/
    3580             : /*                               GetGCPs()                              */
    3581             : /************************************************************************/
    3582             : 
    3583           0 : const GDAL_GCP *NUMPYDataset::GetGCPs()
    3584             : 
    3585             : {
    3586           0 :     return pasGCPList;
    3587             : }
    3588             : 
    3589             : /************************************************************************/
    3590             : /*                              SetGCPs()                               */
    3591             : /************************************************************************/
    3592             : 
    3593           0 : CPLErr NUMPYDataset::SetGCPs( int nGCPCount, const GDAL_GCP *pasGCPList,
    3594             :                               const OGRSpatialReference* poSRS )
    3595             : 
    3596             : {
    3597           0 :     m_oGCPSRS.Clear();
    3598           0 :     if( poSRS )
    3599           0 :         m_oGCPSRS = *poSRS;
    3600             : 
    3601           0 :     if( this->nGCPCount > 0 )
    3602             :     {
    3603           0 :         GDALDeinitGCPs( this->nGCPCount, this->pasGCPList );
    3604           0 :         CPLFree( this->pasGCPList );
    3605             :     }
    3606             : 
    3607           0 :     this->nGCPCount = nGCPCount;
    3608             : 
    3609           0 :     this->pasGCPList = GDALDuplicateGCPs( nGCPCount, pasGCPList );
    3610             : 
    3611           0 :     return CE_None;
    3612             : }
    3613             : 
    3614             : /************************************************************************/
    3615             : /*                                Open()                                */
    3616             : /************************************************************************/
    3617             : 
    3618       28293 : GDALDataset *NUMPYDataset::Open( GDALOpenInfo * poOpenInfo )
    3619             : 
    3620             : {
    3621       28293 :     PyArrayObject *psArray;
    3622             : 
    3623             : /* -------------------------------------------------------------------- */
    3624             : /*      Is this a numpy dataset name?                                   */
    3625             : /* -------------------------------------------------------------------- */
    3626       28293 :     if( !EQUALN(poOpenInfo->pszFilename,"NUMPY:::",8)
    3627           3 :         || poOpenInfo->fpL != NULL )
    3628             :         return NULL;
    3629             : 
    3630           3 :     psArray = NULL;
    3631           3 :     sscanf( poOpenInfo->pszFilename+8, "%p", &(psArray) );
    3632           3 :     if( psArray == NULL )
    3633             :     {
    3634           1 :         CPLError( CE_Failure, CPLE_AppDefined,
    3635             :                   "Failed to parse meaningful pointer value from NUMPY name\n"
    3636             :                   "string: %s\n",
    3637             :                   poOpenInfo->pszFilename );
    3638           1 :         return NULL;
    3639             :     }
    3640             : 
    3641           2 :     if( !CPLTestBool(CPLGetConfigOption("GDAL_ARRAY_OPEN_BY_FILENAME",
    3642             :                                         "FALSE")) )
    3643             :     {
    3644           1 :         if( CPLGetConfigOption("GDAL_ARRAY_OPEN_BY_FILENAME", NULL) == NULL )
    3645             :         {
    3646           1 :             CPLError(CE_Failure, CPLE_NotSupported,
    3647             :                     "Opening a NumPy array through gdal.Open(gdal_array.GetArrayFilename()) "
    3648             :                     "is no longer supported by default unless the GDAL_ARRAY_OPEN_BY_FILENAME "
    3649             :                     "configuration option is set to TRUE. The recommended way is to use "
    3650             :                     "gdal_array.OpenArray() instead.");
    3651             :         }
    3652           1 :         return NULL;
    3653             :     }
    3654             : 
    3655           1 :     return Open(psArray);
    3656             : }
    3657             : 
    3658          49 : static GDALDataType NumpyTypeToGDALType(PyArrayObject *psArray)
    3659             : {
    3660          49 :     switch( PyArray_DESCR(psArray)->type_num )
    3661             :     {
    3662             :       case NPY_CDOUBLE:
    3663             :         return GDT_CFloat64;
    3664             : 
    3665           5 :       case NPY_CFLOAT:
    3666           5 :         return GDT_CFloat32;
    3667             : 
    3668             :       // case NPY_CHALF
    3669             :       //   return GDT_CFloat16;
    3670             : 
    3671           5 :       case NPY_DOUBLE:
    3672           5 :         return GDT_Float64;
    3673             : 
    3674           3 :       case NPY_FLOAT:
    3675           3 :         return GDT_Float32;
    3676             : 
    3677           0 :       case NPY_HALF:
    3678           0 :         return GDT_Float16;
    3679             : 
    3680           3 :       case NPY_INT32:
    3681           3 :         return GDT_Int32;
    3682             : 
    3683           3 :       case NPY_UINT32:
    3684           3 :         return GDT_UInt32;
    3685             : 
    3686           1 :       case NPY_INT64:
    3687           1 :         return GDT_Int64;
    3688             : 
    3689           1 :       case NPY_UINT64:
    3690           1 :         return GDT_UInt64;
    3691             : 
    3692           3 :       case NPY_INT16:
    3693           3 :         return GDT_Int16;
    3694             : 
    3695           3 :       case NPY_UINT16:
    3696           3 :         return GDT_UInt16;
    3697             : 
    3698           2 :       case NPY_BYTE:
    3699           2 :         return GDT_Int8;
    3700             : 
    3701          15 :       case NPY_UBYTE:
    3702          15 :         return GDT_Byte;
    3703             : 
    3704           2 :       default:
    3705           2 :         CPLError( CE_Failure, CPLE_AppDefined,
    3706             :                   "Unable to access numpy arrays of typecode `%c'.",
    3707           2 :                   PyArray_DESCR(psArray)->type );
    3708           2 :         return GDT_Unknown;
    3709             :     }
    3710             : }
    3711             : 
    3712             : /************************************************************************/
    3713             : /*                                Open()                                */
    3714             : /************************************************************************/
    3715             : 
    3716          31 : GDALDataset* NUMPYDataset::Open( PyArrayObject *psArray, bool binterleave )
    3717             : {
    3718          31 :     GDALDataType  eType;
    3719          31 :     int     nBands;
    3720             : 
    3721             : /* -------------------------------------------------------------------- */
    3722             : /*      Is this a directly mappable Python array?  Verify rank, and     */
    3723             : /*      data type.                                                      */
    3724             : /* -------------------------------------------------------------------- */
    3725             : 
    3726          31 :     if( PyArray_NDIM(psArray) < 2 || PyArray_NDIM(psArray) > 3 )
    3727             :     {
    3728           3 :         CPLError( CE_Failure, CPLE_AppDefined,
    3729             :                   "Illegal numpy array rank %d.",
    3730             :                   PyArray_NDIM(psArray) );
    3731           3 :         return NULL;
    3732             :     }
    3733             : 
    3734          28 :     eType = NumpyTypeToGDALType(psArray);
    3735          28 :     if( eType == GDT_Unknown )
    3736             :     {
    3737             :         return NULL;
    3738             :     }
    3739             : 
    3740             : /* -------------------------------------------------------------------- */
    3741             : /*      Create the new NUMPYDataset object.                             */
    3742             : /* -------------------------------------------------------------------- */
    3743          27 :     NUMPYDataset *poDS;
    3744             : 
    3745          27 :     poDS = new NUMPYDataset();
    3746          27 :     poDS->poDriver = static_cast<GDALDriver*>(GDALGetDriverByName("NUMPY"));
    3747             : 
    3748          27 :     poDS->psArray = psArray;
    3749             : 
    3750          27 :     poDS->eAccess = (PyArray_FLAGS(psArray) & NPY_ARRAY_WRITEABLE) ? GA_Update : GA_ReadOnly;
    3751             : 
    3752             : /* -------------------------------------------------------------------- */
    3753             : /*      Add a reference to the array.                                   */
    3754             : /* -------------------------------------------------------------------- */
    3755          27 :     Py_INCREF( psArray );
    3756             : 
    3757             : /* -------------------------------------------------------------------- */
    3758             : /*      Workout the data layout.                                        */
    3759             : /* -------------------------------------------------------------------- */
    3760          27 :     npy_intp nBandOffset;
    3761          27 :     npy_intp nPixelOffset;
    3762          27 :     npy_intp nLineOffset;
    3763             : 
    3764          27 :     int xdim = binterleave ? 2 : 1;
    3765          27 :     int ydim = binterleave ? 1 : 0;
    3766          27 :     int bdim = binterleave ? 0 : 2;
    3767             : 
    3768          27 :     if( PyArray_NDIM(psArray) == 3 )
    3769             :     {
    3770           6 :         if( PyArray_DIMS(psArray)[0] > INT_MAX ||
    3771           6 :             PyArray_DIMS(psArray)[1] > INT_MAX ||
    3772          18 :             PyArray_DIMS(psArray)[2] > INT_MAX ||
    3773           6 :             !GDALCheckBandCount(static_cast<int>(PyArray_DIMS(psArray)[bdim]), 0) )
    3774             :         {
    3775           0 :             CPLError(CE_Failure, CPLE_NotSupported,
    3776             :                      "Too big array dimensions");
    3777           0 :             delete poDS;
    3778           0 :             return NULL;
    3779             :         }
    3780           6 :         nBands = static_cast<int>(PyArray_DIMS(psArray)[bdim]);
    3781           6 :         nBandOffset = PyArray_STRIDES(psArray)[bdim];
    3782           6 :         poDS->nRasterXSize = static_cast<int>(PyArray_DIMS(psArray)[xdim]);
    3783           6 :         nPixelOffset = PyArray_STRIDES(psArray)[xdim];
    3784           6 :         poDS->nRasterYSize = static_cast<int>(PyArray_DIMS(psArray)[ydim]);
    3785           6 :         nLineOffset = PyArray_STRIDES(psArray)[ydim];
    3786             :     }
    3787             :     else
    3788             :     {
    3789          21 :         if( PyArray_DIMS(psArray)[0] > INT_MAX ||
    3790          21 :             PyArray_DIMS(psArray)[1] > INT_MAX )
    3791             :         {
    3792           0 :             delete poDS;
    3793           0 :             return NULL;
    3794             :         }
    3795          21 :         nBands = 1;
    3796          21 :         nBandOffset = 0;
    3797          21 :         poDS->nRasterXSize = static_cast<int>(PyArray_DIMS(psArray)[1]);
    3798          21 :         nPixelOffset = PyArray_STRIDES(psArray)[1];
    3799          21 :         poDS->nRasterYSize = static_cast<int>(PyArray_DIMS(psArray)[0]);
    3800          21 :         nLineOffset = PyArray_STRIDES(psArray)[0];
    3801             :     }
    3802             : 
    3803             : /* -------------------------------------------------------------------- */
    3804             : /*      Create band information objects.                                */
    3805             : /* -------------------------------------------------------------------- */
    3806          62 :     for( int iBand = 0; iBand < nBands; iBand++ )
    3807             :     {
    3808          35 :         poDS->SetBand( iBand+1,
    3809             :                        (GDALRasterBand *)
    3810          35 :                        MEMCreateRasterBandEx( poDS, iBand+1,
    3811          35 :                                 (GByte *) PyArray_DATA(psArray) + nBandOffset*iBand,
    3812             :                                           eType, nPixelOffset, nLineOffset,
    3813             :                                           FALSE ) );
    3814             :     }
    3815             : 
    3816             : /* -------------------------------------------------------------------- */
    3817             : /*      Try to return a regular handle on the file.                     */
    3818             : /* -------------------------------------------------------------------- */
    3819             :     return poDS;
    3820             : }
    3821             : 
    3822             : /************************************************************************/
    3823             : /*                       NUMPYMultiDimensionalDataset                   */
    3824             : /************************************************************************/
    3825             : 
    3826             : class NUMPYMultiDimensionalDataset : public GDALDataset
    3827             : {
    3828             :     PyArrayObject *psArray = nullptr;
    3829             :     std::unique_ptr<GDALDataset> poMEMDS{};
    3830             : 
    3831             :     NUMPYMultiDimensionalDataset();
    3832             :     ~NUMPYMultiDimensionalDataset();
    3833             : 
    3834             : public:
    3835             :     static GDALDataset *Open( PyArrayObject *psArray );
    3836             : 
    3837          20 :     std::shared_ptr<GDALGroup> GetRootGroup() const override { return poMEMDS->GetRootGroup(); }
    3838             : };
    3839             : 
    3840             : /************************************************************************/
    3841             : /*                     NUMPYMultiDimensionalDataset()                   */
    3842             : /************************************************************************/
    3843             : 
    3844          20 : NUMPYMultiDimensionalDataset::NUMPYMultiDimensionalDataset()
    3845             : {
    3846          20 : }
    3847             : 
    3848             : /************************************************************************/
    3849             : /*                    ~NUMPYMultiDimensionalDataset()                   */
    3850             : /************************************************************************/
    3851             : 
    3852          40 : NUMPYMultiDimensionalDataset::~NUMPYMultiDimensionalDataset()
    3853             : {
    3854             :     // Although the module has thread disabled, we go here from GDALClose()
    3855          20 :     SWIG_PYTHON_THREAD_BEGIN_BLOCK;
    3856             : 
    3857          20 :     Py_DECREF( psArray );
    3858             : 
    3859          20 :     SWIG_PYTHON_THREAD_END_BLOCK;
    3860          40 : }
    3861             : 
    3862             : /************************************************************************/
    3863             : /*                                Open()                                */
    3864             : /************************************************************************/
    3865             : 
    3866          21 : GDALDataset* NUMPYMultiDimensionalDataset::Open( PyArrayObject *psArray )
    3867             : {
    3868          21 :     const auto eType = NumpyTypeToGDALType(psArray);
    3869          21 :     if( eType == GDT_Unknown )
    3870             :     {
    3871             :         return nullptr;
    3872             :     }
    3873          20 :     auto poMemDriver = GDALDriver::FromHandle(GDALGetDriverByName("MEM"));
    3874          20 :     if( !poMemDriver )
    3875             :     {
    3876           0 :         CPLError(CE_Failure, CPLE_AppDefined,
    3877             :                  "MEM driver not available");
    3878           0 :         return nullptr;
    3879             :     }
    3880             : 
    3881          20 :     auto poMEMDS = poMemDriver->CreateMultiDimensional("", nullptr, nullptr);
    3882          20 :     assert(poMEMDS);
    3883          41 :     auto poGroup = poMEMDS->GetRootGroup();
    3884          20 :     assert(poGroup);
    3885          40 :     std::vector<std::shared_ptr<GDALDimension>> apoDims;
    3886          20 :     const auto ndims = PyArray_NDIM(psArray);
    3887          40 :     CPLString strides;
    3888          60 :     for( int i = 0; i < ndims; i++ )
    3889             :     {
    3890          80 :         auto poDim = poGroup->CreateDimension(std::string(CPLSPrintf("dim%d", i)),
    3891          40 :                                               std::string(),
    3892          40 :                                               std::string(),
    3893          40 :                                               PyArray_DIMS(psArray)[i],
    3894         120 :                                               nullptr);
    3895          40 :         apoDims.push_back(poDim);
    3896          40 :         if( i > 0 )
    3897          20 :             strides += ',';
    3898          40 :         strides += CPLSPrintf(CPL_FRMT_GIB,
    3899          40 :                               static_cast<GIntBig>(PyArray_STRIDES(psArray)[i]));
    3900             :     }
    3901          40 :     CPLStringList aosOptions;
    3902          20 :     aosOptions.SetNameValue("STRIDES", strides.c_str());
    3903          20 :     auto mdArray = MEMGroupCreateMDArray(poGroup.get(), "array",
    3904             :                                       apoDims,
    3905          20 :                                       GDALExtendedDataType::Create(eType),
    3906             :                                       PyArray_DATA(psArray),
    3907          60 :                                       aosOptions.List());
    3908          20 :     if( !mdArray )
    3909             :     {
    3910           0 :         delete poMEMDS;
    3911           0 :         return nullptr;
    3912             :     }
    3913             : 
    3914          20 :     auto poDS = new NUMPYMultiDimensionalDataset();
    3915          20 :     poDS->poDriver = GDALDriver::FromHandle(GDALGetDriverByName("NUMPY"));
    3916          20 :     poDS->psArray = psArray;
    3917          20 :     Py_INCREF( psArray );
    3918          20 :     poDS->eAccess = GA_ReadOnly;
    3919          20 :     poDS->poMEMDS.reset(poMEMDS);
    3920             :     return poDS;
    3921             : }
    3922             : 
    3923             : 
    3924             : 
    3925           0 : int GDALTermProgress_nocb( double dfProgress, const char * pszMessage=NULL, void *pData=NULL ) {
    3926           0 :   return GDALTermProgress( dfProgress, pszMessage, pData);
    3927             : }
    3928             : 
    3929             : 
    3930             : SWIGINTERN swig_type_info*
    3931           0 : SWIG_pchar_descriptor(void)
    3932             : {
    3933           0 :   static int init = 0;
    3934           0 :   static swig_type_info* info = 0;
    3935           0 :   if (!init) {
    3936           0 :     info = SWIG_TypeQuery("_p_char");
    3937           0 :     init = 1;
    3938             :   }
    3939           0 :   return info;
    3940             : }
    3941             : 
    3942             : 
    3943             : SWIGINTERN int
    3944           0 : SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc)
    3945             : {
    3946             : #if PY_VERSION_HEX>=0x03000000
    3947             : #if defined(SWIG_PYTHON_STRICT_BYTE_CHAR)
    3948             :   if (PyBytes_Check(obj))
    3949             : #else
    3950           0 :   if (PyUnicode_Check(obj))
    3951             : #endif
    3952             : #else  
    3953             :   if (PyString_Check(obj))
    3954             : #endif
    3955             :   {
    3956           0 :     char *cstr; Py_ssize_t len;
    3957           0 :     int ret = SWIG_OK;
    3958             : #if PY_VERSION_HEX>=0x03000000
    3959             : #if !defined(SWIG_PYTHON_STRICT_BYTE_CHAR)
    3960           0 :     if (!alloc && cptr) {
    3961             :         /* We can't allow converting without allocation, since the internal
    3962             :            representation of string in Python 3 is UCS-2/UCS-4 but we require
    3963             :            a UTF-8 representation.
    3964             :            TODO(bhy) More detailed explanation */
    3965             :         return SWIG_RuntimeError;
    3966             :     }
    3967           0 :     obj = PyUnicode_AsUTF8String(obj);
    3968           0 :     if (!obj)
    3969             :       return SWIG_TypeError;
    3970           0 :     if (alloc)
    3971           0 :       *alloc = SWIG_NEWOBJ;
    3972             : #endif
    3973           0 :     PyBytes_AsStringAndSize(obj, &cstr, &len);
    3974             : #else
    3975             :     PyString_AsStringAndSize(obj, &cstr, &len);
    3976             : #endif
    3977           0 :     if (cptr) {
    3978           0 :       if (alloc) {
    3979           0 :   if (*alloc == SWIG_NEWOBJ) {
    3980           0 :     *cptr = reinterpret_cast< char* >(memcpy(new char[len + 1], cstr, sizeof(char)*(len + 1)));
    3981           0 :     *alloc = SWIG_NEWOBJ;
    3982             :   } else {
    3983           0 :     *cptr = cstr;
    3984           0 :     *alloc = SWIG_OLDOBJ;
    3985             :   }
    3986             :       } else {
    3987             : #if PY_VERSION_HEX>=0x03000000
    3988             : #if defined(SWIG_PYTHON_STRICT_BYTE_CHAR)
    3989             :   *cptr = PyBytes_AsString(obj);
    3990             : #else
    3991             :   assert(0); /* Should never reach here with Unicode strings in Python 3 */
    3992             : #endif
    3993             : #else
    3994             :   *cptr = SWIG_Python_str_AsChar(obj);
    3995             :         if (!*cptr)
    3996             :           ret = SWIG_TypeError;
    3997             : #endif
    3998             :       }
    3999             :     }
    4000           0 :     if (psize) *psize = len + 1;
    4001             : #if PY_VERSION_HEX>=0x03000000 && !defined(SWIG_PYTHON_STRICT_BYTE_CHAR)
    4002           0 :     Py_XDECREF(obj);
    4003             : #endif
    4004           0 :     return ret;
    4005             :   } else {
    4006             : #if defined(SWIG_PYTHON_2_UNICODE)
    4007             : #if defined(SWIG_PYTHON_STRICT_BYTE_CHAR)
    4008             : #error "Cannot use both SWIG_PYTHON_2_UNICODE and SWIG_PYTHON_STRICT_BYTE_CHAR at once"
    4009             : #endif
    4010             : #if PY_VERSION_HEX<0x03000000
    4011             :     if (PyUnicode_Check(obj)) {
    4012             :       char *cstr; Py_ssize_t len;
    4013             :       if (!alloc && cptr) {
    4014             :         return SWIG_RuntimeError;
    4015             :       }
    4016             :       obj = PyUnicode_AsUTF8String(obj);
    4017             :       if (!obj)
    4018             :         return SWIG_TypeError;
    4019             :       if (PyString_AsStringAndSize(obj, &cstr, &len) != -1) {
    4020             :         if (cptr) {
    4021             :           if (alloc) *alloc = SWIG_NEWOBJ;
    4022             :           *cptr = reinterpret_cast< char* >(memcpy(new char[len + 1], cstr, sizeof(char)*(len + 1)));
    4023             :         }
    4024             :         if (psize) *psize = len + 1;
    4025             : 
    4026             :         Py_XDECREF(obj);
    4027             :         return SWIG_OK;
    4028             :       } else {
    4029             :         Py_XDECREF(obj);
    4030             :       }
    4031             :     }
    4032             : #endif
    4033             : #endif
    4034             : 
    4035           0 :     swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
    4036           0 :     if (pchar_descriptor) {
    4037           0 :       void* vptr = 0;
    4038           0 :       if (SWIG_ConvertPtr(obj, &vptr, pchar_descriptor, 0) == SWIG_OK) {
    4039           0 :   if (cptr) *cptr = (char *) vptr;
    4040           0 :   if (psize) *psize = vptr ? (strlen((char *)vptr) + 1) : 0;
    4041           0 :   if (alloc) *alloc = SWIG_OLDOBJ;
    4042           0 :   return SWIG_OK;
    4043             :       }
    4044             :     }
    4045             :   }
    4046             :   return SWIG_TypeError;
    4047             : }
    4048             : 
    4049             : 
    4050             : 
    4051             : 
    4052             : 
    4053             : 
    4054             : typedef struct {
    4055             :     PyObject *psPyCallback;
    4056             :     PyObject *psPyCallbackData;
    4057             :     int nLastReported;
    4058             : } PyProgressData;
    4059             : 
    4060             : /************************************************************************/
    4061             : /*                          PyProgressProxy()                           */
    4062             : /************************************************************************/
    4063             : 
    4064             : 
    4065             : static int CPL_STDCALL
    4066             : PyProgressProxy( double dfComplete, const char *pszMessage, void *pData ) CPL_UNUSED;
    4067             : 
    4068             : static int CPL_STDCALL
    4069         362 : PyProgressProxy( double dfComplete, const char *pszMessage, void *pData )
    4070             : 
    4071             : {
    4072         362 :     PyProgressData *psInfo = (PyProgressData *) pData;
    4073         362 :     PyObject *psArgs, *psResult;
    4074         362 :     int      bContinue = TRUE;
    4075             : 
    4076         362 :     if( dfComplete > 0 && psInfo->nLastReported == (int) (100.0 * dfComplete) )
    4077             :         return TRUE;
    4078             : 
    4079         264 :     if( psInfo->psPyCallback == NULL || psInfo->psPyCallback == Py_None )
    4080             :         return TRUE;
    4081             : 
    4082         264 :     psInfo->nLastReported = (int) (100.0 * dfComplete);
    4083             : 
    4084         264 :     if( pszMessage == NULL )
    4085           0 :         pszMessage = "";
    4086             : 
    4087         626 :     SWIG_PYTHON_THREAD_BEGIN_BLOCK;
    4088             : 
    4089         264 :     if( psInfo->psPyCallbackData == NULL )
    4090           0 :         psArgs = Py_BuildValue("(dsO)", dfComplete, pszMessage, Py_None );
    4091             :     else
    4092         264 :         psArgs = Py_BuildValue("(dsO)", dfComplete, pszMessage,
    4093             :                          psInfo->psPyCallbackData );
    4094             : 
    4095         264 :     psResult = PyObject_CallObject( psInfo->psPyCallback, psArgs);
    4096         264 :     Py_XDECREF(psArgs);
    4097             : 
    4098         264 :     if( PyErr_Occurred() != NULL )
    4099             :     {
    4100           0 :         PyErr_Print();
    4101           0 :         PyErr_Clear();
    4102           0 :         SWIG_PYTHON_THREAD_END_BLOCK;
    4103             :         return FALSE;
    4104             :     }
    4105             : 
    4106         264 :     if( psResult == NULL )
    4107             :     {
    4108           0 :         SWIG_PYTHON_THREAD_END_BLOCK;
    4109             :         return TRUE;
    4110             :     }
    4111             : 
    4112         264 :     if( psResult == Py_None )
    4113             :     {
    4114           0 :         SWIG_PYTHON_THREAD_END_BLOCK;
    4115             :         return TRUE;
    4116             :     }
    4117             : 
    4118         264 :     if( !PyArg_Parse( psResult, "i", &bContinue ) )
    4119             :     {
    4120           0 :         PyErr_Clear();
    4121           0 :         CPLError(CE_Failure, CPLE_AppDefined, "bad progress return value");
    4122           0 :         Py_XDECREF(psResult);
    4123           0 :         SWIG_PYTHON_THREAD_END_BLOCK;
    4124             :         return FALSE;
    4125             :     }
    4126             : 
    4127         264 :     Py_XDECREF(psResult);
    4128         264 :     SWIG_PYTHON_THREAD_END_BLOCK;
    4129             : 
    4130         264 :     return bContinue;
    4131             : }
    4132             : 
    4133             : 
    4134          30 : GDALDatasetShadow* OpenNumPyArray(PyArrayObject *psArray, bool binterleave)
    4135             : {
    4136          30 :     return NUMPYDataset::Open( psArray, binterleave );
    4137             : }
    4138             : 
    4139             : 
    4140             : SWIGINTERN int
    4141         213 : SWIG_AsVal_bool (PyObject *obj, bool *val)
    4142             : {
    4143         213 :   int r;
    4144         213 :   if (!PyBool_Check(obj))
    4145             :     return SWIG_ERROR;
    4146         213 :   r = PyObject_IsTrue(obj);
    4147         213 :   if (r == -1)
    4148             :     return SWIG_ERROR;
    4149         213 :   if (val) *val = r ? true : false;
    4150             :   return SWIG_OK;
    4151             : }
    4152             : 
    4153             : 
    4154          21 : GDALDatasetShadow* OpenMultiDimensionalNumPyArray(PyArrayObject *psArray)
    4155             : {
    4156          21 :     return NUMPYMultiDimensionalDataset::Open( psArray );
    4157             : }
    4158             : 
    4159             : 
    4160           2 : retStringAndCPLFree* GetArrayFilename(PyArrayObject *psArray)
    4161             : {
    4162           2 :     char      szString[128];
    4163             : 
    4164           2 :     GDALRegister_NUMPY();
    4165             : 
    4166             :     /* I wish I had a safe way of checking the type */
    4167           2 :     snprintf( szString, sizeof(szString), "NUMPY:::%p", psArray );
    4168           2 :     return CPLStrdup(szString);
    4169             : }
    4170             : 
    4171             : 
    4172       19254 :   CPLErr BandRasterIONumPy( GDALRasterBandShadow* band, int bWrite, double xoff, double yoff, double xsize, double ysize,
    4173             :                             PyArrayObject *psArray,
    4174             :                             GDALDataType buf_type,
    4175             :                             GDALRIOResampleAlg resample_alg,
    4176             :                             GDALProgressFunc callback = NULL,
    4177             :                             void* callback_data = NULL) {
    4178             : 
    4179       19254 :     if( PyArray_NDIM(psArray) < 2 || PyArray_NDIM(psArray) > 3 )
    4180             :     {
    4181           0 :         CPLError( CE_Failure, CPLE_AppDefined,
    4182             :                   "Illegal numpy array rank %d.\n",
    4183             :                   PyArray_NDIM(psArray) );
    4184           0 :         return CE_Failure;
    4185             :     }
    4186             : 
    4187       19254 :     if( !bWrite && !(PyArray_FLAGS(psArray) & NPY_ARRAY_WRITEABLE) )
    4188             :     {
    4189           2 :         CPLError( CE_Failure, CPLE_AppDefined,
    4190             :                   "Cannot read in a non-writeable array." );
    4191           2 :         return CE_Failure;
    4192             :     }
    4193             : 
    4194       19252 :     int xdim = ( PyArray_NDIM(psArray) == 2) ? 1 : 2;
    4195       19252 :     int ydim = ( PyArray_NDIM(psArray) == 2) ? 0 : 1;
    4196             : 
    4197       19252 :     if( PyArray_DIMS(psArray)[xdim] > INT_MAX ||
    4198       19252 :         PyArray_DIMS(psArray)[ydim] > INT_MAX )
    4199             :     {
    4200           0 :         CPLError(CE_Failure, CPLE_NotSupported,
    4201             :                     "Too big array dimensions");
    4202           0 :         return CE_Failure;
    4203             :     }
    4204       19252 :     int nxsize, nysize;
    4205       19252 :     GSpacing pixel_space, line_space;
    4206       19252 :     nxsize = static_cast<int>(PyArray_DIMS(psArray)[xdim]);
    4207       19252 :     nysize = static_cast<int>(PyArray_DIMS(psArray)[ydim]);
    4208       19252 :     pixel_space = PyArray_STRIDES(psArray)[xdim];
    4209       19252 :     line_space = PyArray_STRIDES(psArray)[ydim];
    4210             : 
    4211       19252 :     GDALRasterIOExtraArg sExtraArg;
    4212       19252 :     INIT_RASTERIO_EXTRA_ARG(sExtraArg);
    4213       19252 :     sExtraArg.eResampleAlg = resample_alg;
    4214       19252 :     sExtraArg.pfnProgress = callback;
    4215       19252 :     sExtraArg.pProgressData = callback_data;
    4216       19252 :     int nXOff = (int)(xoff + 0.5);
    4217       19252 :     int nYOff = (int)(yoff + 0.5);
    4218       19252 :     int nXSize = (int)(xsize + 0.5);
    4219       19252 :     int nYSize = (int)(ysize + 0.5);
    4220       19252 :     if( fabs(xoff-nXOff) > 1e-8 || fabs(yoff-nYOff) > 1e-8 ||
    4221       19191 :         fabs(xsize-nXSize) > 1e-8 || fabs(ysize-nYSize) > 1e-8 )
    4222             :     {
    4223          61 :         sExtraArg.bFloatingPointWindowValidity = TRUE;
    4224          61 :         sExtraArg.dfXOff = xoff;
    4225          61 :         sExtraArg.dfYOff = yoff;
    4226          61 :         sExtraArg.dfXSize = xsize;
    4227          61 :         sExtraArg.dfYSize = ysize;
    4228             :     }
    4229             : 
    4230       26867 :     return  GDALRasterIOEx( band, (bWrite) ? GF_Write : GF_Read, nXOff, nYOff, nXSize, nYSize,
    4231             :                           PyArray_DATA(psArray), nxsize, nysize,
    4232             :                           buf_type, pixel_space, line_space, &sExtraArg );
    4233             :   }
    4234             : 
    4235             : 
    4236         105 :   CPLErr DatasetIONumPy( GDALDatasetShadow* ds, int bWrite, double xoff, double yoff, double xsize, double ysize,
    4237             :                          PyArrayObject *psArray,
    4238             :                          GDALDataType buf_type,
    4239             :                          GDALRIOResampleAlg resample_alg,
    4240             :                          GDALProgressFunc callback = NULL,
    4241             :                          void* callback_data = NULL,
    4242             :                          bool binterleave = true,
    4243             :                          int band_list = 0, int *pband_list = 0 )
    4244             : {
    4245         105 :     if( PyArray_NDIM(psArray) != 3 )
    4246             :     {
    4247           0 :         CPLError( CE_Failure, CPLE_AppDefined,
    4248             :                   "Illegal numpy array rank %d.",
    4249             :                   PyArray_NDIM(psArray) );
    4250           0 :         return CE_Failure;
    4251             :     }
    4252             : 
    4253         105 :     if( !bWrite && !(PyArray_FLAGS(psArray) & NPY_ARRAY_WRITEABLE) )
    4254             :     {
    4255           0 :         CPLError( CE_Failure, CPLE_AppDefined,
    4256             :                   "Cannot read in a non-writeable array." );
    4257           0 :         return CE_Failure;
    4258             :     }
    4259             : 
    4260         105 :     int xdim = binterleave ? 2 : 1;
    4261         105 :     int ydim = binterleave ? 1 : 0;
    4262         105 :     int bdim = binterleave ? 0 : 2;
    4263         105 :     if( PyArray_DIMS(psArray)[xdim] > INT_MAX ||
    4264         105 :         PyArray_DIMS(psArray)[ydim] > INT_MAX ||
    4265         105 :         PyArray_DIMS(psArray)[bdim] > INT_MAX )
    4266             :     {
    4267           0 :         CPLError(CE_Failure, CPLE_NotSupported,
    4268             :                     "Too big array dimensions");
    4269           0 :         return CE_Failure;
    4270             :     }
    4271             : 
    4272         105 :     int bandsize, nxsize, nysize;
    4273         105 :     GIntBig pixel_space, line_space, band_space;
    4274         105 :     nxsize = static_cast<int>(PyArray_DIMS(psArray)[xdim]);
    4275         105 :     nysize = static_cast<int>(PyArray_DIMS(psArray)[ydim]);
    4276         105 :     bandsize = static_cast<int>(PyArray_DIMS(psArray)[bdim]);
    4277         105 :     int bandcount = band_list ? band_list : GDALGetRasterCount(ds);
    4278         105 :     if( bandsize != bandcount )
    4279             :     {
    4280           0 :         CPLError( CE_Failure, CPLE_AppDefined,
    4281             :                   "Illegal numpy array band dimension %d. Expected value: %d",
    4282             :                   bandsize, bandcount );
    4283           0 :         return CE_Failure;
    4284             :     }
    4285         105 :     pixel_space = PyArray_STRIDES(psArray)[xdim];
    4286         105 :     line_space = PyArray_STRIDES(psArray)[ydim];
    4287         105 :     band_space = PyArray_STRIDES(psArray)[bdim];
    4288             : 
    4289         105 :     GDALRasterIOExtraArg sExtraArg;
    4290         105 :     INIT_RASTERIO_EXTRA_ARG(sExtraArg);
    4291         105 :     sExtraArg.eResampleAlg = resample_alg;
    4292         105 :     sExtraArg.pfnProgress = callback;
    4293         105 :     sExtraArg.pProgressData = callback_data;
    4294         105 :     int nXOff = (int)(xoff + 0.5);
    4295         105 :     int nYOff = (int)(yoff + 0.5);
    4296         105 :     int nXSize = (int)(xsize + 0.5);
    4297         105 :     int nYSize = (int)(ysize + 0.5);
    4298         105 :     if( fabs(xoff-nXOff) > 1e-8 || fabs(yoff-nYOff) > 1e-8 ||
    4299         104 :         fabs(xsize-nXSize) > 1e-8 || fabs(ysize-nYSize) > 1e-8 )
    4300             :     {
    4301           1 :         sExtraArg.bFloatingPointWindowValidity = TRUE;
    4302           1 :         sExtraArg.dfXOff = xoff;
    4303           1 :         sExtraArg.dfYOff = yoff;
    4304           1 :         sExtraArg.dfXSize = xsize;
    4305           1 :         sExtraArg.dfYSize = ysize;
    4306             :     }
    4307             : 
    4308         171 :     return  GDALDatasetRasterIOEx( ds, (bWrite) ? GF_Write : GF_Read, nXOff, nYOff, nXSize, nYSize,
    4309             :                                    PyArray_DATA(psArray), nxsize, nysize,
    4310             :                                    buf_type,
    4311             :                                    bandcount, pband_list,
    4312             :                                    pixel_space, line_space, band_space, &sExtraArg );
    4313             :   }
    4314             : 
    4315             : 
    4316             : static int*
    4317         105 : CreateCIntListFromSequence( PyObject* pySeq, int* pnSize ) {
    4318             :   /* check if is List */
    4319         105 :   if ( !PySequence_Check(pySeq) ) {
    4320           0 :     PyErr_SetString(PyExc_TypeError, "not a sequence");
    4321           0 :     *pnSize = -1;
    4322           0 :     return NULL;
    4323             :   }
    4324         105 :   Py_ssize_t size = PySequence_Size(pySeq);
    4325         105 :   if( size > (Py_ssize_t)INT_MAX ) {
    4326           0 :     PyErr_SetString(PyExc_RuntimeError, "too big sequence");
    4327           0 :     *pnSize = -1;
    4328           0 :     return NULL;
    4329             :   }
    4330         105 :   if( (size_t)size > SIZE_MAX / sizeof(int) ) {
    4331           0 :     PyErr_SetString(PyExc_RuntimeError, "too big sequence");
    4332           0 :     *pnSize = -1;
    4333           0 :     return NULL;
    4334             :   }
    4335         105 :   *pnSize = (int)size;
    4336         105 :   int* ret = (int*) malloc((*pnSize)*sizeof(int));
    4337         105 :   if( !ret ) {
    4338           0 :     PyErr_SetString(PyExc_MemoryError, "cannot allocate temporary buffer");
    4339           0 :     *pnSize = -1;
    4340           0 :     return NULL;
    4341             :   }
    4342         491 :   for( int i = 0; i<*pnSize; i++ ) {
    4343         386 :     PyObject *o = PySequence_GetItem(pySeq,i);
    4344         386 :     if ( !PyArg_Parse(o,"i",&ret[i]) ) {
    4345           0 :         PyErr_SetString(PyExc_TypeError, "not an integer");
    4346           0 :         Py_DECREF(o);
    4347           0 :         free(ret);
    4348           0 :         *pnSize = -1;
    4349           0 :         return NULL;
    4350             :     }
    4351         386 :     Py_DECREF(o);
    4352             :   }
    4353             :   return ret;
    4354             : }
    4355             : 
    4356             : 
    4357          84 : static bool CheckNumericDataType(GDALExtendedDataTypeHS* dt)
    4358             : {
    4359          84 :     auto klass = GDALExtendedDataTypeGetClass(dt);
    4360          84 :     if( klass == GEDTC_NUMERIC )
    4361             :         return true;
    4362           3 :     if( klass == GEDTC_STRING )
    4363             :         return false;
    4364           3 :     CPLAssert( klass == GEDTC_COMPOUND );
    4365           3 :     size_t nCount = 0;
    4366           3 :     GDALEDTComponentH* comps = GDALExtendedDataTypeGetComponents(dt, &nCount);
    4367             :     bool ret = true;
    4368           9 :     for( size_t i = 0; i < nCount; i++ )
    4369             :     {
    4370           6 :         auto tmpType = GDALEDTComponentGetType(comps[i]);
    4371           6 :         ret = CheckNumericDataType(tmpType);
    4372           6 :         GDALExtendedDataTypeRelease(tmpType);
    4373           6 :         if( !ret )
    4374             :             break;
    4375             :     }
    4376           3 :     GDALExtendedDataTypeFreeComponents(comps, nCount);
    4377             :     return ret;
    4378             : }
    4379             : 
    4380             : 
    4381          78 :   CPLErr MDArrayIONumPy( bool bWrite,
    4382             :                           GDALMDArrayHS* mdarray,
    4383             :                           PyArrayObject *psArray,
    4384             :                           int nDims1, GUIntBig* array_start_idx,
    4385             :                           int nDims3, GIntBig* array_step,
    4386             :                           GDALExtendedDataTypeHS* buffer_datatype) {
    4387             : 
    4388          78 :     if( !CheckNumericDataType(buffer_datatype) )
    4389             :     {
    4390           0 :         CPLError(CE_Failure, CPLE_NotSupported,
    4391             :             "String buffer data type not supported in SWIG bindings");
    4392           0 :         return CE_Failure;
    4393             :     }
    4394          78 :     const int nExpectedDims = (int)GDALMDArrayGetDimensionCount(mdarray);
    4395          78 :     if( PyArray_NDIM(psArray) != nExpectedDims )
    4396             :     {
    4397           0 :         CPLError( CE_Failure, CPLE_AppDefined,
    4398             :                   "Illegal numpy array rank %d.",
    4399             :                   PyArray_NDIM(psArray) );
    4400           0 :         return CE_Failure;
    4401             :     }
    4402             : 
    4403         156 :     std::vector<size_t> count_internal(nExpectedDims+1);
    4404         156 :     std::vector<GPtrDiff_t> buffer_stride_internal(nExpectedDims+1);
    4405          78 :     const size_t nDTSize = GDALExtendedDataTypeGetSize(buffer_datatype);
    4406          78 :     if( nDTSize == 0 )
    4407             :     {
    4408             :         return CE_Failure;
    4409             :     }
    4410         196 :     for( int i = 0; i < nExpectedDims; i++ )
    4411             :     {
    4412         118 :         count_internal[i] = PyArray_DIMS(psArray)[i];
    4413         118 :         if( (PyArray_STRIDES(psArray)[i] % nDTSize) != 0 )
    4414             :         {
    4415           0 :             CPLError( CE_Failure, CPLE_AppDefined,
    4416             :                       "Stride[%d] not a multiple of data type size",
    4417             :                       i );
    4418             :             return CE_Failure;
    4419             :         }
    4420         118 :         buffer_stride_internal[i] = PyArray_STRIDES(psArray)[i] / nDTSize;
    4421             :     }
    4422             : 
    4423          78 :     if( bWrite )
    4424             :     {
    4425          14 :         return GDALMDArrayWrite( mdarray,
    4426             :                                 array_start_idx,
    4427          14 :                                 &count_internal[0],
    4428             :                                 array_step,
    4429          14 :                                 &buffer_stride_internal[0],
    4430             :                                 buffer_datatype,
    4431          14 :                                 PyArray_DATA(psArray),
    4432          14 :                                 NULL, 0) ? CE_None : CE_Failure;
    4433             :     }
    4434             :     else
    4435             :     {
    4436          64 :         return GDALMDArrayRead( mdarray,
    4437             :                                 array_start_idx,
    4438          64 :                                 &count_internal[0],
    4439             :                                 array_step,
    4440          64 :                                 &buffer_stride_internal[0],
    4441             :                                 buffer_datatype,
    4442             :                                 PyArray_DATA(psArray),
    4443          64 :                                 NULL, 0) ? CE_None : CE_Failure;
    4444             :     }
    4445             :   }
    4446             : 
    4447             : 
    4448             : static GUIntBig*
    4449          78 : CreateCGUIntBigListFromSequence( PyObject* pySeq, int* pnSize ) {
    4450             :   /* check if is List */
    4451          78 :   if ( !PySequence_Check(pySeq) ) {
    4452           0 :     PyErr_SetString(PyExc_TypeError, "not a sequence");
    4453           0 :     *pnSize = -1;
    4454           0 :     return NULL;
    4455             :   }
    4456          78 :   Py_ssize_t size = PySequence_Size(pySeq);
    4457          78 :   if( size > (Py_ssize_t)INT_MAX ) {
    4458           0 :     PyErr_SetString(PyExc_RuntimeError, "too big sequence");
    4459           0 :     *pnSize = -1;
    4460           0 :     return NULL;
    4461             :   }
    4462          78 :   if( (size_t)size > SIZE_MAX / sizeof(GUIntBig) ) {
    4463           0 :     PyErr_SetString(PyExc_RuntimeError, "too big sequence");
    4464           0 :     *pnSize = -1;
    4465           0 :     return NULL;
    4466             :   }
    4467          78 :   *pnSize = (int)size;
    4468          78 :   GUIntBig* ret = (GUIntBig*) malloc((*pnSize)*sizeof(GUIntBig));
    4469          78 :   if( !ret ) {
    4470           0 :     PyErr_SetString(PyExc_MemoryError, "cannot allocate temporary buffer");
    4471           0 :     *pnSize = -1;
    4472           0 :     return NULL;
    4473             :   }
    4474         196 :   for( int i = 0; i<*pnSize; i++ ) {
    4475         118 :     PyObject *o = PySequence_GetItem(pySeq,i);
    4476         118 :     if ( !PyArg_Parse(o,"K",&ret[i]) ) {
    4477           0 :         PyErr_SetString(PyExc_TypeError, "not an integer");
    4478           0 :         Py_DECREF(o);
    4479           0 :         free(ret);
    4480           0 :         *pnSize = -1;
    4481           0 :         return NULL;
    4482             :     }
    4483         118 :     Py_DECREF(o);
    4484             :   }
    4485             :   return ret;
    4486             : }
    4487             : 
    4488             : 
    4489             : static GIntBig*
    4490          78 : CreateCGIntBigListFromSequence( PyObject* pySeq, int* pnSize ) {
    4491             :   /* check if is List */
    4492          78 :   if ( !PySequence_Check(pySeq) ) {
    4493           0 :     PyErr_SetString(PyExc_TypeError, "not a sequence");
    4494           0 :     *pnSize = -1;
    4495           0 :     return NULL;
    4496             :   }
    4497          78 :   Py_ssize_t size = PySequence_Size(pySeq);
    4498          78 :   if( size > (Py_ssize_t)INT_MAX ) {
    4499           0 :     PyErr_SetString(PyExc_RuntimeError, "too big sequence");
    4500           0 :     *pnSize = -1;
    4501           0 :     return NULL;
    4502             :   }
    4503          78 :   if( (size_t)size > SIZE_MAX / sizeof(GIntBig) ) {
    4504           0 :     PyErr_SetString(PyExc_RuntimeError, "too big sequence");
    4505           0 :     *pnSize = -1;
    4506           0 :     return NULL;
    4507             :   }
    4508          78 :   *pnSize = (int)size;
    4509          78 :   GIntBig* ret = (GIntBig*) malloc((*pnSize)*sizeof(GIntBig));
    4510          78 :   if( !ret ) {
    4511           0 :     PyErr_SetString(PyExc_MemoryError, "cannot allocate temporary buffer");
    4512           0 :     *pnSize = -1;
    4513           0 :     return NULL;
    4514             :   }
    4515         196 :   for( int i = 0; i<*pnSize; i++ ) {
    4516         118 :     PyObject *o = PySequence_GetItem(pySeq,i);
    4517         118 :     if ( !PyArg_Parse(o,"L",&ret[i]) ) {
    4518           0 :         PyErr_SetString(PyExc_TypeError, "not an integer");
    4519           0 :         Py_DECREF(o);
    4520           0 :         free(ret);
    4521           0 :         *pnSize = -1;
    4522           0 :         return NULL;
    4523             :     }
    4524         118 :     Py_DECREF(o);
    4525             :   }
    4526             :   return ret;
    4527             : }
    4528             : 
    4529             : 
    4530             : typedef void* VoidPtrAsLong;
    4531             : 
    4532        7724 : static bool AddNumpyArrayToDict(PyObject *dict,
    4533             :                                 const struct ArrowSchema* schemaField,
    4534             :                                 const struct ArrowArray* arrayField,
    4535             :                                 const std::string& osPrefix,
    4536             :                                 PyObject* pointerArrayKeeper)
    4537             : {
    4538        7724 :     npy_intp dims = arrayField->length;
    4539        7724 :     const char* arrowType = schemaField->format;
    4540        7724 :     int typenum = -1;
    4541        7724 :     int sizeOfType = 0;
    4542        7724 :     const struct
    4543             :     {
    4544             :         char        arrowType;
    4545             :         int         numpyType;
    4546             :         int         sizeOfType;
    4547        7724 :     } MapArrowTypeToNumpyType[] = {
    4548             :         { 'b', NPY_BOOL,    1 },
    4549             :         { 'C', NPY_UINT8,   1 },
    4550             :         { 'c', NPY_INT8,    1 },
    4551             :         { 'S', NPY_UINT16,  2 },
    4552             :         { 's', NPY_INT16,   2 },
    4553             :         { 'I', NPY_UINT32,  4 },
    4554             :         { 'i', NPY_INT32,   4 },
    4555             :         { 'L', NPY_UINT64,  8 },
    4556             :         { 'l', NPY_INT64,   8 },
    4557             :         { 'e', NPY_FLOAT16, 2 },
    4558             :         { 'f', NPY_FLOAT32, 4 },
    4559             :         { 'g', NPY_FLOAT64, 8 },
    4560             :         // { 'E', NPY_COMPLEX32, 4 },
    4561             :         // { 'F', NPY_COMPLEX64, 8 },
    4562             :         // { 'G', NPY_COMPLEX128, 16 },
    4563             :     };
    4564        7724 :     const size_t nEltsInMapArrowTypeToNumpyType =
    4565             :         sizeof(MapArrowTypeToNumpyType) / sizeof(MapArrowTypeToNumpyType[0]);
    4566       17850 :     const bool bIsLargeList = (arrowType[0] == '+' &&
    4567        2402 :                                arrowType[1] == 'L' &&
    4568        7879 :                                arrowType[2] == '\0' &&
    4569         155 :                                schemaField->n_children == 1);
    4570       17850 :     const bool bIsList = (arrowType[0] == '+' &&
    4571        2402 :                           arrowType[1] == 'l' &&
    4572        9025 :                           arrowType[2] == '\0' &&
    4573        1301 :                           schemaField->n_children == 1);
    4574       17850 :     const bool bIsFixedSizeList = (arrowType[0] == '+' &&
    4575        2402 :                                    arrowType[1] == 'w' &&
    4576        8504 :                                    arrowType[2] == ':' &&
    4577         780 :                                    schemaField->n_children == 1);
    4578       73298 :     for( size_t j = 0; j < nEltsInMapArrowTypeToNumpyType; ++j )
    4579             :     {
    4580       70188 :         if( arrowType[0] == MapArrowTypeToNumpyType[j].arrowType &&
    4581        2794 :             arrowType[1] == '\0' )
    4582             :         {
    4583        2794 :             typenum = MapArrowTypeToNumpyType[j].numpyType;
    4584        2794 :             sizeOfType = MapArrowTypeToNumpyType[j].sizeOfType;
    4585        2794 :             break;
    4586             :         }
    4587       67394 :         else if( (bIsList || bIsLargeList || bIsFixedSizeList) &&
    4588       17245 :                  schemaField->children[0]->format[0] == MapArrowTypeToNumpyType[j].arrowType &&
    4589        1820 :                  schemaField->children[0]->format[1] == '\0' )
    4590             :         {
    4591        1820 :             typenum = MapArrowTypeToNumpyType[j].numpyType;
    4592        1820 :             sizeOfType = MapArrowTypeToNumpyType[j].sizeOfType;
    4593        1820 :             break;
    4594             :         }
    4595             :     }
    4596             : 
    4597        7724 :     PyObject* numpyArray = NULL;
    4598        7724 :     if( typenum != -1 && !bIsList && !bIsLargeList && schemaField->n_children == 0 )
    4599             :     {
    4600        2794 :         if( arrayField->n_buffers != 2 )
    4601             :         {
    4602           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    4603             :                      "Field %s: arrayField->n_buffers != 2",
    4604           0 :                      schemaField->name);
    4605           0 :             return false;
    4606             :         }
    4607        2794 :         if( typenum == NPY_BOOL )
    4608             :         {
    4609         157 :             numpyArray = PyArray_SimpleNew(1, &dims, NPY_BOOL);
    4610         484 :             for( npy_intp j = 0; j < dims; j++ )
    4611             :             {
    4612         327 :                 size_t srcOffset = static_cast<size_t>(arrayField->offset + j);
    4613         327 :                 uint8_t val = (((uint8_t*)arrayField->buffers[1])[srcOffset/8] >> (srcOffset % 8)) & 1;
    4614         327 :                 *(uint8_t*)PyArray_GETPTR1((PyArrayObject *) numpyArray, j) = val;
    4615             :             }
    4616             :         }
    4617             :         else
    4618             :         {
    4619        2637 :             numpyArray = PyArray_SimpleNewFromData(1, &dims, typenum,
    4620             :                                         (char*)arrayField->buffers[1] + static_cast<size_t>(arrayField->offset) * sizeOfType);
    4621             : 
    4622             :             /* Keep a reference to the owner object */
    4623             : #if NPY_API_VERSION >= 0x00000007
    4624        2637 :             PyArray_SetBaseObject((PyArrayObject *) numpyArray, pointerArrayKeeper);
    4625             : #else
    4626             :             PyArray_BASE((PyArrayObject *) numpyArray) = pointerArrayKeeper;
    4627             : #endif
    4628        2637 :             Py_INCREF(pointerArrayKeeper);
    4629             :         }
    4630             :     }
    4631        4930 :     else if( typenum != -1 && (bIsList || bIsLargeList) )
    4632             :     {
    4633        1105 :         if( arrayField->n_buffers != 2 )
    4634             :         {
    4635           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    4636             :                      "Field %s: arrayField->n_buffers != 2",
    4637           0 :                      schemaField->name);
    4638           0 :             return false;
    4639             :         }
    4640        1105 :         if( arrayField->n_children != 1 )
    4641             :         {
    4642           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    4643             :                      "Field %s: arrayField->n_children != 1",
    4644           0 :                      schemaField->name);
    4645           0 :             return false;
    4646             :         }
    4647        1105 :         if( arrayField->children[0]->n_buffers != 2 )
    4648             :         {
    4649           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    4650             :                      "Field %s: arrayField->children[0]->n_buffers != 2",
    4651           0 :                      schemaField->name);
    4652           0 :             return false;
    4653             :         }
    4654        1105 :         const int32_t* offsets = bIsList ? (const int32_t*)arrayField->buffers[1] + arrayField->offset : NULL;
    4655        1105 :         const int64_t* largeOffsets = bIsLargeList ? (const int64_t*)arrayField->buffers[1] + arrayField->offset : NULL;
    4656        1105 :         if( arrayField->children[0]->length < (offsets ? offsets[arrayField->length] : largeOffsets[arrayField->length]) )
    4657             :         {
    4658           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    4659             :                      "Field %s: arrayField->children[0]->length (=%d) < offsets[arrayField->length] (=%d)",
    4660           0 :                      schemaField->name,
    4661             :                      int(arrayField->children[0]->length),
    4662           0 :                      int(offsets ? offsets[arrayField->length] : largeOffsets[arrayField->length]));
    4663           0 :             return false;
    4664             :         }
    4665        1105 :         numpyArray = PyArray_SimpleNew(1, &dims, NPY_OBJECT);
    4666        3212 :         for( npy_intp j = 0; j < dims; j++ )
    4667             :         {
    4668        2107 :             npy_intp nvalues = offsets ? offsets[j+1] - offsets[j] : (npy_intp)(largeOffsets[j+1] - largeOffsets[j]);
    4669        2107 :             PyObject* subObj;
    4670        2107 :             if( typenum == NPY_BOOL )
    4671             :             {
    4672         224 :                 subObj = PyArray_SimpleNew(1, &nvalues, NPY_BOOL);
    4673         660 :                 for( npy_intp k = 0; k < nvalues; k++ )
    4674             :                 {
    4675         436 :                     size_t srcOffset = static_cast<size_t>(arrayField->children[0]->offset + (offsets ? offsets[j] : largeOffsets[j]) + k);
    4676         436 :                     uint8_t val = (((uint8_t*)arrayField->children[0]->buffers[1])[srcOffset / 8]  >> (srcOffset % 8)) & 1;
    4677         436 :                     *(uint8_t*)PyArray_GETPTR1((PyArrayObject *) subObj, k) = val;
    4678             :                 }
    4679             :             }
    4680             :             else
    4681             :             {
    4682        1883 :                 subObj = PyArray_SimpleNewFromData(
    4683             :                     1, &nvalues, typenum,
    4684             :                     (char*)arrayField->children[0]->buffers[1] + (static_cast<size_t>(arrayField->children[0]->offset) + (offsets ? offsets[j] : largeOffsets[j])) * sizeOfType);
    4685             :                 /* Keep a reference to the owner object */
    4686             : #if NPY_API_VERSION >= 0x00000007
    4687        1883 :                 PyArray_SetBaseObject((PyArrayObject *) subObj, pointerArrayKeeper);
    4688             : #else
    4689             :                 PyArray_BASE((PyArrayObject *) subObj) = pointerArrayKeeper;
    4690             : #endif
    4691        1883 :                 Py_INCREF(pointerArrayKeeper);
    4692             :             }
    4693        2107 :             memcpy(PyArray_GETPTR1((PyArrayObject *) numpyArray, j),
    4694             :                    &subObj,
    4695             :                    sizeof(PyObject*));
    4696             :         }
    4697             :     }
    4698        3825 :     else if( typenum != -1 && bIsFixedSizeList )
    4699             :     {
    4700         715 :         if( arrayField->n_buffers != 1 )
    4701             :         {
    4702           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    4703             :                      "Field %s: arrayField->n_buffers != 1",
    4704           0 :                      schemaField->name);
    4705           0 :             return false;
    4706             :         }
    4707         715 :         if( arrayField->n_children != 1 )
    4708             :         {
    4709           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    4710             :                      "Field %s: arrayField->n_children != 1",
    4711           0 :                      schemaField->name);
    4712           0 :             return false;
    4713             :         }
    4714         715 :         const struct ArrowArray* psChildArray = arrayField->children[0];
    4715         715 :         if( psChildArray->n_buffers != 2 )
    4716             :         {
    4717           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    4718             :                      "Field %s: psChildArray->n_buffers != 2",
    4719           0 :                      schemaField->name);
    4720           0 :             return false;
    4721             :         }
    4722         715 :         const int nLength = atoi(arrowType + strlen("+w:"));
    4723         715 :         if( psChildArray->length < nLength * arrayField->length )
    4724             :         {
    4725           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    4726             :                      "Field %s: psChildArray->length < nLength * arrayField->length",
    4727           0 :                      schemaField->name);
    4728           0 :             return false;
    4729             :         }
    4730         715 :         numpyArray = PyArray_SimpleNew(1, &dims, NPY_OBJECT);
    4731        1936 :         for( npy_intp j = 0; j < dims; j++ )
    4732             :         {
    4733        1221 :             PyObject* subObj;
    4734        1221 :             npy_intp nvalues = nLength;
    4735        1221 :             if( typenum == NPY_BOOL )
    4736             :             {
    4737         111 :                 subObj = PyArray_SimpleNew(1, &nvalues, NPY_BOOL);
    4738         333 :                 for( npy_intp k = 0; k < nvalues; k++ )
    4739             :                 {
    4740         222 :                     size_t srcOffset = static_cast<size_t>(psChildArray->offset + (j + arrayField->offset) * nLength + k);
    4741         222 :                     uint8_t val = (((uint8_t*)psChildArray->buffers[1])[srcOffset / 8]  >> (srcOffset % 8)) & 1;
    4742         222 :                     *(uint8_t*)PyArray_GETPTR1((PyArrayObject *) subObj, k) = val;
    4743             :                 }
    4744             :             }
    4745             :             else
    4746             :             {
    4747        1110 :                 subObj = PyArray_SimpleNewFromData(
    4748             :                     1, &nvalues, typenum,
    4749             :                     (char*)psChildArray->buffers[1] + static_cast<size_t>((psChildArray->offset + (j + arrayField->offset) * nLength) * sizeOfType));
    4750             :                 /* Keep a reference to the owner object */
    4751             : #if NPY_API_VERSION >= 0x00000007
    4752        1110 :                 PyArray_SetBaseObject((PyArrayObject *) subObj, pointerArrayKeeper);
    4753             : #else
    4754             :                 PyArray_BASE((PyArrayObject *) subObj) = pointerArrayKeeper;
    4755             : #endif
    4756        1110 :                 Py_INCREF(pointerArrayKeeper);
    4757             :             }
    4758        1221 :             memcpy(PyArray_GETPTR1((PyArrayObject *) numpyArray, j),
    4759             :                    &subObj,
    4760             :                    sizeof(PyObject*));
    4761             :         }
    4762             :     }
    4763        3110 :     else if( (arrowType[0] == 'u' || /* string */
    4764        1285 :               arrowType[0] == 'z'    /* binary */) && arrowType[1] == '\0' &&
    4765        1285 :               schemaField->n_children == 0 )
    4766             :     {
    4767        1285 :         if( arrayField->n_buffers != 3 )
    4768             :         {
    4769           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    4770             :                      "Field %s: arrayField->n_buffers != 3",
    4771           0 :                      schemaField->name);
    4772           0 :             return false;
    4773             :         }
    4774        1285 :         const int32_t* offsets = (const int32_t*)arrayField->buffers[1] + static_cast<size_t>(arrayField->offset);
    4775             :         // numpy can't deal with zero length strings
    4776        1285 :         int32_t maxLength = 1;
    4777        1285 :         int32_t minLength = 0x7FFFFFFF;
    4778        1285 :         int64_t averageLength = 0;
    4779        8295 :         for( npy_intp j = 0; j < dims; j++ )
    4780             :         {
    4781        7010 :             const int32_t nLength = offsets[j+1] - offsets[j];
    4782        7010 :             if( nLength < minLength )
    4783             :                 minLength = nLength;
    4784        7010 :             if( nLength > maxLength )
    4785             :                 maxLength = nLength;
    4786        7010 :             averageLength += nLength;
    4787             :         }
    4788        1285 :         if( dims )
    4789        1285 :             averageLength /= dims;
    4790             : 
    4791             : 
    4792        1285 :         if( arrowType[0] == 'z' && (minLength == 0 || minLength != maxLength) )
    4793             :         {
    4794         816 :             const uint8_t* panNotNulls =
    4795         408 :                  arrayField->null_count == 0 ? NULL :
    4796             :                 (const uint8_t*)arrayField->buffers[0];
    4797         408 :             numpyArray = PyArray_SimpleNew(1, &dims, NPY_OBJECT);
    4798        1417 :             for( npy_intp j = 0; j < dims; j++ )
    4799             :             {
    4800        1009 :                 PyObject* subObj;
    4801        1009 :                 size_t srcOffset = static_cast<size_t>(arrayField->offset + j);
    4802        1009 :                 if( panNotNulls && (panNotNulls[srcOffset / 8] & (1 << (srcOffset%8))) == 0 )
    4803             :                 {
    4804         827 :                     subObj = Py_None;
    4805         827 :                     Py_INCREF(subObj);
    4806             :                 }
    4807             :                 else
    4808             :                 {
    4809         182 :                     const int32_t nLength = offsets[j+1] - offsets[j];
    4810         182 :                     subObj = PyBytes_FromStringAndSize(
    4811         182 :                         ((const char*)arrayField->buffers[2]) + offsets[j],
    4812             :                         nLength);
    4813             :                 }
    4814        1009 :                 memcpy(PyArray_GETPTR1((PyArrayObject *) numpyArray, j),
    4815             :                        &subObj,
    4816             :                        sizeof(PyObject*));
    4817             :             }
    4818             :         }
    4819         877 :         else if( arrowType[0] == 'u' && dims > 0 && maxLength > 32 &&
    4820          69 :                  maxLength > 100 * 1000 / dims &&
    4821           1 :                  maxLength > averageLength * 2 )
    4822             :         {
    4823             :             // If the maximum string size is significantly large, and
    4824             :             // larger than the average one, then do not use fixed size
    4825             :             // strings, but create an array of string objects to save memory
    4826           2 :             const uint8_t* panNotNulls =
    4827           1 :                  arrayField->null_count == 0 ? NULL :
    4828             :                 (const uint8_t*)arrayField->buffers[0];
    4829           1 :             numpyArray = PyArray_SimpleNew(1, &dims, NPY_OBJECT);
    4830           4 :             for( npy_intp j = 0; j < dims; j++ )
    4831             :             {
    4832           3 :                 PyObject* subObj;
    4833           3 :                 size_t srcOffset = static_cast<size_t>(arrayField->offset + j);
    4834           3 :                 if( panNotNulls && (panNotNulls[srcOffset / 8] & (1 << (srcOffset%8))) == 0 )
    4835             :                 {
    4836           1 :                     subObj = Py_None;
    4837           1 :                     Py_INCREF(subObj);
    4838             :                 }
    4839             :                 else
    4840             :                 {
    4841           2 :                     const int32_t nLength = offsets[j+1] - offsets[j];
    4842           2 :                     subObj = PyUnicode_FromStringAndSize(
    4843           2 :                         ((const char*)arrayField->buffers[2]) + offsets[j],
    4844             :                         nLength);
    4845             :                 }
    4846           3 :                 memcpy(PyArray_GETPTR1((PyArrayObject *) numpyArray, j),
    4847             :                        &subObj,
    4848             :                        sizeof(PyObject*));
    4849             :             }
    4850             :         }
    4851             :         else
    4852             :         {
    4853             :             // create the dtype string
    4854        1219 :             PyObject *pDTypeString = PyUnicode_FromFormat("%c%u",
    4855             :                 arrowType[0] == 'u' ? 'S' : 'V', maxLength);
    4856             :             // out type description object
    4857         876 :             PyArray_Descr *pDescr = NULL;
    4858         876 :             PyArray_DescrConverter(pDTypeString, &pDescr);
    4859         876 :             Py_DECREF(pDTypeString);
    4860             : 
    4861         876 :             if( minLength == maxLength )
    4862             :             {
    4863        1070 :                 numpyArray = PyArray_NewFromDescr(
    4864             :                     &PyArray_Type, pDescr, 1, &dims, NULL,
    4865         535 :                     (char*)arrayField->buffers[2] + offsets[0], 0, NULL);
    4866             : 
    4867             :                 /* Keep a reference to the owner object */
    4868             : #if NPY_API_VERSION >= 0x00000007
    4869         535 :                 PyArray_SetBaseObject((PyArrayObject *) numpyArray, pointerArrayKeeper);
    4870             : #else
    4871             :                 PyArray_BASE((PyArrayObject *) numpyArray) = pointerArrayKeeper;
    4872             : #endif
    4873         535 :                 Py_INCREF(pointerArrayKeeper);
    4874             :             }
    4875             :             else
    4876             :             {
    4877             :                 // create array
    4878         341 :                 numpyArray = PyArray_SimpleNewFromDescr(1, &dims, pDescr);
    4879        1308 :                 for( npy_intp j = 0; j < dims; j++ )
    4880             :                 {
    4881         967 :                     const int32_t nLength = offsets[j+1] - offsets[j];
    4882         967 :                     if( nLength > 0 )
    4883             :                     {
    4884        1453 :                         memcpy(PyArray_GETPTR1((PyArrayObject *) numpyArray, j),
    4885         486 :                                ((const char*)arrayField->buffers[2]) + offsets[j],
    4886             :                                nLength);
    4887             :                     }
    4888         967 :                     if( nLength < maxLength )
    4889             :                     {
    4890         967 :                         memset(((char*)PyArray_GETPTR1((PyArrayObject *) numpyArray, j)) + nLength,
    4891             :                                0,
    4892         803 :                                maxLength - nLength);
    4893             :                     }
    4894             :                 }
    4895             :             }
    4896             :         }
    4897             :     }
    4898        1825 :     else if( (arrowType[0] == 'U' || /* string */
    4899         228 :               arrowType[0] == 'Z'    /* binary */) && arrowType[1] == '\0' &&
    4900         228 :               schemaField->n_children == 0 )
    4901             :     {
    4902         228 :         if( arrayField->n_buffers != 3 )
    4903             :         {
    4904           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    4905             :                      "Field %s: arrayField->n_buffers != 3",
    4906           0 :                      schemaField->name);
    4907           0 :             return false;
    4908             :         }
    4909         228 :         const int64_t* offsets = (const int64_t*)arrayField->buffers[1] + static_cast<size_t>(arrayField->offset);
    4910             :         // numpy can't deal with zero length strings
    4911         228 :         int64_t maxLength = 1;
    4912         228 :         int64_t minLength = ((int64_t)0x7FFFFFFF << 32) | 0xFFFFFFFF;
    4913         228 :         int64_t averageLength = 0;
    4914         634 :         for( npy_intp j = 0; j < dims; j++ )
    4915             :         {
    4916         406 :             const int64_t nLength = offsets[j+1] - offsets[j];
    4917         406 :             if( nLength < minLength )
    4918             :                 minLength = nLength;
    4919         406 :             if( nLength > maxLength )
    4920             :                 maxLength = nLength;
    4921         406 :             averageLength += nLength;
    4922             :         }
    4923         228 :         if( dims )
    4924         208 :             averageLength /= dims;
    4925             : 
    4926         228 :         if( arrowType[0] == 'Z' && (minLength == 0 || minLength != maxLength || maxLength > 0x7FFFFFFF) )
    4927             :         {
    4928          90 :             const uint8_t* panNotNulls =
    4929          45 :                  arrayField->null_count == 0 ? NULL :
    4930             :                 (const uint8_t*)arrayField->buffers[0];
    4931          45 :             numpyArray = PyArray_SimpleNew(1, &dims, NPY_OBJECT);
    4932         141 :             for( npy_intp j = 0; j < dims; j++ )
    4933             :             {
    4934          96 :                 PyObject* subObj;
    4935          96 :                 size_t srcOffset = static_cast<size_t>(arrayField->offset + j);
    4936          96 :                 if( panNotNulls && (panNotNulls[srcOffset / 8] & (1 << (srcOffset%8))) == 0 )
    4937             :                 {
    4938           8 :                     subObj = Py_None;
    4939           8 :                     Py_INCREF(subObj);
    4940             :                 }
    4941             :                 else
    4942             :                 {
    4943          88 :                     const int64_t nLength = offsets[j+1] - offsets[j];
    4944          88 :                     subObj = PyBytes_FromStringAndSize(
    4945          88 :                         ((const char*)arrayField->buffers[2]) + offsets[j],
    4946             :                         static_cast<size_t>(nLength));
    4947             :                 }
    4948          96 :                 memcpy(PyArray_GETPTR1((PyArrayObject *) numpyArray, j),
    4949             :                        &subObj,
    4950             :                        sizeof(PyObject*));
    4951             :             }
    4952             :         }
    4953         183 :         else if( arrowType[0] == 'U' && dims > 0 && maxLength > 32 &&
    4954           0 :                  maxLength <= 0x7FFFFFFF &&
    4955           0 :                  maxLength > 100 * 1000 / dims &&
    4956           0 :                  maxLength > averageLength * 2 )
    4957             :         {
    4958             :             // If the maximum string size is significantly large, and
    4959             :             // larger than the average one, then do not use fixed size
    4960             :             // strings, but create an array of string objects to save memory
    4961           0 :             const uint8_t* panNotNulls =
    4962           0 :                  arrayField->null_count == 0 ? NULL :
    4963             :                 (const uint8_t*)arrayField->buffers[0];
    4964           0 :             numpyArray = PyArray_SimpleNew(1, &dims, NPY_OBJECT);
    4965           0 :             for( npy_intp j = 0; j < dims; j++ )
    4966             :             {
    4967           0 :                 PyObject* subObj;
    4968           0 :                 size_t srcOffset = static_cast<size_t>(arrayField->offset + j);
    4969           0 :                 if( panNotNulls && (panNotNulls[srcOffset / 8] & (1 << (srcOffset%8))) == 0 )
    4970             :                 {
    4971           0 :                     subObj = Py_None;
    4972           0 :                     Py_INCREF(subObj);
    4973             :                 }
    4974             :                 else
    4975             :                 {
    4976           0 :                     const int32_t nLength = int(offsets[j+1] - offsets[j]);
    4977           0 :                     subObj = PyUnicode_FromStringAndSize(
    4978           0 :                         ((const char*)arrayField->buffers[2]) + offsets[j],
    4979             :                         nLength);
    4980             :                 }
    4981           0 :                 memcpy(PyArray_GETPTR1((PyArrayObject *) numpyArray, j),
    4982             :                        &subObj,
    4983             :                        sizeof(PyObject*));
    4984             :             }
    4985             :         }
    4986             :         else
    4987             :         {
    4988             :             // We could possibly handle this...
    4989         183 :             if( maxLength > 0x7FFFFFFF )
    4990             :             {
    4991           0 :                 CPLError(CE_Failure, CPLE_AppDefined,
    4992             :                          "Field %s: too large value",
    4993           0 :                          schemaField->name);
    4994           0 :                 return false;
    4995             :             }
    4996             : 
    4997             :             // create the dtype string
    4998         272 :             PyObject *pDTypeString = PyUnicode_FromFormat("%c%u",
    4999             :                 arrowType[0] == 'U' ? 'S' : 'V', static_cast<int32_t>(maxLength));
    5000             :             // out type description object
    5001         183 :             PyArray_Descr *pDescr = NULL;
    5002         183 :             PyArray_DescrConverter(pDTypeString, &pDescr);
    5003         183 :             Py_DECREF(pDTypeString);
    5004             : 
    5005         183 :             if( minLength == maxLength )
    5006             :             {
    5007         262 :                 numpyArray = PyArray_NewFromDescr(
    5008             :                     &PyArray_Type, pDescr, 1, &dims, NULL,
    5009         131 :                     (char*)arrayField->buffers[2] + offsets[0], 0, NULL);
    5010             : 
    5011             :                 /* Keep a reference to the owner object */
    5012             : #if NPY_API_VERSION >= 0x00000007
    5013         131 :                 PyArray_SetBaseObject((PyArrayObject *) numpyArray, pointerArrayKeeper);
    5014             : #else
    5015             :                 PyArray_BASE((PyArrayObject *) numpyArray) = pointerArrayKeeper;
    5016             : #endif
    5017         131 :                 Py_INCREF(pointerArrayKeeper);
    5018             :             }
    5019             :             else
    5020             :             {
    5021             :                 // create array
    5022          52 :                 numpyArray = PyArray_SimpleNewFromDescr(1, &dims, pDescr);
    5023         159 :                 for( npy_intp j = 0; j < dims; j++ )
    5024             :                 {
    5025         107 :                     const int32_t nLength = static_cast<int32_t>(offsets[j+1] - offsets[j]);
    5026         107 :                     if( nLength > 0 )
    5027             :                     {
    5028         157 :                         memcpy(PyArray_GETPTR1((PyArrayObject *) numpyArray, j),
    5029          50 :                                ((const char*)arrayField->buffers[2]) + offsets[j],
    5030             :                                nLength);
    5031             :                     }
    5032         107 :                     if( nLength < maxLength )
    5033             :                     {
    5034         107 :                         memset(((char*)PyArray_GETPTR1((PyArrayObject *) numpyArray, j)) + nLength,
    5035             :                                0,
    5036          74 :                                static_cast<int32_t>(maxLength) - nLength);
    5037             :                     }
    5038             :                 }
    5039             :             }
    5040             :         }
    5041             :     }
    5042        1597 :     else if( arrowType[0] == 'w' && arrowType[1] == ':' &&
    5043          69 :              schemaField->n_children == 0 )
    5044             :     {
    5045             :         // Fixed width binary
    5046          69 :         if( arrayField->n_buffers != 2 )
    5047             :         {
    5048           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5049             :                      "field %s:arrayField->n_buffers != 2",
    5050           0 :                      schemaField->name);
    5051           0 :             return false;
    5052             :         }
    5053          69 :         const int nLength = atoi(arrowType + strlen("w:"));
    5054          69 :         numpyArray = PyArray_SimpleNew(1, &dims, NPY_OBJECT);
    5055         193 :         for( npy_intp j = 0; j < dims; j++ )
    5056             :         {
    5057         124 :             PyObject* subObj = PyBytes_FromStringAndSize(
    5058         124 :                     ((const char*)arrayField->buffers[1]) + static_cast<size_t>(arrayField->offset + j) * nLength,
    5059         124 :                     nLength);
    5060         124 :             memcpy(PyArray_GETPTR1((PyArrayObject *) numpyArray, j),
    5061             :                    &subObj,
    5062             :                    sizeof(PyObject*));
    5063             :         }
    5064             :     }
    5065        1528 :     else if( bIsList &&
    5066         351 :              schemaField->children[0]->format[0] == 'u' &&
    5067          91 :              schemaField->children[0]->format[1] == '\0' )
    5068             :     {
    5069             :         // List of strings
    5070          91 :         if( arrayField->n_buffers != 2 )
    5071             :         {
    5072           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5073             :                      "Field %s: arrayField->n_buffers != 2",
    5074           0 :                      schemaField->name);
    5075           0 :             return false;
    5076             :         }
    5077          91 :         if( arrayField->n_children != 1 )
    5078             :         {
    5079           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5080             :                      "Field %s: arrayField->n_children != 1",
    5081           0 :                      schemaField->name);
    5082           0 :             return false;
    5083             :         }
    5084          91 :         if( arrayField->children[0]->n_buffers != 3 )
    5085             :         {
    5086           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5087             :                      "Field %s: arrayField->children[0]->n_buffers != 3",
    5088           0 :                      schemaField->name);
    5089           0 :             return false;
    5090             :         }
    5091          91 :         const int32_t* offsets = (const int32_t*)arrayField->buffers[1] + static_cast<size_t>(arrayField->offset);
    5092          91 :         if( arrayField->children[0]->length < offsets[arrayField->length] )
    5093             :         {
    5094           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5095             :                      "Field %s: arrayField->children[0]->length = (%d) < offsets[arrayField->length] (=%d)",
    5096           0 :                      schemaField->name,
    5097             :                      int(arrayField->children[0]->length),
    5098             :                      int(offsets[arrayField->length]));
    5099           0 :             return false;
    5100             :         }
    5101          91 :         const int32_t* offsetsToBytes = (const int32_t*)arrayField->children[0]->buffers[1] + static_cast<size_t>(arrayField->children[0]->offset);
    5102          91 :         const char* bytes = (const char*)arrayField->children[0]->buffers[2];
    5103          91 :         numpyArray = PyArray_SimpleNew(1, &dims, NPY_OBJECT);
    5104         263 :         for( npy_intp j = 0; j < dims; j++ )
    5105             :         {
    5106         172 :             npy_intp nStrings = offsets[j+1] - offsets[j];
    5107         172 :             int32_t maxLength = 1;
    5108         352 :             for( npy_intp k = 0; k < nStrings; k++ )
    5109             :             {
    5110         180 :                 const int32_t nLength = offsetsToBytes[offsets[j] + k + 1] - offsetsToBytes[offsets[j] + k];
    5111         180 :                 if( nLength > maxLength )
    5112             :                     maxLength = nLength;
    5113             :             }
    5114             : 
    5115             :             // create the dtype string
    5116         172 :             PyObject *pDTypeString = PyUnicode_FromFormat("S%d", maxLength);
    5117             :             // out type description object
    5118         172 :             PyArray_Descr *pDescr = NULL;
    5119         172 :             PyArray_DescrConverter(pDTypeString, &pDescr);
    5120         172 :             Py_DECREF(pDTypeString);
    5121             : 
    5122         172 :             PyObject* subArray = PyArray_SimpleNewFromDescr(1, &nStrings, pDescr);
    5123         352 :             for( npy_intp k = 0; k < nStrings; k++ )
    5124             :             {
    5125         180 :                 const int32_t nLength = offsetsToBytes[offsets[j] + k + 1] - offsetsToBytes[offsets[j] + k];
    5126         180 :                 if( nLength > 0 )
    5127             :                 {
    5128         333 :                     memcpy(PyArray_GETPTR1((PyArrayObject *) subArray, k),
    5129         153 :                            bytes + offsetsToBytes[offsets[j] + k],
    5130             :                            nLength);
    5131             :                 }
    5132         180 :                 if( nLength < maxLength )
    5133             :                 {
    5134         180 :                     memset(((char*)PyArray_GETPTR1((PyArrayObject *) subArray, k)) + nLength,
    5135             :                            0,
    5136          90 :                            maxLength - nLength);
    5137             :                 }
    5138             :             }
    5139             : 
    5140         172 :             memcpy(PyArray_GETPTR1((PyArrayObject *) numpyArray, j),
    5141             :                    &subArray,
    5142             :                    sizeof(PyObject*));
    5143             :         }
    5144             :     }
    5145        1437 :     else if( bIsLargeList &&
    5146           0 :              schemaField->children[0]->format[0] == 'U' &&
    5147           0 :              schemaField->children[0]->format[1] == '\0' )
    5148             :     {
    5149             :         // List of strings
    5150           0 :         if( arrayField->n_buffers != 2 )
    5151             :         {
    5152           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5153             :                      "Field %s: arrayField->n_buffers != 2",
    5154           0 :                      schemaField->name);
    5155           0 :             return false;
    5156             :         }
    5157           0 :         if( arrayField->n_children != 1 )
    5158             :         {
    5159           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5160             :                      "Field %s: arrayField->n_children != 1",
    5161           0 :                      schemaField->name);
    5162           0 :             return false;
    5163             :         }
    5164           0 :         if( arrayField->children[0]->n_buffers != 3 )
    5165             :         {
    5166           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5167             :                      "Field %s: arrayField->children[0]->n_buffers != 3",
    5168           0 :                      schemaField->name);
    5169           0 :             return false;
    5170             :         }
    5171           0 :         const int64_t* offsets = (const int64_t*)arrayField->buffers[1] + static_cast<size_t>(arrayField->offset);
    5172           0 :         if( arrayField->children[0]->length < offsets[arrayField->length] )
    5173             :         {
    5174           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5175             :                      "Field %s: arrayField->children[0]->length = (%d) < offsets[arrayField->length] (=%d)",
    5176           0 :                      schemaField->name,
    5177             :                      int(arrayField->children[0]->length),
    5178             :                      int(offsets[arrayField->length]));
    5179           0 :             return false;
    5180             :         }
    5181           0 :         const int64_t* offsetsToBytes = (const int64_t*)arrayField->children[0]->buffers[1] + static_cast<size_t>(arrayField->children[0]->offset);
    5182           0 :         const char* bytes = (const char*)arrayField->children[0]->buffers[2];
    5183           0 :         numpyArray = PyArray_SimpleNew(1, &dims, NPY_OBJECT);
    5184           0 :         for( npy_intp j = 0; j < dims; j++ )
    5185             :         {
    5186           0 :             npy_intp nStrings = offsets[j+1] - offsets[j];
    5187           0 :             int64_t maxLength = 1;
    5188           0 :             for( npy_intp k = 0; k < nStrings; k++ )
    5189             :             {
    5190           0 :                 const int64_t nLength = offsetsToBytes[offsets[j] + k + 1] - offsetsToBytes[offsets[j] + k];
    5191           0 :                 if( nLength > maxLength )
    5192             :                     maxLength = nLength;
    5193             :             }
    5194           0 :             if( maxLength >= INT_MAX )
    5195             :             {
    5196           0 :                 CPLError(CE_Failure, CPLE_AppDefined, "Too large string");
    5197           0 :                 return false;
    5198             :             }
    5199             : 
    5200             :             // create the dtype string
    5201           0 :             PyObject *pDTypeString = PyUnicode_FromFormat("S%d", int(maxLength));
    5202             :             // out type description object
    5203           0 :             PyArray_Descr *pDescr = NULL;
    5204           0 :             PyArray_DescrConverter(pDTypeString, &pDescr);
    5205           0 :             Py_DECREF(pDTypeString);
    5206             : 
    5207           0 :             PyObject* subArray = PyArray_SimpleNewFromDescr(1, &nStrings, pDescr);
    5208           0 :             for( npy_intp k = 0; k < nStrings; k++ )
    5209             :             {
    5210           0 :                 const int64_t nLength = offsetsToBytes[offsets[j] + k + 1] - offsetsToBytes[offsets[j] + k];
    5211           0 :                 if( nLength > 0 )
    5212             :                 {
    5213           0 :                     memcpy(PyArray_GETPTR1((PyArrayObject *) subArray, k),
    5214           0 :                            bytes + offsetsToBytes[offsets[j] + k],
    5215             :                            int(nLength));
    5216             :                 }
    5217           0 :                 if( nLength < maxLength )
    5218             :                 {
    5219           0 :                     memset(((char*)PyArray_GETPTR1((PyArrayObject *) subArray, k)) + nLength,
    5220             :                            0,
    5221           0 :                            int(maxLength - nLength));
    5222             :                 }
    5223             :             }
    5224             : 
    5225           0 :             memcpy(PyArray_GETPTR1((PyArrayObject *) numpyArray, j),
    5226             :                    &subArray,
    5227             :                    sizeof(PyObject*));
    5228             :         }
    5229             :     }
    5230        1437 :     else if( bIsFixedSizeList &&
    5231          65 :              schemaField->children[0]->format[0] == 'u' &&
    5232          65 :              schemaField->children[0]->format[1] == '\0' )
    5233             :     {
    5234             :         // Fixed size list of strings
    5235          65 :         const int nStrings = atoi(arrowType + strlen("+w:"));
    5236          65 :         if( arrayField->n_buffers != 1 )
    5237             :         {
    5238           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5239             :                      "Field %s: arrayField->n_buffers != 1",
    5240           0 :                      schemaField->name);
    5241           0 :             return false;
    5242             :         }
    5243          65 :         if( arrayField->n_children != 1 )
    5244             :         {
    5245           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5246             :                      "Field %s: arrayField->n_children != 1",
    5247           0 :                      schemaField->name);
    5248           0 :             return false;
    5249             :         }
    5250          65 :         if( arrayField->children[0]->n_buffers != 3 )
    5251             :         {
    5252           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5253             :                      "Field %s: arrayField->children[0]->n_buffers != 3",
    5254           0 :                      schemaField->name);
    5255           0 :             return false;
    5256             :         }
    5257          65 :         if( arrayField->children[0]->length < nStrings * arrayField->length )
    5258             :         {
    5259           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5260             :                      "Field %s: arrayField->children[0]->length < nStrings * arrayField->length",
    5261           0 :                      schemaField->name);
    5262           0 :             return false;
    5263             :         }
    5264          65 :         const int32_t* offsetsToBytes = (const int32_t*)arrayField->children[0]->buffers[1] + arrayField->offset * nStrings + static_cast<size_t>(arrayField->children[0]->offset);
    5265          65 :         const char* bytes = (const char*)arrayField->children[0]->buffers[2];
    5266          65 :         numpyArray = PyArray_SimpleNew(1, &dims, NPY_OBJECT);
    5267         176 :         for( npy_intp j = 0; j < dims; j++ )
    5268             :         {
    5269             :             int32_t maxLength = 1;
    5270         333 :             for( int k = 0; k < nStrings; k++ )
    5271             :             {
    5272         222 :                 const int32_t nLength = offsetsToBytes[j * nStrings + k + 1] - offsetsToBytes[j * nStrings + k];
    5273         222 :                 if( nLength > maxLength )
    5274             :                     maxLength = nLength;
    5275             :             }
    5276             : 
    5277             :             // create the dtype string
    5278         111 :             PyObject *pDTypeString = PyUnicode_FromFormat("S%u", maxLength);
    5279             :             // out type description object
    5280         111 :             PyArray_Descr *pDescr = NULL;
    5281         111 :             PyArray_DescrConverter(pDTypeString, &pDescr);
    5282         111 :             Py_DECREF(pDTypeString);
    5283             : 
    5284         111 :             npy_intp nStringsNpyIntp = nStrings;
    5285         111 :             PyObject* subArray = PyArray_SimpleNewFromDescr(1, &nStringsNpyIntp, pDescr);
    5286         333 :             for( int k = 0; k < nStrings; k++ )
    5287             :             {
    5288         222 :                 const int32_t nLength = offsetsToBytes[j * nStrings + k + 1] - offsetsToBytes[j * nStrings + k];
    5289         222 :                 if( nLength > 0 )
    5290             :                 {
    5291         444 :                     memcpy(PyArray_GETPTR1((PyArrayObject *) subArray, k),
    5292         222 :                            bytes + offsetsToBytes[j * nStrings + k],
    5293             :                            nLength);
    5294             :                 }
    5295         222 :                 if( nLength < maxLength )
    5296             :                 {
    5297         222 :                     memset(((char*)PyArray_GETPTR1((PyArrayObject *) subArray, k)) + nLength,
    5298             :                            0,
    5299           0 :                            maxLength - nLength);
    5300             :                 }
    5301             :             }
    5302             : 
    5303         111 :             memcpy(PyArray_GETPTR1((PyArrayObject *) numpyArray, j),
    5304             :                    &subArray,
    5305             :                    sizeof(PyObject*));
    5306             :         }
    5307             :     }
    5308        1372 :     else if( strcmp(arrowType, "tdD") == 0 &&
    5309         205 :              schemaField->n_children == 0 )
    5310             :     {
    5311             :         // Date(32) in days since Epoch
    5312         205 :         if( arrayField->n_buffers != 2 )
    5313             :         {
    5314           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5315             :                      "Field %s: arrayField->n_buffers != 2",
    5316           0 :                      schemaField->name);
    5317           0 :             return false;
    5318             :         }
    5319             : 
    5320             :         // create the dtype string
    5321         205 :         PyObject *pDTypeString = PyUnicode_FromString("datetime64[D]");
    5322             :         // out type description object
    5323         205 :         PyArray_Descr *pDescr = NULL;
    5324         205 :         PyArray_DescrConverter(pDTypeString, &pDescr);
    5325         205 :         Py_DECREF(pDTypeString);
    5326         205 :         CPLAssert(pDescr);
    5327             : 
    5328             :         // create array
    5329         205 :         numpyArray = PyArray_SimpleNewFromDescr(1, &dims, pDescr);
    5330         569 :         for( npy_intp j = 0; j < dims; j++ )
    5331             :         {
    5332         364 :             *(int64_t*)PyArray_GETPTR1((PyArrayObject *) numpyArray, j) =
    5333         364 :                 ((int*)arrayField->buffers[1])[j + static_cast<size_t>(arrayField->offset)];
    5334         205 :         }
    5335             :     }
    5336        1167 :     else if( strcmp(arrowType, "ttm") == 0 &&
    5337         185 :              schemaField->n_children == 0 )
    5338             :     {
    5339             :         // Time(32) in milliseconds
    5340         185 :         if( arrayField->n_buffers != 2 )
    5341             :         {
    5342           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5343             :                      "Field %s: arrayField->n_buffers != 2",
    5344           0 :                      schemaField->name);
    5345           0 :             return false;
    5346             :         }
    5347             : #if 0
    5348             :         // create the dtype string
    5349             :         PyObject *pDTypeString = PyUnicode_FromString("datetime64[ms]");
    5350             :         // out type description object
    5351             :         PyArray_Descr *pDescr = NULL;
    5352             :         PyArray_DescrConverter(pDTypeString, &pDescr);
    5353             :         Py_DECREF(pDTypeString);
    5354             :         CPLAssert(pDescr);
    5355             : 
    5356             :         // create array
    5357             :         numpyArray = PyArray_SimpleNewFromDescr(1, &dims, pDescr);
    5358             :         for( npy_intp j = 0; j < dims; j++ )
    5359             :         {
    5360             :             *(int64_t*)PyArray_GETPTR1((PyArrayObject *) numpyArray, j) =
    5361             :                 ((int*)arrayField->buffers[1])[j + static_cast<size_t>(arrayField->offset)];
    5362             :         }
    5363             : #else
    5364             :         // create array
    5365         185 :         numpyArray = PyArray_SimpleNew(1, &dims, NPY_OBJECT);
    5366         520 :         for( npy_intp j = 0; j < dims; j++ )
    5367             :         {
    5368         335 :             int timeMs = ((int*)arrayField->buffers[1])[j + static_cast<size_t>(arrayField->offset)];
    5369         335 :             PyObject* subObj = PyTime_FromTime((timeMs / 1000) / 3600,
    5370             :                                                ((timeMs / 1000) % 3600) / 60,
    5371             :                                                ((timeMs / 1000) % 3600) % 60,
    5372             :                                                (timeMs % 1000) * 1000);
    5373         335 :             memcpy(PyArray_GETPTR1((PyArrayObject *) numpyArray, j),
    5374             :                    &subObj,
    5375             :                    sizeof(PyObject*));
    5376             :         }
    5377             : #endif
    5378             :     }
    5379         982 :     else if( strcmp(arrowType, "ttu") == 0 &&
    5380          65 :              schemaField->n_children == 0 )
    5381             :     {
    5382             :         // Time(64) in microseconds
    5383          65 :         if( arrayField->n_buffers != 2 )
    5384             :         {
    5385           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5386             :                      "Field %s: arrayField->n_buffers != 2",
    5387           0 :                      schemaField->name);
    5388           0 :             return false;
    5389             :         }
    5390             : 
    5391             :         // create array
    5392          65 :         numpyArray = PyArray_SimpleNew(1, &dims, NPY_OBJECT);
    5393         176 :         for( npy_intp j = 0; j < dims; j++ )
    5394             :         {
    5395         111 :             const int64_t timeUs = ((int64_t*)arrayField->buffers[1])[j + static_cast<size_t>(arrayField->offset)];
    5396         111 :             PyObject* subObj = PyTime_FromTime(static_cast<int>((timeUs / 1000000) / 3600),
    5397             :                                                static_cast<int>(((timeUs / 1000000) % 3600) / 60),
    5398             :                                                static_cast<int>(((timeUs / 1000000) % 3600) % 60),
    5399             :                                                static_cast<int>(timeUs % 1000000));
    5400         111 :             memcpy(PyArray_GETPTR1((PyArrayObject *) numpyArray, j),
    5401             :                    &subObj,
    5402             :                    sizeof(PyObject*));
    5403             :         }
    5404             :     }
    5405         917 :     else if( (strncmp(arrowType, "tsm:", 4) == 0 || // DateTime in milliseconds
    5406         562 :               strncmp(arrowType, "tsu:", 4) == 0 || // DateTime in microseconds
    5407         432 :               strncmp(arrowType, "tsn:", 4) == 0) &&  // DateTime in nanoseconds
    5408         485 :              schemaField->n_children == 0 )
    5409             :     {
    5410             :         // DateTime(64)
    5411         485 :         if( arrayField->n_buffers != 2 )
    5412             :         {
    5413           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5414             :                      "Field %s: arrayField->n_buffers != 2",
    5415           0 :                      schemaField->name);
    5416           0 :             return false;
    5417             :         }
    5418             : 
    5419             :         // create the dtype string
    5420         615 :         PyObject *pDTypeString = PyUnicode_FromString(
    5421             :             strncmp(arrowType, "tsm:", 4) == 0 ? "datetime64[ms]" :
    5422         130 :             strncmp(arrowType, "tsu:", 4) == 0 ? "datetime64[us]" :
    5423             :                                                  "datetime64[ns]");
    5424             :         // out type description object
    5425         485 :         PyArray_Descr *pDescr = NULL;
    5426         485 :         PyArray_DescrConverter(pDTypeString, &pDescr);
    5427         485 :         Py_DECREF(pDTypeString);
    5428         485 :         CPLAssert(pDescr);
    5429             : 
    5430             :         // create array
    5431         970 :         numpyArray = PyArray_NewFromDescr(
    5432             :                     &PyArray_Type, pDescr, 1, &dims, NULL,
    5433         485 :                     (int64_t*)arrayField->buffers[1] + static_cast<size_t>(arrayField->offset), 0, NULL);
    5434             : 
    5435             :         /* Keep a reference to the owner object */
    5436             : #if NPY_API_VERSION >= 0x00000007
    5437         485 :         PyArray_SetBaseObject((PyArrayObject *) numpyArray, pointerArrayKeeper);
    5438             : #else
    5439             :         PyArray_BASE((PyArrayObject *) numpyArray) = pointerArrayKeeper;
    5440             : #endif
    5441         485 :         Py_INCREF(pointerArrayKeeper);
    5442             :     }
    5443         432 :     else if( strcmp(arrowType, "+s") == 0 )
    5444             :     {
    5445         585 :         for( int iField = 0; iField < arrayField->n_children; iField++ )
    5446             :         {
    5447         455 :             const struct ArrowArray* childArray = arrayField ->children[iField];
    5448         455 :             const struct ArrowSchema* childSchema = schemaField->children[iField];
    5449             : 
    5450         455 :             if( !AddNumpyArrayToDict(dict, childSchema, childArray,
    5451         910 :                                      osPrefix + schemaField->name + ".",
    5452             :                                      pointerArrayKeeper) )
    5453             :             {
    5454             :                 return false;
    5455             :             }
    5456             :         }
    5457             :     }
    5458             :     else
    5459             :     {
    5460         302 :         if( strcmp(arrowType, "+l") == 0 || strcmp(arrowType, "+L") == 0 )
    5461             :         {
    5462         260 :             CPLError(CE_Warning, CPLE_AppDefined,
    5463             :                      "Field %s: Unhandled arrow type: %s %s",
    5464           0 :                      (osPrefix + schemaField->name).c_str(),
    5465         260 :                      arrowType, schemaField->children[0]->format);
    5466             :         }
    5467             :         else
    5468             :         {
    5469          42 :             CPLError(CE_Warning, CPLE_AppDefined,
    5470             :                      "Field %s: Unhandled arrow type: %s",
    5471          42 :                      (osPrefix + schemaField->name).c_str(),
    5472             :                      arrowType);
    5473             :         }
    5474             :     }
    5475             : 
    5476        7724 :     if( numpyArray )
    5477             :     {
    5478        7292 :         const uint8_t* panNotNulls = (const uint8_t*)arrayField->buffers[0];
    5479        7292 :         if( panNotNulls && arrayField->null_count != 0 )
    5480             :         {
    5481        2950 :             PyObject* maskArray = PyArray_SimpleNew(1, &dims, NPY_BOOL);
    5482        8625 :             for( npy_intp j = 0; j < dims; j++ )
    5483             :             {
    5484        5675 :                 size_t srcOffset = static_cast<size_t>(arrayField->offset + j);
    5485             :                 // Inverse convention between arrow not-null bitmap, where
    5486             :                 // 1 means valid, and numpy masks where 1 means invalid
    5487        5675 :                 *(char*)PyArray_GETPTR1((PyArrayObject *) maskArray, j) =
    5488        5675 :                     ((panNotNulls[srcOffset / 8] & (1 << (srcOffset%8))) == 0) ? 1 : 0;
    5489             :             }
    5490        2950 :             PyObject *subdict = PyDict_New();
    5491        2950 :             PyDict_SetItemString( subdict, "mask", maskArray );
    5492        2950 :             PyDict_SetItemString( subdict, "data", numpyArray );
    5493        2950 :             PyDict_SetItemString( dict, (osPrefix + schemaField->name).c_str(), subdict);
    5494        2950 :             Py_DECREF(maskArray);
    5495        2950 :             Py_DECREF(subdict);
    5496             :         }
    5497             :         else
    5498             :         {
    5499        8684 :             PyDict_SetItemString( dict, (osPrefix + schemaField->name).c_str(), numpyArray );
    5500             :         }
    5501        7724 :         Py_DECREF(numpyArray);
    5502             :     }
    5503             : 
    5504             :     return true;
    5505             : }
    5506             : 
    5507             : /* Internal method used by ogr.Layer.GetNextRecordBatchAsNumpy() */
    5508         475 : PyObject* _RecordBatchAsNumpy(VoidPtrAsLong recordBatchPtr,
    5509             :                               VoidPtrAsLong schemaPtr,
    5510             :                               PyObject* pointerArrayKeeper)
    5511             : {
    5512         475 :     const struct ArrowSchema* schema = (const struct ArrowSchema* )schemaPtr;
    5513         475 :     const struct ArrowArray* array = (const struct ArrowArray* )recordBatchPtr;
    5514         475 :     if( strcmp(schema->format, "+s") != 0 )
    5515             :     {
    5516           0 :       CPLError(CE_Failure, CPLE_AppDefined, "schema->format != '+s'");
    5517           0 :       Py_RETURN_NONE;
    5518             :     }
    5519         475 :     if( schema->n_children != array->n_children )
    5520             :     {
    5521           0 :       CPLError(CE_Failure, CPLE_AppDefined,
    5522             :                "schema->n_children(=%d) != array->n_children(=%d)",
    5523             :                static_cast<int>(schema->n_children),
    5524             :                static_cast<int>(array->n_children));
    5525           0 :       Py_RETURN_NONE;
    5526             :     }
    5527         475 :     PyObject *dict = PyDict_New();
    5528        7744 :     for( int iField = 0; iField < array->n_children; iField++ )
    5529             :     {
    5530        7269 :         const struct ArrowArray* childArray = array->children[iField];
    5531        7269 :         const struct ArrowSchema* childSchema = schema->children[iField];
    5532             : 
    5533        7269 :         if( !AddNumpyArrayToDict(dict, childSchema, childArray, std::string(), pointerArrayKeeper) )
    5534             :         {
    5535           0 :             Py_DECREF(dict);
    5536           0 :             Py_RETURN_NONE;
    5537             :         }
    5538             :     }
    5539             :     return dict;
    5540             : }
    5541             : 
    5542             : 
    5543             : 
    5544             : SWIGINTERNINLINE PyObject*
    5545           0 :   SWIG_From_bool  (bool value)
    5546             : {
    5547           0 :   return PyBool_FromLong(value ? 1 : 0);
    5548             : }
    5549             : 
    5550             : 
    5551          28 :     void VirtualMemGetArray(CPLVirtualMemShadow* virtualmem, CPLVirtualMemShadow** pvirtualmem, int numpytypemap)
    5552             :     {
    5553          28 :         *pvirtualmem = virtualmem;
    5554          28 :     }
    5555             : 
    5556             : 
    5557             :   // need different functions for read and write
    5558             :   // since reading strings requires us to know the
    5559             :   // length of the longest string before creating array
    5560          13 :   CPLErr RATValuesIONumPyWrite( GDALRasterAttributeTableShadow* poRAT, int nField, int nStart,
    5561             :                        PyArrayObject *psArray) {
    5562             : 
    5563          13 :     if( PyArray_NDIM(psArray) != 1 )
    5564             :     {
    5565           0 :         CPLError( CE_Failure, CPLE_AppDefined,
    5566             :                   "Illegal numpy array rank %d.\n",
    5567             :                   PyArray_NDIM(psArray) );
    5568           0 :         return CE_Failure;
    5569             :     }
    5570          13 :     if( PyArray_DIM(psArray, 0) > INT_MAX )
    5571             :     {
    5572           0 :         CPLError( CE_Failure, CPLE_NotSupported,
    5573             :                   "Too big array dimension");
    5574           0 :         return CE_Failure;
    5575             :     }
    5576             : 
    5577          13 :     int nLength = static_cast<int>(PyArray_DIM(psArray, 0));
    5578          13 :     int nType = PyArray_TYPE(psArray);
    5579          13 :     CPLErr retval = CE_None;
    5580             : 
    5581          13 :     if( nType == NPY_INT32 )
    5582             :     {
    5583           4 :         retval = GDALRATValuesIOAsInteger(poRAT, GF_Write, nField, nStart, nLength,
    5584           4 :                         (int*)PyArray_DATA(psArray) );
    5585             :     }
    5586           9 :     else if( nType == NPY_DOUBLE )
    5587             :     {
    5588           4 :         retval = GDALRATValuesIOAsDouble(poRAT, GF_Write, nField, nStart, nLength,
    5589           4 :                         (double*)PyArray_DATA(psArray) );
    5590             :     }
    5591           5 :     else if( nType == NPY_STRING )
    5592             :     {
    5593             :         // max size of string
    5594           5 :         const size_t nMaxLen = PyArray_ITEMSIZE(psArray);
    5595           5 :         char *pszBuffer = (char*)VSIMalloc(nMaxLen+1);
    5596           5 :         if (!pszBuffer)
    5597             :         {
    5598           0 :             CPLError( CE_Failure, CPLE_OutOfMemory,
    5599             :                       "Out of memory in RATValuesIONumPyWrite()" );
    5600           0 :             return CE_Failure;
    5601             :         }
    5602             :         // make sure there is a null char on the end
    5603             :         // as there won't be if this string is the maximum size
    5604           5 :         pszBuffer[nMaxLen] = '\0';
    5605             : 
    5606             :         // have to convert array of strings to a char **
    5607           5 :         char **papszStringData = (char**)CPLCalloc(sizeof(char*), nLength);
    5608             : 
    5609             :         // we can't just use the memory location in the array
    5610             :         // since long strings won't be null terminated
    5611          55 :         for( int i = 0; i < nLength; i++ )
    5612             :         {
    5613          50 :             strncpy(pszBuffer, (char*)PyArray_GETPTR1(psArray, i), nMaxLen);
    5614          50 :             papszStringData[i] = CPLStrdup(pszBuffer);
    5615             :         }
    5616           5 :         CPLFree(pszBuffer);
    5617             : 
    5618           5 :         retval = GDALRATValuesIOAsString(poRAT, GF_Write, nField, nStart, nLength,
    5619             :                                             papszStringData);
    5620             : 
    5621          55 :         for( int i = 0; i < nLength; i++ )
    5622             :         {
    5623          50 :             CPLFree(papszStringData[i]);
    5624             :         }
    5625           5 :         CPLFree(papszStringData);
    5626             :     }
    5627             :     else
    5628             :     {
    5629           0 :         CPLError( CE_Failure, CPLE_AppDefined,
    5630             :                   "Illegal numpy array type %d.\n",
    5631             :                   nType );
    5632           0 :         return CE_Failure;
    5633             :     }
    5634             :     return retval;
    5635             :   }
    5636             : 
    5637             : 
    5638             :   // need different functions for read and write
    5639             :   // since reading strings requires us to know the
    5640             :   // length of the longest string before creating array
    5641          52 :   PyObject *RATValuesIONumPyRead( GDALRasterAttributeTableShadow* poRAT, int nField, int nStart,
    5642             :                        int nLength) {
    5643             : 
    5644          52 :     GDALRATFieldType colType = GDALRATGetTypeOfCol(poRAT, nField);
    5645          52 :     npy_intp dims = nLength;
    5646          52 :     PyObject *pOutArray = NULL;
    5647          52 :     if( colType == GFT_Integer )
    5648             :     {
    5649          19 :         pOutArray = PyArray_SimpleNew(1, &dims, NPY_INT32);
    5650          19 :         if( GDALRATValuesIOAsInteger(poRAT, GF_Read, nField, nStart, nLength,
    5651          19 :                         (int*)PyArray_DATA((PyArrayObject *) pOutArray)) != CE_None)
    5652             :         {
    5653           1 :             Py_DECREF(pOutArray);
    5654           1 :             Py_RETURN_NONE;
    5655             :         }
    5656             :     }
    5657          33 :     else if( colType == GFT_Real )
    5658             :     {
    5659          16 :         pOutArray = PyArray_SimpleNew(1, &dims, NPY_DOUBLE);
    5660          16 :         if( GDALRATValuesIOAsDouble(poRAT, GF_Read, nField, nStart, nLength,
    5661          16 :                         (double*)PyArray_DATA((PyArrayObject *) pOutArray)) != CE_None)
    5662             :         {
    5663           0 :             Py_DECREF(pOutArray);
    5664           0 :             Py_RETURN_NONE;
    5665             :         }
    5666             :     }
    5667          17 :     else if( colType == GFT_String )
    5668             :     {
    5669             :         // must read the data first to work out max size
    5670             :         // of strings to create array
    5671          17 :         int n;
    5672          17 :         char **papszStringList = (char**)CPLCalloc(sizeof(char*), nLength);
    5673          17 :         if( GDALRATValuesIOAsString(poRAT, GF_Read, nField, nStart, nLength, papszStringList) != CE_None )
    5674             :         {
    5675           0 :             CPLFree(papszStringList);
    5676           0 :             Py_RETURN_NONE;
    5677             :         }
    5678             :         int nMaxLen = 0, nLen;
    5679         168 :         for( n = 0; n < nLength; n++ )
    5680             :         {
    5681             :             // note strlen doesn't include null char
    5682             :             // but that is what numpy expects so all good
    5683         151 :             nLen = static_cast<int>(strlen(papszStringList[n]));
    5684         151 :             if( nLen > nMaxLen )
    5685             :                 nMaxLen = nLen;
    5686             :         }
    5687          17 :         int bZeroLength = FALSE;
    5688             :         // numpy can't deal with zero length strings
    5689          17 :         if( nMaxLen == 0 )
    5690             :         {
    5691           0 :             nMaxLen = 1;
    5692           0 :             bZeroLength = TRUE;
    5693             :         }
    5694             : 
    5695             :         // create the dtype string
    5696          17 :         PyObject *pDTypeString = PyUnicode_FromFormat("S%d", nMaxLen);
    5697             :         // out type description object
    5698          17 :         PyArray_Descr *pDescr;
    5699          17 :         PyArray_DescrConverter(pDTypeString, &pDescr);
    5700          17 :         Py_DECREF(pDTypeString);
    5701             : 
    5702             :         // create array
    5703          17 :         pOutArray = PyArray_SimpleNewFromDescr(1, &dims, pDescr);
    5704             : 
    5705             :         // copy data in
    5706          17 :         if( !bZeroLength )
    5707             :         {
    5708         168 :             for( n = 0; n < nLength; n++ )
    5709             :             {
    5710             :                 // we use strncpy so that we don't go over nMaxLen
    5711             :                 // which we would if the null char is copied
    5712             :                 // (which we don't want as numpy 'knows' to interpret the string as nMaxLen long)
    5713         151 :                 strncpy((char*)PyArray_GETPTR1((PyArrayObject *) pOutArray, n), papszStringList[n], nMaxLen);
    5714             :             }
    5715             :         }
    5716             :         else
    5717             :         {
    5718             :             // so there isn't rubbish in the 1 char strings
    5719           0 :             PyArray_FILLWBYTE((PyArrayObject *) pOutArray, 0);
    5720             :         }
    5721             : 
    5722             :         // free strings
    5723         168 :         for( n = 0; n < nLength; n++ )
    5724             :         {
    5725         151 :             CPLFree(papszStringList[n]);
    5726             :         }
    5727          17 :         CPLFree(papszStringList);
    5728             :     }
    5729             :     return pOutArray;
    5730             :   }
    5731             : 
    5732             : #ifdef __cplusplus
    5733             : extern "C" {
    5734             : #endif
    5735          28 : SWIGINTERN PyObject *_wrap_delete_VirtualMem(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    5736          28 :   PyObject *resultobj = 0;
    5737          28 :   CPLVirtualMemShadow *arg1 = (CPLVirtualMemShadow *) 0 ;
    5738          28 :   void *argp1 = 0 ;
    5739          28 :   int res1 = 0 ;
    5740          28 :   PyObject *swig_obj[1] ;
    5741             :   
    5742          28 :   if (!args) SWIG_fail;
    5743          28 :   swig_obj[0] = args;
    5744          28 :   res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_CPLVirtualMemShadow, SWIG_POINTER_DISOWN |  0 );
    5745          28 :   if (!SWIG_IsOK(res1)) {
    5746           0 :     SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_VirtualMem" "', argument " "1"" of type '" "CPLVirtualMemShadow *""'"); 
    5747             :   }
    5748          28 :   arg1 = reinterpret_cast< CPLVirtualMemShadow * >(argp1);
    5749          28 :   {
    5750          28 :     SWIG_PYTHON_THREAD_BEGIN_ALLOW;
    5751          28 :     delete_CPLVirtualMemShadow(arg1);
    5752          28 :     SWIG_PYTHON_THREAD_END_ALLOW;
    5753             :   }
    5754          28 :   resultobj = SWIG_Py_Void();
    5755          28 :   return resultobj;
    5756             : fail:
    5757             :   return NULL;
    5758             : }
    5759             : 
    5760             : 
    5761           0 : SWIGINTERN PyObject *_wrap_VirtualMem_GetAddr(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    5762           0 :   PyObject *resultobj = 0;
    5763           0 :   CPLVirtualMemShadow *arg1 = (CPLVirtualMemShadow *) 0 ;
    5764           0 :   void **arg2 = (void **) 0 ;
    5765           0 :   size_t *arg3 = (size_t *) 0 ;
    5766           0 :   GDALDataType *arg4 = (GDALDataType *) 0 ;
    5767           0 :   int *arg5 = (int *) 0 ;
    5768           0 :   void *argp1 = 0 ;
    5769           0 :   int res1 = 0 ;
    5770           0 :   void *ptr2 ;
    5771           0 :   size_t nsize2 ;
    5772           0 :   GDALDataType datatype2 ;
    5773           0 :   int readonly2 ;
    5774           0 :   PyObject *swig_obj[1] ;
    5775             :   
    5776           0 :   {
    5777             :     /* %typemap(in,numinputs=0) (void** pptr, size_t* pnsize, GDALDataType* pdatatype, int* preadonly) */
    5778           0 :     arg2 = &ptr2;
    5779           0 :     arg3 = &nsize2;
    5780           0 :     arg4 = &datatype2;
    5781           0 :     arg5 = &readonly2;
    5782             :   }
    5783           0 :   if (!args) SWIG_fail;
    5784           0 :   swig_obj[0] = args;
    5785           0 :   res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_CPLVirtualMemShadow, 0 |  0 );
    5786           0 :   if (!SWIG_IsOK(res1)) {
    5787           0 :     SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "VirtualMem_GetAddr" "', argument " "1"" of type '" "CPLVirtualMemShadow *""'"); 
    5788             :   }
    5789           0 :   arg1 = reinterpret_cast< CPLVirtualMemShadow * >(argp1);
    5790           0 :   {
    5791           0 :     SWIG_PYTHON_THREAD_BEGIN_ALLOW;
    5792           0 :     CPLVirtualMemShadow_GetAddr(arg1,arg2,arg3,arg4,arg5);
    5793           0 :     SWIG_PYTHON_THREAD_END_ALLOW;
    5794             :   }
    5795           0 :   resultobj = SWIG_Py_Void();
    5796           0 :   {
    5797             :     /* %typemap(argout) (void** pptr, size_t* pnsize, GDALDataType* pdatatype, int* preadonly)*/
    5798           0 :     Py_buffer *buf=(Py_buffer*)malloc(sizeof(Py_buffer));
    5799             :     
    5800           0 :     if (PyBuffer_FillInfo(buf, swig_obj[0], *(arg2), *(arg3), *(arg5), PyBUF_ND)) {
    5801             :       // error, handle
    5802             :     }
    5803           0 :     if( *(arg4) == GDT_Byte )
    5804             :     {
    5805           0 :       buf->format = (char*) "B";
    5806           0 :       buf->itemsize = 1;
    5807             :     }
    5808           0 :     else if( *(arg4) == GDT_Int16 )
    5809             :     {
    5810           0 :       buf->format = (char*) "h";
    5811           0 :       buf->itemsize = 2;
    5812             :     }
    5813           0 :     else if( *(arg4) == GDT_UInt16 )
    5814             :     {
    5815           0 :       buf->format = (char*) "H";
    5816           0 :       buf->itemsize = 2;
    5817             :     }
    5818           0 :     else if( *(arg4) == GDT_Int32 )
    5819             :     {
    5820           0 :       buf->format = (char*) "i";
    5821           0 :       buf->itemsize = 4;
    5822             :     }
    5823           0 :     else if( *(arg4) == GDT_UInt32 )
    5824             :     {
    5825           0 :       buf->format = (char*) "I";
    5826           0 :       buf->itemsize = 4;
    5827             :     }
    5828           0 :     else if( *(arg4) == GDT_Float16 )
    5829             :     {
    5830           0 :       buf->format = (char*) "f";
    5831           0 :       buf->itemsize = 2;
    5832             :     }
    5833           0 :     else if( *(arg4) == GDT_Float32 )
    5834             :     {
    5835           0 :       buf->format = (char*) "f";
    5836           0 :       buf->itemsize = 4;
    5837             :     }
    5838           0 :     else if( *(arg4) == GDT_Float64 )
    5839             :     {
    5840           0 :       buf->format = (char*) "F";
    5841           0 :       buf->itemsize = 8;
    5842             :     }
    5843             :     else
    5844             :     {
    5845           0 :       buf->format = (char*) "B";
    5846           0 :       buf->itemsize = 1;
    5847             :     }
    5848           0 :     Py_DECREF(resultobj);
    5849           0 :     resultobj = PyMemoryView_FromBuffer(buf);
    5850             :   }
    5851             :   return resultobj;
    5852             : fail:
    5853             :   return NULL;
    5854             : }
    5855             : 
    5856             : 
    5857             : SWIGINTERN PyObject *_wrap_VirtualMem_Pin__SWIG_0(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
    5858             :   PyObject *resultobj = 0;
    5859             :   CPLVirtualMemShadow *arg1 = (CPLVirtualMemShadow *) 0 ;
    5860             :   size_t arg2 ;
    5861             :   size_t arg3 ;
    5862             :   int arg4 ;
    5863             :   void *argp1 = 0 ;
    5864             :   int res1 = 0 ;
    5865             :   size_t val2 ;
    5866             :   int ecode2 = 0 ;
    5867             :   size_t val3 ;
    5868             :   int ecode3 = 0 ;
    5869             :   int val4 ;
    5870             :   int ecode4 = 0 ;
    5871             :   
    5872             :   if ((nobjs < 4) || (nobjs > 4)) SWIG_fail;
    5873             :   res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_CPLVirtualMemShadow, 0 |  0 );
    5874             :   if (!SWIG_IsOK(res1)) {
    5875             :     SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "VirtualMem_Pin" "', argument " "1"" of type '" "CPLVirtualMemShadow *""'"); 
    5876             :   }
    5877             :   arg1 = reinterpret_cast< CPLVirtualMemShadow * >(argp1);
    5878             :   ecode2 = SWIG_AsVal_size_t(swig_obj[1], &val2);
    5879             :   if (!SWIG_IsOK(ecode2)) {
    5880             :     SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "VirtualMem_Pin" "', argument " "2"" of type '" "size_t""'");
    5881             :   } 
    5882             :   arg2 = static_cast< size_t >(val2);
    5883             :   ecode3 = SWIG_AsVal_size_t(swig_obj[2], &val3);
    5884             :   if (!SWIG_IsOK(ecode3)) {
    5885             :     SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "VirtualMem_Pin" "', argument " "3"" of type '" "size_t""'");
    5886             :   } 
    5887             :   arg3 = static_cast< size_t >(val3);
    5888             :   ecode4 = SWIG_AsVal_int(swig_obj[3], &val4);
    5889             :   if (!SWIG_IsOK(ecode4)) {
    5890             :     SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "VirtualMem_Pin" "', argument " "4"" of type '" "int""'");
    5891             :   } 
    5892             :   arg4 = static_cast< int >(val4);
    5893             :   {
    5894             :     SWIG_PYTHON_THREAD_BEGIN_ALLOW;
    5895             :     CPLVirtualMemShadow_Pin__SWIG_0(arg1,arg2,arg3,arg4);
    5896             :     SWIG_PYTHON_THREAD_END_ALLOW;
    5897             :   }
    5898             :   resultobj = SWIG_Py_Void();
    5899             :   return resultobj;
    5900             : fail:
    5901             :   return NULL;
    5902             : }
    5903             : 
    5904             : 
    5905             : SWIGINTERN PyObject *_wrap_VirtualMem_Pin__SWIG_1(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
    5906             :   PyObject *resultobj = 0;
    5907             :   CPLVirtualMemShadow *arg1 = (CPLVirtualMemShadow *) 0 ;
    5908             :   size_t arg2 ;
    5909             :   size_t arg3 ;
    5910             :   void *argp1 = 0 ;
    5911             :   int res1 = 0 ;
    5912             :   size_t val2 ;
    5913             :   int ecode2 = 0 ;
    5914             :   size_t val3 ;
    5915             :   int ecode3 = 0 ;
    5916             :   
    5917             :   if ((nobjs < 3) || (nobjs > 3)) SWIG_fail;
    5918             :   res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_CPLVirtualMemShadow, 0 |  0 );
    5919             :   if (!SWIG_IsOK(res1)) {
    5920             :     SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "VirtualMem_Pin" "', argument " "1"" of type '" "CPLVirtualMemShadow *""'"); 
    5921             :   }
    5922             :   arg1 = reinterpret_cast< CPLVirtualMemShadow * >(argp1);
    5923             :   ecode2 = SWIG_AsVal_size_t(swig_obj[1], &val2);
    5924             :   if (!SWIG_IsOK(ecode2)) {
    5925             :     SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "VirtualMem_Pin" "', argument " "2"" of type '" "size_t""'");
    5926             :   } 
    5927             :   arg2 = static_cast< size_t >(val2);
    5928             :   ecode3 = SWIG_AsVal_size_t(swig_obj[2], &val3);
    5929             :   if (!SWIG_IsOK(ecode3)) {
    5930             :     SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "VirtualMem_Pin" "', argument " "3"" of type '" "size_t""'");
    5931             :   } 
    5932             :   arg3 = static_cast< size_t >(val3);
    5933             :   {
    5934             :     SWIG_PYTHON_THREAD_BEGIN_ALLOW;
    5935             :     CPLVirtualMemShadow_Pin__SWIG_0(arg1,arg2,arg3);
    5936             :     SWIG_PYTHON_THREAD_END_ALLOW;
    5937             :   }
    5938             :   resultobj = SWIG_Py_Void();
    5939             :   return resultobj;
    5940             : fail:
    5941             :   return NULL;
    5942             : }
    5943             : 
    5944             : 
    5945             : SWIGINTERN PyObject *_wrap_VirtualMem_Pin__SWIG_2(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
    5946             :   PyObject *resultobj = 0;
    5947             :   CPLVirtualMemShadow *arg1 = (CPLVirtualMemShadow *) 0 ;
    5948             :   size_t arg2 ;
    5949             :   void *argp1 = 0 ;
    5950             :   int res1 = 0 ;
    5951             :   size_t val2 ;
    5952             :   int ecode2 = 0 ;
    5953             :   
    5954             :   if ((nobjs < 2) || (nobjs > 2)) SWIG_fail;
    5955             :   res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_CPLVirtualMemShadow, 0 |  0 );
    5956             :   if (!SWIG_IsOK(res1)) {
    5957             :     SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "VirtualMem_Pin" "', argument " "1"" of type '" "CPLVirtualMemShadow *""'"); 
    5958             :   }
    5959             :   arg1 = reinterpret_cast< CPLVirtualMemShadow * >(argp1);
    5960             :   ecode2 = SWIG_AsVal_size_t(swig_obj[1], &val2);
    5961             :   if (!SWIG_IsOK(ecode2)) {
    5962             :     SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "VirtualMem_Pin" "', argument " "2"" of type '" "size_t""'");
    5963             :   } 
    5964             :   arg2 = static_cast< size_t >(val2);
    5965             :   {
    5966             :     SWIG_PYTHON_THREAD_BEGIN_ALLOW;
    5967             :     CPLVirtualMemShadow_Pin__SWIG_0(arg1,arg2);
    5968             :     SWIG_PYTHON_THREAD_END_ALLOW;
    5969             :   }
    5970             :   resultobj = SWIG_Py_Void();
    5971             :   return resultobj;
    5972             : fail:
    5973             :   return NULL;
    5974             : }
    5975             : 
    5976             : 
    5977             : SWIGINTERN PyObject *_wrap_VirtualMem_Pin__SWIG_3(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
    5978             :   PyObject *resultobj = 0;
    5979             :   CPLVirtualMemShadow *arg1 = (CPLVirtualMemShadow *) 0 ;
    5980             :   void *argp1 = 0 ;
    5981             :   int res1 = 0 ;
    5982             :   
    5983             :   if ((nobjs < 1) || (nobjs > 1)) SWIG_fail;
    5984             :   res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_CPLVirtualMemShadow, 0 |  0 );
    5985             :   if (!SWIG_IsOK(res1)) {
    5986             :     SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "VirtualMem_Pin" "', argument " "1"" of type '" "CPLVirtualMemShadow *""'"); 
    5987             :   }
    5988             :   arg1 = reinterpret_cast< CPLVirtualMemShadow * >(argp1);
    5989             :   {
    5990             :     SWIG_PYTHON_THREAD_BEGIN_ALLOW;
    5991             :     CPLVirtualMemShadow_Pin__SWIG_0(arg1);
    5992             :     SWIG_PYTHON_THREAD_END_ALLOW;
    5993             :   }
    5994             :   resultobj = SWIG_Py_Void();
    5995             :   return resultobj;
    5996             : fail:
    5997             :   return NULL;
    5998             : }
    5999             : 
    6000             : 
    6001           0 : SWIGINTERN PyObject *_wrap_VirtualMem_Pin(PyObject *self, PyObject *args) {
    6002           0 :   Py_ssize_t argc;
    6003           0 :   PyObject *argv[5] = {
    6004             :     0
    6005             :   };
    6006             :   
    6007           0 :   if (!(argc = SWIG_Python_UnpackTuple(args, "VirtualMem_Pin", 0, 4, argv))) SWIG_fail;
    6008           0 :   --argc;
    6009           0 :   if (argc == 1) {
    6010           0 :     int _v;
    6011           0 :     void *vptr = 0;
    6012           0 :     int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_CPLVirtualMemShadow, 0);
    6013           0 :     _v = SWIG_CheckState(res);
    6014           0 :     if (_v) {
    6015           0 :       return _wrap_VirtualMem_Pin__SWIG_3(self, argc, argv);
    6016             :     }
    6017             :   }
    6018           0 :   if (argc == 2) {
    6019           0 :     int _v;
    6020           0 :     void *vptr = 0;
    6021           0 :     int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_CPLVirtualMemShadow, 0);
    6022           0 :     _v = SWIG_CheckState(res);
    6023           0 :     if (_v) {
    6024           0 :       {
    6025           0 :         int res = SWIG_AsVal_size_t(argv[1], NULL);
    6026           0 :         _v = SWIG_CheckState(res);
    6027             :       }
    6028           0 :       if (_v) {
    6029           0 :         return _wrap_VirtualMem_Pin__SWIG_2(self, argc, argv);
    6030             :       }
    6031             :     }
    6032             :   }
    6033           0 :   if (argc == 3) {
    6034           0 :     int _v;
    6035           0 :     void *vptr = 0;
    6036           0 :     int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_CPLVirtualMemShadow, 0);
    6037           0 :     _v = SWIG_CheckState(res);
    6038           0 :     if (_v) {
    6039           0 :       {
    6040           0 :         int res = SWIG_AsVal_size_t(argv[1], NULL);
    6041           0 :         _v = SWIG_CheckState(res);
    6042             :       }
    6043           0 :       if (_v) {
    6044           0 :         {
    6045           0 :           int res = SWIG_AsVal_size_t(argv[2], NULL);
    6046           0 :           _v = SWIG_CheckState(res);
    6047             :         }
    6048           0 :         if (_v) {
    6049           0 :           return _wrap_VirtualMem_Pin__SWIG_1(self, argc, argv);
    6050             :         }
    6051             :       }
    6052             :     }
    6053             :   }
    6054           0 :   if (argc == 4) {
    6055           0 :     int _v;
    6056           0 :     void *vptr = 0;
    6057           0 :     int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_CPLVirtualMemShadow, 0);
    6058           0 :     _v = SWIG_CheckState(res);
    6059           0 :     if (_v) {
    6060           0 :       {
    6061           0 :         int res = SWIG_AsVal_size_t(argv[1], NULL);
    6062           0 :         _v = SWIG_CheckState(res);
    6063             :       }
    6064           0 :       if (_v) {
    6065           0 :         {
    6066           0 :           int res = SWIG_AsVal_size_t(argv[2], NULL);
    6067           0 :           _v = SWIG_CheckState(res);
    6068             :         }
    6069           0 :         if (_v) {
    6070           0 :           {
    6071           0 :             int res = SWIG_AsVal_int(argv[3], NULL);
    6072           0 :             _v = SWIG_CheckState(res);
    6073             :           }
    6074           0 :           if (_v) {
    6075           0 :             return _wrap_VirtualMem_Pin__SWIG_0(self, argc, argv);
    6076             :           }
    6077             :         }
    6078             :       }
    6079             :     }
    6080             :   }
    6081             :   
    6082           0 : fail:
    6083           0 :   SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'VirtualMem_Pin'.\n"
    6084             :     "  Possible C/C++ prototypes are:\n"
    6085             :     "    CPLVirtualMemShadow::Pin(size_t,size_t,int)\n"
    6086             :     "    CPLVirtualMemShadow::Pin(size_t,size_t)\n"
    6087             :     "    CPLVirtualMemShadow::Pin(size_t)\n"
    6088             :     "    CPLVirtualMemShadow::Pin()\n");
    6089             :   return 0;
    6090             : }
    6091             : 
    6092             : 
    6093         225 : SWIGINTERN PyObject *VirtualMem_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    6094         225 :   PyObject *obj;
    6095         225 :   if (!SWIG_Python_UnpackTuple(args, "swigregister", 1, 1, &obj)) return NULL;
    6096         225 :   SWIG_TypeNewClientData(SWIGTYPE_p_CPLVirtualMemShadow, SWIG_NewClientData(obj));
    6097         225 :   return SWIG_Py_Void();
    6098             : }
    6099             : 
    6100           0 : SWIGINTERN PyObject *_wrap_GetUseExceptions(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    6101           0 :   PyObject *resultobj = 0;
    6102           0 :   int result;
    6103             :   
    6104           0 :   if (!SWIG_Python_UnpackTuple(args, "GetUseExceptions", 0, 0, 0)) SWIG_fail;
    6105           0 :   {
    6106             : #ifdef SED_HACKS
    6107             :     if( ReturnSame(TRUE) ) bLocalUseExceptionsCode = FALSE;
    6108             : #endif
    6109           0 :     result = GetUseExceptions();
    6110             :   }
    6111           0 :   resultobj = SWIG_From_int(static_cast< int >(result));
    6112           0 :   return resultobj;
    6113           0 : fail:
    6114           0 :   return NULL;
    6115             : }
    6116             : 
    6117             : 
    6118           0 : SWIGINTERN PyObject *_wrap__GetExceptionsLocal(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    6119           0 :   PyObject *resultobj = 0;
    6120           0 :   int result;
    6121             :   
    6122           0 :   if (!SWIG_Python_UnpackTuple(args, "_GetExceptionsLocal", 0, 0, 0)) SWIG_fail;
    6123           0 :   {
    6124             : #ifdef SED_HACKS
    6125             :     if( ReturnSame(TRUE) ) bLocalUseExceptionsCode = FALSE;
    6126             : #endif
    6127           0 :     {
    6128           0 :       SWIG_PYTHON_THREAD_BEGIN_ALLOW;
    6129           0 :       result = (int)_GetExceptionsLocal();
    6130           0 :       SWIG_PYTHON_THREAD_END_ALLOW;
    6131             :     }
    6132             :   }
    6133           0 :   resultobj = SWIG_From_int(static_cast< int >(result));
    6134           0 :   return resultobj;
    6135           0 : fail:
    6136           0 :   return NULL;
    6137             : }
    6138             : 
    6139             : 
    6140       22780 : SWIGINTERN PyObject *_wrap__SetExceptionsLocal(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    6141       22780 :   PyObject *resultobj = 0;
    6142       22780 :   int arg1 ;
    6143       22780 :   int val1 ;
    6144       22780 :   int ecode1 = 0 ;
    6145       22780 :   PyObject *swig_obj[1] ;
    6146             :   
    6147       22780 :   if (!args) SWIG_fail;
    6148       22780 :   swig_obj[0] = args;
    6149       22780 :   ecode1 = SWIG_AsVal_int(swig_obj[0], &val1);
    6150       22780 :   if (!SWIG_IsOK(ecode1)) {
    6151           0 :     SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "_SetExceptionsLocal" "', argument " "1"" of type '" "int""'");
    6152             :   } 
    6153       22780 :   arg1 = static_cast< int >(val1);
    6154       22780 :   {
    6155             : #ifdef SED_HACKS
    6156             :     if( ReturnSame(TRUE) ) bLocalUseExceptionsCode = FALSE;
    6157             : #endif
    6158       22780 :     {
    6159       22780 :       SWIG_PYTHON_THREAD_BEGIN_ALLOW;
    6160       22780 :       _SetExceptionsLocal(arg1);
    6161       22780 :       SWIG_PYTHON_THREAD_END_ALLOW;
    6162             :     }
    6163             :   }
    6164       22780 :   resultobj = SWIG_Py_Void();
    6165       22780 :   return resultobj;
    6166             : fail:
    6167             :   return NULL;
    6168             : }
    6169             : 
    6170             : 
    6171          29 : SWIGINTERN PyObject *_wrap__UseExceptions(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    6172          29 :   PyObject *resultobj = 0;
    6173             :   
    6174          29 :   if (!SWIG_Python_UnpackTuple(args, "_UseExceptions", 0, 0, 0)) SWIG_fail;
    6175          29 :   {
    6176          29 :     SWIG_PYTHON_THREAD_BEGIN_ALLOW;
    6177          29 :     _UseExceptions();
    6178          29 :     SWIG_PYTHON_THREAD_END_ALLOW;
    6179             :   }
    6180          29 :   resultobj = SWIG_Py_Void();
    6181          29 :   return resultobj;
    6182           0 : fail:
    6183           0 :   return NULL;
    6184             : }
    6185             : 
    6186             : 
    6187           5 : SWIGINTERN PyObject *_wrap__DontUseExceptions(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    6188           5 :   PyObject *resultobj = 0;
    6189             :   
    6190           5 :   if (!SWIG_Python_UnpackTuple(args, "_DontUseExceptions", 0, 0, 0)) SWIG_fail;
    6191           5 :   {
    6192           5 :     SWIG_PYTHON_THREAD_BEGIN_ALLOW;
    6193           5 :     _DontUseExceptions();
    6194           5 :     SWIG_PYTHON_THREAD_END_ALLOW;
    6195             :   }
    6196           5 :   resultobj = SWIG_Py_Void();
    6197           5 :   return resultobj;
    6198           0 : fail:
    6199           0 :   return NULL;
    6200             : }
    6201             : 
    6202             : 
    6203           0 : SWIGINTERN PyObject *_wrap__UserHasSpecifiedIfUsingExceptions(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    6204           0 :   PyObject *resultobj = 0;
    6205           0 :   int result;
    6206             :   
    6207           0 :   if (!SWIG_Python_UnpackTuple(args, "_UserHasSpecifiedIfUsingExceptions", 0, 0, 0)) SWIG_fail;
    6208           0 :   {
    6209             : #ifdef SED_HACKS
    6210             :     if( ReturnSame(TRUE) ) bLocalUseExceptionsCode = FALSE;
    6211             : #endif
    6212           0 :     {
    6213           0 :       SWIG_PYTHON_THREAD_BEGIN_ALLOW;
    6214           0 :       result = (int)_UserHasSpecifiedIfUsingExceptions();
    6215           0 :       SWIG_PYTHON_THREAD_END_ALLOW;
    6216             :     }
    6217             :   }
    6218           0 :   resultobj = SWIG_From_int(static_cast< int >(result));
    6219           0 :   return resultobj;
    6220           0 : fail:
    6221           0 :   return NULL;
    6222             : }
    6223             : 
    6224             : 
    6225           0 : SWIGINTERN PyObject *_wrap_TermProgress_nocb(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
    6226           0 :   PyObject *resultobj = 0;
    6227           0 :   double arg1 ;
    6228           0 :   char *arg2 = (char *) NULL ;
    6229           0 :   void *arg3 = (void *) NULL ;
    6230           0 :   double val1 ;
    6231           0 :   int ecode1 = 0 ;
    6232           0 :   int res2 ;
    6233           0 :   char *buf2 = 0 ;
    6234           0 :   int alloc2 = 0 ;
    6235           0 :   int res3 ;
    6236           0 :   PyObject * obj0 = 0 ;
    6237           0 :   PyObject * obj1 = 0 ;
    6238           0 :   PyObject * obj2 = 0 ;
    6239           0 :   char * kwnames[] = {
    6240             :     (char *)"dfProgress",  (char *)"pszMessage",  (char *)"pData",  NULL 
    6241             :   };
    6242           0 :   int result;
    6243             :   
    6244           0 :   if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|OO:TermProgress_nocb", kwnames, &obj0, &obj1, &obj2)) SWIG_fail;
    6245           0 :   ecode1 = SWIG_AsVal_double(obj0, &val1);
    6246           0 :   if (!SWIG_IsOK(ecode1)) {
    6247           0 :     SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "TermProgress_nocb" "', argument " "1"" of type '" "double""'");
    6248             :   } 
    6249           0 :   arg1 = static_cast< double >(val1);
    6250           0 :   if (obj1) {
    6251           0 :     res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2);
    6252           0 :     if (!SWIG_IsOK(res2)) {
    6253           0 :       SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "TermProgress_nocb" "', argument " "2"" of type '" "char const *""'");
    6254             :     }
    6255           0 :     arg2 = reinterpret_cast< char * >(buf2);
    6256             :   }
    6257           0 :   if (obj2) {
    6258           0 :     res3 = SWIG_ConvertPtr(obj2,SWIG_as_voidptrptr(&arg3), 0, 0);
    6259           0 :     if (!SWIG_IsOK(res3)) {
    6260           0 :       SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "TermProgress_nocb" "', argument " "3"" of type '" "void *""'"); 
    6261             :     }
    6262             :   }
    6263           0 :   {
    6264           0 :     const int bLocalUseExceptions = GetUseExceptions();
    6265           0 :     if ( bLocalUseExceptions ) {
    6266           0 :       pushErrorHandler();
    6267             :     }
    6268           0 :     result = (int)GDALTermProgress_nocb(arg1,(char const *)arg2,arg3);
    6269           0 :     if ( bLocalUseExceptions ) {
    6270           0 :       popErrorHandler();
    6271             :     }
    6272             : #ifndef SED_HACKS
    6273           0 :     if ( bLocalUseExceptions ) {
    6274           0 :       CPLErr eclass = CPLGetLastErrorType();
    6275           0 :       if ( eclass == CE_Failure || eclass == CE_Fatal ) {
    6276           0 :         SWIG_exception( SWIG_RuntimeError, CPLGetLastErrorMsg() );
    6277             :       }
    6278             :     }
    6279             : #endif
    6280             :   }
    6281           0 :   resultobj = SWIG_From_int(static_cast< int >(result));
    6282           0 :   if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
    6283             :   return resultobj;
    6284           0 : fail:
    6285           0 :   if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
    6286             :   return NULL;
    6287             : }
    6288             : 
    6289             : 
    6290          30 : SWIGINTERN PyObject *_wrap_OpenNumPyArray(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    6291          30 :   PyObject *resultobj = 0;
    6292          30 :   PyArrayObject *arg1 = (PyArrayObject *) 0 ;
    6293          30 :   bool arg2 ;
    6294          30 :   bool val2 ;
    6295          30 :   int ecode2 = 0 ;
    6296          30 :   PyObject *swig_obj[2] ;
    6297          30 :   GDALDatasetShadow *result = 0 ;
    6298             :   
    6299          30 :   if (!SWIG_Python_UnpackTuple(args, "OpenNumPyArray", 2, 2, swig_obj)) SWIG_fail;
    6300          30 :   {
    6301             :     /* %typemap(in,numinputs=1) (PyArrayObject  *psArray) */
    6302          30 :     if (swig_obj[0] != NULL && PyArray_Check(swig_obj[0]))
    6303             :     {
    6304          30 :       arg1 = (PyArrayObject*)(swig_obj[0]);
    6305             :     }
    6306             :     else
    6307             :     {
    6308           0 :       PyErr_SetString(PyExc_TypeError, "not a numpy array");
    6309           0 :       SWIG_fail;
    6310             :     }
    6311             :   }
    6312          30 :   ecode2 = SWIG_AsVal_bool(swig_obj[1], &val2);
    6313          30 :   if (!SWIG_IsOK(ecode2)) {
    6314           0 :     SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "OpenNumPyArray" "', argument " "2"" of type '" "bool""'");
    6315             :   } 
    6316          30 :   arg2 = static_cast< bool >(val2);
    6317          30 :   {
    6318          30 :     const int bLocalUseExceptions = GetUseExceptions();
    6319          30 :     if ( bLocalUseExceptions ) {
    6320           4 :       pushErrorHandler();
    6321             :     }
    6322          30 :     result = (GDALDatasetShadow *)OpenNumPyArray(arg1,arg2);
    6323          30 :     if ( bLocalUseExceptions ) {
    6324           4 :       popErrorHandler();
    6325             :     }
    6326             : #ifndef SED_HACKS
    6327          30 :     if( result == NULL && bLocalUseExceptions ) {
    6328           1 :       CPLErr eclass = CPLGetLastErrorType();
    6329           1 :       if ( eclass == CE_Failure || eclass == CE_Fatal ) {
    6330           1 :         SWIG_exception( SWIG_RuntimeError, CPLGetLastErrorMsg() );
    6331             :       }
    6332             :     }
    6333             : #endif
    6334          29 :     if( result != NULL && bLocalUseExceptions ) {
    6335             : #ifdef SED_HACKS
    6336             :       bLocalUseExceptionsCode = FALSE;
    6337             : #endif
    6338             :     }
    6339             :   }
    6340          29 :   resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_GDALDatasetShadow, SWIG_POINTER_OWN |  0 );
    6341             :   return resultobj;
    6342             : fail:
    6343             :   return NULL;
    6344             : }
    6345             : 
    6346             : 
    6347          21 : SWIGINTERN PyObject *_wrap_OpenMultiDimensionalNumPyArray(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    6348          21 :   PyObject *resultobj = 0;
    6349          21 :   PyArrayObject *arg1 = (PyArrayObject *) 0 ;
    6350          21 :   PyObject *swig_obj[1] ;
    6351          21 :   GDALDatasetShadow *result = 0 ;
    6352             :   
    6353          21 :   if (!args) SWIG_fail;
    6354          21 :   swig_obj[0] = args;
    6355          21 :   {
    6356             :     /* %typemap(in,numinputs=1) (PyArrayObject  *psArray) */
    6357          21 :     if (swig_obj[0] != NULL && PyArray_Check(swig_obj[0]))
    6358             :     {
    6359          21 :       arg1 = (PyArrayObject*)(swig_obj[0]);
    6360             :     }
    6361             :     else
    6362             :     {
    6363           0 :       PyErr_SetString(PyExc_TypeError, "not a numpy array");
    6364           0 :       SWIG_fail;
    6365             :     }
    6366             :   }
    6367          21 :   {
    6368          21 :     const int bLocalUseExceptions = GetUseExceptions();
    6369          21 :     if ( bLocalUseExceptions ) {
    6370          21 :       pushErrorHandler();
    6371             :     }
    6372          21 :     result = (GDALDatasetShadow *)OpenMultiDimensionalNumPyArray(arg1);
    6373          21 :     if ( bLocalUseExceptions ) {
    6374          21 :       popErrorHandler();
    6375             :     }
    6376             : #ifndef SED_HACKS
    6377          21 :     if( result == NULL && bLocalUseExceptions ) {
    6378           1 :       CPLErr eclass = CPLGetLastErrorType();
    6379           1 :       if ( eclass == CE_Failure || eclass == CE_Fatal ) {
    6380           1 :         SWIG_exception( SWIG_RuntimeError, CPLGetLastErrorMsg() );
    6381             :       }
    6382             :     }
    6383             : #endif
    6384          20 :     if( result != NULL && bLocalUseExceptions ) {
    6385             : #ifdef SED_HACKS
    6386             :       bLocalUseExceptionsCode = FALSE;
    6387             : #endif
    6388             :     }
    6389             :   }
    6390          20 :   resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_GDALDatasetShadow, SWIG_POINTER_OWN |  0 );
    6391             :   return resultobj;
    6392             : fail:
    6393             :   return NULL;
    6394             : }
    6395             : 
    6396             : 
    6397           2 : SWIGINTERN PyObject *_wrap_GetArrayFilename(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    6398           2 :   PyObject *resultobj = 0;
    6399           2 :   PyArrayObject *arg1 = (PyArrayObject *) 0 ;
    6400           2 :   PyObject *swig_obj[1] ;
    6401           2 :   retStringAndCPLFree *result = 0 ;
    6402             :   
    6403           2 :   if (!args) SWIG_fail;
    6404           2 :   swig_obj[0] = args;
    6405           2 :   {
    6406             :     /* %typemap(in,numinputs=1) (PyArrayObject  *psArray) */
    6407           2 :     if (swig_obj[0] != NULL && PyArray_Check(swig_obj[0]))
    6408             :     {
    6409           2 :       arg1 = (PyArrayObject*)(swig_obj[0]);
    6410             :     }
    6411             :     else
    6412             :     {
    6413           0 :       PyErr_SetString(PyExc_TypeError, "not a numpy array");
    6414           0 :       SWIG_fail;
    6415             :     }
    6416             :   }
    6417           2 :   {
    6418           2 :     const int bLocalUseExceptions = GetUseExceptions();
    6419           2 :     if ( bLocalUseExceptions ) {
    6420           0 :       pushErrorHandler();
    6421             :     }
    6422           2 :     result = (retStringAndCPLFree *)GetArrayFilename(arg1);
    6423           2 :     if ( bLocalUseExceptions ) {
    6424           0 :       popErrorHandler();
    6425             :     }
    6426             : #ifndef SED_HACKS
    6427           2 :     if ( bLocalUseExceptions ) {
    6428           0 :       CPLErr eclass = CPLGetLastErrorType();
    6429           0 :       if ( eclass == CE_Failure || eclass == CE_Fatal ) {
    6430           0 :         SWIG_exception( SWIG_RuntimeError, CPLGetLastErrorMsg() );
    6431             :       }
    6432             :     }
    6433             : #endif
    6434             :   }
    6435           2 :   {
    6436             :     /* %typemap(out) (retStringAndCPLFree*) */
    6437           2 :     Py_XDECREF(resultobj);
    6438           2 :     if(result)
    6439             :     {
    6440           2 :       resultobj = GDALPythonObjectFromCStr( (const char *)result);
    6441           2 :       CPLFree(result);
    6442             :     }
    6443             :     else
    6444             :     {
    6445           0 :       resultobj = Py_None;
    6446           0 :       Py_INCREF(resultobj);
    6447             :     }
    6448             :   }
    6449             :   return resultobj;
    6450             : fail:
    6451             :   return NULL;
    6452             : }
    6453             : 
    6454             : 
    6455       19260 : SWIGINTERN PyObject *_wrap_BandRasterIONumPy(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
    6456       19260 :   PyObject *resultobj = 0;
    6457       19260 :   GDALRasterBandShadow *arg1 = (GDALRasterBandShadow *) 0 ;
    6458       19260 :   int arg2 ;
    6459       19260 :   double arg3 ;
    6460       19260 :   double arg4 ;
    6461       19260 :   double arg5 ;
    6462       19260 :   double arg6 ;
    6463       19260 :   PyArrayObject *arg7 = (PyArrayObject *) 0 ;
    6464       19260 :   GDALDataType arg8 ;
    6465       19260 :   GDALRIOResampleAlg arg9 ;
    6466       19260 :   GDALProgressFunc arg10 = (GDALProgressFunc) NULL ;
    6467       19260 :   void *arg11 = (void *) NULL ;
    6468       19260 :   void *argp1 = 0 ;
    6469       19260 :   int res1 = 0 ;
    6470       19260 :   int val2 ;
    6471       19260 :   int ecode2 = 0 ;
    6472       19260 :   double val3 ;
    6473       19260 :   int ecode3 = 0 ;
    6474       19260 :   double val4 ;
    6475       19260 :   int ecode4 = 0 ;
    6476       19260 :   double val5 ;
    6477       19260 :   int ecode5 = 0 ;
    6478       19260 :   double val6 ;
    6479       19260 :   int ecode6 = 0 ;
    6480       19260 :   PyObject * obj0 = 0 ;
    6481       19260 :   PyObject * obj1 = 0 ;
    6482       19260 :   PyObject * obj2 = 0 ;
    6483       19260 :   PyObject * obj3 = 0 ;
    6484       19260 :   PyObject * obj4 = 0 ;
    6485       19260 :   PyObject * obj5 = 0 ;
    6486       19260 :   PyObject * obj6 = 0 ;
    6487       19260 :   PyObject * obj7 = 0 ;
    6488       19260 :   PyObject * obj8 = 0 ;
    6489       19260 :   PyObject * obj9 = 0 ;
    6490       19260 :   PyObject * obj10 = 0 ;
    6491       19260 :   char * kwnames[] = {
    6492             :     (char *)"band",  (char *)"bWrite",  (char *)"xoff",  (char *)"yoff",  (char *)"xsize",  (char *)"ysize",  (char *)"psArray",  (char *)"buf_type",  (char *)"resample_alg",  (char *)"callback",  (char *)"callback_data",  NULL 
    6493             :   };
    6494       19260 :   CPLErr result;
    6495             :   
    6496             :   /* %typemap(arginit) ( const char* callback_data=NULL)  */
    6497       19260 :   PyProgressData *psProgressInfo;
    6498       19260 :   psProgressInfo = (PyProgressData *) CPLCalloc(1,sizeof(PyProgressData));
    6499       19260 :   psProgressInfo->nLastReported = -1;
    6500       19260 :   psProgressInfo->psPyCallback = NULL;
    6501       19260 :   psProgressInfo->psPyCallbackData = NULL;
    6502       19260 :   arg11 = psProgressInfo;
    6503       19260 :   if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOOOOOOOO|OO:BandRasterIONumPy", kwnames, &obj0, &obj1, &obj2, &obj3, &obj4, &obj5, &obj6, &obj7, &obj8, &obj9, &obj10)) SWIG_fail;
    6504       19260 :   res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_GDALRasterBandShadow, 0 |  0 );
    6505       19260 :   if (!SWIG_IsOK(res1)) {
    6506           0 :     SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "BandRasterIONumPy" "', argument " "1"" of type '" "GDALRasterBandShadow *""'"); 
    6507             :   }
    6508       19260 :   arg1 = reinterpret_cast< GDALRasterBandShadow * >(argp1);
    6509       19260 :   ecode2 = SWIG_AsVal_int(obj1, &val2);
    6510       19260 :   if (!SWIG_IsOK(ecode2)) {
    6511           0 :     SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "BandRasterIONumPy" "', argument " "2"" of type '" "int""'");
    6512             :   } 
    6513       19260 :   arg2 = static_cast< int >(val2);
    6514       19260 :   ecode3 = SWIG_AsVal_double(obj2, &val3);
    6515       19260 :   if (!SWIG_IsOK(ecode3)) {
    6516           0 :     SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "BandRasterIONumPy" "', argument " "3"" of type '" "double""'");
    6517             :   } 
    6518       19260 :   arg3 = static_cast< double >(val3);
    6519       19260 :   ecode4 = SWIG_AsVal_double(obj3, &val4);
    6520       19260 :   if (!SWIG_IsOK(ecode4)) {
    6521           0 :     SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "BandRasterIONumPy" "', argument " "4"" of type '" "double""'");
    6522             :   } 
    6523       19260 :   arg4 = static_cast< double >(val4);
    6524       19260 :   ecode5 = SWIG_AsVal_double(obj4, &val5);
    6525       19260 :   if (!SWIG_IsOK(ecode5)) {
    6526           0 :     SWIG_exception_fail(SWIG_ArgError(ecode5), "in method '" "BandRasterIONumPy" "', argument " "5"" of type '" "double""'");
    6527             :   } 
    6528       19260 :   arg5 = static_cast< double >(val5);
    6529       19260 :   ecode6 = SWIG_AsVal_double(obj5, &val6);
    6530       19260 :   if (!SWIG_IsOK(ecode6)) {
    6531           0 :     SWIG_exception_fail(SWIG_ArgError(ecode6), "in method '" "BandRasterIONumPy" "', argument " "6"" of type '" "double""'");
    6532             :   } 
    6533       19260 :   arg6 = static_cast< double >(val6);
    6534       19260 :   {
    6535             :     /* %typemap(in,numinputs=1) (PyArrayObject  *psArray) */
    6536       19260 :     if (obj6 != NULL && PyArray_Check(obj6))
    6537             :     {
    6538       19260 :       arg7 = (PyArrayObject*)(obj6);
    6539             :     }
    6540             :     else
    6541             :     {
    6542           0 :       PyErr_SetString(PyExc_TypeError, "not a numpy array");
    6543           0 :       SWIG_fail;
    6544             :     }
    6545             :   }
    6546       19260 :   {
    6547             :     // %typemap(in) GDALDataType
    6548       19260 :     int val = 0;
    6549       19260 :     int ecode = SWIG_AsVal_int(obj7, &val);
    6550       19260 :     if (!SWIG_IsOK(ecode)) {
    6551           0 :       SWIG_exception_fail(SWIG_ArgError(ecode), "invalid value for GDALDataType");
    6552             :     }
    6553       19260 :     if( val < GDT_Unknown || val >= GDT_TypeCount )
    6554             :     {
    6555           0 :       SWIG_exception_fail(SWIG_ValueError, "Invalid value for GDALDataType");
    6556             :     }
    6557       19260 :     arg8 = static_cast<GDALDataType>(val);
    6558             :   }
    6559       19260 :   {
    6560             :     // %typemap(in) GDALRIOResampleAlg
    6561       19260 :     int val = 0;
    6562       19260 :     int ecode = SWIG_AsVal_int(obj8, &val);
    6563       19260 :     if (!SWIG_IsOK(ecode)) {
    6564           2 :       SWIG_exception_fail(SWIG_ArgError(ecode), "invalid value for GDALRIOResampleAlg");
    6565             :     }
    6566       19258 :     if( val < 0 ||
    6567       19256 :       ( val >= static_cast<int>(GRIORA_RESERVED_START) &&
    6568       19254 :         val <= static_cast<int>(GRIORA_RESERVED_END) ) ||
    6569             :       val > static_cast<int>(GRIORA_LAST) )
    6570             :     {
    6571           4 :       SWIG_exception_fail(SWIG_ValueError, "Invalid value for resample_alg");
    6572             :     }
    6573       19254 :     arg9 = static_cast< GDALRIOResampleAlg >(val);
    6574             :   }
    6575       19254 :   if (obj9) {
    6576       19254 :     {
    6577             :       /* %typemap(in) (GDALProgressFunc callback = NULL) */
    6578             :       /* callback_func typemap */
    6579             :       
    6580             :       /* In some cases 0 is passed instead of None. */
    6581             :       /* See https://github.com/OSGeo/gdal/pull/219 */
    6582       19254 :       if ( PyLong_Check(obj9) || PyInt_Check(obj9) )
    6583             :       {
    6584           0 :         if( PyLong_AsLong(obj9) == 0 )
    6585             :         {
    6586           0 :           obj9 = Py_None;
    6587             :         }
    6588             :       }
    6589             :       
    6590       19254 :       if (obj9 && obj9 != Py_None ) {
    6591           4 :         void* cbfunction = NULL;
    6592           4 :         CPL_IGNORE_RET_VAL(SWIG_ConvertPtr( obj9,
    6593             :             (void**)&cbfunction,
    6594             :             SWIGTYPE_p_f_double_p_q_const__char_p_void__int,
    6595             :             SWIG_POINTER_EXCEPTION | 0 ));
    6596             :         
    6597           4 :         if ( cbfunction == GDALTermProgress ) {
    6598             :           arg10 = GDALTermProgress;
    6599             :         } else {
    6600           4 :           if (!PyCallable_Check(obj9)) {
    6601           0 :             PyErr_SetString( PyExc_RuntimeError,
    6602             :               "Object given is not a Python function" );
    6603           0 :             SWIG_fail;
    6604             :           }
    6605           4 :           psProgressInfo->psPyCallback = obj9;
    6606           4 :           arg10 = PyProgressProxy;
    6607             :         }
    6608             :         
    6609             :       }
    6610             :       
    6611             :     }
    6612             :   }
    6613       19254 :   if (obj10) {
    6614       19254 :     {
    6615             :       /* %typemap(in) ( void* callback_data=NULL)  */
    6616       19254 :       psProgressInfo->psPyCallbackData = obj10 ;
    6617             :     }
    6618             :   }
    6619       19254 :   {
    6620       19254 :     const int bLocalUseExceptions = GetUseExceptions();
    6621       19254 :     if ( bLocalUseExceptions ) {
    6622       16285 :       pushErrorHandler();
    6623             :     }
    6624       19254 :     {
    6625       19254 :       SWIG_PYTHON_THREAD_BEGIN_ALLOW;
    6626       19254 :       result = (CPLErr)BandRasterIONumPy(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11);
    6627       19254 :       SWIG_PYTHON_THREAD_END_ALLOW;
    6628             :     }
    6629       19254 :     if ( bLocalUseExceptions ) {
    6630       16285 :       popErrorHandler();
    6631             :     }
    6632             : #ifndef SED_HACKS
    6633       19254 :     if ( bLocalUseExceptions ) {
    6634       16285 :       CPLErr eclass = CPLGetLastErrorType();
    6635       16285 :       if ( eclass == CE_Failure || eclass == CE_Fatal ) {
    6636          19 :         SWIG_exception( SWIG_RuntimeError, CPLGetLastErrorMsg() );
    6637             :       }
    6638             :     }
    6639             : #endif
    6640             :   }
    6641       19235 :   resultobj = SWIG_From_int(static_cast< int >(result));
    6642       19235 :   {
    6643             :     /* %typemap(freearg) ( void* callback_data=NULL)  */
    6644             :     
    6645       19235 :     CPLFree(psProgressInfo);
    6646             :     
    6647             :   }
    6648             :   return resultobj;
    6649          25 : fail:
    6650          25 :   {
    6651             :     /* %typemap(freearg) ( void* callback_data=NULL)  */
    6652             :     
    6653          25 :     CPLFree(psProgressInfo);
    6654             :     
    6655             :   }
    6656             :   return NULL;
    6657             : }
    6658             : 
    6659             : 
    6660         105 : SWIGINTERN PyObject *_wrap_DatasetIONumPy(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
    6661         105 :   PyObject *resultobj = 0;
    6662         105 :   GDALDatasetShadow *arg1 = (GDALDatasetShadow *) 0 ;
    6663         105 :   int arg2 ;
    6664         105 :   double arg3 ;
    6665         105 :   double arg4 ;
    6666         105 :   double arg5 ;
    6667         105 :   double arg6 ;
    6668         105 :   PyArrayObject *arg7 = (PyArrayObject *) 0 ;
    6669         105 :   GDALDataType arg8 ;
    6670         105 :   GDALRIOResampleAlg arg9 ;
    6671         105 :   GDALProgressFunc arg10 = (GDALProgressFunc) NULL ;
    6672         105 :   void *arg11 = (void *) NULL ;
    6673         105 :   bool arg12 = (bool) true ;
    6674         105 :   int arg13 = (int) 0 ;
    6675         105 :   int *arg14 = (int *) 0 ;
    6676         105 :   void *argp1 = 0 ;
    6677         105 :   int res1 = 0 ;
    6678         105 :   int val2 ;
    6679         105 :   int ecode2 = 0 ;
    6680         105 :   double val3 ;
    6681         105 :   int ecode3 = 0 ;
    6682         105 :   double val4 ;
    6683         105 :   int ecode4 = 0 ;
    6684         105 :   double val5 ;
    6685         105 :   int ecode5 = 0 ;
    6686         105 :   double val6 ;
    6687         105 :   int ecode6 = 0 ;
    6688         105 :   bool val12 ;
    6689         105 :   int ecode12 = 0 ;
    6690         105 :   PyObject * obj0 = 0 ;
    6691         105 :   PyObject * obj1 = 0 ;
    6692         105 :   PyObject * obj2 = 0 ;
    6693         105 :   PyObject * obj3 = 0 ;
    6694         105 :   PyObject * obj4 = 0 ;
    6695         105 :   PyObject * obj5 = 0 ;
    6696         105 :   PyObject * obj6 = 0 ;
    6697         105 :   PyObject * obj7 = 0 ;
    6698         105 :   PyObject * obj8 = 0 ;
    6699         105 :   PyObject * obj9 = 0 ;
    6700         105 :   PyObject * obj10 = 0 ;
    6701         105 :   PyObject * obj11 = 0 ;
    6702         105 :   PyObject * obj12 = 0 ;
    6703         105 :   char * kwnames[] = {
    6704             :     (char *)"ds",  (char *)"bWrite",  (char *)"xoff",  (char *)"yoff",  (char *)"xsize",  (char *)"ysize",  (char *)"psArray",  (char *)"buf_type",  (char *)"resample_alg",  (char *)"callback",  (char *)"callback_data",  (char *)"binterleave",  (char *)"band_list",  NULL 
    6705             :   };
    6706         105 :   CPLErr result;
    6707             :   
    6708             :   /* %typemap(arginit) ( const char* callback_data=NULL)  */
    6709         105 :   PyProgressData *psProgressInfo;
    6710         105 :   psProgressInfo = (PyProgressData *) CPLCalloc(1,sizeof(PyProgressData));
    6711         105 :   psProgressInfo->nLastReported = -1;
    6712         105 :   psProgressInfo->psPyCallback = NULL;
    6713         105 :   psProgressInfo->psPyCallbackData = NULL;
    6714         105 :   arg11 = psProgressInfo;
    6715         105 :   if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOOOOOOOO|OOOO:DatasetIONumPy", kwnames, &obj0, &obj1, &obj2, &obj3, &obj4, &obj5, &obj6, &obj7, &obj8, &obj9, &obj10, &obj11, &obj12)) SWIG_fail;
    6716         105 :   res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_GDALDatasetShadow, 0 |  0 );
    6717         105 :   if (!SWIG_IsOK(res1)) {
    6718           0 :     SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "DatasetIONumPy" "', argument " "1"" of type '" "GDALDatasetShadow *""'"); 
    6719             :   }
    6720         105 :   arg1 = reinterpret_cast< GDALDatasetShadow * >(argp1);
    6721         105 :   ecode2 = SWIG_AsVal_int(obj1, &val2);
    6722         105 :   if (!SWIG_IsOK(ecode2)) {
    6723           0 :     SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "DatasetIONumPy" "', argument " "2"" of type '" "int""'");
    6724             :   } 
    6725         105 :   arg2 = static_cast< int >(val2);
    6726         105 :   ecode3 = SWIG_AsVal_double(obj2, &val3);
    6727         105 :   if (!SWIG_IsOK(ecode3)) {
    6728           0 :     SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "DatasetIONumPy" "', argument " "3"" of type '" "double""'");
    6729             :   } 
    6730         105 :   arg3 = static_cast< double >(val3);
    6731         105 :   ecode4 = SWIG_AsVal_double(obj3, &val4);
    6732         105 :   if (!SWIG_IsOK(ecode4)) {
    6733           0 :     SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "DatasetIONumPy" "', argument " "4"" of type '" "double""'");
    6734             :   } 
    6735         105 :   arg4 = static_cast< double >(val4);
    6736         105 :   ecode5 = SWIG_AsVal_double(obj4, &val5);
    6737         105 :   if (!SWIG_IsOK(ecode5)) {
    6738           0 :     SWIG_exception_fail(SWIG_ArgError(ecode5), "in method '" "DatasetIONumPy" "', argument " "5"" of type '" "double""'");
    6739             :   } 
    6740         105 :   arg5 = static_cast< double >(val5);
    6741         105 :   ecode6 = SWIG_AsVal_double(obj5, &val6);
    6742         105 :   if (!SWIG_IsOK(ecode6)) {
    6743           0 :     SWIG_exception_fail(SWIG_ArgError(ecode6), "in method '" "DatasetIONumPy" "', argument " "6"" of type '" "double""'");
    6744             :   } 
    6745         105 :   arg6 = static_cast< double >(val6);
    6746         105 :   {
    6747             :     /* %typemap(in,numinputs=1) (PyArrayObject  *psArray) */
    6748         105 :     if (obj6 != NULL && PyArray_Check(obj6))
    6749             :     {
    6750         105 :       arg7 = (PyArrayObject*)(obj6);
    6751             :     }
    6752             :     else
    6753             :     {
    6754           0 :       PyErr_SetString(PyExc_TypeError, "not a numpy array");
    6755           0 :       SWIG_fail;
    6756             :     }
    6757             :   }
    6758         105 :   {
    6759             :     // %typemap(in) GDALDataType
    6760         105 :     int val = 0;
    6761         105 :     int ecode = SWIG_AsVal_int(obj7, &val);
    6762         105 :     if (!SWIG_IsOK(ecode)) {
    6763           0 :       SWIG_exception_fail(SWIG_ArgError(ecode), "invalid value for GDALDataType");
    6764             :     }
    6765         105 :     if( val < GDT_Unknown || val >= GDT_TypeCount )
    6766             :     {
    6767           0 :       SWIG_exception_fail(SWIG_ValueError, "Invalid value for GDALDataType");
    6768             :     }
    6769         105 :     arg8 = static_cast<GDALDataType>(val);
    6770             :   }
    6771         105 :   {
    6772             :     // %typemap(in) GDALRIOResampleAlg
    6773         105 :     int val = 0;
    6774         105 :     int ecode = SWIG_AsVal_int(obj8, &val);
    6775         105 :     if (!SWIG_IsOK(ecode)) {
    6776           0 :       SWIG_exception_fail(SWIG_ArgError(ecode), "invalid value for GDALRIOResampleAlg");
    6777             :     }
    6778         105 :     if( val < 0 ||
    6779         105 :       ( val >= static_cast<int>(GRIORA_RESERVED_START) &&
    6780         105 :         val <= static_cast<int>(GRIORA_RESERVED_END) ) ||
    6781             :       val > static_cast<int>(GRIORA_LAST) )
    6782             :     {
    6783           0 :       SWIG_exception_fail(SWIG_ValueError, "Invalid value for resample_alg");
    6784             :     }
    6785         105 :     arg9 = static_cast< GDALRIOResampleAlg >(val);
    6786             :   }
    6787         105 :   if (obj9) {
    6788         105 :     {
    6789             :       /* %typemap(in) (GDALProgressFunc callback = NULL) */
    6790             :       /* callback_func typemap */
    6791             :       
    6792             :       /* In some cases 0 is passed instead of None. */
    6793             :       /* See https://github.com/OSGeo/gdal/pull/219 */
    6794         105 :       if ( PyLong_Check(obj9) || PyInt_Check(obj9) )
    6795             :       {
    6796           0 :         if( PyLong_AsLong(obj9) == 0 )
    6797             :         {
    6798           0 :           obj9 = Py_None;
    6799             :         }
    6800             :       }
    6801             :       
    6802         105 :       if (obj9 && obj9 != Py_None ) {
    6803           3 :         void* cbfunction = NULL;
    6804           3 :         CPL_IGNORE_RET_VAL(SWIG_ConvertPtr( obj9,
    6805             :             (void**)&cbfunction,
    6806             :             SWIGTYPE_p_f_double_p_q_const__char_p_void__int,
    6807             :             SWIG_POINTER_EXCEPTION | 0 ));
    6808             :         
    6809           3 :         if ( cbfunction == GDALTermProgress ) {
    6810             :           arg10 = GDALTermProgress;
    6811             :         } else {
    6812           3 :           if (!PyCallable_Check(obj9)) {
    6813           0 :             PyErr_SetString( PyExc_RuntimeError,
    6814             :               "Object given is not a Python function" );
    6815           0 :             SWIG_fail;
    6816             :           }
    6817           3 :           psProgressInfo->psPyCallback = obj9;
    6818           3 :           arg10 = PyProgressProxy;
    6819             :         }
    6820             :         
    6821             :       }
    6822             :       
    6823             :     }
    6824             :   }
    6825         105 :   if (obj10) {
    6826         105 :     {
    6827             :       /* %typemap(in) ( void* callback_data=NULL)  */
    6828         105 :       psProgressInfo->psPyCallbackData = obj10 ;
    6829             :     }
    6830             :   }
    6831         105 :   if (obj11) {
    6832         105 :     ecode12 = SWIG_AsVal_bool(obj11, &val12);
    6833         105 :     if (!SWIG_IsOK(ecode12)) {
    6834           0 :       SWIG_exception_fail(SWIG_ArgError(ecode12), "in method '" "DatasetIONumPy" "', argument " "12"" of type '" "bool""'");
    6835             :     } 
    6836             :     arg12 = static_cast< bool >(val12);
    6837             :   }
    6838         105 :   if (obj12) {
    6839         105 :     {
    6840             :       /* %typemap(in,numinputs=1) (int nList, int* pList)*/
    6841         105 :       arg14 = CreateCIntListFromSequence(obj12, &arg13);
    6842         105 :       if( arg13 < 0 ) {
    6843           0 :         SWIG_fail;
    6844             :       }
    6845             :     }
    6846             :   }
    6847         105 :   {
    6848         105 :     const int bLocalUseExceptions = GetUseExceptions();
    6849         105 :     if ( bLocalUseExceptions ) {
    6850          73 :       pushErrorHandler();
    6851             :     }
    6852         105 :     {
    6853         105 :       SWIG_PYTHON_THREAD_BEGIN_ALLOW;
    6854         105 :       result = (CPLErr)DatasetIONumPy(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12,arg13,arg14);
    6855         105 :       SWIG_PYTHON_THREAD_END_ALLOW;
    6856             :     }
    6857         105 :     if ( bLocalUseExceptions ) {
    6858          73 :       popErrorHandler();
    6859             :     }
    6860             : #ifndef SED_HACKS
    6861         105 :     if ( bLocalUseExceptions ) {
    6862          73 :       CPLErr eclass = CPLGetLastErrorType();
    6863          73 :       if ( eclass == CE_Failure || eclass == CE_Fatal ) {
    6864           5 :         SWIG_exception( SWIG_RuntimeError, CPLGetLastErrorMsg() );
    6865             :       }
    6866             :     }
    6867             : #endif
    6868             :   }
    6869         100 :   resultobj = SWIG_From_int(static_cast< int >(result));
    6870         100 :   {
    6871             :     /* %typemap(freearg) ( void* callback_data=NULL)  */
    6872             :     
    6873         100 :     CPLFree(psProgressInfo);
    6874             :     
    6875             :   }
    6876         100 :   {
    6877             :     /* %typemap(freearg) (int nList, int* pList) */
    6878         100 :     free(arg14);
    6879             :   }
    6880         100 :   return resultobj;
    6881           5 : fail:
    6882           5 :   {
    6883             :     /* %typemap(freearg) ( void* callback_data=NULL)  */
    6884             :     
    6885           5 :     CPLFree(psProgressInfo);
    6886             :     
    6887             :   }
    6888           5 :   {
    6889             :     /* %typemap(freearg) (int nList, int* pList) */
    6890           5 :     free(arg14);
    6891             :   }
    6892           5 :   return NULL;
    6893             : }
    6894             : 
    6895             : 
    6896          78 : SWIGINTERN PyObject *_wrap_MDArrayIONumPy(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    6897          78 :   PyObject *resultobj = 0;
    6898          78 :   bool arg1 ;
    6899          78 :   GDALMDArrayHS *arg2 = (GDALMDArrayHS *) 0 ;
    6900          78 :   PyArrayObject *arg3 = (PyArrayObject *) 0 ;
    6901          78 :   int arg4 ;
    6902          78 :   GUIntBig *arg5 = (GUIntBig *) 0 ;
    6903          78 :   int arg6 ;
    6904          78 :   GIntBig *arg7 = (GIntBig *) 0 ;
    6905          78 :   GDALExtendedDataTypeHS *arg8 = (GDALExtendedDataTypeHS *) 0 ;
    6906          78 :   bool val1 ;
    6907          78 :   int ecode1 = 0 ;
    6908          78 :   void *argp2 = 0 ;
    6909          78 :   int res2 = 0 ;
    6910          78 :   void *argp8 = 0 ;
    6911          78 :   int res8 = 0 ;
    6912          78 :   PyObject *swig_obj[6] ;
    6913          78 :   CPLErr result;
    6914             :   
    6915          78 :   if (!SWIG_Python_UnpackTuple(args, "MDArrayIONumPy", 6, 6, swig_obj)) SWIG_fail;
    6916          78 :   ecode1 = SWIG_AsVal_bool(swig_obj[0], &val1);
    6917          78 :   if (!SWIG_IsOK(ecode1)) {
    6918           0 :     SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "MDArrayIONumPy" "', argument " "1"" of type '" "bool""'");
    6919             :   } 
    6920          78 :   arg1 = static_cast< bool >(val1);
    6921          78 :   res2 = SWIG_ConvertPtr(swig_obj[1], &argp2,SWIGTYPE_p_GDALMDArrayHS, 0 |  0 );
    6922          78 :   if (!SWIG_IsOK(res2)) {
    6923           0 :     SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "MDArrayIONumPy" "', argument " "2"" of type '" "GDALMDArrayHS *""'"); 
    6924             :   }
    6925          78 :   arg2 = reinterpret_cast< GDALMDArrayHS * >(argp2);
    6926          78 :   {
    6927             :     /* %typemap(in,numinputs=1) (PyArrayObject  *psArray) */
    6928          78 :     if (swig_obj[2] != NULL && PyArray_Check(swig_obj[2]))
    6929             :     {
    6930          78 :       arg3 = (PyArrayObject*)(swig_obj[2]);
    6931             :     }
    6932             :     else
    6933             :     {
    6934           0 :       PyErr_SetString(PyExc_TypeError, "not a numpy array");
    6935           0 :       SWIG_fail;
    6936             :     }
    6937             :   }
    6938          78 :   {
    6939             :     /* %typemap(in,numinputs=1) (int nList, GUIntBig* pList)*/
    6940          78 :     arg5 = CreateCGUIntBigListFromSequence(swig_obj[3], &arg4);
    6941          78 :     if( arg4 < 0 ) {
    6942           0 :       SWIG_fail;
    6943             :     }
    6944             :   }
    6945          78 :   {
    6946             :     /* %typemap(in,numinputs=1) (int nList, GIntBig* pList)*/
    6947          78 :     arg7 = CreateCGIntBigListFromSequence(swig_obj[4], &arg6);
    6948          78 :     if( arg6 < 0 ) {
    6949           0 :       SWIG_fail;
    6950             :     }
    6951             :   }
    6952          78 :   res8 = SWIG_ConvertPtr(swig_obj[5], &argp8,SWIGTYPE_p_GDALExtendedDataTypeHS, 0 |  0 );
    6953          78 :   if (!SWIG_IsOK(res8)) {
    6954           0 :     SWIG_exception_fail(SWIG_ArgError(res8), "in method '" "MDArrayIONumPy" "', argument " "8"" of type '" "GDALExtendedDataTypeHS *""'"); 
    6955             :   }
    6956          78 :   arg8 = reinterpret_cast< GDALExtendedDataTypeHS * >(argp8);
    6957          78 :   {
    6958          78 :     const int bLocalUseExceptions = GetUseExceptions();
    6959          78 :     if ( bLocalUseExceptions ) {
    6960          76 :       pushErrorHandler();
    6961             :     }
    6962          78 :     {
    6963          78 :       SWIG_PYTHON_THREAD_BEGIN_ALLOW;
    6964          78 :       result = (CPLErr)MDArrayIONumPy(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8);
    6965          78 :       SWIG_PYTHON_THREAD_END_ALLOW;
    6966             :     }
    6967          78 :     if ( bLocalUseExceptions ) {
    6968          76 :       popErrorHandler();
    6969             :     }
    6970             : #ifndef SED_HACKS
    6971          78 :     if ( bLocalUseExceptions ) {
    6972          76 :       CPLErr eclass = CPLGetLastErrorType();
    6973          76 :       if ( eclass == CE_Failure || eclass == CE_Fatal ) {
    6974           0 :         SWIG_exception( SWIG_RuntimeError, CPLGetLastErrorMsg() );
    6975             :       }
    6976             :     }
    6977             : #endif
    6978             :   }
    6979          78 :   resultobj = SWIG_From_int(static_cast< int >(result));
    6980          78 :   {
    6981             :     /* %typemap(freearg) (int nList, GUIntBig* pList) */
    6982          78 :     free(arg5);
    6983             :   }
    6984          78 :   {
    6985             :     /* %typemap(freearg) (int nList, GIntBig* pList) */
    6986          78 :     free(arg7);
    6987             :   }
    6988          78 :   return resultobj;
    6989           0 : fail:
    6990           0 :   {
    6991             :     /* %typemap(freearg) (int nList, GUIntBig* pList) */
    6992           0 :     free(arg5);
    6993             :   }
    6994           0 :   {
    6995             :     /* %typemap(freearg) (int nList, GIntBig* pList) */
    6996           0 :     free(arg7);
    6997             :   }
    6998           0 :   return NULL;
    6999             : }
    7000             : 
    7001             : 
    7002           0 : SWIGINTERN PyObject *_wrap_AddNumpyArrayToDict(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    7003           0 :   PyObject *resultobj = 0;
    7004           0 :   PyObject *arg1 = (PyObject *) 0 ;
    7005           0 :   ArrowSchema *arg2 = (ArrowSchema *) 0 ;
    7006           0 :   ArrowArray *arg3 = (ArrowArray *) 0 ;
    7007           0 :   std::string *arg4 = 0 ;
    7008           0 :   PyObject *arg5 = (PyObject *) 0 ;
    7009           0 :   void *argp2 = 0 ;
    7010           0 :   int res2 = 0 ;
    7011           0 :   void *argp3 = 0 ;
    7012           0 :   int res3 = 0 ;
    7013           0 :   void *argp4 = 0 ;
    7014           0 :   int res4 = 0 ;
    7015           0 :   PyObject *swig_obj[5] ;
    7016           0 :   bool result;
    7017             :   
    7018           0 :   if (!SWIG_Python_UnpackTuple(args, "AddNumpyArrayToDict", 5, 5, swig_obj)) SWIG_fail;
    7019           0 :   arg1 = swig_obj[0];
    7020           0 :   res2 = SWIG_ConvertPtr(swig_obj[1], &argp2,SWIGTYPE_p_ArrowSchema, 0 |  0 );
    7021           0 :   if (!SWIG_IsOK(res2)) {
    7022           0 :     SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "AddNumpyArrayToDict" "', argument " "2"" of type '" "ArrowSchema const *""'"); 
    7023             :   }
    7024           0 :   arg2 = reinterpret_cast< ArrowSchema * >(argp2);
    7025           0 :   res3 = SWIG_ConvertPtr(swig_obj[2], &argp3,SWIGTYPE_p_ArrowArray, 0 |  0 );
    7026           0 :   if (!SWIG_IsOK(res3)) {
    7027           0 :     SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "AddNumpyArrayToDict" "', argument " "3"" of type '" "ArrowArray const *""'"); 
    7028             :   }
    7029           0 :   arg3 = reinterpret_cast< ArrowArray * >(argp3);
    7030           0 :   res4 = SWIG_ConvertPtr(swig_obj[3], &argp4, SWIGTYPE_p_std__string,  0  | 0);
    7031           0 :   if (!SWIG_IsOK(res4)) {
    7032           0 :     SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "AddNumpyArrayToDict" "', argument " "4"" of type '" "std::string const &""'"); 
    7033             :   }
    7034           0 :   if (!argp4) {
    7035           0 :     SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "AddNumpyArrayToDict" "', argument " "4"" of type '" "std::string const &""'"); 
    7036             :   }
    7037           0 :   arg4 = reinterpret_cast< std::string * >(argp4);
    7038           0 :   arg5 = swig_obj[4];
    7039           0 :   {
    7040           0 :     const int bLocalUseExceptions = GetUseExceptions();
    7041           0 :     if ( bLocalUseExceptions ) {
    7042           0 :       pushErrorHandler();
    7043             :     }
    7044           0 :     result = (bool)AddNumpyArrayToDict(arg1,(ArrowSchema const *)arg2,(ArrowArray const *)arg3,(std::string const &)*arg4,arg5);
    7045           0 :     if ( bLocalUseExceptions ) {
    7046           0 :       popErrorHandler();
    7047             :     }
    7048             : #ifndef SED_HACKS
    7049           0 :     if ( bLocalUseExceptions ) {
    7050           0 :       CPLErr eclass = CPLGetLastErrorType();
    7051           0 :       if ( eclass == CE_Failure || eclass == CE_Fatal ) {
    7052           0 :         SWIG_exception( SWIG_RuntimeError, CPLGetLastErrorMsg() );
    7053             :       }
    7054             :     }
    7055             : #endif
    7056             :   }
    7057           0 :   resultobj = SWIG_From_bool(static_cast< bool >(result));
    7058             :   return resultobj;
    7059             : fail:
    7060             :   return NULL;
    7061             : }
    7062             : 
    7063             : 
    7064         475 : SWIGINTERN PyObject *_wrap__RecordBatchAsNumpy(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    7065         475 :   PyObject *resultobj = 0;
    7066         475 :   VoidPtrAsLong arg1 = (VoidPtrAsLong) 0 ;
    7067         475 :   VoidPtrAsLong arg2 = (VoidPtrAsLong) 0 ;
    7068         475 :   PyObject *arg3 = (PyObject *) 0 ;
    7069         475 :   PyObject *swig_obj[3] ;
    7070         475 :   PyObject *result = 0 ;
    7071             :   
    7072         475 :   if (!SWIG_Python_UnpackTuple(args, "_RecordBatchAsNumpy", 3, 3, swig_obj)) SWIG_fail;
    7073         475 :   {
    7074         475 :     arg1 = PyLong_AsVoidPtr(swig_obj[0]);
    7075             :   }
    7076         475 :   {
    7077         475 :     arg2 = PyLong_AsVoidPtr(swig_obj[1]);
    7078             :   }
    7079         475 :   arg3 = swig_obj[2];
    7080         475 :   {
    7081         475 :     const int bLocalUseExceptions = GetUseExceptions();
    7082         475 :     if ( bLocalUseExceptions ) {
    7083         160 :       pushErrorHandler();
    7084             :     }
    7085         475 :     result = (PyObject *)_RecordBatchAsNumpy(arg1,arg2,arg3);
    7086         475 :     if ( bLocalUseExceptions ) {
    7087         160 :       popErrorHandler();
    7088             :     }
    7089             : #ifndef SED_HACKS
    7090         475 :     if ( bLocalUseExceptions ) {
    7091         160 :       CPLErr eclass = CPLGetLastErrorType();
    7092         160 :       if ( eclass == CE_Failure || eclass == CE_Fatal ) {
    7093           0 :         SWIG_exception( SWIG_RuntimeError, CPLGetLastErrorMsg() );
    7094             :       }
    7095             :     }
    7096             : #endif
    7097             :   }
    7098         475 :   resultobj = result;
    7099             :   return resultobj;
    7100             : fail:
    7101             :   return NULL;
    7102             : }
    7103             : 
    7104             : 
    7105          28 : SWIGINTERN PyObject *_wrap_VirtualMemGetArray(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    7106          28 :   PyObject *resultobj = 0;
    7107          28 :   CPLVirtualMemShadow *arg1 = (CPLVirtualMemShadow *) 0 ;
    7108          28 :   CPLVirtualMemShadow **arg2 = (CPLVirtualMemShadow **) 0 ;
    7109          28 :   int arg3 ;
    7110          28 :   void *argp1 = 0 ;
    7111          28 :   int res1 = 0 ;
    7112          28 :   CPLVirtualMemShadow *virtualmem2 ;
    7113          28 :   PyObject *swig_obj[1] ;
    7114             :   
    7115          28 :   {
    7116          28 :     arg2 = &virtualmem2;
    7117          28 :     arg3 = 0;
    7118             :   }
    7119          28 :   if (!args) SWIG_fail;
    7120          28 :   swig_obj[0] = args;
    7121          28 :   res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_CPLVirtualMemShadow, 0 |  0 );
    7122          28 :   if (!SWIG_IsOK(res1)) {
    7123           0 :     SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "VirtualMemGetArray" "', argument " "1"" of type '" "CPLVirtualMemShadow *""'"); 
    7124             :   }
    7125          28 :   arg1 = reinterpret_cast< CPLVirtualMemShadow * >(argp1);
    7126          28 :   {
    7127          28 :     if (!arg1) {
    7128           0 :       SWIG_exception(SWIG_ValueError,"Received a NULL pointer.");
    7129             :     }
    7130             :   }
    7131          28 :   {
    7132          28 :     const int bLocalUseExceptions = GetUseExceptions();
    7133          28 :     if ( bLocalUseExceptions ) {
    7134          28 :       pushErrorHandler();
    7135             :     }
    7136          28 :     VirtualMemGetArray(arg1,arg2,arg3);
    7137          28 :     if ( bLocalUseExceptions ) {
    7138          28 :       popErrorHandler();
    7139             :     }
    7140             : #ifndef SED_HACKS
    7141          28 :     if ( bLocalUseExceptions ) {
    7142          28 :       CPLErr eclass = CPLGetLastErrorType();
    7143          28 :       if ( eclass == CE_Failure || eclass == CE_Fatal ) {
    7144           0 :         SWIG_exception( SWIG_RuntimeError, CPLGetLastErrorMsg() );
    7145             :       }
    7146             :     }
    7147             : #endif
    7148             :   }
    7149          28 :   resultobj = SWIG_Py_Void();
    7150          28 :   {
    7151          28 :     CPLVirtualMemShadow* virtualmem = *(arg2);
    7152          28 :     void* ptr = CPLVirtualMemGetAddr( virtualmem->vmem );
    7153             :     /*size_t nsize = CPLVirtualMemGetSize( virtualmem->vmem );*/
    7154          28 :     GDALDataType datatype = virtualmem->eBufType;
    7155          28 :     int readonly = virtualmem->bReadOnly;
    7156          28 :     GIntBig nBufXSize = virtualmem->nBufXSize;
    7157          28 :     GIntBig nBufYSize = virtualmem->nBufYSize;
    7158          28 :     int nBandCount = virtualmem->nBandCount;
    7159          28 :     int bIsBandSequential = virtualmem->bIsBandSequential;
    7160          28 :     GDALTileOrganization eTileOrganization = virtualmem->eTileOrganization;
    7161          28 :     int nTileXSize = virtualmem->nTileXSize;
    7162          28 :     int nTileYSize = virtualmem->nTileYSize;
    7163          28 :     int bAuto = virtualmem->bAuto;
    7164          28 :     int            nPixelSpace = virtualmem->nPixelSpace; /* if bAuto == TRUE */
    7165          28 :     GIntBig        nLineSpace = virtualmem->nLineSpace; /* if bAuto == TRUE */
    7166          28 :     int numpytype;
    7167             :     
    7168          28 :     if( datatype == GDT_CInt16 || datatype == GDT_CInt32 || datatype == GDT_CFloat16 )
    7169             :     {
    7170           0 :       PyErr_SetString( PyExc_RuntimeError, "GDT_CInt16, GDT_CInt32, and GDT_CFloat16 not supported for now" );
    7171           0 :       SWIG_fail;
    7172             :     }
    7173             :     
    7174          28 :     switch(datatype)
    7175             :     {
    7176             :       case GDT_Byte: numpytype = NPY_UBYTE; break;
    7177             :       case GDT_Int8: numpytype = NPY_INT8; break;
    7178             :       case GDT_Int16: numpytype = NPY_INT16; break;
    7179             :       case GDT_UInt16: numpytype = NPY_UINT16; break;
    7180             :       case GDT_Int32: numpytype = NPY_INT32; break;
    7181             :       case GDT_UInt32: numpytype = NPY_UINT32; break;
    7182             :       case GDT_Int64: numpytype = NPY_INT64; break;
    7183             :       case GDT_UInt64: numpytype = NPY_UINT64; break;
    7184             :       case GDT_Float16: numpytype = NPY_FLOAT16; break;
    7185             :       case GDT_Float32: numpytype = NPY_FLOAT32; break;
    7186             :       case GDT_Float64: numpytype = NPY_FLOAT64; break;
    7187             :       //case GDT_CInt16: numpytype = NPY_INT16; break;
    7188             :       //case GDT_CInt32: numpytype = NPY_INT32; break;
    7189             :       //case GDT_CFloat16: numpytype = NPY_CHALF; break;
    7190             :       case GDT_CFloat32: numpytype = NPY_CFLOAT; break;
    7191             :       case GDT_CFloat64: numpytype = NPY_CDOUBLE; break;
    7192             :       default: numpytype = NPY_UBYTE; break;
    7193             :     }
    7194          28 :     PyArrayObject* ar;
    7195          28 :     int flags = (readonly) ? 0x1 : 0x1 | 0x0400;
    7196          28 :     int nDataTypeSize = GDALGetDataTypeSizeBytes(datatype);
    7197          28 :     if( bAuto )
    7198             :     {
    7199          20 :       if( nBandCount == 1 )
    7200             :       {
    7201          20 :         npy_intp shape[2], stride[2];
    7202          20 :         shape[0] = nBufYSize;
    7203          20 :         shape[1] = nBufXSize;
    7204          20 :         stride[1] = nPixelSpace;
    7205          20 :         stride[0] = nLineSpace;
    7206          20 :         ar = (PyArrayObject*) PyArray_New(&PyArray_Type, 2, shape,
    7207             :           numpytype, stride, ptr, 0, flags , NULL);
    7208             :       }
    7209             :       else
    7210             :       {
    7211           0 :         PyErr_SetString( PyExc_RuntimeError, "Code update needed for bAuto and nBandCount > 1 !" );
    7212           0 :         SWIG_fail;
    7213             :       }
    7214             :     }
    7215           8 :     else if( bIsBandSequential >= 0 )
    7216             :     {
    7217           4 :       if( nBandCount == 1 )
    7218             :       {
    7219           2 :         npy_intp shape[2], stride[2];
    7220           2 :         shape[0] = nBufYSize;
    7221           2 :         shape[1] = nBufXSize;
    7222           2 :         stride[1] = nDataTypeSize;
    7223           2 :         stride[0] = stride[1] * nBufXSize;
    7224           2 :         ar = (PyArrayObject*) PyArray_New(&PyArray_Type, 2, shape,
    7225             :           numpytype, stride, ptr, 0, flags , NULL);
    7226             :       }
    7227             :       else
    7228             :       {
    7229           2 :         npy_intp shape[3], stride[3];
    7230           2 :         if( bIsBandSequential )
    7231             :         {
    7232           1 :           shape[0] = nBandCount;
    7233           1 :           shape[1] = nBufYSize;
    7234           1 :           shape[2] = nBufXSize;
    7235           1 :           stride[2] = nDataTypeSize;
    7236           1 :           stride[1] = stride[2] * nBufXSize;
    7237           1 :           stride[0] = stride[1] * nBufYSize;
    7238             :         }
    7239             :         else
    7240             :         {
    7241           1 :           shape[0] = nBufYSize;
    7242           1 :           shape[1] = nBufXSize;
    7243           1 :           shape[2] = nBandCount;
    7244           1 :           stride[2] = nDataTypeSize;
    7245           1 :           stride[1] = stride[2] * nBandCount;
    7246           1 :           stride[0] = stride[1] * nBufXSize;
    7247             :         }
    7248           2 :         ar = (PyArrayObject*) PyArray_New(&PyArray_Type, 3, shape,
    7249             :           numpytype, stride, ptr, 0, flags , NULL);
    7250             :       }
    7251             :     }
    7252             :     else
    7253             :     {
    7254           4 :       npy_intp nTilesPerRow = static_cast<npy_intp>(DIV_ROUND_UP(nBufXSize, nTileXSize));
    7255           4 :       npy_intp nTilesPerCol = static_cast<npy_intp>(DIV_ROUND_UP(nBufYSize, nTileYSize));
    7256           4 :       npy_intp shape[5], stride[5];
    7257           4 :       if( nBandCount == 1 )
    7258             :       {
    7259           1 :         shape[0] = nTilesPerCol;
    7260           1 :         shape[1] = nTilesPerRow;
    7261           1 :         shape[2] = nTileYSize;
    7262           1 :         shape[3] = nTileXSize;
    7263           1 :         stride[3] = nDataTypeSize;
    7264           1 :         stride[2] = stride[3] * nTileXSize;
    7265           1 :         stride[1] = stride[2] * nTileYSize;
    7266           1 :         stride[0] = stride[1] * nTilesPerRow;
    7267           1 :         ar = (PyArrayObject*) PyArray_New(&PyArray_Type, 4, shape,
    7268             :           numpytype, stride, ptr, 0, flags , NULL);
    7269             :       }
    7270           3 :       else if( eTileOrganization == GTO_TIP )
    7271             :       {
    7272           1 :         shape[0] = nTilesPerCol;
    7273           1 :         shape[1] = nTilesPerRow;
    7274           1 :         shape[2] = nTileYSize;
    7275           1 :         shape[3] = nTileXSize;
    7276           1 :         shape[4] = nBandCount;
    7277           1 :         stride[4] = nDataTypeSize;
    7278           1 :         stride[3] = stride[4] * nBandCount;
    7279           1 :         stride[2] = stride[3] * nTileXSize;
    7280           1 :         stride[1] = stride[2] * nTileYSize;
    7281           1 :         stride[0] = stride[1] * nTilesPerRow;
    7282           1 :         ar = (PyArrayObject*) PyArray_New(&PyArray_Type, 5, shape,
    7283             :           numpytype, stride, ptr, 0, flags , NULL);
    7284             :       }
    7285           2 :       else if( eTileOrganization == GTO_BIT )
    7286             :       {
    7287           1 :         shape[0] = nTilesPerCol;
    7288           1 :         shape[1] = nTilesPerRow;
    7289           1 :         shape[2] = nBandCount;
    7290           1 :         shape[3] = nTileYSize;
    7291           1 :         shape[4] = nTileXSize;
    7292           1 :         stride[4] = nDataTypeSize;
    7293           1 :         stride[3] = stride[4] * nTileXSize;
    7294           1 :         stride[2] = stride[3] * nTileYSize;
    7295           1 :         stride[1] = stride[2] * nBandCount;
    7296           1 :         stride[0] = stride[1] * nTilesPerRow;
    7297           1 :         ar = (PyArrayObject*) PyArray_New(&PyArray_Type, 5, shape,
    7298             :           numpytype, stride, ptr, 0, flags , NULL);
    7299             :       }
    7300             :       else /* GTO_BSQ */
    7301             :       {
    7302           1 :         shape[0] = nBandCount;
    7303           1 :         shape[1] = nTilesPerCol;
    7304           1 :         shape[2] = nTilesPerRow;
    7305           1 :         shape[3] = nTileYSize;
    7306           1 :         shape[4] = nTileXSize;
    7307           1 :         stride[4] = nDataTypeSize;
    7308           1 :         stride[3] = stride[4] * nTileXSize;
    7309           1 :         stride[2] = stride[3] * nTileYSize;
    7310           1 :         stride[1] = stride[2] * nTilesPerRow;
    7311           1 :         stride[0] = stride[1] * nTilesPerCol;
    7312           1 :         ar = (PyArrayObject*) PyArray_New(&PyArray_Type, 5, shape,
    7313             :           numpytype, stride, ptr, 0, flags , NULL);
    7314             :       }
    7315             :     }
    7316             :     
    7317             :     /* Keep a reference to the VirtualMem object */
    7318             : #if NPY_API_VERSION >= 0x00000007
    7319          28 :     PyArray_SetBaseObject(ar, swig_obj[0]);
    7320             : #else
    7321             :     PyArray_BASE(ar) = swig_obj[0];
    7322             : #endif
    7323          28 :     Py_INCREF(swig_obj[0]);
    7324          28 :     Py_DECREF(resultobj);
    7325          28 :     resultobj = (PyObject*) ar;
    7326             :   }
    7327             :   return resultobj;
    7328             : fail:
    7329             :   return NULL;
    7330             : }
    7331             : 
    7332             : 
    7333          13 : SWIGINTERN PyObject *_wrap_RATValuesIONumPyWrite(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
    7334          13 :   PyObject *resultobj = 0;
    7335          13 :   GDALRasterAttributeTableShadow *arg1 = (GDALRasterAttributeTableShadow *) 0 ;
    7336          13 :   int arg2 ;
    7337          13 :   int arg3 ;
    7338          13 :   PyArrayObject *arg4 = (PyArrayObject *) 0 ;
    7339          13 :   void *argp1 = 0 ;
    7340          13 :   int res1 = 0 ;
    7341          13 :   int val2 ;
    7342          13 :   int ecode2 = 0 ;
    7343          13 :   int val3 ;
    7344          13 :   int ecode3 = 0 ;
    7345          13 :   PyObject * obj0 = 0 ;
    7346          13 :   PyObject * obj1 = 0 ;
    7347          13 :   PyObject * obj2 = 0 ;
    7348          13 :   PyObject * obj3 = 0 ;
    7349          13 :   char * kwnames[] = {
    7350             :     (char *)"poRAT",  (char *)"nField",  (char *)"nStart",  (char *)"psArray",  NULL 
    7351             :   };
    7352          13 :   CPLErr result;
    7353             :   
    7354          13 :   if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOOO:RATValuesIONumPyWrite", kwnames, &obj0, &obj1, &obj2, &obj3)) SWIG_fail;
    7355          13 :   res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_GDALRasterAttributeTableShadow, 0 |  0 );
    7356          13 :   if (!SWIG_IsOK(res1)) {
    7357           0 :     SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "RATValuesIONumPyWrite" "', argument " "1"" of type '" "GDALRasterAttributeTableShadow *""'"); 
    7358             :   }
    7359          13 :   arg1 = reinterpret_cast< GDALRasterAttributeTableShadow * >(argp1);
    7360          13 :   ecode2 = SWIG_AsVal_int(obj1, &val2);
    7361          13 :   if (!SWIG_IsOK(ecode2)) {
    7362           0 :     SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "RATValuesIONumPyWrite" "', argument " "2"" of type '" "int""'");
    7363             :   } 
    7364          13 :   arg2 = static_cast< int >(val2);
    7365          13 :   ecode3 = SWIG_AsVal_int(obj2, &val3);
    7366          13 :   if (!SWIG_IsOK(ecode3)) {
    7367           0 :     SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "RATValuesIONumPyWrite" "', argument " "3"" of type '" "int""'");
    7368             :   } 
    7369          13 :   arg3 = static_cast< int >(val3);
    7370          13 :   {
    7371             :     /* %typemap(in,numinputs=1) (PyArrayObject  *psArray) */
    7372          13 :     if (obj3 != NULL && PyArray_Check(obj3))
    7373             :     {
    7374          13 :       arg4 = (PyArrayObject*)(obj3);
    7375             :     }
    7376             :     else
    7377             :     {
    7378           0 :       PyErr_SetString(PyExc_TypeError, "not a numpy array");
    7379           0 :       SWIG_fail;
    7380             :     }
    7381             :   }
    7382          13 :   {
    7383          13 :     const int bLocalUseExceptions = GetUseExceptions();
    7384          13 :     if ( bLocalUseExceptions ) {
    7385          13 :       pushErrorHandler();
    7386             :     }
    7387          13 :     result = (CPLErr)RATValuesIONumPyWrite(arg1,arg2,arg3,arg4);
    7388          13 :     if ( bLocalUseExceptions ) {
    7389          13 :       popErrorHandler();
    7390             :     }
    7391             : #ifndef SED_HACKS
    7392          13 :     if ( bLocalUseExceptions ) {
    7393          13 :       CPLErr eclass = CPLGetLastErrorType();
    7394          13 :       if ( eclass == CE_Failure || eclass == CE_Fatal ) {
    7395           0 :         SWIG_exception( SWIG_RuntimeError, CPLGetLastErrorMsg() );
    7396             :       }
    7397             :     }
    7398             : #endif
    7399             :   }
    7400          13 :   resultobj = SWIG_From_int(static_cast< int >(result));
    7401             :   return resultobj;
    7402             : fail:
    7403             :   return NULL;
    7404             : }
    7405             : 
    7406             : 
    7407          52 : SWIGINTERN PyObject *_wrap_RATValuesIONumPyRead(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
    7408          52 :   PyObject *resultobj = 0;
    7409          52 :   GDALRasterAttributeTableShadow *arg1 = (GDALRasterAttributeTableShadow *) 0 ;
    7410          52 :   int arg2 ;
    7411          52 :   int arg3 ;
    7412          52 :   int arg4 ;
    7413          52 :   void *argp1 = 0 ;
    7414          52 :   int res1 = 0 ;
    7415          52 :   int val2 ;
    7416          52 :   int ecode2 = 0 ;
    7417          52 :   int val3 ;
    7418          52 :   int ecode3 = 0 ;
    7419          52 :   int val4 ;
    7420          52 :   int ecode4 = 0 ;
    7421          52 :   PyObject * obj0 = 0 ;
    7422          52 :   PyObject * obj1 = 0 ;
    7423          52 :   PyObject * obj2 = 0 ;
    7424          52 :   PyObject * obj3 = 0 ;
    7425          52 :   char * kwnames[] = {
    7426             :     (char *)"poRAT",  (char *)"nField",  (char *)"nStart",  (char *)"nLength",  NULL 
    7427             :   };
    7428          52 :   PyObject *result = 0 ;
    7429             :   
    7430          52 :   if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOOO:RATValuesIONumPyRead", kwnames, &obj0, &obj1, &obj2, &obj3)) SWIG_fail;
    7431          52 :   res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_GDALRasterAttributeTableShadow, 0 |  0 );
    7432          52 :   if (!SWIG_IsOK(res1)) {
    7433           0 :     SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "RATValuesIONumPyRead" "', argument " "1"" of type '" "GDALRasterAttributeTableShadow *""'"); 
    7434             :   }
    7435          52 :   arg1 = reinterpret_cast< GDALRasterAttributeTableShadow * >(argp1);
    7436          52 :   ecode2 = SWIG_AsVal_int(obj1, &val2);
    7437          52 :   if (!SWIG_IsOK(ecode2)) {
    7438           0 :     SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "RATValuesIONumPyRead" "', argument " "2"" of type '" "int""'");
    7439             :   } 
    7440          52 :   arg2 = static_cast< int >(val2);
    7441          52 :   ecode3 = SWIG_AsVal_int(obj2, &val3);
    7442          52 :   if (!SWIG_IsOK(ecode3)) {
    7443           0 :     SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "RATValuesIONumPyRead" "', argument " "3"" of type '" "int""'");
    7444             :   } 
    7445          52 :   arg3 = static_cast< int >(val3);
    7446          52 :   ecode4 = SWIG_AsVal_int(obj3, &val4);
    7447          52 :   if (!SWIG_IsOK(ecode4)) {
    7448           0 :     SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "RATValuesIONumPyRead" "', argument " "4"" of type '" "int""'");
    7449             :   } 
    7450          52 :   arg4 = static_cast< int >(val4);
    7451          52 :   {
    7452          52 :     const int bLocalUseExceptions = GetUseExceptions();
    7453          52 :     if ( bLocalUseExceptions ) {
    7454          52 :       pushErrorHandler();
    7455             :     }
    7456          52 :     result = (PyObject *)RATValuesIONumPyRead(arg1,arg2,arg3,arg4);
    7457          52 :     if ( bLocalUseExceptions ) {
    7458          52 :       popErrorHandler();
    7459             :     }
    7460             : #ifndef SED_HACKS
    7461          52 :     if ( bLocalUseExceptions ) {
    7462          52 :       CPLErr eclass = CPLGetLastErrorType();
    7463          52 :       if ( eclass == CE_Failure || eclass == CE_Fatal ) {
    7464           5 :         SWIG_exception( SWIG_RuntimeError, CPLGetLastErrorMsg() );
    7465             :       }
    7466             :     }
    7467             : #endif
    7468             :   }
    7469          52 :   resultobj = result;
    7470             :   return resultobj;
    7471             : fail:
    7472             :   return NULL;
    7473             : }
    7474             : 
    7475             : 
    7476             : static PyMethodDef SwigMethods[] = {
    7477             :    { "SWIG_PyInstanceMethod_New", SWIG_PyInstanceMethod_New, METH_O, NULL},
    7478             :    { "delete_VirtualMem", _wrap_delete_VirtualMem, METH_O, "delete_VirtualMem(VirtualMem self)"},
    7479             :    { "VirtualMem_GetAddr", _wrap_VirtualMem_GetAddr, METH_O, "VirtualMem_GetAddr(VirtualMem self)"},
    7480             :    { "VirtualMem_Pin", _wrap_VirtualMem_Pin, METH_VARARGS, "VirtualMem_Pin(VirtualMem self, size_t start_offset=0, size_t nsize=0, int bWriteOp=0)"},
    7481             :    { "VirtualMem_swigregister", VirtualMem_swigregister, METH_O, NULL},
    7482             :    { "GetUseExceptions", _wrap_GetUseExceptions, METH_NOARGS, "GetUseExceptions() -> int"},
    7483             :    { "_GetExceptionsLocal", _wrap__GetExceptionsLocal, METH_NOARGS, "_GetExceptionsLocal() -> int"},
    7484             :    { "_SetExceptionsLocal", _wrap__SetExceptionsLocal, METH_O, "_SetExceptionsLocal(int bVal)"},
    7485             :    { "_UseExceptions", _wrap__UseExceptions, METH_NOARGS, "_UseExceptions()"},
    7486             :    { "_DontUseExceptions", _wrap__DontUseExceptions, METH_NOARGS, "_DontUseExceptions()"},
    7487             :    { "_UserHasSpecifiedIfUsingExceptions", _wrap__UserHasSpecifiedIfUsingExceptions, METH_NOARGS, "_UserHasSpecifiedIfUsingExceptions() -> int"},
    7488             :    { "TermProgress_nocb", (PyCFunction)(void(*)(void))_wrap_TermProgress_nocb, METH_VARARGS|METH_KEYWORDS, "TermProgress_nocb(double dfProgress, char const * pszMessage=None, void * pData=None) -> int"},
    7489             :    { "OpenNumPyArray", _wrap_OpenNumPyArray, METH_VARARGS, "OpenNumPyArray(PyArrayObject * psArray, bool binterleave) -> Dataset"},
    7490             :    { "OpenMultiDimensionalNumPyArray", _wrap_OpenMultiDimensionalNumPyArray, METH_O, "OpenMultiDimensionalNumPyArray(PyArrayObject * psArray) -> Dataset"},
    7491             :    { "GetArrayFilename", _wrap_GetArrayFilename, METH_O, "GetArrayFilename(PyArrayObject * psArray) -> retStringAndCPLFree *"},
    7492             :    { "BandRasterIONumPy", (PyCFunction)(void(*)(void))_wrap_BandRasterIONumPy, METH_VARARGS|METH_KEYWORDS, "BandRasterIONumPy(Band band, int bWrite, double xoff, double yoff, double xsize, double ysize, PyArrayObject * psArray, GDALDataType buf_type, GDALRIOResampleAlg resample_alg, GDALProgressFunc callback=0, void * callback_data=None) -> CPLErr"},
    7493             :    { "DatasetIONumPy", (PyCFunction)(void(*)(void))_wrap_DatasetIONumPy, METH_VARARGS|METH_KEYWORDS, "DatasetIONumPy(Dataset ds, int bWrite, double xoff, double yoff, double xsize, double ysize, PyArrayObject * psArray, GDALDataType buf_type, GDALRIOResampleAlg resample_alg, GDALProgressFunc callback=0, void * callback_data=None, bool binterleave=True, int band_list=0) -> CPLErr"},
    7494             :    { "MDArrayIONumPy", _wrap_MDArrayIONumPy, METH_VARARGS, "MDArrayIONumPy(bool bWrite, GDALMDArrayHS * mdarray, PyArrayObject * psArray, int nDims1, int nDims3, GDALExtendedDataTypeHS * buffer_datatype) -> CPLErr"},
    7495             :    { "AddNumpyArrayToDict", _wrap_AddNumpyArrayToDict, METH_VARARGS, "AddNumpyArrayToDict(PyObject * dict, ArrowSchema const * schemaField, ArrowArray const * arrayField, std::string const & osPrefix, PyObject * pointerArrayKeeper) -> bool"},
    7496             :    { "_RecordBatchAsNumpy", _wrap__RecordBatchAsNumpy, METH_VARARGS, "_RecordBatchAsNumpy(VoidPtrAsLong recordBatchPtr, VoidPtrAsLong schemaPtr, PyObject * pointerArrayKeeper) -> PyObject *"},
    7497             :    { "VirtualMemGetArray", _wrap_VirtualMemGetArray, METH_O, "VirtualMemGetArray(VirtualMem virtualmem)"},
    7498             :    { "RATValuesIONumPyWrite", (PyCFunction)(void(*)(void))_wrap_RATValuesIONumPyWrite, METH_VARARGS|METH_KEYWORDS, "RATValuesIONumPyWrite(RasterAttributeTable poRAT, int nField, int nStart, PyArrayObject * psArray) -> CPLErr"},
    7499             :    { "RATValuesIONumPyRead", (PyCFunction)(void(*)(void))_wrap_RATValuesIONumPyRead, METH_VARARGS|METH_KEYWORDS, "RATValuesIONumPyRead(RasterAttributeTable poRAT, int nField, int nStart, int nLength) -> PyObject *"},
    7500             :    { NULL, NULL, 0, NULL }
    7501             : };
    7502             : 
    7503             : static PyMethodDef SwigMethods_proxydocs[] = {
    7504             :    { NULL, NULL, 0, NULL }
    7505             : };
    7506             : 
    7507             : 
    7508             : /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */
    7509             : 
    7510           0 : static void *_p_GDALComputedRasterBandShadowTo_p_GDALRasterBandShadow(void *x, int *SWIGUNUSEDPARM(newmemory)) {
    7511           0 :     return (void *)((GDALRasterBandShadow *)  ((GDALComputedRasterBandShadow *) x));
    7512             : }
    7513             : static swig_type_info _swigt__p_ArrowArray = {"_p_ArrowArray", "ArrowArray *", 0, 0, (void*)0, 0};
    7514             : static swig_type_info _swigt__p_ArrowSchema = {"_p_ArrowSchema", "ArrowSchema *", 0, 0, (void*)0, 0};
    7515             : static swig_type_info _swigt__p_CPLVirtualMemShadow = {"_p_CPLVirtualMemShadow", "CPLVirtualMemShadow *", 0, 0, (void*)0, 0};
    7516             : static swig_type_info _swigt__p_GDALDataType = {"_p_GDALDataType", "GDALDataType *", 0, 0, (void*)0, 0};
    7517             : static swig_type_info _swigt__p_GDALDatasetShadow = {"_p_GDALDatasetShadow", "GDALDatasetShadow *", 0, 0, (void*)0, 0};
    7518             : static swig_type_info _swigt__p_GDALExtendedDataTypeHS = {"_p_GDALExtendedDataTypeHS", "GDALExtendedDataTypeHS *", 0, 0, (void*)0, 0};
    7519             : static swig_type_info _swigt__p_GDALMDArrayHS = {"_p_GDALMDArrayHS", "GDALMDArrayHS *", 0, 0, (void*)0, 0};
    7520             : static swig_type_info _swigt__p_GDALProgressFunc = {"_p_GDALProgressFunc", "GDALProgressFunc *", 0, 0, (void*)0, 0};
    7521             : static swig_type_info _swigt__p_GDALRasterAttributeTableShadow = {"_p_GDALRasterAttributeTableShadow", "GDALRasterAttributeTableShadow *", 0, 0, (void*)0, 0};
    7522             : static swig_type_info _swigt__p_GDALRasterBandShadow = {"_p_GDALRasterBandShadow", "GDALRasterBandShadow *", 0, 0, (void*)0, 0};
    7523             : static swig_type_info _swigt__p_GDALComputedRasterBandShadow = {"_p_GDALComputedRasterBandShadow", 0, 0, 0, 0, 0};
    7524             : static swig_type_info _swigt__p_GIntBig = {"_p_GIntBig", "GIntBig *", 0, 0, (void*)0, 0};
    7525             : static swig_type_info _swigt__p_GUIntBig = {"_p_GUIntBig", "GUIntBig *", 0, 0, (void*)0, 0};
    7526             : static swig_type_info _swigt__p_PyArrayObject = {"_p_PyArrayObject", "PyArrayObject *", 0, 0, (void*)0, 0};
    7527             : static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0};
    7528             : static swig_type_info _swigt__p_f_double_p_q_const__char_p_void__int = {"_p_f_double_p_q_const__char_p_void__int", "int (*)(double,char const *,void *)", 0, 0, (void*)0, 0};
    7529             : static swig_type_info _swigt__p_int = {"_p_int", "GDALRATFieldType *|CPLErr *|int *|GDALRATTableType *|GDALRATFieldUsage *|GDALRIOResampleAlg *", 0, 0, (void*)0, 0};
    7530             : static swig_type_info _swigt__p_p_CPLVirtualMemShadow = {"_p_p_CPLVirtualMemShadow", "CPLVirtualMemShadow **", 0, 0, (void*)0, 0};
    7531             : static swig_type_info _swigt__p_p_void = {"_p_p_void", "void **", 0, 0, (void*)0, 0};
    7532             : static swig_type_info _swigt__p_size_t = {"_p_size_t", "size_t *", 0, 0, (void*)0, 0};
    7533             : static swig_type_info _swigt__p_std__string = {"_p_std__string", "std::string *", 0, 0, (void*)0, 0};
    7534             : 
    7535             : static swig_type_info *swig_type_initial[] = {
    7536             :   &_swigt__p_ArrowArray,
    7537             :   &_swigt__p_ArrowSchema,
    7538             :   &_swigt__p_CPLVirtualMemShadow,
    7539             :   &_swigt__p_GDALComputedRasterBandShadow,
    7540             :   &_swigt__p_GDALDataType,
    7541             :   &_swigt__p_GDALDatasetShadow,
    7542             :   &_swigt__p_GDALExtendedDataTypeHS,
    7543             :   &_swigt__p_GDALMDArrayHS,
    7544             :   &_swigt__p_GDALProgressFunc,
    7545             :   &_swigt__p_GDALRasterAttributeTableShadow,
    7546             :   &_swigt__p_GDALRasterBandShadow,
    7547             :   &_swigt__p_GIntBig,
    7548             :   &_swigt__p_GUIntBig,
    7549             :   &_swigt__p_PyArrayObject,
    7550             :   &_swigt__p_char,
    7551             :   &_swigt__p_f_double_p_q_const__char_p_void__int,
    7552             :   &_swigt__p_int,
    7553             :   &_swigt__p_p_CPLVirtualMemShadow,
    7554             :   &_swigt__p_p_void,
    7555             :   &_swigt__p_size_t,
    7556             :   &_swigt__p_std__string,
    7557             : };
    7558             : 
    7559             : static swig_cast_info _swigc__p_ArrowArray[] = {  {&_swigt__p_ArrowArray, 0, 0, 0},{0, 0, 0, 0}};
    7560             : static swig_cast_info _swigc__p_ArrowSchema[] = {  {&_swigt__p_ArrowSchema, 0, 0, 0},{0, 0, 0, 0}};
    7561             : static swig_cast_info _swigc__p_CPLVirtualMemShadow[] = {  {&_swigt__p_CPLVirtualMemShadow, 0, 0, 0},{0, 0, 0, 0}};
    7562             : static swig_cast_info _swigc__p_GDALDataType[] = {  {&_swigt__p_GDALDataType, 0, 0, 0},{0, 0, 0, 0}};
    7563             : static swig_cast_info _swigc__p_GDALDatasetShadow[] = {  {&_swigt__p_GDALDatasetShadow, 0, 0, 0},{0, 0, 0, 0}};
    7564             : static swig_cast_info _swigc__p_GDALExtendedDataTypeHS[] = {  {&_swigt__p_GDALExtendedDataTypeHS, 0, 0, 0},{0, 0, 0, 0}};
    7565             : static swig_cast_info _swigc__p_GDALMDArrayHS[] = {  {&_swigt__p_GDALMDArrayHS, 0, 0, 0},{0, 0, 0, 0}};
    7566             : static swig_cast_info _swigc__p_GDALProgressFunc[] = {  {&_swigt__p_GDALProgressFunc, 0, 0, 0},{0, 0, 0, 0}};
    7567             : static swig_cast_info _swigc__p_GDALRasterAttributeTableShadow[] = {  {&_swigt__p_GDALRasterAttributeTableShadow, 0, 0, 0},{0, 0, 0, 0}};
    7568             : static swig_cast_info _swigc__p_GDALComputedRasterBandShadow[] = {{&_swigt__p_GDALComputedRasterBandShadow, 0, 0, 0},{0, 0, 0, 0}};
    7569             : static swig_cast_info _swigc__p_GDALRasterBandShadow[] = {  {&_swigt__p_GDALRasterBandShadow, 0, 0, 0},  {&_swigt__p_GDALComputedRasterBandShadow, _p_GDALComputedRasterBandShadowTo_p_GDALRasterBandShadow, 0, 0},{0, 0, 0, 0}};
    7570             : static swig_cast_info _swigc__p_GIntBig[] = {  {&_swigt__p_GIntBig, 0, 0, 0},{0, 0, 0, 0}};
    7571             : static swig_cast_info _swigc__p_GUIntBig[] = {  {&_swigt__p_GUIntBig, 0, 0, 0},{0, 0, 0, 0}};
    7572             : static swig_cast_info _swigc__p_PyArrayObject[] = {  {&_swigt__p_PyArrayObject, 0, 0, 0},{0, 0, 0, 0}};
    7573             : static swig_cast_info _swigc__p_char[] = {  {&_swigt__p_char, 0, 0, 0},{0, 0, 0, 0}};
    7574             : static swig_cast_info _swigc__p_f_double_p_q_const__char_p_void__int[] = {  {&_swigt__p_f_double_p_q_const__char_p_void__int, 0, 0, 0},{0, 0, 0, 0}};
    7575             : static swig_cast_info _swigc__p_int[] = {  {&_swigt__p_int, 0, 0, 0},{0, 0, 0, 0}};
    7576             : static swig_cast_info _swigc__p_p_CPLVirtualMemShadow[] = {  {&_swigt__p_p_CPLVirtualMemShadow, 0, 0, 0},{0, 0, 0, 0}};
    7577             : static swig_cast_info _swigc__p_p_void[] = {  {&_swigt__p_p_void, 0, 0, 0},{0, 0, 0, 0}};
    7578             : static swig_cast_info _swigc__p_size_t[] = {  {&_swigt__p_size_t, 0, 0, 0},{0, 0, 0, 0}};
    7579             : static swig_cast_info _swigc__p_std__string[] = {  {&_swigt__p_std__string, 0, 0, 0},{0, 0, 0, 0}};
    7580             : 
    7581             : static swig_cast_info *swig_cast_initial[] = {
    7582             :   _swigc__p_ArrowArray,
    7583             :   _swigc__p_ArrowSchema,
    7584             :   _swigc__p_CPLVirtualMemShadow,
    7585             :   _swigc__p_GDALComputedRasterBandShadow,
    7586             :   _swigc__p_GDALDataType,
    7587             :   _swigc__p_GDALDatasetShadow,
    7588             :   _swigc__p_GDALExtendedDataTypeHS,
    7589             :   _swigc__p_GDALMDArrayHS,
    7590             :   _swigc__p_GDALProgressFunc,
    7591             :   _swigc__p_GDALRasterAttributeTableShadow,
    7592             :   _swigc__p_GDALRasterBandShadow,
    7593             :   _swigc__p_GIntBig,
    7594             :   _swigc__p_GUIntBig,
    7595             :   _swigc__p_PyArrayObject,
    7596             :   _swigc__p_char,
    7597             :   _swigc__p_f_double_p_q_const__char_p_void__int,
    7598             :   _swigc__p_int,
    7599             :   _swigc__p_p_CPLVirtualMemShadow,
    7600             :   _swigc__p_p_void,
    7601             :   _swigc__p_size_t,
    7602             :   _swigc__p_std__string,
    7603             : };
    7604             : 
    7605             : 
    7606             : /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */
    7607             : 
    7608             : static swig_const_info swig_const_table[] = {
    7609             : { SWIG_PY_POINTER, "TermProgress", 0, 0, (void *)((int (*)(double,char const *,void *))(GDALTermProgress)), &SWIGTYPE_p_f_double_p_q_const__char_p_void__int },
    7610             : {0, 0, 0, 0.0, 0, 0}};
    7611             : 
    7612             : #ifdef __cplusplus
    7613             : }
    7614             : #endif
    7615             : /* -----------------------------------------------------------------------------
    7616             :  * Type initialization:
    7617             :  * This problem is tough by the requirement that no dynamic
    7618             :  * memory is used. Also, since swig_type_info structures store pointers to
    7619             :  * swig_cast_info structures and swig_cast_info structures store pointers back
    7620             :  * to swig_type_info structures, we need some lookup code at initialization.
    7621             :  * The idea is that swig generates all the structures that are needed.
    7622             :  * The runtime then collects these partially filled structures.
    7623             :  * The SWIG_InitializeModule function takes these initial arrays out of
    7624             :  * swig_module, and does all the lookup, filling in the swig_module.types
    7625             :  * array with the correct data and linking the correct swig_cast_info
    7626             :  * structures together.
    7627             :  *
    7628             :  * The generated swig_type_info structures are assigned statically to an initial
    7629             :  * array. We just loop through that array, and handle each type individually.
    7630             :  * First we lookup if this type has been already loaded, and if so, use the
    7631             :  * loaded structure instead of the generated one. Then we have to fill in the
    7632             :  * cast linked list. The cast data is initially stored in something like a
    7633             :  * two-dimensional array. Each row corresponds to a type (there are the same
    7634             :  * number of rows as there are in the swig_type_initial array). Each entry in
    7635             :  * a column is one of the swig_cast_info structures for that type.
    7636             :  * The cast_initial array is actually an array of arrays, because each row has
    7637             :  * a variable number of columns. So to actually build the cast linked list,
    7638             :  * we find the array of casts associated with the type, and loop through it
    7639             :  * adding the casts to the list. The one last trick we need to do is making
    7640             :  * sure the type pointer in the swig_cast_info struct is correct.
    7641             :  *
    7642             :  * First off, we lookup the cast->type name to see if it is already loaded.
    7643             :  * There are three cases to handle:
    7644             :  *  1) If the cast->type has already been loaded AND the type we are adding
    7645             :  *     casting info to has not been loaded (it is in this module), THEN we
    7646             :  *     replace the cast->type pointer with the type pointer that has already
    7647             :  *     been loaded.
    7648             :  *  2) If BOTH types (the one we are adding casting info to, and the
    7649             :  *     cast->type) are loaded, THEN the cast info has already been loaded by
    7650             :  *     the previous module so we just ignore it.
    7651             :  *  3) Finally, if cast->type has not already been loaded, then we add that
    7652             :  *     swig_cast_info to the linked list (because the cast->type) pointer will
    7653             :  *     be correct.
    7654             :  * ----------------------------------------------------------------------------- */
    7655             : 
    7656             : #ifdef __cplusplus
    7657             : extern "C" {
    7658             : #if 0
    7659             : } /* c-mode */
    7660             : #endif
    7661             : #endif
    7662             : 
    7663             : #if 0
    7664             : #define SWIGRUNTIME_DEBUG
    7665             : #endif
    7666             : 
    7667             : 
    7668             : SWIGRUNTIME void
    7669             : SWIG_InitializeModule(void *clientdata) {
    7670             :   size_t i;
    7671             :   swig_module_info *module_head, *iter;
    7672             :   int init;
    7673             :   
    7674             :   /* check to see if the circular list has been setup, if not, set it up */
    7675             :   if (swig_module.next==0) {
    7676             :     /* Initialize the swig_module */
    7677             :     swig_module.type_initial = swig_type_initial;
    7678             :     swig_module.cast_initial = swig_cast_initial;
    7679             :     swig_module.next = &swig_module;
    7680             :     init = 1;
    7681             :   } else {
    7682             :     init = 0;
    7683             :   }
    7684             :   
    7685             :   /* Try and load any already created modules */
    7686             :   module_head = SWIG_GetModule(clientdata);
    7687             :   if (!module_head) {
    7688             :     /* This is the first module loaded for this interpreter */
    7689             :     /* so set the swig module into the interpreter */
    7690             :     SWIG_SetModule(clientdata, &swig_module);
    7691             :   } else {
    7692             :     /* the interpreter has loaded a SWIG module, but has it loaded this one? */
    7693             :     iter=module_head;
    7694             :     do {
    7695             :       if (iter==&swig_module) {
    7696             :         /* Our module is already in the list, so there's nothing more to do. */
    7697             :         return;
    7698             :       }
    7699             :       iter=iter->next;
    7700             :     } while (iter!= module_head);
    7701             :     
    7702             :     /* otherwise we must add our module into the list */
    7703             :     swig_module.next = module_head->next;
    7704             :     module_head->next = &swig_module;
    7705             :   }
    7706             :   
    7707             :   /* When multiple interpreters are used, a module could have already been initialized in
    7708             :        a different interpreter, but not yet have a pointer in this interpreter.
    7709             :        In this case, we do not want to continue adding types... everything should be
    7710             :        set up already */
    7711             :   if (init == 0) return;
    7712             :   
    7713             :   /* Now work on filling in swig_module.types */
    7714             : #ifdef SWIGRUNTIME_DEBUG
    7715             :   printf("SWIG_InitializeModule: size %lu\n", (unsigned long)swig_module.size);
    7716             : #endif
    7717             :   for (i = 0; i < swig_module.size; ++i) {
    7718             :     swig_type_info *type = 0;
    7719             :     swig_type_info *ret;
    7720             :     swig_cast_info *cast;
    7721             :     
    7722             : #ifdef SWIGRUNTIME_DEBUG
    7723             :     printf("SWIG_InitializeModule: type %lu %s\n", (unsigned long)i, swig_module.type_initial[i]->name);
    7724             : #endif
    7725             :     
    7726             :     /* if there is another module already loaded */
    7727             :     if (swig_module.next != &swig_module) {
    7728             :       type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name);
    7729             :     }
    7730             :     if (type) {
    7731             :       /* Overwrite clientdata field */
    7732             : #ifdef SWIGRUNTIME_DEBUG
    7733             :       printf("SWIG_InitializeModule: found type %s\n", type->name);
    7734             : #endif
    7735             :       if (swig_module.type_initial[i]->clientdata) {
    7736             :         type->clientdata = swig_module.type_initial[i]->clientdata;
    7737             : #ifdef SWIGRUNTIME_DEBUG
    7738             :         printf("SWIG_InitializeModule: found and overwrite type %s \n", type->name);
    7739             : #endif
    7740             :       }
    7741             :     } else {
    7742             :       type = swig_module.type_initial[i];
    7743             :     }
    7744             :     
    7745             :     /* Insert casting types */
    7746             :     cast = swig_module.cast_initial[i];
    7747             :     while (cast->type) {
    7748             :       /* Don't need to add information already in the list */
    7749             :       ret = 0;
    7750             : #ifdef SWIGRUNTIME_DEBUG
    7751             :       printf("SWIG_InitializeModule: look cast %s\n", cast->type->name);
    7752             : #endif
    7753             :       if (swig_module.next != &swig_module) {
    7754             :         ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name);
    7755             : #ifdef SWIGRUNTIME_DEBUG
    7756             :         if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name);
    7757             : #endif
    7758             :       }
    7759             :       if (ret) {
    7760             :         if (type == swig_module.type_initial[i]) {
    7761             : #ifdef SWIGRUNTIME_DEBUG
    7762             :           printf("SWIG_InitializeModule: skip old type %s\n", ret->name);
    7763             : #endif
    7764             :           cast->type = ret;
    7765             :           ret = 0;
    7766             :         } else {
    7767             :           /* Check for casting already in the list */
    7768             :           swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type);
    7769             : #ifdef SWIGRUNTIME_DEBUG
    7770             :           if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name);
    7771             : #endif
    7772             :           if (!ocast) ret = 0;
    7773             :         }
    7774             :       }
    7775             :       
    7776             :       if (!ret) {
    7777             : #ifdef SWIGRUNTIME_DEBUG
    7778             :         printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name);
    7779             : #endif
    7780             :         if (type->cast) {
    7781             :           type->cast->prev = cast;
    7782             :           cast->next = type->cast;
    7783             :         }
    7784             :         type->cast = cast;
    7785             :       }
    7786             :       cast++;
    7787             :     }
    7788             :     /* Set entry in modules->types array equal to the type */
    7789             :     swig_module.types[i] = type;
    7790             :   }
    7791             :   swig_module.types[i] = 0;
    7792             :   
    7793             : #ifdef SWIGRUNTIME_DEBUG
    7794             :   printf("**** SWIG_InitializeModule: Cast List ******\n");
    7795             :   for (i = 0; i < swig_module.size; ++i) {
    7796             :     int j = 0;
    7797             :     swig_cast_info *cast = swig_module.cast_initial[i];
    7798             :     printf("SWIG_InitializeModule: type %lu %s\n", (unsigned long)i, swig_module.type_initial[i]->name);
    7799             :     while (cast->type) {
    7800             :       printf("SWIG_InitializeModule: cast type %s\n", cast->type->name);
    7801             :       cast++;
    7802             :       ++j;
    7803             :     }
    7804             :     printf("---- Total casts: %d\n",j);
    7805             :   }
    7806             :   printf("**** SWIG_InitializeModule: Cast List ******\n");
    7807             : #endif
    7808             : }
    7809             : 
    7810             : /* This function will propagate the clientdata field of type to
    7811             : * any new swig_type_info structures that have been added into the list
    7812             : * of equivalent types.  It is like calling
    7813             : * SWIG_TypeClientData(type, clientdata) a second time.
    7814             : */
    7815             : SWIGRUNTIME void
    7816             : SWIG_PropagateClientData(void) {
    7817             :   size_t i;
    7818             :   swig_cast_info *equiv;
    7819             :   static int init_run = 0;
    7820             :   
    7821             :   if (init_run) return;
    7822             :   init_run = 1;
    7823             :   
    7824             :   for (i = 0; i < swig_module.size; i++) {
    7825             :     if (swig_module.types[i]->clientdata) {
    7826             :       equiv = swig_module.types[i]->cast;
    7827             :       while (equiv) {
    7828             :         if (!equiv->converter) {
    7829             :           if (equiv->type && !equiv->type->clientdata)
    7830             :           SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata);
    7831             :         }
    7832             :         equiv = equiv->next;
    7833             :       }
    7834             :     }
    7835             :   }
    7836             : }
    7837             : 
    7838             : #ifdef __cplusplus
    7839             : #if 0
    7840             : {
    7841             :   /* c-mode */
    7842             : #endif
    7843             : }
    7844             : #endif
    7845             : 
    7846             : 
    7847             : 
    7848             : #ifdef __cplusplus
    7849             : extern "C" {
    7850             : #endif
    7851             :   
    7852             :   /* Python-specific SWIG API */
    7853             : #define SWIG_newvarlink()                             SWIG_Python_newvarlink()
    7854             : #define SWIG_addvarlink(p, name, get_attr, set_attr)  SWIG_Python_addvarlink(p, name, get_attr, set_attr)
    7855             : #define SWIG_InstallConstants(d, constants)           SWIG_Python_InstallConstants(d, constants)
    7856             :   
    7857             :   /* -----------------------------------------------------------------------------
    7858             :    * global variable support code.
    7859             :    * ----------------------------------------------------------------------------- */
    7860             :   
    7861             :   typedef struct swig_globalvar {
    7862             :     char       *name;                  /* Name of global variable */
    7863             :     PyObject *(*get_attr)(void);       /* Return the current value */
    7864             :     int       (*set_attr)(PyObject *); /* Set the value */
    7865             :     struct swig_globalvar *next;
    7866             :   } swig_globalvar;
    7867             :   
    7868             :   typedef struct swig_varlinkobject {
    7869             :     PyObject_HEAD
    7870             :     swig_globalvar *vars;
    7871             :   } swig_varlinkobject;
    7872             :   
    7873             :   SWIGINTERN PyObject *
    7874             :   swig_varlink_repr(swig_varlinkobject *SWIGUNUSEDPARM(v)) {
    7875             : #if PY_VERSION_HEX >= 0x03000000
    7876             :     return PyUnicode_InternFromString("<Swig global variables>");
    7877             : #else
    7878             :     return PyString_FromString("<Swig global variables>");
    7879             : #endif
    7880             :   }
    7881             :   
    7882             :   SWIGINTERN PyObject *
    7883             :   swig_varlink_str(swig_varlinkobject *v) {
    7884             : #if PY_VERSION_HEX >= 0x03000000
    7885             :     PyObject *str = PyUnicode_InternFromString("(");
    7886             :     PyObject *tail;
    7887             :     PyObject *joined;
    7888             :     swig_globalvar *var;
    7889             :     for (var = v->vars; var; var=var->next) {
    7890             :       tail = PyUnicode_FromString(var->name);
    7891             :       joined = PyUnicode_Concat(str, tail);
    7892             :       Py_DecRef(str);
    7893             :       Py_DecRef(tail);
    7894             :       str = joined;
    7895             :       if (var->next) {
    7896             :         tail = PyUnicode_InternFromString(", ");
    7897             :         joined = PyUnicode_Concat(str, tail);
    7898             :         Py_DecRef(str);
    7899             :         Py_DecRef(tail);
    7900             :         str = joined;
    7901             :       }
    7902             :     }
    7903             :     tail = PyUnicode_InternFromString(")");
    7904             :     joined = PyUnicode_Concat(str, tail);
    7905             :     Py_DecRef(str);
    7906             :     Py_DecRef(tail);
    7907             :     str = joined;
    7908             : #else
    7909             :     PyObject *str = PyString_FromString("(");
    7910             :     swig_globalvar *var;
    7911             :     for (var = v->vars; var; var=var->next) {
    7912             :       PyString_ConcatAndDel(&str,PyString_FromString(var->name));
    7913             :       if (var->next) PyString_ConcatAndDel(&str,PyString_FromString(", "));
    7914             :     }
    7915             :     PyString_ConcatAndDel(&str,PyString_FromString(")"));
    7916             : #endif
    7917             :     return str;
    7918             :   }
    7919             :   
    7920             :   SWIGINTERN void
    7921             :   swig_varlink_dealloc(swig_varlinkobject *v) {
    7922             :     swig_globalvar *var = v->vars;
    7923             :     while (var) {
    7924             :       swig_globalvar *n = var->next;
    7925             :       free(var->name);
    7926             :       free(var);
    7927             :       var = n;
    7928             :     }
    7929             :   }
    7930             :   
    7931             :   SWIGINTERN PyObject *
    7932             :   swig_varlink_getattr(swig_varlinkobject *v, char *n) {
    7933             :     PyObject *res = NULL;
    7934             :     swig_globalvar *var = v->vars;
    7935             :     while (var) {
    7936             :       if (strcmp(var->name,n) == 0) {
    7937             :         res = (*var->get_attr)();
    7938             :         break;
    7939             :       }
    7940             :       var = var->next;
    7941             :     }
    7942             :     if (res == NULL && !PyErr_Occurred()) {
    7943             :       PyErr_Format(PyExc_AttributeError, "Unknown C global variable '%s'", n);
    7944             :     }
    7945             :     return res;
    7946             :   }
    7947             :   
    7948             :   SWIGINTERN int
    7949             :   swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p) {
    7950             :     int res = 1;
    7951             :     swig_globalvar *var = v->vars;
    7952             :     while (var) {
    7953             :       if (strcmp(var->name,n) == 0) {
    7954             :         res = (*var->set_attr)(p);
    7955             :         break;
    7956             :       }
    7957             :       var = var->next;
    7958             :     }
    7959             :     if (res == 1 && !PyErr_Occurred()) {
    7960             :       PyErr_Format(PyExc_AttributeError, "Unknown C global variable '%s'", n);
    7961             :     }
    7962             :     return res;
    7963             :   }
    7964             :   
    7965             :   SWIGINTERN PyTypeObject*
    7966             :   swig_varlink_type(void) {
    7967             :     static char varlink__doc__[] = "Swig var link object";
    7968             :     static PyTypeObject varlink_type;
    7969             :     static int type_init = 0;
    7970             :     if (!type_init) {
    7971             :       const PyTypeObject tmp = {
    7972             : #if PY_VERSION_HEX >= 0x03000000
    7973             :         PyVarObject_HEAD_INIT(NULL, 0)
    7974             : #else
    7975             :         PyObject_HEAD_INIT(NULL)
    7976             :         0,                                  /* ob_size */
    7977             : #endif
    7978             :         "swigvarlink",                      /* tp_name */
    7979             :         sizeof(swig_varlinkobject),         /* tp_basicsize */
    7980             :         0,                                  /* tp_itemsize */
    7981             :         (destructor) swig_varlink_dealloc,  /* tp_dealloc */
    7982             :         0,                                  /* tp_print */
    7983             :         (getattrfunc) swig_varlink_getattr, /* tp_getattr */
    7984             :         (setattrfunc) swig_varlink_setattr, /* tp_setattr */
    7985             :         0,                                  /* tp_compare */
    7986             :         (reprfunc) swig_varlink_repr,       /* tp_repr */
    7987             :         0,                                  /* tp_as_number */
    7988             :         0,                                  /* tp_as_sequence */
    7989             :         0,                                  /* tp_as_mapping */
    7990             :         0,                                  /* tp_hash */
    7991             :         0,                                  /* tp_call */
    7992             :         (reprfunc) swig_varlink_str,        /* tp_str */
    7993             :         0,                                  /* tp_getattro */
    7994             :         0,                                  /* tp_setattro */
    7995             :         0,                                  /* tp_as_buffer */
    7996             :         0,                                  /* tp_flags */
    7997             :         varlink__doc__,                     /* tp_doc */
    7998             :         0,                                  /* tp_traverse */
    7999             :         0,                                  /* tp_clear */
    8000             :         0,                                  /* tp_richcompare */
    8001             :         0,                                  /* tp_weaklistoffset */
    8002             :         0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */
    8003             :         0,                                  /* tp_del */
    8004             :         0,                                  /* tp_version_tag */
    8005             : #if PY_VERSION_HEX >= 0x03040000
    8006             :         0,                                  /* tp_finalize */
    8007             : #endif
    8008             : #ifdef COUNT_ALLOCS
    8009             :         0,                                  /* tp_allocs */
    8010             :         0,                                  /* tp_frees */
    8011             :         0,                                  /* tp_maxalloc */
    8012             :         0,                                  /* tp_prev */
    8013             :         0                                   /* tp_next */
    8014             : #endif
    8015             :       };
    8016             :       varlink_type = tmp;
    8017             :       type_init = 1;
    8018             :       if (PyType_Ready(&varlink_type) < 0)
    8019             :       return NULL;
    8020             :     }
    8021             :     return &varlink_type;
    8022             :   }
    8023             :   
    8024             :   /* Create a variable linking object for use later */
    8025             :   SWIGINTERN PyObject *
    8026             :   SWIG_Python_newvarlink(void) {
    8027             :     swig_varlinkobject *result = PyObject_NEW(swig_varlinkobject, swig_varlink_type());
    8028             :     if (result) {
    8029             :       result->vars = 0;
    8030             :     }
    8031             :     return ((PyObject*) result);
    8032             :   }
    8033             :   
    8034             :   SWIGINTERN void 
    8035             :   SWIG_Python_addvarlink(PyObject *p, const char *name, PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p)) {
    8036             :     swig_varlinkobject *v = (swig_varlinkobject *) p;
    8037             :     swig_globalvar *gv = (swig_globalvar *) malloc(sizeof(swig_globalvar));
    8038             :     if (gv) {
    8039             :       size_t size = strlen(name)+1;
    8040             :       gv->name = (char *)malloc(size);
    8041             :       if (gv->name) {
    8042             :         memcpy(gv->name, name, size);
    8043             :         gv->get_attr = get_attr;
    8044             :         gv->set_attr = set_attr;
    8045             :         gv->next = v->vars;
    8046             :       }
    8047             :     }
    8048             :     v->vars = gv;
    8049             :   }
    8050             :   
    8051             :   SWIGINTERN PyObject *
    8052             :   SWIG_globals(void) {
    8053             :     static PyObject *globals = 0;
    8054             :     if (!globals) {
    8055             :       globals = SWIG_newvarlink();
    8056             :     }
    8057             :     return globals;
    8058             :   }
    8059             :   
    8060             :   /* -----------------------------------------------------------------------------
    8061             :    * constants/methods manipulation
    8062             :    * ----------------------------------------------------------------------------- */
    8063             :   
    8064             :   /* Install Constants */
    8065             :   SWIGINTERN void
    8066         225 :   SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) {
    8067         225 :     PyObject *obj = 0;
    8068         225 :     size_t i;
    8069         450 :     for (i = 0; constants[i].type; ++i) {
    8070         225 :       switch(constants[i].type) {
    8071         225 :       case SWIG_PY_POINTER:
    8072         225 :         obj = SWIG_InternalNewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0);
    8073         225 :         break;
    8074           0 :       case SWIG_PY_BINARY:
    8075           0 :         obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype));
    8076             :         break;
    8077             :       default:
    8078             :         obj = 0;
    8079             :         break;
    8080             :       }
    8081         225 :       if (obj) {
    8082         225 :         PyDict_SetItemString(d, constants[i].name, obj);
    8083         225 :         Py_DECREF(obj);
    8084             :       }
    8085             :     }
    8086         225 :   }
    8087             :   
    8088             :   /* -----------------------------------------------------------------------------*/
    8089             :   /* Fix SwigMethods to carry the callback ptrs when needed */
    8090             :   /* -----------------------------------------------------------------------------*/
    8091             :   
    8092             :   SWIGINTERN void
    8093         225 :   SWIG_Python_FixMethods(PyMethodDef *methods,
    8094             :     swig_const_info *const_table,
    8095             :     swig_type_info **types,
    8096             :     swig_type_info **types_initial) {
    8097         225 :     size_t i;
    8098        5400 :     for (i = 0; methods[i].ml_name; ++i) {
    8099        5175 :       const char *c = methods[i].ml_doc;
    8100        5175 :       if (!c) continue;
    8101        4725 :       c = strstr(c, "swig_ptr: ");
    8102        4725 :       if (c) {
    8103           0 :         int j;
    8104           0 :         swig_const_info *ci = 0;
    8105           0 :         const char *name = c + 10;
    8106           0 :         for (j = 0; const_table[j].type; ++j) {
    8107           0 :           if (strncmp(const_table[j].name, name, 
    8108             :               strlen(const_table[j].name)) == 0) {
    8109             :             ci = &(const_table[j]);
    8110             :             break;
    8111             :           }
    8112             :         }
    8113           0 :         if (ci) {
    8114        5175 :           void *ptr = (ci->type == SWIG_PY_POINTER) ? ci->pvalue : 0;
    8115           0 :           if (ptr) {
    8116           0 :             size_t shift = (ci->ptype) - types;
    8117           0 :             swig_type_info *ty = types_initial[shift];
    8118           0 :             size_t ldoc = (c - methods[i].ml_doc);
    8119           0 :             size_t lptr = strlen(ty->name)+2*sizeof(void*)+2;
    8120           0 :             char *ndoc = (char*)malloc(ldoc + lptr + 10);
    8121           0 :             if (ndoc) {
    8122           0 :               char *buff = ndoc;
    8123           0 :               memcpy(buff, methods[i].ml_doc, ldoc);
    8124           0 :               buff += ldoc;
    8125           0 :               memcpy(buff, "swig_ptr: ", 10);
    8126           0 :               buff += 10;
    8127           0 :               SWIG_PackVoidPtr(buff, ptr, ty->name, lptr);
    8128           0 :               methods[i].ml_doc = ndoc;
    8129             :             }
    8130             :           }
    8131             :         }
    8132             :       }
    8133             :     }
    8134         225 :   } 
    8135             :   
    8136             :   /* -----------------------------------------------------------------------------
    8137             :    * Method creation and docstring support functions
    8138             :    * ----------------------------------------------------------------------------- */
    8139             :   
    8140             :   /* -----------------------------------------------------------------------------
    8141             :    * Function to find the method definition with the correct docstring for the
    8142             :    * proxy module as opposed to the low-level API
    8143             :    * ----------------------------------------------------------------------------- */
    8144             :   
    8145           0 :   SWIGINTERN PyMethodDef *SWIG_PythonGetProxyDoc(const char *name) {
    8146             :     /* Find the function in the modified method table */
    8147           0 :     size_t offset = 0;
    8148           0 :     int found = 0;
    8149           0 :     while (SwigMethods_proxydocs[offset].ml_meth != NULL) {
    8150           0 :       if (strcmp(SwigMethods_proxydocs[offset].ml_name, name) == 0) {
    8151             :         found = 1;
    8152             :         break;
    8153             :       }
    8154           0 :       offset++;
    8155             :     }
    8156             :     /* Use the copy with the modified docstring if available */
    8157           0 :     return found ? &SwigMethods_proxydocs[offset] : NULL;
    8158             :   }
    8159             :   
    8160             :   /* -----------------------------------------------------------------------------
    8161             :    * Wrapper of PyInstanceMethod_New() used in Python 3
    8162             :    * It is exported to the generated module, used for -fastproxy
    8163             :    * ----------------------------------------------------------------------------- */
    8164             :   
    8165           0 :   SWIGINTERN PyObject *SWIG_PyInstanceMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *func) {
    8166           0 :     if (PyCFunction_Check(func)) {
    8167           0 :       PyCFunctionObject *funcobj = (PyCFunctionObject *)func;
    8168           0 :       PyMethodDef *ml = SWIG_PythonGetProxyDoc(funcobj->m_ml->ml_name);
    8169           0 :       if (ml)
    8170           0 :       func = PyCFunction_NewEx(ml, funcobj->m_self, funcobj->m_module);
    8171             :     }
    8172             : #if PY_VERSION_HEX >= 0x03000000
    8173           0 :     return PyInstanceMethod_New(func);
    8174             : #else
    8175             :     return PyMethod_New(func, NULL, NULL);
    8176             : #endif
    8177             :   }
    8178             :   
    8179             :   /* -----------------------------------------------------------------------------
    8180             :    * Wrapper of PyStaticMethod_New()
    8181             :    * It is exported to the generated module, used for -fastproxy
    8182             :    * ----------------------------------------------------------------------------- */
    8183             :   
    8184             :   SWIGINTERN PyObject *SWIG_PyStaticMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *func) {
    8185             :     if (PyCFunction_Check(func)) {
    8186             :       PyCFunctionObject *funcobj = (PyCFunctionObject *)func;
    8187             :       PyMethodDef *ml = SWIG_PythonGetProxyDoc(funcobj->m_ml->ml_name);
    8188             :       if (ml)
    8189             :       func = PyCFunction_NewEx(ml, funcobj->m_self, funcobj->m_module);
    8190             :     }
    8191             :     return PyStaticMethod_New(func);
    8192             :   }
    8193             :   
    8194             : #ifdef __cplusplus
    8195             : }
    8196             : #endif
    8197             : 
    8198             : /* -----------------------------------------------------------------------------*
    8199             :  *  Partial Init method
    8200             :  * -----------------------------------------------------------------------------*/
    8201             : 
    8202             : #ifdef __cplusplus
    8203             : extern "C"
    8204             : #endif
    8205             : 
    8206             : SWIGEXPORT 
    8207             : #if PY_VERSION_HEX >= 0x03000000
    8208             : PyObject*
    8209             : #else
    8210             : void
    8211             : #endif
    8212         225 : SWIG_init(void) {
    8213         225 :   PyObject *m, *d, *md, *globals;
    8214             :   
    8215             : #if PY_VERSION_HEX >= 0x03000000
    8216         225 :   static struct PyModuleDef SWIG_module = {
    8217             :     PyModuleDef_HEAD_INIT,
    8218             :     SWIG_name,
    8219             :     NULL,
    8220             :     -1,
    8221             :     SwigMethods,
    8222             :     NULL,
    8223             :     NULL,
    8224             :     NULL,
    8225             :     NULL
    8226             :   };
    8227             : #endif
    8228             :   
    8229             : #if defined(SWIGPYTHON_BUILTIN)
    8230             :   static SwigPyClientData SwigPyObject_clientdata = {
    8231             :     0, 0, 0, 0, 0, 0, 0
    8232             :   };
    8233             :   static PyGetSetDef this_getset_def = {
    8234             :     (char *)"this", &SwigPyBuiltin_ThisClosure, NULL, NULL, NULL
    8235             :   };
    8236             :   static SwigPyGetSet thisown_getset_closure = {
    8237             :     SwigPyObject_own,
    8238             :     SwigPyObject_own
    8239             :   };
    8240             :   static PyGetSetDef thisown_getset_def = {
    8241             :     (char *)"thisown", SwigPyBuiltin_GetterClosure, SwigPyBuiltin_SetterClosure, NULL, &thisown_getset_closure
    8242             :   };
    8243             :   PyTypeObject *builtin_pytype;
    8244             :   int builtin_base_count;
    8245             :   swig_type_info *builtin_basetype;
    8246             :   PyObject *tuple;
    8247             :   PyGetSetDescrObject *static_getset;
    8248             :   PyTypeObject *metatype;
    8249             :   PyTypeObject *swigpyobject;
    8250             :   SwigPyClientData *cd;
    8251             :   PyObject *public_interface, *public_symbol;
    8252             :   PyObject *this_descr;
    8253             :   PyObject *thisown_descr;
    8254             :   PyObject *self = 0;
    8255             :   int i;
    8256             :   
    8257             :   (void)builtin_pytype;
    8258             :   (void)builtin_base_count;
    8259             :   (void)builtin_basetype;
    8260             :   (void)tuple;
    8261             :   (void)static_getset;
    8262             :   (void)self;
    8263             :   
    8264             :   /* Metaclass is used to implement static member variables */
    8265             :   metatype = SwigPyObjectType();
    8266             :   assert(metatype);
    8267             : #endif
    8268             :   
    8269         225 :   (void)globals;
    8270             :   
    8271             :   /* Create singletons now to avoid potential deadlocks with multi-threaded usage after module initialization */
    8272         225 :   SWIG_This();
    8273         225 :   SWIG_Python_TypeCache();
    8274         225 :   SwigPyPacked_type();
    8275             : #ifndef SWIGPYTHON_BUILTIN
    8276         225 :   SwigPyObject_type();
    8277             : #endif
    8278             :   
    8279             :   /* Fix SwigMethods to carry the callback ptrs when needed */
    8280         225 :   SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_type_initial);
    8281             :   
    8282             : #if PY_VERSION_HEX >= 0x03000000
    8283         225 :   m = PyModule_Create(&SWIG_module);
    8284             : #else
    8285             :   m = Py_InitModule(SWIG_name, SwigMethods);
    8286             : #endif
    8287             :   
    8288         225 :   md = d = PyModule_GetDict(m);
    8289         225 :   (void)md;
    8290             :   
    8291         225 :   SWIG_InitializeModule(0);
    8292             :   
    8293             : #ifdef SWIGPYTHON_BUILTIN
    8294             :   swigpyobject = SwigPyObject_TypeOnce();
    8295             :   
    8296             :   SwigPyObject_stype = SWIG_MangledTypeQuery("_p_SwigPyObject");
    8297             :   assert(SwigPyObject_stype);
    8298             :   cd = (SwigPyClientData*) SwigPyObject_stype->clientdata;
    8299             :   if (!cd) {
    8300             :     SwigPyObject_stype->clientdata = &SwigPyObject_clientdata;
    8301             :     SwigPyObject_clientdata.pytype = swigpyobject;
    8302             :   } else if (swigpyobject->tp_basicsize != cd->pytype->tp_basicsize) {
    8303             :     PyErr_SetString(PyExc_RuntimeError, "Import error: attempted to load two incompatible swig-generated modules.");
    8304             : # if PY_VERSION_HEX >= 0x03000000
    8305             :     return NULL;
    8306             : # else
    8307             :     return;
    8308             : # endif
    8309             :   }
    8310             :   
    8311             :   /* All objects have a 'this' attribute */
    8312             :   this_descr = PyDescr_NewGetSet(SwigPyObject_type(), &this_getset_def);
    8313             :   (void)this_descr;
    8314             :   
    8315             :   /* All objects have a 'thisown' attribute */
    8316             :   thisown_descr = PyDescr_NewGetSet(SwigPyObject_type(), &thisown_getset_def);
    8317             :   (void)thisown_descr;
    8318             :   
    8319             :   public_interface = PyList_New(0);
    8320             :   public_symbol = 0;
    8321             :   (void)public_symbol;
    8322             :   
    8323             :   PyDict_SetItemString(md, "__all__", public_interface);
    8324             :   Py_DECREF(public_interface);
    8325             :   for (i = 0; SwigMethods[i].ml_name != NULL; ++i)
    8326             :   SwigPyBuiltin_AddPublicSymbol(public_interface, SwigMethods[i].ml_name);
    8327             :   for (i = 0; swig_const_table[i].name != 0; ++i)
    8328             :   SwigPyBuiltin_AddPublicSymbol(public_interface, swig_const_table[i].name);
    8329             : #endif
    8330             :   
    8331         225 :   SWIG_InstallConstants(d,swig_const_table);
    8332             :   
    8333             :   
    8334             : #if SWIG_VERSION >= 0x040400
    8335             :   import_array1(-1);
    8336             : #else
    8337         225 :   import_array();
    8338             : #endif
    8339         225 :   PyDateTime_IMPORT;
    8340         225 :   GDALRegister_NUMPY();
    8341             :   
    8342             :   
    8343             :   
    8344             :   /* Initialize threading */
    8345         225 :   SWIG_PYTHON_INITIALIZE_THREADS;
    8346             : #if PY_VERSION_HEX >= 0x03000000
    8347         225 :   return m;
    8348             : #else
    8349             :   return;
    8350             : #endif
    8351             : }
    8352             : 

Generated by: LCOV version 1.14