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: 1867 2921 63.9 %
Date: 2026-04-19 18:43: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        4427 : SWIG_TypeCheck(const char *c, swig_type_info *ty) {
     448        4427 :   if (ty) {
     449        4427 :     swig_cast_info *iter = ty->cast;
     450        4893 :     while (iter) {
     451        4893 :       if (strcmp(iter->type->name, c) == 0) {
     452        4427 :         if (iter == ty->cast)
     453             :           return iter;
     454             :         /* Move iter to the top of the linked list */
     455         466 :         iter->prev->next = iter->next;
     456         466 :         if (iter->next)
     457           0 :           iter->next->prev = iter->prev;
     458         466 :         iter->next = ty->cast;
     459         466 :         iter->prev = 0;
     460         466 :         if (ty->cast) ty->cast->prev = iter;
     461         466 :         ty->cast = iter;
     462         466 :         return iter;
     463             :       }
     464         466 :       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         233 : SWIG_TypeNewClientData(swig_type_info *ti, void *clientdata) {
     570         233 :   SWIG_TypeClientData(ti, clientdata);
     571         233 :   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       10485 : SWIG_MangledTypeQueryModule(swig_module_info *start,
     584             :                             swig_module_info *end,
     585             :                 const char *name) {
     586       10485 :   swig_module_info *iter = start;
     587       32620 :   do {
     588       32620 :     if (iter->size) {
     589       32620 :       size_t l = 0;
     590       32620 :       size_t r = iter->size - 1;
     591      128383 :       do {
     592             :   /* since l+r >= 0, we can (>> 1) instead (/ 2) */
     593      128383 :   size_t i = (l + r) >> 1;
     594      128383 :   const char *iname = iter->types[i]->name;
     595      128383 :   if (iname) {
     596      128383 :     int compare = strcmp(name, iname);
     597      128383 :     if (compare == 0) {
     598        8621 :       return iter->types[i];
     599      119762 :     } else if (compare < 0) {
     600       67570 :       if (i) {
     601       55920 :         r = i - 1;
     602             :       } else {
     603             :         break;
     604             :       }
     605       52192 :     } else if (compare > 0) {
     606       52192 :       l = i + 1;
     607             :     }
     608             :   } else {
     609             :     break; /* should never happen */
     610             :   }
     611      108112 :       } while (l <= r);
     612             :     }
     613       23999 :     iter = iter->next;
     614       23999 :   } 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         233 : SWIG_Python_str_FromChar(const char *c)
     838             : {
     839             : #if PY_VERSION_HEX >= 0x03000000
     840         233 :   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          43 : SWIG_Python_ErrorType(int code) {
     867          43 :   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          37 :   case SWIG_RuntimeError:
     876          37 :     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          43 :   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         972 :          void end() { if (status) { PyGILState_Release(state); status = false;} }
     985         708 :          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       89586 :          void end() { if (status) { PyEval_RestoreThread(save); status = false; }}
     993       89586 :          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          43 : SWIG_Python_SetErrorMsg(PyObject *errtype, const char *msg) {
    1142          43 :   SWIG_PYTHON_THREAD_BEGIN_BLOCK;
    1143          43 :   PyErr_SetString(errtype, msg);
    1144          43 :   SWIG_PYTHON_THREAD_END_BLOCK;
    1145          43 : }
    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         859 : SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t max, PyObject **objs)
    1203             : {
    1204         859 :   if (!args) {
    1205          37 :     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         822 :   if (!PyTuple_Check(args)) {
    1214         233 :     if (min <= 1 && max >= 1) {
    1215         233 :       Py_ssize_t i;
    1216         233 :       objs[0] = args;
    1217         233 :       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         589 :     Py_ssize_t l = PyTuple_GET_SIZE(args);
    1226         589 :     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         589 :     } 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        2578 :       for (i = 0; i < l; ++i) {
    1237        1989 :   objs[i] = PyTuple_GET_ITEM(args, i);
    1238             :       }
    1239         589 :       for (; l < max; ++l) {
    1240           0 :   objs[l] = 0;
    1241             :       }
    1242         589 :       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       25475 : SWIG_Py_Void(void)
    1281             : {
    1282       25475 :   PyObject *none = Py_None;
    1283           0 :   Py_INCREF(none);
    1284         236 :   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         233 : SwigPyClientData_New(PyObject* obj)
    1319             : {
    1320         233 :   if (!obj) {
    1321             :     return 0;
    1322             :   } else {
    1323         233 :     SwigPyClientData *data = (SwigPyClientData *)malloc(sizeof(SwigPyClientData));
    1324             :     /* the klass element */
    1325         233 :     data->klass = obj;
    1326         233 :     Py_INCREF(data->klass);
    1327             :     /* the newraw method and newargs arguments used to create a new raw instance */
    1328         233 :     if (PyClass_Check(obj)) {
    1329         233 :       data->newraw = 0;
    1330         233 :       data->newargs = obj;
    1331         233 :       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         233 :     data->destroy = PyObject_GetAttrString(data->klass, "__swig_destroy__");
    1345         233 :     if (PyErr_Occurred()) {
    1346           0 :       PyErr_Clear();
    1347           0 :       data->destroy = 0;
    1348             :     }
    1349         233 :     if (data->destroy) {
    1350         233 :       int flags;
    1351         233 :       Py_INCREF(data->destroy);
    1352         233 :       flags = PyCFunction_GET_FLAGS(data->destroy);
    1353         233 :       data->delargs = !(flags & (METH_O));
    1354             :     } else {
    1355           0 :       data->delargs = 0;
    1356             :     }
    1357         233 :     data->implicitconv = 0;
    1358         233 :     data->pytype = 0;
    1359         233 :     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       40376 : SwigPyObject_type(void) {
    1505       40376 :   static PyTypeObject *SWIG_STATIC_POINTER(type) = SwigPyObject_TypeOnce();
    1506       40376 :   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         233 : SwigPyObject_TypeOnce(void) {
    1651         233 :   static char swigobject_doc[] = "Swig object carries a C/C++ instance pointer";
    1652             : 
    1653         233 :   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         233 :   static PyTypeObject swigpyobject_type;
    1698         233 :   static int type_init = 0;
    1699         233 :   if (!type_init) {
    1700         233 :     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         233 :     swigpyobject_type = tmp;
    1769         233 :     type_init = 1;
    1770         233 :     if (PyType_Ready(&swigpyobject_type) < 0)
    1771           0 :       return NULL;
    1772             :   }
    1773             :   return &swigpyobject_type;
    1774             : }
    1775             : 
    1776             : SWIGRUNTIME PyObject *
    1777         279 : SwigPyObject_New(void *ptr, swig_type_info *ty, int own)
    1778             : {
    1779         279 :   SwigPyObject *sobj = PyObject_NEW(SwigPyObject, SwigPyObject_type());
    1780         279 :   if (sobj) {
    1781         279 :     sobj->ptr  = ptr;
    1782         279 :     sobj->ty   = ty;
    1783         279 :     sobj->own  = own;
    1784         279 :     sobj->next = 0;
    1785             :   }
    1786         279 :   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         233 : SwigPyPacked_type(void) {
    1835         233 :   static PyTypeObject *SWIG_STATIC_POINTER(type) = SwigPyPacked_TypeOnce();
    1836         233 :   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         233 : SwigPyPacked_TypeOnce(void) {
    1857         233 :   static char swigpacked_doc[] = "Swig object carries a C/C++ instance pointer";
    1858         233 :   static PyTypeObject swigpypacked_type;
    1859         233 :   static int type_init = 0;
    1860         233 :   if (!type_init) {
    1861         233 :     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         233 :     swigpypacked_type = tmp;
    1930         233 :     type_init = 1;
    1931         233 :     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       20015 : SWIG_This(void)
    1977             : {
    1978       20015 :   if (Swig_This_global == NULL)
    1979         233 :     Swig_This_global = SWIG_Python_str_FromChar("this");
    1980       20015 :   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       19810 : SWIG_Python_GetSwigThis(PyObject *pyobj) 
    1992             : {
    1993       19810 :   PyObject *obj;
    1994             : 
    1995       19810 :   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       19782 :   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       19782 :   obj = PyObject_GetAttr(pyobj,SWIG_This());
    2038       19782 :   if (obj) {
    2039       19775 :     Py_DECREF(obj);
    2040             :   } else {
    2041           7 :     if (PyErr_Occurred()) PyErr_Clear();
    2042           7 :     return 0;
    2043             :   }
    2044             : #endif
    2045       19775 :   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       19810 : SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int flags, int *own) {
    2073       19810 :   int res;
    2074       19810 :   SwigPyObject *sobj;
    2075       19810 :   int implicit_conv = (flags & SWIG_POINTER_IMPLICIT_CONV) != 0;
    2076             : 
    2077       19810 :   if (!obj)
    2078             :     return SWIG_ERROR;
    2079       19810 :   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       19810 :   res = SWIG_ERROR;
    2086             : 
    2087       19810 :   sobj = SWIG_Python_GetSwigThis(obj);
    2088       19810 :   if (own)
    2089           0 :     *own = 0;
    2090       19810 :   while (sobj) {
    2091       19803 :     void *vptr = sobj->ptr;
    2092       19803 :     if (ty) {
    2093       19803 :       swig_type_info *to = sobj->ty;
    2094       19803 :       if (to == ty) {
    2095             :         /* no type cast needed */
    2096       19803 :         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       19810 :   if (sobj) {
    2121       19803 :     if (own)
    2122           0 :       *own = *own | sobj->own;
    2123       19803 :     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         282 : SWIG_Python_NewPointerObj(PyObject *self, void *ptr, swig_type_info *type, int flags) {
    2320         282 :   SwigPyClientData *clientdata;
    2321         282 :   PyObject * robj;
    2322         282 :   int own;
    2323             : 
    2324         282 :   if (!ptr)
    2325           3 :     return SWIG_Py_Void();
    2326             : 
    2327         279 :   clientdata = type ? (SwigPyClientData *)(type->clientdata) : 0;
    2328         279 :   own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0;
    2329         279 :   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         279 :   assert(!(flags & SWIG_BUILTIN_TP_INIT));
    2360             : 
    2361         279 :   robj = SwigPyObject_New(ptr, type, own);
    2362         279 :   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         233 : SWIG_Python_TypeCache(void) {
    2440         233 :   static PyObject *SWIG_STATIC_POINTER(cache) = PyDict_New();
    2441         233 :   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_GDALRATDateTime swig_types[9]
    2674             : #define SWIGTYPE_p_GDALRasterAttributeTableShadow swig_types[10]
    2675             : #define SWIGTYPE_p_GDALRasterBandShadow swig_types[11]
    2676             : #define SWIGTYPE_p_GIntBig swig_types[12]
    2677             : #define SWIGTYPE_p_GUIntBig swig_types[13]
    2678             : #define SWIGTYPE_p_PyArrayObject swig_types[14]
    2679             : #define SWIGTYPE_p_char swig_types[15]
    2680             : #define SWIGTYPE_p_f_double_p_q_const__char_p_void__int swig_types[16]
    2681             : #define SWIGTYPE_p_int swig_types[17]
    2682             : #define SWIGTYPE_p_p_CPLVirtualMemShadow swig_types[18]
    2683             : #define SWIGTYPE_p_p_void swig_types[19]
    2684             : #define SWIGTYPE_p_size_t swig_types[20]
    2685             : #define SWIGTYPE_p_std__string swig_types[21]
    2686             : static swig_type_info *swig_types[23];
    2687             : static swig_module_info swig_module = {swig_types, 22, 0, 0, 0, 0};
    2688             : #define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name)
    2689             : #define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name)
    2690             : 
    2691             : /* -------- TYPES TABLE (END) -------- */
    2692             : 
    2693             : #ifdef SWIG_TypeQuery
    2694             : # undef SWIG_TypeQuery
    2695             : #endif
    2696             : #define SWIG_TypeQuery SWIG_Python_TypeQuery
    2697             : 
    2698             : /*-----------------------------------------------
    2699             :               @(target):= _gdal_array.so
    2700             :   ------------------------------------------------*/
    2701             : #if PY_VERSION_HEX >= 0x03000000
    2702             : #  define SWIG_init    PyInit__gdal_array
    2703             : 
    2704             : #else
    2705             : #  define SWIG_init    init_gdal_array
    2706             : 
    2707             : #endif
    2708             : #define SWIG_name    "_gdal_array"
    2709             : 
    2710             : #define SWIGVERSION 0x040001 
    2711             : #define SWIG_VERSION SWIGVERSION
    2712             : 
    2713             : 
    2714             : #define SWIG_as_voidptr(a) const_cast< void * >(static_cast< const void * >(a)) 
    2715             : #define SWIG_as_voidptrptr(a) ((void)SWIG_as_voidptr(*a),reinterpret_cast< void** >(a)) 
    2716             : 
    2717             : 
    2718             : #include <stdexcept>
    2719             : 
    2720             : 
    2721             : namespace swig {
    2722             :   class SwigPtr_PyObject {
    2723             :   protected:
    2724             :     PyObject *_obj;
    2725             : 
    2726             :   public:
    2727             :     SwigPtr_PyObject() :_obj(0)
    2728             :     {
    2729             :     }
    2730             : 
    2731             :     SwigPtr_PyObject(const SwigPtr_PyObject& item) : _obj(item._obj)
    2732             :     {
    2733             :       SWIG_PYTHON_THREAD_BEGIN_BLOCK;
    2734             :       Py_XINCREF(_obj);      
    2735             :       SWIG_PYTHON_THREAD_END_BLOCK;
    2736             :     }
    2737             :     
    2738             :     SwigPtr_PyObject(PyObject *obj, bool initial_ref = true) :_obj(obj)
    2739             :     {
    2740             :       if (initial_ref) {
    2741             :         SWIG_PYTHON_THREAD_BEGIN_BLOCK;
    2742             :         Py_XINCREF(_obj);
    2743             :         SWIG_PYTHON_THREAD_END_BLOCK;
    2744             :       }
    2745             :     }
    2746             :     
    2747             :     SwigPtr_PyObject & operator=(const SwigPtr_PyObject& item) 
    2748             :     {
    2749             :       SWIG_PYTHON_THREAD_BEGIN_BLOCK;
    2750             :       Py_XINCREF(item._obj);
    2751             :       Py_XDECREF(_obj);
    2752             :       _obj = item._obj;
    2753             :       SWIG_PYTHON_THREAD_END_BLOCK;
    2754             :       return *this;      
    2755             :     }
    2756             :     
    2757             :     ~SwigPtr_PyObject() 
    2758             :     {
    2759             :       SWIG_PYTHON_THREAD_BEGIN_BLOCK;
    2760             :       Py_XDECREF(_obj);
    2761             :       SWIG_PYTHON_THREAD_END_BLOCK;
    2762             :     }
    2763             :     
    2764             :     operator PyObject *() const
    2765             :     {
    2766             :       return _obj;
    2767             :     }
    2768             : 
    2769             :     PyObject *operator->() const
    2770             :     {
    2771             :       return _obj;
    2772             :     }
    2773             :   };
    2774             : }
    2775             : 
    2776             : 
    2777             : namespace swig {
    2778             :   struct SwigVar_PyObject : SwigPtr_PyObject {
    2779             :     SwigVar_PyObject(PyObject* obj = 0) : SwigPtr_PyObject(obj, false) { }
    2780             :     
    2781             :     SwigVar_PyObject & operator = (PyObject* obj)
    2782             :     {
    2783             :       Py_XDECREF(_obj);
    2784             :       _obj = obj;
    2785             :       return *this;      
    2786             :     }
    2787             :   };
    2788             : }
    2789             : 
    2790             : 
    2791             : #include "gdal.h"
    2792             : 
    2793             : typedef struct
    2794             : {
    2795             :     CPLVirtualMem *vmem;
    2796             :     int            bAuto;
    2797             :     GDALDataType   eBufType;
    2798             :     int            bIsBandSequential;
    2799             :     int            bReadOnly;
    2800             :     int            nBufXSize;
    2801             :     int            nBufYSize;
    2802             :     int            nBandCount;
    2803             :     GDALTileOrganization eTileOrganization;
    2804             :     int                  nTileXSize;
    2805             :     int                  nTileYSize;
    2806             :     int            nPixelSpace; /* if bAuto == TRUE */
    2807             :     GIntBig        nLineSpace; /* if bAuto == TRUE */
    2808             : } CPLVirtualMemShadow;
    2809             : 
    2810             : 
    2811          28 : SWIGINTERN void delete_CPLVirtualMemShadow(CPLVirtualMemShadow *self){
    2812          28 :         CPLVirtualMemFree( self->vmem );
    2813          28 :         free(self);
    2814             :     }
    2815           0 : SWIGINTERN void CPLVirtualMemShadow_GetAddr(CPLVirtualMemShadow *self,void **pptr,size_t *pnsize,GDALDataType *pdatatype,int *preadonly){
    2816           0 :         *pptr = CPLVirtualMemGetAddr( self->vmem );
    2817           0 :         *pnsize = CPLVirtualMemGetSize( self->vmem );
    2818           0 :         *pdatatype = self->eBufType;
    2819           0 :         *preadonly = self->bReadOnly;
    2820             :     }
    2821             : 
    2822             : SWIGINTERN int
    2823       78016 : SWIG_AsVal_double (PyObject *obj, double *val)
    2824             : {
    2825       78016 :   int res = SWIG_TypeError;
    2826       78016 :   if (PyFloat_Check(obj)) {
    2827         278 :     if (val) *val = PyFloat_AsDouble(obj);
    2828         278 :     return SWIG_OK;
    2829             : #if PY_VERSION_HEX < 0x03000000
    2830             :   } else if (PyInt_Check(obj)) {
    2831             :     if (val) *val = (double) PyInt_AsLong(obj);
    2832             :     return SWIG_OK;
    2833             : #endif
    2834       77738 :   } else if (PyLong_Check(obj)) {
    2835       77738 :     double v = PyLong_AsDouble(obj);
    2836       77738 :     if (!PyErr_Occurred()) {
    2837       77738 :       if (val) *val = v;
    2838       77738 :       return SWIG_OK;
    2839             :     } else {
    2840           0 :       PyErr_Clear();
    2841             :     }
    2842             :   }
    2843             : #ifdef SWIG_PYTHON_CAST_MODE
    2844             :   {
    2845             :     int dispatch = 0;
    2846             :     double d = PyFloat_AsDouble(obj);
    2847             :     if (!PyErr_Occurred()) {
    2848             :       if (val) *val = d;
    2849             :       return SWIG_AddCast(SWIG_OK);
    2850             :     } else {
    2851             :       PyErr_Clear();
    2852             :     }
    2853             :     if (!dispatch) {
    2854             :       long v = PyLong_AsLong(obj);
    2855             :       if (!PyErr_Occurred()) {
    2856             :   if (val) *val = v;
    2857             :   return SWIG_AddCast(SWIG_AddCast(SWIG_OK));
    2858             :       } else {
    2859             :   PyErr_Clear();
    2860             :       }
    2861             :     }
    2862             :   }
    2863             : #endif
    2864             :   return res;
    2865             : }
    2866             : 
    2867             : 
    2868             : #include <float.h>
    2869             : 
    2870             : 
    2871             : #include <math.h>
    2872             : 
    2873             : 
    2874             : SWIGINTERNINLINE int
    2875             : SWIG_CanCastAsInteger(double *d, double min, double max) {
    2876             :   double x = *d;
    2877             :   if ((min <= x && x <= max)) {
    2878             :    double fx = floor(x);
    2879             :    double cx = ceil(x);
    2880             :    double rd =  ((x - fx) < 0.5) ? fx : cx; /* simple rint */
    2881             :    if ((errno == EDOM) || (errno == ERANGE)) {
    2882             :      errno = 0;
    2883             :    } else {
    2884             :      double summ, reps, diff;
    2885             :      if (rd < x) {
    2886             :        diff = x - rd;
    2887             :      } else if (rd > x) {
    2888             :        diff = rd - x;
    2889             :      } else {
    2890             :        return 1;
    2891             :      }
    2892             :      summ = rd + x;
    2893             :      reps = diff/summ;
    2894             :      if (reps < 8*DBL_EPSILON) {
    2895             :        *d = rd;
    2896             :        return 1;
    2897             :      }
    2898             :    }
    2899             :   }
    2900             :   return 0;
    2901             : }
    2902             : 
    2903             : 
    2904             : SWIGINTERN int
    2905           0 : SWIG_AsVal_unsigned_SS_long (PyObject *obj, unsigned long *val) 
    2906             : {
    2907             : #if PY_VERSION_HEX < 0x03000000
    2908             :   if (PyInt_Check(obj)) {
    2909             :     long v = PyInt_AsLong(obj);
    2910             :     if (v >= 0) {
    2911             :       if (val) *val = v;
    2912             :       return SWIG_OK;
    2913             :     } else {
    2914             :       return SWIG_OverflowError;
    2915             :     }
    2916             :   } else
    2917             : #endif
    2918           0 :   if (PyLong_Check(obj)) {
    2919           0 :     unsigned long v = PyLong_AsUnsignedLong(obj);
    2920           0 :     if (!PyErr_Occurred()) {
    2921           0 :       if (val) *val = v;
    2922           0 :       return SWIG_OK;
    2923             :     } else {
    2924           0 :       PyErr_Clear();
    2925           0 :       return SWIG_OverflowError;
    2926             :     }
    2927             :   }
    2928             : #ifdef SWIG_PYTHON_CAST_MODE
    2929             :   {
    2930             :     int dispatch = 0;
    2931             :     unsigned long v = PyLong_AsUnsignedLong(obj);
    2932             :     if (!PyErr_Occurred()) {
    2933             :       if (val) *val = v;
    2934             :       return SWIG_AddCast(SWIG_OK);
    2935             :     } else {
    2936             :       PyErr_Clear();
    2937             :     }
    2938             :     if (!dispatch) {
    2939             :       double d;
    2940             :       int res = SWIG_AddCast(SWIG_AsVal_double (obj,&d));
    2941             :       if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, 0, ULONG_MAX)) {
    2942             :   if (val) *val = (unsigned long)(d);
    2943             :   return res;
    2944             :       }
    2945             :     }
    2946             :   }
    2947             : #endif
    2948             :   return SWIG_TypeError;
    2949             : }
    2950             : 
    2951             : 
    2952             : #include <limits.h>
    2953             : #if !defined(SWIG_NO_LLONG_MAX)
    2954             : # if !defined(LLONG_MAX) && defined(__GNUC__) && defined (__LONG_LONG_MAX__)
    2955             : #   define LLONG_MAX __LONG_LONG_MAX__
    2956             : #   define LLONG_MIN (-LLONG_MAX - 1LL)
    2957             : #   define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL)
    2958             : # endif
    2959             : #endif
    2960             : 
    2961             : 
    2962             : #if defined(LLONG_MAX) && !defined(SWIG_LONG_LONG_AVAILABLE)
    2963             : #  define SWIG_LONG_LONG_AVAILABLE
    2964             : #endif
    2965             : 
    2966             : 
    2967             : #ifdef SWIG_LONG_LONG_AVAILABLE
    2968             : SWIGINTERN int
    2969             : SWIG_AsVal_unsigned_SS_long_SS_long (PyObject *obj, unsigned long long *val)
    2970             : {
    2971             :   int res = SWIG_TypeError;
    2972             :   if (PyLong_Check(obj)) {
    2973             :     unsigned long long v = PyLong_AsUnsignedLongLong(obj);
    2974             :     if (!PyErr_Occurred()) {
    2975             :       if (val) *val = v;
    2976             :       return SWIG_OK;
    2977             :     } else {
    2978             :       PyErr_Clear();
    2979             :       res = SWIG_OverflowError;
    2980             :     }
    2981             :   } else {
    2982             :     unsigned long v;
    2983             :     res = SWIG_AsVal_unsigned_SS_long (obj,&v);
    2984             :     if (SWIG_IsOK(res)) {
    2985             :       if (val) *val = v;
    2986             :       return res;
    2987             :     }
    2988             :   }
    2989             : #ifdef SWIG_PYTHON_CAST_MODE
    2990             :   {
    2991             :     const double mant_max = 1LL << DBL_MANT_DIG;
    2992             :     double d;
    2993             :     res = SWIG_AsVal_double (obj,&d);
    2994             :     if (SWIG_IsOK(res) && !SWIG_CanCastAsInteger(&d, 0, mant_max))
    2995             :       return SWIG_OverflowError;
    2996             :     if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, 0, mant_max)) {
    2997             :       if (val) *val = (unsigned long long)(d);
    2998             :       return SWIG_AddCast(res);
    2999             :     }
    3000             :     res = SWIG_TypeError;
    3001             :   }
    3002             : #endif
    3003             :   return res;
    3004             : }
    3005             : #endif
    3006             : 
    3007             : 
    3008             : SWIGINTERNINLINE int
    3009           0 : SWIG_AsVal_size_t (PyObject * obj, size_t *val)
    3010             : {
    3011           0 :   int res = SWIG_TypeError;
    3012             : #ifdef SWIG_LONG_LONG_AVAILABLE
    3013           0 :   if (sizeof(size_t) <= sizeof(unsigned long)) {
    3014             : #endif
    3015           0 :     unsigned long v;
    3016           0 :     res = SWIG_AsVal_unsigned_SS_long (obj, val ? &v : 0);
    3017           0 :     if (SWIG_IsOK(res) && val) *val = static_cast< size_t >(v);
    3018             : #ifdef SWIG_LONG_LONG_AVAILABLE
    3019             :   } else if (sizeof(size_t) <= sizeof(unsigned long long)) {
    3020             :     unsigned long long v;
    3021             :     res = SWIG_AsVal_unsigned_SS_long_SS_long (obj, val ? &v : 0);
    3022             :     if (SWIG_IsOK(res) && val) *val = static_cast< size_t >(v);
    3023             :   }
    3024             : #endif
    3025           0 :   return res;
    3026             : }
    3027             : 
    3028             : 
    3029             : SWIGINTERN int
    3030      103361 : SWIG_AsVal_long (PyObject *obj, long* val)
    3031             : {
    3032             : #if PY_VERSION_HEX < 0x03000000
    3033             :   if (PyInt_Check(obj)) {
    3034             :     if (val) *val = PyInt_AsLong(obj);
    3035             :     return SWIG_OK;
    3036             :   } else
    3037             : #endif
    3038      103361 :   if (PyLong_Check(obj)) {
    3039      103359 :     long v = PyLong_AsLong(obj);
    3040      103359 :     if (!PyErr_Occurred()) {
    3041      103359 :       if (val) *val = v;
    3042      103359 :       return SWIG_OK;
    3043             :     } else {
    3044           0 :       PyErr_Clear();
    3045           0 :       return SWIG_OverflowError;
    3046             :     }
    3047             :   }
    3048             : #ifdef SWIG_PYTHON_CAST_MODE
    3049             :   {
    3050             :     int dispatch = 0;
    3051             :     long v = PyInt_AsLong(obj);
    3052             :     if (!PyErr_Occurred()) {
    3053             :       if (val) *val = v;
    3054             :       return SWIG_AddCast(SWIG_OK);
    3055             :     } else {
    3056             :       PyErr_Clear();
    3057             :     }
    3058             :     if (!dispatch) {
    3059             :       double d;
    3060             :       int res = SWIG_AddCast(SWIG_AsVal_double (obj,&d));
    3061             :       if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, LONG_MIN, LONG_MAX)) {
    3062             :   if (val) *val = (long)(d);
    3063             :   return res;
    3064             :       }
    3065             :     }
    3066             :   }
    3067             : #endif
    3068             :   return SWIG_TypeError;
    3069             : }
    3070             : 
    3071             : 
    3072             : SWIGINTERN int
    3073      103361 : SWIG_AsVal_int (PyObject * obj, int *val)
    3074             : {
    3075      103361 :   long v;
    3076      206722 :   int res = SWIG_AsVal_long (obj, &v);
    3077      103361 :   if (SWIG_IsOK(res)) {
    3078      103359 :     if ((v < INT_MIN || v > INT_MAX)) {
    3079             :       return SWIG_OverflowError;
    3080             :     } else {
    3081      103359 :       if (val) *val = static_cast< int >(v);
    3082             :     }
    3083             :   }  
    3084             :   return res;
    3085             : }
    3086             : 
    3087             : SWIGINTERN void CPLVirtualMemShadow_Pin__SWIG_0(CPLVirtualMemShadow *self,size_t start_offset=0,size_t nsize=0,int bWriteOp=0){
    3088             :         if( nsize == 0 || start_offset + nsize >= CPLVirtualMemGetSize( self->vmem ) )
    3089             :             nsize = CPLVirtualMemGetSize( self->vmem ) - start_offset;
    3090             :         char* start_addr = (char*)CPLVirtualMemGetAddr( self->vmem ) + start_offset;
    3091             :         CPLVirtualMemPin(self->vmem, start_addr, nsize, bWriteOp);
    3092             :     }
    3093             : 
    3094             : #include "cpl_string.h"
    3095             : #include "cpl_conv.h"
    3096             : 
    3097             : static int bUseExceptions=0;
    3098             : static int bUserHasSpecifiedIfUsingExceptions = FALSE;
    3099             : static thread_local int bUseExceptionsLocal = -1;
    3100             : 
    3101       16926 : struct PythonBindingErrorHandlerContext
    3102             : {
    3103             :     std::string     osInitialMsg{};
    3104             :     std::string     osFailureMsg{};
    3105             :     CPLErrorNum     nLastCode = CPLE_None;
    3106             :     bool            bMemoryError = false;
    3107             : };
    3108             : 
    3109             : static void CPL_STDCALL
    3110         356 : PythonBindingErrorHandler(CPLErr eclass, CPLErrorNum err_no, const char *msg )
    3111             : {
    3112         356 :   PythonBindingErrorHandlerContext* ctxt = static_cast<
    3113         356 :       PythonBindingErrorHandlerContext*>(CPLGetErrorHandlerUserData());
    3114             : 
    3115             :   /*
    3116             :   ** Generally we want to suppress error reporting if we have exceptions
    3117             :   ** enabled as the error message will be in the exception thrown in
    3118             :   ** Python.
    3119             :   */
    3120             : 
    3121             :   /* If the error class is CE_Fatal, we want to have a message issued
    3122             :      because the CPL support code does an abort() before any exception
    3123             :      can be generated */
    3124         356 :   if (eclass == CE_Fatal ) {
    3125           0 :     CPLCallPreviousHandler(eclass, err_no, msg );
    3126             :   }
    3127             : 
    3128             :   /*
    3129             :   ** We do not want to interfere with non-failure messages since
    3130             :   ** they won't be translated into exceptions.
    3131             :   */
    3132         356 :   else if (eclass != CE_Failure ) {
    3133         302 :     CPLCallPreviousHandler(eclass, err_no, msg );
    3134             :   }
    3135             :   else {
    3136          54 :     ctxt->nLastCode = err_no;
    3137          54 :     try
    3138             :     {
    3139          54 :         if( ctxt->osFailureMsg.empty() ) {
    3140          37 :           ctxt->osFailureMsg = msg;
    3141          37 :           ctxt->osInitialMsg = ctxt->osFailureMsg;
    3142             :         } else {
    3143          17 :           if( ctxt->osFailureMsg.size() < 10000 ) {
    3144          34 :             std::string osTmp(msg);
    3145          17 :             osTmp += "\nMay be caused by: ";
    3146          17 :             osTmp += ctxt->osFailureMsg;
    3147          17 :             ctxt->osFailureMsg = std::move(osTmp);
    3148          17 :             ctxt->osInitialMsg = ctxt->osFailureMsg;
    3149             :           }
    3150             :           else
    3151             :           {
    3152           0 :             std::string osTmp(msg);
    3153           0 :             osTmp += "\n[...]\nMay be caused by: ";
    3154           0 :             osTmp += ctxt->osInitialMsg;
    3155           0 :             ctxt->osFailureMsg = std::move(osTmp);
    3156             :           }
    3157             :         }
    3158             :     }
    3159           0 :     catch( const std::exception& )
    3160             :     {
    3161           0 :         ctxt->bMemoryError = true;
    3162             :     }
    3163             :   }
    3164         356 : }
    3165             : 
    3166             : 
    3167             : 
    3168             : 
    3169             : static
    3170       20213 : int GetUseExceptions() {
    3171        1533 :   return bUseExceptionsLocal >= 0 ? bUseExceptionsLocal : bUseExceptions;
    3172             : }
    3173             : 
    3174           0 : static int _GetExceptionsLocal()
    3175             : {
    3176           0 :   return bUseExceptionsLocal;
    3177             : }
    3178             : 
    3179       25146 : static void _SetExceptionsLocal(int bVal)
    3180             : {
    3181       25146 :   bUseExceptionsLocal = bVal;
    3182             : }
    3183             : 
    3184             : static
    3185          32 : void _UseExceptions() {
    3186          32 :   CPLErrorReset();
    3187          32 :   bUserHasSpecifiedIfUsingExceptions = TRUE;
    3188          32 :   if( !bUseExceptions )
    3189             :   {
    3190          26 :     bUseExceptions = 1;
    3191             :   }
    3192             : }
    3193             : 
    3194             : static
    3195           5 : void _DontUseExceptions() {
    3196           5 :   CPLErrorReset();
    3197           5 :   bUserHasSpecifiedIfUsingExceptions = TRUE;
    3198           5 :   if( bUseExceptions )
    3199             :   {
    3200           0 :     bUseExceptions = 0;
    3201             :   }
    3202             : }
    3203             : 
    3204           0 : static int _UserHasSpecifiedIfUsingExceptions()
    3205             : {
    3206           0 :     return bUserHasSpecifiedIfUsingExceptions || bUseExceptionsLocal >= 0;
    3207             : }
    3208             : 
    3209             : 
    3210             : 
    3211             : SWIGINTERNINLINE PyObject*
    3212       19572 :   SWIG_From_int  (int value)
    3213             : {
    3214       19572 :   return PyInt_FromLong((long) value);
    3215             : }
    3216             : 
    3217             : 
    3218             : /* Completely unrelated: just to avoid Coverity warnings */
    3219             : 
    3220             : static int bReturnSame = 1;
    3221             : 
    3222           0 : void NeverCallMePlease() {
    3223           0 :     bReturnSame = 0;
    3224           0 : }
    3225             : 
    3226             : /* Some SWIG code generates dead code, which Coverity warns about */
    3227             : template<class T> static T ReturnSame(T x)
    3228             : {
    3229             :     if( bReturnSame )
    3230             :         return x;
    3231             :     return 0;
    3232             : }
    3233             : 
    3234       16926 : static void pushErrorHandler()
    3235             : {
    3236       16926 :     CPLErrorReset();
    3237       16926 :     PythonBindingErrorHandlerContext* ctxt = new PythonBindingErrorHandlerContext();
    3238       16926 :     CPLPushErrorHandlerEx(PythonBindingErrorHandler, ctxt);
    3239       16926 : }
    3240             : 
    3241       16926 : static void popErrorHandler()
    3242             : {
    3243       16926 :     PythonBindingErrorHandlerContext* ctxt = static_cast<
    3244       16926 :       PythonBindingErrorHandlerContext*>(CPLGetErrorHandlerUserData());
    3245       16926 :     CPLPopErrorHandler();
    3246       16926 :     if( ctxt->bMemoryError )
    3247             :     {
    3248           0 :         CPLErrorSetState(
    3249             :           CE_Failure, CPLE_OutOfMemory, "Out of memory");
    3250             :     }
    3251       16926 :     else if( !ctxt->osFailureMsg.empty() )
    3252             :     {
    3253          37 :       CPLErrorSetState(
    3254          37 :           CPLGetLastErrorType() == CE_Failure ? CE_Failure: CE_Warning,
    3255             :           ctxt->nLastCode, ctxt->osFailureMsg.c_str());
    3256             :     }
    3257       16926 :     delete ctxt;
    3258       16926 : }
    3259             : 
    3260             : 
    3261             : 
    3262             : 
    3263             : /* Return a PyObject* from a NULL terminated C String */
    3264             : static PyObject* GDALPythonObjectFromCStr(const char *pszStr) CPL_UNUSED;
    3265           2 : static PyObject* GDALPythonObjectFromCStr(const char *pszStr)
    3266             : {
    3267           2 :   const unsigned char* pszIter = (const unsigned char*) pszStr;
    3268          46 :   while(*pszIter != 0)
    3269             :   {
    3270          44 :     if (*pszIter > 127)
    3271             :     {
    3272           0 :         PyObject* pyObj = PyUnicode_DecodeUTF8(pszStr, strlen(pszStr), "strict");
    3273           0 :         if (pyObj != NULL && !PyErr_Occurred())
    3274             :             return pyObj;
    3275           0 :         PyErr_Clear();
    3276           0 :         return PyBytes_FromString(pszStr);
    3277             :     }
    3278          44 :     pszIter ++;
    3279             :   }
    3280           2 :   return PyUnicode_FromString(pszStr);
    3281             : }
    3282             : 
    3283             : /* Return a NULL terminated c String from a PyObject */
    3284             : /* Result must be freed with GDALPythonFreeCStr */
    3285             : static char* GDALPythonObjectToCStr(PyObject* pyObject, int* pbToFree) CPL_UNUSED;
    3286             : static char* GDALPythonObjectToCStr(PyObject* pyObject, int* pbToFree)
    3287             : {
    3288             :   *pbToFree = 0;
    3289             :   if (PyUnicode_Check(pyObject))
    3290             :   {
    3291             :       char *pszStr;
    3292             :       char *pszNewStr;
    3293             :       Py_ssize_t nLen;
    3294             :       PyObject* pyUTF8Str = PyUnicode_AsUTF8String(pyObject);
    3295             :       if( pyUTF8Str == NULL )
    3296             :         return NULL;
    3297             :       PyBytes_AsStringAndSize(pyUTF8Str, &pszStr, &nLen);
    3298             :       pszNewStr = (char *) malloc(nLen+1);
    3299             :       if( pszNewStr == NULL )
    3300             :       {
    3301             :           CPLError(CE_Failure, CPLE_OutOfMemory, "Failed to allocate %llu bytes",
    3302             :                    (unsigned long long)(nLen + 1));
    3303             :           Py_XDECREF(pyUTF8Str);
    3304             :           return NULL;
    3305             :       }
    3306             :       memcpy(pszNewStr, pszStr, nLen+1);
    3307             :       Py_XDECREF(pyUTF8Str);
    3308             :       *pbToFree = 1;
    3309             :       return pszNewStr;
    3310             :   }
    3311             :   else if( PyBytes_Check(pyObject) )
    3312             :   {
    3313             :       char* ret = PyBytes_AsString(pyObject);
    3314             : 
    3315             :       // Check if there are \0 bytes inside the string
    3316             :       const Py_ssize_t size = PyBytes_Size(pyObject);
    3317             :       for( Py_ssize_t i = 0; i < size; i++ )
    3318             :       {
    3319             :           if( ret[i] == 0 )
    3320             :           {
    3321             :               CPLError(CE_Failure, CPLE_AppDefined,
    3322             :                        "bytes object cast as string contains a zero-byte.");
    3323             :               return NULL;
    3324             :           }
    3325             :       }
    3326             : 
    3327             :       return ret;
    3328             :   }
    3329             :   else
    3330             :   {
    3331             :       CPLError(CE_Failure, CPLE_AppDefined,
    3332             :                "Passed object is neither of type string nor bytes");
    3333             :       return NULL;
    3334             :   }
    3335             : }
    3336             : 
    3337             : static char * GDALPythonPathToCStr(PyObject* pyObject, int* pbToFree) CPL_UNUSED;
    3338             : static char * GDALPythonPathToCStr(PyObject* pyObject, int* pbToFree)
    3339             : {
    3340             :     PyObject* os = PyImport_ImportModule("os");
    3341             :     if (os == NULL)
    3342             :     {
    3343             :         return NULL;
    3344             :     }
    3345             : 
    3346             :     PyObject* pathLike = PyObject_GetAttrString(os, "PathLike");
    3347             :     if (pathLike == NULL)
    3348             :     {
    3349             :         Py_DECREF(os);
    3350             :         return NULL;
    3351             :     }
    3352             : 
    3353             :     if (!PyObject_IsInstance(pyObject, pathLike))
    3354             :     {
    3355             :         Py_DECREF(pathLike);
    3356             :         Py_DECREF(os);
    3357             :         return NULL;
    3358             :     }
    3359             : 
    3360             :     PyObject* str = PyObject_Str(pyObject);
    3361             :     char* ret = NULL;
    3362             :     if (str != NULL)
    3363             :     {
    3364             :         ret = GDALPythonObjectToCStr(str, pbToFree);
    3365             :         Py_DECREF(str);
    3366             :     }
    3367             : 
    3368             :     Py_DECREF(pathLike);
    3369             :     Py_DECREF(os);
    3370             : 
    3371             :     return ret;
    3372             : }
    3373             : 
    3374             : 
    3375             : static void GDALPythonFreeCStr(void* ptr, int bToFree) CPL_UNUSED;
    3376             : static void GDALPythonFreeCStr(void* ptr, int bToFree)
    3377             : {
    3378             :    if (bToFree)
    3379             :        free(ptr);
    3380             : }
    3381             : 
    3382             : 
    3383             : 
    3384             : #include <vector>
    3385             : #include "cpl_time.h"
    3386             : #include "gdal_priv.h"
    3387             : #include "ogr_recordbatch.h"
    3388             : 
    3389             : #ifdef _DEBUG
    3390             : #undef _DEBUG
    3391             : #include "Python.h"
    3392             : #include "datetime.h"
    3393             : #define _DEBUG
    3394             : #else
    3395             : #include "Python.h"
    3396             : #include "datetime.h"
    3397             : #endif
    3398             : #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
    3399             : #include "numpy/arrayobject.h"
    3400             : 
    3401             : #ifdef DEBUG
    3402             : typedef struct GDALRasterBandHS GDALRasterBandShadow;
    3403             : typedef struct GDALDatasetHS GDALDatasetShadow;
    3404             : typedef struct RasterAttributeTableHS GDALRasterAttributeTableShadow;
    3405             : #else
    3406             : typedef void GDALRasterBandShadow;
    3407             : typedef void GDALDatasetShadow;
    3408             : typedef void GDALRasterAttributeTableShadow;
    3409             : #endif
    3410             : typedef void GDALComputedRasterBandShadow;
    3411             : 
    3412             : // Declaration from memmultidim.h
    3413             : std::shared_ptr<GDALMDArray> CPL_DLL MEMGroupCreateMDArray(GDALGroup* poGroup,
    3414             :                                                    const std::string& osName,
    3415             :                                                    const std::vector<std::shared_ptr<GDALDimension>>& aoDimensions,
    3416             :                                                    const GDALExtendedDataType& oDataType,
    3417             :                                                    void* pData,
    3418             :                                                    CSLConstList papszOptions);
    3419             : 
    3420             : 
    3421             : CPL_C_START
    3422             : 
    3423             : GDALRasterBandH CPL_DLL MEMCreateRasterBandEx( GDALDataset *, int, GByte *,
    3424             :                                                GDALDataType, GSpacing, GSpacing, int );
    3425             : CPL_C_END
    3426             : 
    3427             : typedef char retStringAndCPLFree;
    3428             : 
    3429             : class NUMPYDataset : public GDALDataset
    3430             : {
    3431             :     PyArrayObject *psArray = nullptr;
    3432             : 
    3433             :     bool             bValidGeoTransform = false;
    3434             :     GDALGeoTransform m_gt{};
    3435             :     OGRSpatialReference m_oSRS{};
    3436             : 
    3437             :     int           nGCPCount = 0;
    3438             :     GDAL_GCP      *pasGCPList = nullptr;
    3439             :     OGRSpatialReference m_oGCPSRS{};
    3440             : 
    3441             :   public:
    3442          27 :                  NUMPYDataset() = default;
    3443             :                  ~NUMPYDataset();
    3444             : 
    3445             :     const OGRSpatialReference* GetSpatialRef() const override;
    3446             :     CPLErr SetSpatialRef(const OGRSpatialReference* poSRS) override;
    3447             : 
    3448             :     virtual CPLErr GetGeoTransform( GDALGeoTransform& gt ) const override;
    3449             :     virtual CPLErr SetGeoTransform( const GDALGeoTransform& gt ) override;
    3450             : 
    3451             :     virtual int    GetGCPCount() override;
    3452             :     const OGRSpatialReference* GetGCPSpatialRef() const override;
    3453             :     virtual const GDAL_GCP *GetGCPs() override;
    3454             :     CPLErr SetGCPs( int nGCPCount, const GDAL_GCP *pasGCPList,
    3455             :                     const OGRSpatialReference* poSRS ) override;
    3456             : 
    3457             :     static GDALDataset *Open( PyArrayObject *psArray, bool binterleave = true );
    3458             :     static GDALDataset *Open( GDALOpenInfo * );
    3459             : };
    3460             : 
    3461             : 
    3462             : /************************************************************************/
    3463             : /*                          GDALRegister_NUMPY()                        */
    3464             : /************************************************************************/
    3465             : 
    3466         235 : static void GDALRegister_NUMPY(void)
    3467             : 
    3468             : {
    3469         235 :     GDALDriver  *poDriver;
    3470         235 :     if (! GDAL_CHECK_VERSION("NUMPY driver"))
    3471             :         return;
    3472         235 :     if( GDALGetDriverByName( "NUMPY" ) == NULL )
    3473             :     {
    3474         233 :         poDriver = static_cast<GDALDriver*>(GDALCreateDriver());
    3475             : 
    3476         233 :         poDriver->SetDescription( "NUMPY" );
    3477         233 :         poDriver->SetMetadataItem( GDAL_DMD_LONGNAME,
    3478         233 :                                    "Numeric Python Array" );
    3479         233 :         poDriver->SetMetadataItem( GDAL_DCAP_RASTER, "YES" );
    3480             : 
    3481         233 :         poDriver->pfnOpen = NUMPYDataset::Open;
    3482             : 
    3483         233 :         GetGDALDriverManager()->RegisterDriver( poDriver );
    3484             : 
    3485             :     }
    3486             : }
    3487             : 
    3488             : /************************************************************************/
    3489             : /*                            ~NUMPYDataset()                            */
    3490             : /************************************************************************/
    3491             : 
    3492          54 : NUMPYDataset::~NUMPYDataset()
    3493             : 
    3494             : {
    3495          27 :     if( nGCPCount > 0 )
    3496             :     {
    3497           0 :         GDALDeinitGCPs( nGCPCount, pasGCPList );
    3498           0 :         CPLFree( pasGCPList );
    3499             :     }
    3500             : 
    3501          27 :     FlushCache(true);
    3502             : 
    3503             :     // Although the module has thread disabled, we go here from GDALClose()
    3504          27 :     SWIG_PYTHON_THREAD_BEGIN_BLOCK;
    3505             : 
    3506          27 :     Py_DECREF( psArray );
    3507             : 
    3508          27 :     SWIG_PYTHON_THREAD_END_BLOCK;
    3509          54 : }
    3510             : 
    3511             : /************************************************************************/
    3512             : /*                          GetSpatialRef()                             */
    3513             : /************************************************************************/
    3514             : 
    3515           0 : const OGRSpatialReference *NUMPYDataset::GetSpatialRef() const
    3516             : 
    3517             : {
    3518           0 :     return m_oSRS.IsEmpty() ? nullptr:  &m_oSRS;
    3519             : }
    3520             : 
    3521             : /************************************************************************/
    3522             : /*                           SetSpatialRef()                            */
    3523             : /************************************************************************/
    3524             : 
    3525           0 : CPLErr NUMPYDataset::SetSpatialRef( const OGRSpatialReference* poSRS )
    3526             : 
    3527             : {
    3528           0 :     m_oSRS.Clear();
    3529           0 :     if( poSRS )
    3530           0 :         m_oSRS = *poSRS;
    3531             : 
    3532           0 :     return CE_None;
    3533             : }
    3534             : 
    3535             : /************************************************************************/
    3536             : /*                          GetGeoTransform()                           */
    3537             : /************************************************************************/
    3538             : 
    3539           2 : CPLErr NUMPYDataset::GetGeoTransform(GDALGeoTransform &gt) const
    3540             : 
    3541             : {
    3542           2 :     gt = m_gt;
    3543           2 :     if( bValidGeoTransform )
    3544             :         return CE_None;
    3545             :     else
    3546           1 :         return CE_Failure;
    3547             : }
    3548             : 
    3549             : /************************************************************************/
    3550             : /*                          SetGeoTransform()                           */
    3551             : /************************************************************************/
    3552             : 
    3553           1 : CPLErr NUMPYDataset::SetGeoTransform(const GDALGeoTransform& gt)
    3554             : 
    3555             : {
    3556           1 :     bValidGeoTransform = true;
    3557           1 :     m_gt = gt;
    3558           1 :     return( CE_None );
    3559             : }
    3560             : 
    3561             : /************************************************************************/
    3562             : /*                            GetGCPCount()                             */
    3563             : /************************************************************************/
    3564             : 
    3565           0 : int NUMPYDataset::GetGCPCount()
    3566             : 
    3567             : {
    3568           0 :     return nGCPCount;
    3569             : }
    3570             : 
    3571             : /************************************************************************/
    3572             : /*                          GetGCPSpatialRef()                          */
    3573             : /************************************************************************/
    3574             : 
    3575           0 : const OGRSpatialReference *NUMPYDataset::GetGCPSpatialRef() const
    3576             : 
    3577             : {
    3578           0 :     return m_oGCPSRS.IsEmpty() ? nullptr:  &m_oGCPSRS;
    3579             : }
    3580             : 
    3581             : /************************************************************************/
    3582             : /*                               GetGCPs()                              */
    3583             : /************************************************************************/
    3584             : 
    3585           0 : const GDAL_GCP *NUMPYDataset::GetGCPs()
    3586             : 
    3587             : {
    3588           0 :     return pasGCPList;
    3589             : }
    3590             : 
    3591             : /************************************************************************/
    3592             : /*                              SetGCPs()                               */
    3593             : /************************************************************************/
    3594             : 
    3595           0 : CPLErr NUMPYDataset::SetGCPs( int nGCPCount, const GDAL_GCP *pasGCPList,
    3596             :                               const OGRSpatialReference* poSRS )
    3597             : 
    3598             : {
    3599           0 :     m_oGCPSRS.Clear();
    3600           0 :     if( poSRS )
    3601           0 :         m_oGCPSRS = *poSRS;
    3602             : 
    3603           0 :     if( this->nGCPCount > 0 )
    3604             :     {
    3605           0 :         GDALDeinitGCPs( this->nGCPCount, this->pasGCPList );
    3606           0 :         CPLFree( this->pasGCPList );
    3607             :     }
    3608             : 
    3609           0 :     this->nGCPCount = nGCPCount;
    3610             : 
    3611           0 :     this->pasGCPList = GDALDuplicateGCPs( nGCPCount, pasGCPList );
    3612             : 
    3613           0 :     return CE_None;
    3614             : }
    3615             : 
    3616             : /************************************************************************/
    3617             : /*                                Open()                                */
    3618             : /************************************************************************/
    3619             : 
    3620       29131 : GDALDataset *NUMPYDataset::Open( GDALOpenInfo * poOpenInfo )
    3621             : 
    3622             : {
    3623       29131 :     PyArrayObject *psArray;
    3624             : 
    3625             : /* -------------------------------------------------------------------- */
    3626             : /*      Is this a numpy dataset name?                                   */
    3627             : /* -------------------------------------------------------------------- */
    3628       29131 :     if( !EQUALN(poOpenInfo->pszFilename,"NUMPY:::",8)
    3629           3 :         || poOpenInfo->fpL != NULL )
    3630             :         return NULL;
    3631             : 
    3632           3 :     psArray = NULL;
    3633           3 :     sscanf( poOpenInfo->pszFilename+8, "%p", &(psArray) );
    3634           3 :     if( psArray == NULL )
    3635             :     {
    3636           1 :         CPLError( CE_Failure, CPLE_AppDefined,
    3637             :                   "Failed to parse meaningful pointer value from NUMPY name\n"
    3638             :                   "string: %s\n",
    3639             :                   poOpenInfo->pszFilename );
    3640           1 :         return NULL;
    3641             :     }
    3642             : 
    3643           2 :     if( !CPLTestBool(CPLGetConfigOption("GDAL_ARRAY_OPEN_BY_FILENAME",
    3644             :                                         "FALSE")) )
    3645             :     {
    3646           1 :         if( CPLGetConfigOption("GDAL_ARRAY_OPEN_BY_FILENAME", NULL) == NULL )
    3647             :         {
    3648           1 :             CPLError(CE_Failure, CPLE_NotSupported,
    3649             :                     "Opening a NumPy array through gdal.Open(gdal_array.GetArrayFilename()) "
    3650             :                     "is no longer supported by default unless the GDAL_ARRAY_OPEN_BY_FILENAME "
    3651             :                     "configuration option is set to TRUE. The recommended way is to use "
    3652             :                     "gdal_array.OpenArray() instead.");
    3653             :         }
    3654           1 :         return NULL;
    3655             :     }
    3656             : 
    3657           1 :     return Open(psArray);
    3658             : }
    3659             : 
    3660          49 : static GDALDataType NumpyTypeToGDALType(PyArrayObject *psArray)
    3661             : {
    3662          49 :     switch( PyArray_DESCR(psArray)->type_num )
    3663             :     {
    3664             :       case NPY_CDOUBLE:
    3665             :         return GDT_CFloat64;
    3666             : 
    3667           5 :       case NPY_CFLOAT:
    3668           5 :         return GDT_CFloat32;
    3669             : 
    3670             :       // case NPY_CHALF
    3671             :       //   return GDT_CFloat16;
    3672             : 
    3673           5 :       case NPY_DOUBLE:
    3674           5 :         return GDT_Float64;
    3675             : 
    3676           3 :       case NPY_FLOAT:
    3677           3 :         return GDT_Float32;
    3678             : 
    3679           0 :       case NPY_HALF:
    3680           0 :         return GDT_Float16;
    3681             : 
    3682           3 :       case NPY_INT32:
    3683           3 :         return GDT_Int32;
    3684             : 
    3685           3 :       case NPY_UINT32:
    3686           3 :         return GDT_UInt32;
    3687             : 
    3688           1 :       case NPY_INT64:
    3689           1 :         return GDT_Int64;
    3690             : 
    3691           1 :       case NPY_UINT64:
    3692           1 :         return GDT_UInt64;
    3693             : 
    3694           3 :       case NPY_INT16:
    3695           3 :         return GDT_Int16;
    3696             : 
    3697           3 :       case NPY_UINT16:
    3698           3 :         return GDT_UInt16;
    3699             : 
    3700           2 :       case NPY_BYTE:
    3701           2 :         return GDT_Int8;
    3702             : 
    3703          15 :       case NPY_UBYTE:
    3704          15 :         return GDT_Byte;
    3705             : 
    3706           2 :       default:
    3707           2 :         CPLError( CE_Failure, CPLE_AppDefined,
    3708             :                   "Unable to access numpy arrays of typecode `%c'.",
    3709           2 :                   PyArray_DESCR(psArray)->type );
    3710           2 :         return GDT_Unknown;
    3711             :     }
    3712             : }
    3713             : 
    3714             : /************************************************************************/
    3715             : /*                                Open()                                */
    3716             : /************************************************************************/
    3717             : 
    3718          31 : GDALDataset* NUMPYDataset::Open( PyArrayObject *psArray, bool binterleave )
    3719             : {
    3720          31 :     GDALDataType  eType;
    3721          31 :     int     nBands;
    3722             : 
    3723             : /* -------------------------------------------------------------------- */
    3724             : /*      Is this a directly mappable Python array?  Verify rank, and     */
    3725             : /*      data type.                                                      */
    3726             : /* -------------------------------------------------------------------- */
    3727             : 
    3728          31 :     if( PyArray_NDIM(psArray) < 2 || PyArray_NDIM(psArray) > 3 )
    3729             :     {
    3730           3 :         CPLError( CE_Failure, CPLE_AppDefined,
    3731             :                   "Illegal numpy array rank %d.",
    3732             :                   PyArray_NDIM(psArray) );
    3733           3 :         return NULL;
    3734             :     }
    3735             : 
    3736          28 :     eType = NumpyTypeToGDALType(psArray);
    3737          28 :     if( eType == GDT_Unknown )
    3738             :     {
    3739             :         return NULL;
    3740             :     }
    3741             : 
    3742             : /* -------------------------------------------------------------------- */
    3743             : /*      Create the new NUMPYDataset object.                             */
    3744             : /* -------------------------------------------------------------------- */
    3745          27 :     NUMPYDataset *poDS;
    3746             : 
    3747          27 :     poDS = new NUMPYDataset();
    3748          27 :     poDS->poDriver = static_cast<GDALDriver*>(GDALGetDriverByName("NUMPY"));
    3749             : 
    3750          27 :     poDS->psArray = psArray;
    3751             : 
    3752          27 :     poDS->eAccess = (PyArray_FLAGS(psArray) & NPY_ARRAY_WRITEABLE) ? GA_Update : GA_ReadOnly;
    3753             : 
    3754             : /* -------------------------------------------------------------------- */
    3755             : /*      Add a reference to the array.                                   */
    3756             : /* -------------------------------------------------------------------- */
    3757          27 :     Py_INCREF( psArray );
    3758             : 
    3759             : /* -------------------------------------------------------------------- */
    3760             : /*      Workout the data layout.                                        */
    3761             : /* -------------------------------------------------------------------- */
    3762          27 :     npy_intp nBandOffset;
    3763          27 :     npy_intp nPixelOffset;
    3764          27 :     npy_intp nLineOffset;
    3765             : 
    3766          27 :     int xdim = binterleave ? 2 : 1;
    3767          27 :     int ydim = binterleave ? 1 : 0;
    3768          27 :     int bdim = binterleave ? 0 : 2;
    3769             : 
    3770          27 :     if( PyArray_NDIM(psArray) == 3 )
    3771             :     {
    3772           6 :         if( PyArray_DIMS(psArray)[0] > INT_MAX ||
    3773           6 :             PyArray_DIMS(psArray)[1] > INT_MAX ||
    3774          18 :             PyArray_DIMS(psArray)[2] > INT_MAX ||
    3775           6 :             !GDALCheckBandCount(static_cast<int>(PyArray_DIMS(psArray)[bdim]), 0) )
    3776             :         {
    3777           0 :             CPLError(CE_Failure, CPLE_NotSupported,
    3778             :                      "Too big array dimensions");
    3779           0 :             delete poDS;
    3780           0 :             return NULL;
    3781             :         }
    3782           6 :         nBands = static_cast<int>(PyArray_DIMS(psArray)[bdim]);
    3783           6 :         nBandOffset = PyArray_STRIDES(psArray)[bdim];
    3784           6 :         poDS->nRasterXSize = static_cast<int>(PyArray_DIMS(psArray)[xdim]);
    3785           6 :         nPixelOffset = PyArray_STRIDES(psArray)[xdim];
    3786           6 :         poDS->nRasterYSize = static_cast<int>(PyArray_DIMS(psArray)[ydim]);
    3787           6 :         nLineOffset = PyArray_STRIDES(psArray)[ydim];
    3788             :     }
    3789             :     else
    3790             :     {
    3791          21 :         if( PyArray_DIMS(psArray)[0] > INT_MAX ||
    3792          21 :             PyArray_DIMS(psArray)[1] > INT_MAX )
    3793             :         {
    3794           0 :             delete poDS;
    3795           0 :             return NULL;
    3796             :         }
    3797          21 :         nBands = 1;
    3798          21 :         nBandOffset = 0;
    3799          21 :         poDS->nRasterXSize = static_cast<int>(PyArray_DIMS(psArray)[1]);
    3800          21 :         nPixelOffset = PyArray_STRIDES(psArray)[1];
    3801          21 :         poDS->nRasterYSize = static_cast<int>(PyArray_DIMS(psArray)[0]);
    3802          21 :         nLineOffset = PyArray_STRIDES(psArray)[0];
    3803             :     }
    3804             : 
    3805             : /* -------------------------------------------------------------------- */
    3806             : /*      Create band information objects.                                */
    3807             : /* -------------------------------------------------------------------- */
    3808          62 :     for( int iBand = 0; iBand < nBands; iBand++ )
    3809             :     {
    3810          35 :         poDS->SetBand( iBand+1,
    3811             :                        (GDALRasterBand *)
    3812          35 :                        MEMCreateRasterBandEx( poDS, iBand+1,
    3813          35 :                                 (GByte *) PyArray_DATA(psArray) + nBandOffset*iBand,
    3814             :                                           eType, nPixelOffset, nLineOffset,
    3815             :                                           FALSE ) );
    3816             :     }
    3817             : 
    3818             : /* -------------------------------------------------------------------- */
    3819             : /*      Try to return a regular handle on the file.                     */
    3820             : /* -------------------------------------------------------------------- */
    3821             :     return poDS;
    3822             : }
    3823             : 
    3824             : /************************************************************************/
    3825             : /*                       NUMPYMultiDimensionalDataset                   */
    3826             : /************************************************************************/
    3827             : 
    3828             : class NUMPYMultiDimensionalDataset : public GDALDataset
    3829             : {
    3830             :     PyArrayObject *psArray = nullptr;
    3831             :     std::unique_ptr<GDALDataset> poMEMDS{};
    3832             : 
    3833             :     NUMPYMultiDimensionalDataset();
    3834             :     ~NUMPYMultiDimensionalDataset();
    3835             : 
    3836             : public:
    3837             :     static GDALDataset *Open( PyArrayObject *psArray );
    3838             : 
    3839          20 :     std::shared_ptr<GDALGroup> GetRootGroup() const override { return poMEMDS->GetRootGroup(); }
    3840             : };
    3841             : 
    3842             : /************************************************************************/
    3843             : /*                     NUMPYMultiDimensionalDataset()                   */
    3844             : /************************************************************************/
    3845             : 
    3846          20 : NUMPYMultiDimensionalDataset::NUMPYMultiDimensionalDataset()
    3847             : {
    3848          20 : }
    3849             : 
    3850             : /************************************************************************/
    3851             : /*                    ~NUMPYMultiDimensionalDataset()                   */
    3852             : /************************************************************************/
    3853             : 
    3854          40 : NUMPYMultiDimensionalDataset::~NUMPYMultiDimensionalDataset()
    3855             : {
    3856             :     // Although the module has thread disabled, we go here from GDALClose()
    3857          20 :     SWIG_PYTHON_THREAD_BEGIN_BLOCK;
    3858             : 
    3859          20 :     Py_DECREF( psArray );
    3860             : 
    3861          20 :     SWIG_PYTHON_THREAD_END_BLOCK;
    3862          40 : }
    3863             : 
    3864             : /************************************************************************/
    3865             : /*                                Open()                                */
    3866             : /************************************************************************/
    3867             : 
    3868          21 : GDALDataset* NUMPYMultiDimensionalDataset::Open( PyArrayObject *psArray )
    3869             : {
    3870          21 :     const auto eType = NumpyTypeToGDALType(psArray);
    3871          21 :     if( eType == GDT_Unknown )
    3872             :     {
    3873             :         return nullptr;
    3874             :     }
    3875          20 :     auto poMemDriver = GDALDriver::FromHandle(GDALGetDriverByName("MEM"));
    3876          20 :     if( !poMemDriver )
    3877             :     {
    3878           0 :         CPLError(CE_Failure, CPLE_AppDefined,
    3879             :                  "MEM driver not available");
    3880           0 :         return nullptr;
    3881             :     }
    3882             : 
    3883          20 :     auto poMEMDS = poMemDriver->CreateMultiDimensional("", nullptr, nullptr);
    3884          20 :     assert(poMEMDS);
    3885          41 :     auto poGroup = poMEMDS->GetRootGroup();
    3886          20 :     assert(poGroup);
    3887          40 :     std::vector<std::shared_ptr<GDALDimension>> apoDims;
    3888          20 :     const auto ndims = PyArray_NDIM(psArray);
    3889          40 :     CPLString strides;
    3890          60 :     for( int i = 0; i < ndims; i++ )
    3891             :     {
    3892          80 :         auto poDim = poGroup->CreateDimension(std::string(CPLSPrintf("dim%d", i)),
    3893          40 :                                               std::string(),
    3894          40 :                                               std::string(),
    3895          40 :                                               PyArray_DIMS(psArray)[i],
    3896         120 :                                               nullptr);
    3897          40 :         apoDims.push_back(poDim);
    3898          40 :         if( i > 0 )
    3899          20 :             strides += ',';
    3900          40 :         strides += CPLSPrintf(CPL_FRMT_GIB,
    3901          40 :                               static_cast<GIntBig>(PyArray_STRIDES(psArray)[i]));
    3902             :     }
    3903          40 :     CPLStringList aosOptions;
    3904          20 :     aosOptions.SetNameValue("STRIDES", strides.c_str());
    3905          20 :     auto mdArray = MEMGroupCreateMDArray(poGroup.get(), "array",
    3906             :                                       apoDims,
    3907          20 :                                       GDALExtendedDataType::Create(eType),
    3908             :                                       PyArray_DATA(psArray),
    3909          60 :                                       aosOptions.List());
    3910          20 :     if( !mdArray )
    3911             :     {
    3912           0 :         delete poMEMDS;
    3913           0 :         return nullptr;
    3914             :     }
    3915             : 
    3916          20 :     auto poDS = new NUMPYMultiDimensionalDataset();
    3917          20 :     poDS->poDriver = GDALDriver::FromHandle(GDALGetDriverByName("NUMPY"));
    3918          20 :     poDS->psArray = psArray;
    3919          20 :     Py_INCREF( psArray );
    3920          20 :     poDS->eAccess = GA_ReadOnly;
    3921          20 :     poDS->poMEMDS.reset(poMEMDS);
    3922             :     return poDS;
    3923             : }
    3924             : 
    3925             : 
    3926             : 
    3927           0 : int GDALTermProgress_nocb( double dfProgress, const char * pszMessage=NULL, void *pData=NULL ) {
    3928           0 :   return GDALTermProgress( dfProgress, pszMessage, pData);
    3929             : }
    3930             : 
    3931             : 
    3932             : SWIGINTERN swig_type_info*
    3933           0 : SWIG_pchar_descriptor(void)
    3934             : {
    3935           0 :   static int init = 0;
    3936           0 :   static swig_type_info* info = 0;
    3937           0 :   if (!init) {
    3938           0 :     info = SWIG_TypeQuery("_p_char");
    3939           0 :     init = 1;
    3940             :   }
    3941           0 :   return info;
    3942             : }
    3943             : 
    3944             : 
    3945             : SWIGINTERN int
    3946           0 : SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc)
    3947             : {
    3948             : #if PY_VERSION_HEX>=0x03000000
    3949             : #if defined(SWIG_PYTHON_STRICT_BYTE_CHAR)
    3950             :   if (PyBytes_Check(obj))
    3951             : #else
    3952           0 :   if (PyUnicode_Check(obj))
    3953             : #endif
    3954             : #else  
    3955             :   if (PyString_Check(obj))
    3956             : #endif
    3957             :   {
    3958           0 :     char *cstr; Py_ssize_t len;
    3959           0 :     int ret = SWIG_OK;
    3960             : #if PY_VERSION_HEX>=0x03000000
    3961             : #if !defined(SWIG_PYTHON_STRICT_BYTE_CHAR)
    3962           0 :     if (!alloc && cptr) {
    3963             :         /* We can't allow converting without allocation, since the internal
    3964             :            representation of string in Python 3 is UCS-2/UCS-4 but we require
    3965             :            a UTF-8 representation.
    3966             :            TODO(bhy) More detailed explanation */
    3967             :         return SWIG_RuntimeError;
    3968             :     }
    3969           0 :     obj = PyUnicode_AsUTF8String(obj);
    3970           0 :     if (!obj)
    3971             :       return SWIG_TypeError;
    3972           0 :     if (alloc)
    3973           0 :       *alloc = SWIG_NEWOBJ;
    3974             : #endif
    3975           0 :     PyBytes_AsStringAndSize(obj, &cstr, &len);
    3976             : #else
    3977             :     PyString_AsStringAndSize(obj, &cstr, &len);
    3978             : #endif
    3979           0 :     if (cptr) {
    3980           0 :       if (alloc) {
    3981           0 :   if (*alloc == SWIG_NEWOBJ) {
    3982           0 :     *cptr = reinterpret_cast< char* >(memcpy(new char[len + 1], cstr, sizeof(char)*(len + 1)));
    3983           0 :     *alloc = SWIG_NEWOBJ;
    3984             :   } else {
    3985           0 :     *cptr = cstr;
    3986           0 :     *alloc = SWIG_OLDOBJ;
    3987             :   }
    3988             :       } else {
    3989             : #if PY_VERSION_HEX>=0x03000000
    3990             : #if defined(SWIG_PYTHON_STRICT_BYTE_CHAR)
    3991             :   *cptr = PyBytes_AsString(obj);
    3992             : #else
    3993             :   assert(0); /* Should never reach here with Unicode strings in Python 3 */
    3994             : #endif
    3995             : #else
    3996             :   *cptr = SWIG_Python_str_AsChar(obj);
    3997             :         if (!*cptr)
    3998             :           ret = SWIG_TypeError;
    3999             : #endif
    4000             :       }
    4001             :     }
    4002           0 :     if (psize) *psize = len + 1;
    4003             : #if PY_VERSION_HEX>=0x03000000 && !defined(SWIG_PYTHON_STRICT_BYTE_CHAR)
    4004           0 :     Py_XDECREF(obj);
    4005             : #endif
    4006           0 :     return ret;
    4007             :   } else {
    4008             : #if defined(SWIG_PYTHON_2_UNICODE)
    4009             : #if defined(SWIG_PYTHON_STRICT_BYTE_CHAR)
    4010             : #error "Cannot use both SWIG_PYTHON_2_UNICODE and SWIG_PYTHON_STRICT_BYTE_CHAR at once"
    4011             : #endif
    4012             : #if PY_VERSION_HEX<0x03000000
    4013             :     if (PyUnicode_Check(obj)) {
    4014             :       char *cstr; Py_ssize_t len;
    4015             :       if (!alloc && cptr) {
    4016             :         return SWIG_RuntimeError;
    4017             :       }
    4018             :       obj = PyUnicode_AsUTF8String(obj);
    4019             :       if (!obj)
    4020             :         return SWIG_TypeError;
    4021             :       if (PyString_AsStringAndSize(obj, &cstr, &len) != -1) {
    4022             :         if (cptr) {
    4023             :           if (alloc) *alloc = SWIG_NEWOBJ;
    4024             :           *cptr = reinterpret_cast< char* >(memcpy(new char[len + 1], cstr, sizeof(char)*(len + 1)));
    4025             :         }
    4026             :         if (psize) *psize = len + 1;
    4027             : 
    4028             :         Py_XDECREF(obj);
    4029             :         return SWIG_OK;
    4030             :       } else {
    4031             :         Py_XDECREF(obj);
    4032             :       }
    4033             :     }
    4034             : #endif
    4035             : #endif
    4036             : 
    4037           0 :     swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
    4038           0 :     if (pchar_descriptor) {
    4039           0 :       void* vptr = 0;
    4040           0 :       if (SWIG_ConvertPtr(obj, &vptr, pchar_descriptor, 0) == SWIG_OK) {
    4041           0 :   if (cptr) *cptr = (char *) vptr;
    4042           0 :   if (psize) *psize = vptr ? (strlen((char *)vptr) + 1) : 0;
    4043           0 :   if (alloc) *alloc = SWIG_OLDOBJ;
    4044           0 :   return SWIG_OK;
    4045             :       }
    4046             :     }
    4047             :   }
    4048             :   return SWIG_TypeError;
    4049             : }
    4050             : 
    4051             : 
    4052             : 
    4053             : 
    4054             : 
    4055             : 
    4056             : typedef struct {
    4057             :     PyObject *psPyCallback;
    4058             :     PyObject *psPyCallbackData;
    4059             :     int nLastReported;
    4060             : } PyProgressData;
    4061             : 
    4062             : /************************************************************************/
    4063             : /*                          PyProgressProxy()                           */
    4064             : /************************************************************************/
    4065             : 
    4066             : 
    4067             : static int CPL_STDCALL
    4068             : PyProgressProxy( double dfComplete, const char *pszMessage, void *pData ) CPL_UNUSED;
    4069             : 
    4070             : static int CPL_STDCALL
    4071         362 : PyProgressProxy( double dfComplete, const char *pszMessage, void *pData )
    4072             : 
    4073             : {
    4074         362 :     PyProgressData *psInfo = (PyProgressData *) pData;
    4075         362 :     PyObject *psArgs, *psResult;
    4076         362 :     int      bContinue = TRUE;
    4077             : 
    4078         362 :     if( dfComplete > 0 && psInfo->nLastReported == (int) (100.0 * dfComplete) )
    4079             :         return TRUE;
    4080             : 
    4081         264 :     if( psInfo->psPyCallback == NULL || psInfo->psPyCallback == Py_None )
    4082             :         return TRUE;
    4083             : 
    4084         264 :     psInfo->nLastReported = (int) (100.0 * dfComplete);
    4085             : 
    4086         264 :     if( pszMessage == NULL )
    4087           0 :         pszMessage = "";
    4088             : 
    4089         626 :     SWIG_PYTHON_THREAD_BEGIN_BLOCK;
    4090             : 
    4091         264 :     if( psInfo->psPyCallbackData == NULL )
    4092           0 :         psArgs = Py_BuildValue("(dsO)", dfComplete, pszMessage, Py_None );
    4093             :     else
    4094         264 :         psArgs = Py_BuildValue("(dsO)", dfComplete, pszMessage,
    4095             :                            psInfo->psPyCallbackData );
    4096             : 
    4097         264 :     psResult = PyObject_CallObject( psInfo->psPyCallback, psArgs);
    4098         264 :     Py_XDECREF(psArgs);
    4099             : 
    4100         264 :     if( PyErr_Occurred() != NULL )
    4101             :     {
    4102           0 :         PyErr_Print();
    4103           0 :         PyErr_Clear();
    4104           0 :         SWIG_PYTHON_THREAD_END_BLOCK;
    4105             :         return FALSE;
    4106             :     }
    4107             : 
    4108         264 :     if( psResult == NULL )
    4109             :     {
    4110           0 :         SWIG_PYTHON_THREAD_END_BLOCK;
    4111             :         return TRUE;
    4112             :     }
    4113             : 
    4114         264 :     if( psResult == Py_None )
    4115             :     {
    4116           0 :         SWIG_PYTHON_THREAD_END_BLOCK;
    4117             :         return TRUE;
    4118             :     }
    4119             : 
    4120         264 :     if( !PyArg_Parse( psResult, "i", &bContinue ) )
    4121             :     {
    4122           0 :         PyErr_Clear();
    4123           0 :         CPLError(CE_Failure, CPLE_AppDefined, "bad progress return value");
    4124           0 :         Py_XDECREF(psResult);
    4125           0 :         SWIG_PYTHON_THREAD_END_BLOCK;
    4126             :         return FALSE;
    4127             :     }
    4128             : 
    4129         264 :     Py_XDECREF(psResult);
    4130         264 :     SWIG_PYTHON_THREAD_END_BLOCK;
    4131             : 
    4132         264 :     return bContinue;
    4133             : }
    4134             : 
    4135             : 
    4136          30 : GDALDatasetShadow* OpenNumPyArray(PyArrayObject *psArray, bool binterleave)
    4137             : {
    4138          30 :     return NUMPYDataset::Open( psArray, binterleave );
    4139             : }
    4140             : 
    4141             : 
    4142             : SWIGINTERN int
    4143         222 : SWIG_AsVal_bool (PyObject *obj, bool *val)
    4144             : {
    4145         222 :   int r;
    4146         222 :   if (!PyBool_Check(obj))
    4147             :     return SWIG_ERROR;
    4148         222 :   r = PyObject_IsTrue(obj);
    4149         222 :   if (r == -1)
    4150             :     return SWIG_ERROR;
    4151         222 :   if (val) *val = r ? true : false;
    4152             :   return SWIG_OK;
    4153             : }
    4154             : 
    4155             : 
    4156          21 : GDALDatasetShadow* OpenMultiDimensionalNumPyArray(PyArrayObject *psArray)
    4157             : {
    4158          21 :     return NUMPYMultiDimensionalDataset::Open( psArray );
    4159             : }
    4160             : 
    4161             : 
    4162           2 : retStringAndCPLFree* GetArrayFilename(PyArrayObject *psArray)
    4163             : {
    4164           2 :     char      szString[128];
    4165             : 
    4166           2 :     GDALRegister_NUMPY();
    4167             : 
    4168             :     /* I wish I had a safe way of checking the type */
    4169           2 :     snprintf( szString, sizeof(szString), "NUMPY:::%p", psArray );
    4170           2 :     return CPLStrdup(szString);
    4171             : }
    4172             : 
    4173             : 
    4174       19390 :   CPLErr BandRasterIONumPy( GDALRasterBandShadow* band, int bWrite, double xoff, double yoff, double xsize, double ysize,
    4175             :                             PyArrayObject *psArray,
    4176             :                             GDALDataType buf_type,
    4177             :                             GDALRIOResampleAlg resample_alg,
    4178             :                             int operate_in_buf_type,
    4179             :                             GDALProgressFunc callback = NULL,
    4180             :                             void* callback_data = NULL) {
    4181             : 
    4182       19390 :     if( PyArray_NDIM(psArray) < 2 || PyArray_NDIM(psArray) > 3 )
    4183             :     {
    4184           0 :         CPLError( CE_Failure, CPLE_AppDefined,
    4185             :                   "Illegal numpy array rank %d.\n",
    4186             :                   PyArray_NDIM(psArray) );
    4187           0 :         return CE_Failure;
    4188             :     }
    4189             : 
    4190       19390 :     if( !bWrite && !(PyArray_FLAGS(psArray) & NPY_ARRAY_WRITEABLE) )
    4191             :     {
    4192           2 :         CPLError( CE_Failure, CPLE_AppDefined,
    4193             :                   "Cannot read in a non-writeable array." );
    4194           2 :         return CE_Failure;
    4195             :     }
    4196             : 
    4197       19388 :     int xdim = ( PyArray_NDIM(psArray) == 2) ? 1 : 2;
    4198       19388 :     int ydim = ( PyArray_NDIM(psArray) == 2) ? 0 : 1;
    4199             : 
    4200       19388 :     if( PyArray_DIMS(psArray)[xdim] > INT_MAX ||
    4201       19388 :         PyArray_DIMS(psArray)[ydim] > INT_MAX )
    4202             :     {
    4203           0 :         CPLError(CE_Failure, CPLE_NotSupported,
    4204             :                     "Too big array dimensions");
    4205           0 :         return CE_Failure;
    4206             :     }
    4207       19388 :     int nxsize, nysize;
    4208       19388 :     GSpacing pixel_space, line_space;
    4209       19388 :     nxsize = static_cast<int>(PyArray_DIMS(psArray)[xdim]);
    4210       19388 :     nysize = static_cast<int>(PyArray_DIMS(psArray)[ydim]);
    4211       19388 :     pixel_space = PyArray_STRIDES(psArray)[xdim];
    4212       19388 :     line_space = PyArray_STRIDES(psArray)[ydim];
    4213             : 
    4214       19388 :     GDALRasterIOExtraArg sExtraArg;
    4215       19388 :     INIT_RASTERIO_EXTRA_ARG(sExtraArg);
    4216       19388 :     sExtraArg.eResampleAlg = resample_alg;
    4217       19388 :     sExtraArg.pfnProgress = callback;
    4218       19388 :     sExtraArg.pProgressData = callback_data;
    4219       19388 :     sExtraArg.bOperateInBufType = operate_in_buf_type;
    4220       19388 :     int nXOff = (int)(xoff + 0.5);
    4221       19388 :     int nYOff = (int)(yoff + 0.5);
    4222       19388 :     int nXSize = (int)(xsize + 0.5);
    4223       19388 :     int nYSize = (int)(ysize + 0.5);
    4224       19388 :     if( fabs(xoff-nXOff) > 1e-8 || fabs(yoff-nYOff) > 1e-8 ||
    4225       19327 :         fabs(xsize-nXSize) > 1e-8 || fabs(ysize-nYSize) > 1e-8 )
    4226             :     {
    4227          61 :         sExtraArg.bFloatingPointWindowValidity = TRUE;
    4228          61 :         sExtraArg.dfXOff = xoff;
    4229          61 :         sExtraArg.dfYOff = yoff;
    4230          61 :         sExtraArg.dfXSize = xsize;
    4231          61 :         sExtraArg.dfYSize = ysize;
    4232             :     }
    4233             : 
    4234       27026 :     return  GDALRasterIOEx( band, (bWrite) ? GF_Write : GF_Read, nXOff, nYOff, nXSize, nYSize,
    4235             :                           PyArray_DATA(psArray), nxsize, nysize,
    4236             :                           buf_type, pixel_space, line_space, &sExtraArg );
    4237             :   }
    4238             : 
    4239             : 
    4240         108 :   CPLErr DatasetIONumPy( GDALDatasetShadow* ds, int bWrite, double xoff, double yoff, double xsize, double ysize,
    4241             :                          PyArrayObject *psArray,
    4242             :                          GDALDataType buf_type,
    4243             :                          GDALRIOResampleAlg resample_alg,
    4244             :                          int operate_in_buf_type,
    4245             :                          GDALProgressFunc callback = NULL,
    4246             :                          void* callback_data = NULL,
    4247             :                          bool binterleave = true,
    4248             :                          int band_list = 0, int *pband_list = 0 )
    4249             : {
    4250         108 :     if( PyArray_NDIM(psArray) != 3 )
    4251             :     {
    4252           0 :         CPLError( CE_Failure, CPLE_AppDefined,
    4253             :                   "Illegal numpy array rank %d.",
    4254             :                   PyArray_NDIM(psArray) );
    4255           0 :         return CE_Failure;
    4256             :     }
    4257             : 
    4258         108 :     if( !bWrite && !(PyArray_FLAGS(psArray) & NPY_ARRAY_WRITEABLE) )
    4259             :     {
    4260           0 :         CPLError( CE_Failure, CPLE_AppDefined,
    4261             :                   "Cannot read in a non-writeable array." );
    4262           0 :         return CE_Failure;
    4263             :     }
    4264             : 
    4265         108 :     int xdim = binterleave ? 2 : 1;
    4266         108 :     int ydim = binterleave ? 1 : 0;
    4267         108 :     int bdim = binterleave ? 0 : 2;
    4268         108 :     if( PyArray_DIMS(psArray)[xdim] > INT_MAX ||
    4269         108 :         PyArray_DIMS(psArray)[ydim] > INT_MAX ||
    4270         108 :         PyArray_DIMS(psArray)[bdim] > INT_MAX )
    4271             :     {
    4272           0 :         CPLError(CE_Failure, CPLE_NotSupported,
    4273             :                     "Too big array dimensions");
    4274           0 :         return CE_Failure;
    4275             :     }
    4276             : 
    4277         108 :     int bandsize, nxsize, nysize;
    4278         108 :     GIntBig pixel_space, line_space, band_space;
    4279         108 :     nxsize = static_cast<int>(PyArray_DIMS(psArray)[xdim]);
    4280         108 :     nysize = static_cast<int>(PyArray_DIMS(psArray)[ydim]);
    4281         108 :     bandsize = static_cast<int>(PyArray_DIMS(psArray)[bdim]);
    4282         108 :     int bandcount = band_list ? band_list : GDALGetRasterCount(ds);
    4283         108 :     if( bandsize != bandcount )
    4284             :     {
    4285           0 :         CPLError( CE_Failure, CPLE_AppDefined,
    4286             :                   "Illegal numpy array band dimension %d. Expected value: %d",
    4287             :                   bandsize, bandcount );
    4288           0 :         return CE_Failure;
    4289             :     }
    4290         108 :     pixel_space = PyArray_STRIDES(psArray)[xdim];
    4291         108 :     line_space = PyArray_STRIDES(psArray)[ydim];
    4292         108 :     band_space = PyArray_STRIDES(psArray)[bdim];
    4293             : 
    4294         108 :     GDALRasterIOExtraArg sExtraArg;
    4295         108 :     INIT_RASTERIO_EXTRA_ARG(sExtraArg);
    4296         108 :     sExtraArg.eResampleAlg = resample_alg;
    4297         108 :     sExtraArg.pfnProgress = callback;
    4298         108 :     sExtraArg.pProgressData = callback_data;
    4299         108 :     sExtraArg.bOperateInBufType = operate_in_buf_type;
    4300         108 :     int nXOff = (int)(xoff + 0.5);
    4301         108 :     int nYOff = (int)(yoff + 0.5);
    4302         108 :     int nXSize = (int)(xsize + 0.5);
    4303         108 :     int nYSize = (int)(ysize + 0.5);
    4304         108 :     if( fabs(xoff-nXOff) > 1e-8 || fabs(yoff-nYOff) > 1e-8 ||
    4305         107 :         fabs(xsize-nXSize) > 1e-8 || fabs(ysize-nYSize) > 1e-8 )
    4306             :     {
    4307           1 :         sExtraArg.bFloatingPointWindowValidity = TRUE;
    4308           1 :         sExtraArg.dfXOff = xoff;
    4309           1 :         sExtraArg.dfYOff = yoff;
    4310           1 :         sExtraArg.dfXSize = xsize;
    4311           1 :         sExtraArg.dfYSize = ysize;
    4312             :     }
    4313             : 
    4314         177 :     return  GDALDatasetRasterIOEx( ds, (bWrite) ? GF_Write : GF_Read, nXOff, nYOff, nXSize, nYSize,
    4315             :                                    PyArray_DATA(psArray), nxsize, nysize,
    4316             :                                    buf_type,
    4317             :                                    bandcount, pband_list,
    4318             :                                    pixel_space, line_space, band_space, &sExtraArg );
    4319             :   }
    4320             : 
    4321             : 
    4322             : static int*
    4323         108 : CreateCIntListFromSequence( PyObject* pySeq, int* pnSize ) {
    4324             :   /* check if is List */
    4325         108 :   if ( !PySequence_Check(pySeq) ) {
    4326           0 :     PyErr_SetString(PyExc_TypeError, "not a sequence");
    4327           0 :     *pnSize = -1;
    4328           0 :     return NULL;
    4329             :   }
    4330         108 :   Py_ssize_t size = PySequence_Size(pySeq);
    4331         108 :   if( size > (Py_ssize_t)INT_MAX ) {
    4332           0 :     PyErr_SetString(PyExc_RuntimeError, "too big sequence");
    4333           0 :     *pnSize = -1;
    4334           0 :     return NULL;
    4335             :   }
    4336         108 :   if( (size_t)size > SIZE_MAX / sizeof(int) ) {
    4337           0 :     PyErr_SetString(PyExc_RuntimeError, "too big sequence");
    4338           0 :     *pnSize = -1;
    4339           0 :     return NULL;
    4340             :   }
    4341         108 :   *pnSize = (int)size;
    4342         108 :   int* ret = (int*) malloc((*pnSize)*sizeof(int));
    4343         108 :   if( !ret ) {
    4344           0 :     PyErr_SetString(PyExc_MemoryError, "cannot allocate temporary buffer");
    4345           0 :     *pnSize = -1;
    4346           0 :     return NULL;
    4347             :   }
    4348         500 :   for( int i = 0; i<*pnSize; i++ ) {
    4349         392 :     PyObject *o = PySequence_GetItem(pySeq,i);
    4350         392 :     if ( !PyArg_Parse(o,"i",&ret[i]) ) {
    4351           0 :         PyErr_SetString(PyExc_TypeError, "not an integer");
    4352           0 :         Py_DECREF(o);
    4353           0 :         free(ret);
    4354           0 :         *pnSize = -1;
    4355           0 :         return NULL;
    4356             :     }
    4357         392 :     Py_DECREF(o);
    4358             :   }
    4359             :   return ret;
    4360             : }
    4361             : 
    4362             : 
    4363         219 : static bool CheckNumericDataType(GDALExtendedDataTypeHS* dt)
    4364             : {
    4365         219 :     auto klass = GDALExtendedDataTypeGetClass(dt);
    4366         219 :     if( klass == GEDTC_NUMERIC )
    4367             :         return true;
    4368          27 :     if( klass == GEDTC_STRING )
    4369             :         return false;
    4370          27 :     CPLAssert( klass == GEDTC_COMPOUND );
    4371          27 :     size_t nCount = 0;
    4372          27 :     GDALEDTComponentH* comps = GDALExtendedDataTypeGetComponents(dt, &nCount);
    4373             :     bool ret = true;
    4374         162 :     for( size_t i = 0; i < nCount; i++ )
    4375             :     {
    4376         135 :         auto tmpType = GDALEDTComponentGetType(comps[i]);
    4377         135 :         ret = CheckNumericDataType(tmpType);
    4378         135 :         GDALExtendedDataTypeRelease(tmpType);
    4379         135 :         if( !ret )
    4380             :             break;
    4381             :     }
    4382          27 :     GDALExtendedDataTypeFreeComponents(comps, nCount);
    4383             :     return ret;
    4384             : }
    4385             : 
    4386             : 
    4387          84 :   CPLErr MDArrayIONumPy( bool bWrite,
    4388             :                           GDALMDArrayHS* mdarray,
    4389             :                           PyArrayObject *psArray,
    4390             :                           int nDims1, GUIntBig* array_start_idx,
    4391             :                           int nDims3, GIntBig* array_step,
    4392             :                           GDALExtendedDataTypeHS* buffer_datatype) {
    4393             : 
    4394          84 :     if( !CheckNumericDataType(buffer_datatype) )
    4395             :     {
    4396           0 :         CPLError(CE_Failure, CPLE_NotSupported,
    4397             :             "String buffer data type not supported in SWIG bindings");
    4398           0 :         return CE_Failure;
    4399             :     }
    4400          84 :     const int nExpectedDims = (int)GDALMDArrayGetDimensionCount(mdarray);
    4401          84 :     if( PyArray_NDIM(psArray) != nExpectedDims )
    4402             :     {
    4403           0 :         CPLError( CE_Failure, CPLE_AppDefined,
    4404             :                   "Illegal numpy array rank %d.",
    4405             :                   PyArray_NDIM(psArray) );
    4406           0 :         return CE_Failure;
    4407             :     }
    4408             : 
    4409         168 :     std::vector<size_t> count_internal(nExpectedDims+1);
    4410         168 :     std::vector<GPtrDiff_t> buffer_stride_internal(nExpectedDims+1);
    4411          84 :     const size_t nDTSize = GDALExtendedDataTypeGetSize(buffer_datatype);
    4412          84 :     if( nDTSize == 0 )
    4413             :     {
    4414             :         return CE_Failure;
    4415             :     }
    4416         211 :     for( int i = 0; i < nExpectedDims; i++ )
    4417             :     {
    4418         127 :         count_internal[i] = PyArray_DIMS(psArray)[i];
    4419         127 :         if( (PyArray_STRIDES(psArray)[i] % nDTSize) != 0 )
    4420             :         {
    4421           0 :             CPLError( CE_Failure, CPLE_AppDefined,
    4422             :                       "Stride[%d] not a multiple of data type size",
    4423             :                       i );
    4424             :             return CE_Failure;
    4425             :         }
    4426         127 :         buffer_stride_internal[i] = PyArray_STRIDES(psArray)[i] / nDTSize;
    4427             :     }
    4428             : 
    4429          84 :     if( bWrite )
    4430             :     {
    4431          14 :         return GDALMDArrayWrite( mdarray,
    4432             :                                 array_start_idx,
    4433          14 :                                 &count_internal[0],
    4434             :                                 array_step,
    4435          14 :                                 &buffer_stride_internal[0],
    4436             :                                 buffer_datatype,
    4437          14 :                                 PyArray_DATA(psArray),
    4438          14 :                                 NULL, 0) ? CE_None : CE_Failure;
    4439             :     }
    4440             :     else
    4441             :     {
    4442          70 :         return GDALMDArrayRead( mdarray,
    4443             :                                 array_start_idx,
    4444          70 :                                 &count_internal[0],
    4445             :                                 array_step,
    4446          70 :                                 &buffer_stride_internal[0],
    4447             :                                 buffer_datatype,
    4448             :                                 PyArray_DATA(psArray),
    4449          70 :                                 NULL, 0) ? CE_None : CE_Failure;
    4450             :     }
    4451             :   }
    4452             : 
    4453             : 
    4454             : static GUIntBig*
    4455          84 : CreateCGUIntBigListFromSequence( PyObject* pySeq, int* pnSize ) {
    4456             :   /* check if is List */
    4457          84 :   if ( !PySequence_Check(pySeq) ) {
    4458           0 :     PyErr_SetString(PyExc_TypeError, "not a sequence");
    4459           0 :     *pnSize = -1;
    4460           0 :     return NULL;
    4461             :   }
    4462          84 :   Py_ssize_t size = PySequence_Size(pySeq);
    4463          84 :   if( size > (Py_ssize_t)INT_MAX ) {
    4464           0 :     PyErr_SetString(PyExc_RuntimeError, "too big sequence");
    4465           0 :     *pnSize = -1;
    4466           0 :     return NULL;
    4467             :   }
    4468          84 :   if( (size_t)size > SIZE_MAX / sizeof(GUIntBig) ) {
    4469           0 :     PyErr_SetString(PyExc_RuntimeError, "too big sequence");
    4470           0 :     *pnSize = -1;
    4471           0 :     return NULL;
    4472             :   }
    4473          84 :   *pnSize = (int)size;
    4474          84 :   GUIntBig* ret = (GUIntBig*) malloc((*pnSize)*sizeof(GUIntBig));
    4475          84 :   if( !ret ) {
    4476           0 :     PyErr_SetString(PyExc_MemoryError, "cannot allocate temporary buffer");
    4477           0 :     *pnSize = -1;
    4478           0 :     return NULL;
    4479             :   }
    4480         211 :   for( int i = 0; i<*pnSize; i++ ) {
    4481         127 :     PyObject *o = PySequence_GetItem(pySeq,i);
    4482         127 :     if ( !PyArg_Parse(o,"K",&ret[i]) ) {
    4483           0 :         PyErr_SetString(PyExc_TypeError, "not an integer");
    4484           0 :         Py_DECREF(o);
    4485           0 :         free(ret);
    4486           0 :         *pnSize = -1;
    4487           0 :         return NULL;
    4488             :     }
    4489         127 :     Py_DECREF(o);
    4490             :   }
    4491             :   return ret;
    4492             : }
    4493             : 
    4494             : 
    4495             : static GIntBig*
    4496          84 : CreateCGIntBigListFromSequence( PyObject* pySeq, int* pnSize ) {
    4497             :   /* check if is List */
    4498          84 :   if ( !PySequence_Check(pySeq) ) {
    4499           0 :     PyErr_SetString(PyExc_TypeError, "not a sequence");
    4500           0 :     *pnSize = -1;
    4501           0 :     return NULL;
    4502             :   }
    4503          84 :   Py_ssize_t size = PySequence_Size(pySeq);
    4504          84 :   if( size > (Py_ssize_t)INT_MAX ) {
    4505           0 :     PyErr_SetString(PyExc_RuntimeError, "too big sequence");
    4506           0 :     *pnSize = -1;
    4507           0 :     return NULL;
    4508             :   }
    4509          84 :   if( (size_t)size > SIZE_MAX / sizeof(GIntBig) ) {
    4510           0 :     PyErr_SetString(PyExc_RuntimeError, "too big sequence");
    4511           0 :     *pnSize = -1;
    4512           0 :     return NULL;
    4513             :   }
    4514          84 :   *pnSize = (int)size;
    4515          84 :   GIntBig* ret = (GIntBig*) malloc((*pnSize)*sizeof(GIntBig));
    4516          84 :   if( !ret ) {
    4517           0 :     PyErr_SetString(PyExc_MemoryError, "cannot allocate temporary buffer");
    4518           0 :     *pnSize = -1;
    4519           0 :     return NULL;
    4520             :   }
    4521         211 :   for( int i = 0; i<*pnSize; i++ ) {
    4522         127 :     PyObject *o = PySequence_GetItem(pySeq,i);
    4523         127 :     if ( !PyArg_Parse(o,"L",&ret[i]) ) {
    4524           0 :         PyErr_SetString(PyExc_TypeError, "not an integer");
    4525           0 :         Py_DECREF(o);
    4526           0 :         free(ret);
    4527           0 :         *pnSize = -1;
    4528           0 :         return NULL;
    4529             :     }
    4530         127 :     Py_DECREF(o);
    4531             :   }
    4532             :   return ret;
    4533             : }
    4534             : 
    4535             : 
    4536             : typedef void* VoidPtrAsLong;
    4537             : 
    4538        7724 : static bool AddNumpyArrayToDict(PyObject *dict,
    4539             :                                 const struct ArrowSchema* schemaField,
    4540             :                                 const struct ArrowArray* arrayField,
    4541             :                                 const std::string& osPrefix,
    4542             :                                 PyObject* pointerArrayKeeper)
    4543             : {
    4544        7724 :     npy_intp dims = arrayField->length;
    4545        7724 :     const char* arrowType = schemaField->format;
    4546        7724 :     int typenum = -1;
    4547        7724 :     int sizeOfType = 0;
    4548        7724 :     const struct
    4549             :     {
    4550             :         char        arrowType;
    4551             :         int         numpyType;
    4552             :         int         sizeOfType;
    4553        7724 :     } MapArrowTypeToNumpyType[] = {
    4554             :         { 'b', NPY_BOOL,    1 },
    4555             :         { 'C', NPY_UINT8,   1 },
    4556             :         { 'c', NPY_INT8,    1 },
    4557             :         { 'S', NPY_UINT16,  2 },
    4558             :         { 's', NPY_INT16,   2 },
    4559             :         { 'I', NPY_UINT32,  4 },
    4560             :         { 'i', NPY_INT32,   4 },
    4561             :         { 'L', NPY_UINT64,  8 },
    4562             :         { 'l', NPY_INT64,   8 },
    4563             :         { 'e', NPY_FLOAT16, 2 },
    4564             :         { 'f', NPY_FLOAT32, 4 },
    4565             :         { 'g', NPY_FLOAT64, 8 },
    4566             :         // { 'E', NPY_COMPLEX32, 4 },
    4567             :         // { 'F', NPY_COMPLEX64, 8 },
    4568             :         // { 'G', NPY_COMPLEX128, 16 },
    4569             :     };
    4570        7724 :     const size_t nEltsInMapArrowTypeToNumpyType =
    4571             :         sizeof(MapArrowTypeToNumpyType) / sizeof(MapArrowTypeToNumpyType[0]);
    4572       17850 :     const bool bIsLargeList = (arrowType[0] == '+' &&
    4573        2402 :                                arrowType[1] == 'L' &&
    4574        7879 :                                arrowType[2] == '\0' &&
    4575         155 :                                schemaField->n_children == 1);
    4576       17850 :     const bool bIsList = (arrowType[0] == '+' &&
    4577        2402 :                           arrowType[1] == 'l' &&
    4578        9025 :                           arrowType[2] == '\0' &&
    4579        1301 :                           schemaField->n_children == 1);
    4580       17850 :     const bool bIsFixedSizeList = (arrowType[0] == '+' &&
    4581        2402 :                                    arrowType[1] == 'w' &&
    4582        8504 :                                    arrowType[2] == ':' &&
    4583         780 :                                    schemaField->n_children == 1);
    4584       73298 :     for( size_t j = 0; j < nEltsInMapArrowTypeToNumpyType; ++j )
    4585             :     {
    4586       70188 :         if( arrowType[0] == MapArrowTypeToNumpyType[j].arrowType &&
    4587        2794 :             arrowType[1] == '\0' )
    4588             :         {
    4589        2794 :             typenum = MapArrowTypeToNumpyType[j].numpyType;
    4590        2794 :             sizeOfType = MapArrowTypeToNumpyType[j].sizeOfType;
    4591        2794 :             break;
    4592             :         }
    4593       67394 :         else if( (bIsList || bIsLargeList || bIsFixedSizeList) &&
    4594       17245 :                  schemaField->children[0]->format[0] == MapArrowTypeToNumpyType[j].arrowType &&
    4595        1820 :                  schemaField->children[0]->format[1] == '\0' )
    4596             :         {
    4597        1820 :             typenum = MapArrowTypeToNumpyType[j].numpyType;
    4598        1820 :             sizeOfType = MapArrowTypeToNumpyType[j].sizeOfType;
    4599        1820 :             break;
    4600             :         }
    4601             :     }
    4602             : 
    4603        7724 :     PyObject* numpyArray = NULL;
    4604        7724 :     if( typenum != -1 && !bIsList && !bIsLargeList && schemaField->n_children == 0 )
    4605             :     {
    4606        2794 :         if( arrayField->n_buffers != 2 )
    4607             :         {
    4608           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    4609             :                      "Field %s: arrayField->n_buffers != 2",
    4610           0 :                      schemaField->name);
    4611           0 :             return false;
    4612             :         }
    4613        2794 :         if( typenum == NPY_BOOL )
    4614             :         {
    4615         157 :             numpyArray = PyArray_SimpleNew(1, &dims, NPY_BOOL);
    4616         484 :             for( npy_intp j = 0; j < dims; j++ )
    4617             :             {
    4618         327 :                 size_t srcOffset = static_cast<size_t>(arrayField->offset + j);
    4619         327 :                 uint8_t val = (((uint8_t*)arrayField->buffers[1])[srcOffset/8] >> (srcOffset % 8)) & 1;
    4620         327 :                 *(uint8_t*)PyArray_GETPTR1((PyArrayObject *) numpyArray, j) = val;
    4621             :             }
    4622             :         }
    4623             :         else
    4624             :         {
    4625        2637 :             numpyArray = PyArray_SimpleNewFromData(1, &dims, typenum,
    4626             :                                         (char*)arrayField->buffers[1] + static_cast<size_t>(arrayField->offset) * sizeOfType);
    4627             : 
    4628             :             /* Keep a reference to the owner object */
    4629             : #if NPY_API_VERSION >= 0x00000007
    4630        2637 :             PyArray_SetBaseObject((PyArrayObject *) numpyArray, pointerArrayKeeper);
    4631             : #else
    4632             :             PyArray_BASE((PyArrayObject *) numpyArray) = pointerArrayKeeper;
    4633             : #endif
    4634        2637 :             Py_INCREF(pointerArrayKeeper);
    4635             :         }
    4636             :     }
    4637        4930 :     else if( typenum != -1 && (bIsList || bIsLargeList) )
    4638             :     {
    4639        1105 :         if( arrayField->n_buffers != 2 )
    4640             :         {
    4641           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    4642             :                      "Field %s: arrayField->n_buffers != 2",
    4643           0 :                      schemaField->name);
    4644           0 :             return false;
    4645             :         }
    4646        1105 :         if( arrayField->n_children != 1 )
    4647             :         {
    4648           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    4649             :                      "Field %s: arrayField->n_children != 1",
    4650           0 :                      schemaField->name);
    4651           0 :             return false;
    4652             :         }
    4653        1105 :         if( arrayField->children[0]->n_buffers != 2 )
    4654             :         {
    4655           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    4656             :                      "Field %s: arrayField->children[0]->n_buffers != 2",
    4657           0 :                      schemaField->name);
    4658           0 :             return false;
    4659             :         }
    4660        1105 :         const int32_t* offsets = bIsList ? (const int32_t*)arrayField->buffers[1] + arrayField->offset : NULL;
    4661        1105 :         const int64_t* largeOffsets = bIsLargeList ? (const int64_t*)arrayField->buffers[1] + arrayField->offset : NULL;
    4662        1105 :         if( arrayField->children[0]->length < (offsets ? offsets[arrayField->length] : largeOffsets[arrayField->length]) )
    4663             :         {
    4664           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    4665             :                      "Field %s: arrayField->children[0]->length (=%d) < offsets[arrayField->length] (=%d)",
    4666           0 :                      schemaField->name,
    4667             :                      int(arrayField->children[0]->length),
    4668           0 :                      int(offsets ? offsets[arrayField->length] : largeOffsets[arrayField->length]));
    4669           0 :             return false;
    4670             :         }
    4671        1105 :         numpyArray = PyArray_SimpleNew(1, &dims, NPY_OBJECT);
    4672        3212 :         for( npy_intp j = 0; j < dims; j++ )
    4673             :         {
    4674        2107 :             npy_intp nvalues = offsets ? offsets[j+1] - offsets[j] : (npy_intp)(largeOffsets[j+1] - largeOffsets[j]);
    4675        2107 :             PyObject* subObj;
    4676        2107 :             if( typenum == NPY_BOOL )
    4677             :             {
    4678         224 :                 subObj = PyArray_SimpleNew(1, &nvalues, NPY_BOOL);
    4679         660 :                 for( npy_intp k = 0; k < nvalues; k++ )
    4680             :                 {
    4681         436 :                     size_t srcOffset = static_cast<size_t>(arrayField->children[0]->offset + (offsets ? offsets[j] : largeOffsets[j]) + k);
    4682         436 :                     uint8_t val = (((uint8_t*)arrayField->children[0]->buffers[1])[srcOffset / 8]  >> (srcOffset % 8)) & 1;
    4683         436 :                     *(uint8_t*)PyArray_GETPTR1((PyArrayObject *) subObj, k) = val;
    4684             :                 }
    4685             :             }
    4686             :             else
    4687             :             {
    4688        1883 :                 subObj = PyArray_SimpleNewFromData(
    4689             :                     1, &nvalues, typenum,
    4690             :                     (char*)arrayField->children[0]->buffers[1] + (static_cast<size_t>(arrayField->children[0]->offset) + (offsets ? offsets[j] : largeOffsets[j])) * sizeOfType);
    4691             :                 /* Keep a reference to the owner object */
    4692             : #if NPY_API_VERSION >= 0x00000007
    4693        1883 :                 PyArray_SetBaseObject((PyArrayObject *) subObj, pointerArrayKeeper);
    4694             : #else
    4695             :                 PyArray_BASE((PyArrayObject *) subObj) = pointerArrayKeeper;
    4696             : #endif
    4697        1883 :                 Py_INCREF(pointerArrayKeeper);
    4698             :             }
    4699        2107 :             memcpy(PyArray_GETPTR1((PyArrayObject *) numpyArray, j),
    4700             :                    &subObj,
    4701             :                    sizeof(PyObject*));
    4702             :         }
    4703             :     }
    4704        3825 :     else if( typenum != -1 && bIsFixedSizeList )
    4705             :     {
    4706         715 :         if( arrayField->n_buffers != 1 )
    4707             :         {
    4708           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    4709             :                      "Field %s: arrayField->n_buffers != 1",
    4710           0 :                      schemaField->name);
    4711           0 :             return false;
    4712             :         }
    4713         715 :         if( arrayField->n_children != 1 )
    4714             :         {
    4715           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    4716             :                      "Field %s: arrayField->n_children != 1",
    4717           0 :                      schemaField->name);
    4718           0 :             return false;
    4719             :         }
    4720         715 :         const struct ArrowArray* psChildArray = arrayField->children[0];
    4721         715 :         if( psChildArray->n_buffers != 2 )
    4722             :         {
    4723           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    4724             :                      "Field %s: psChildArray->n_buffers != 2",
    4725           0 :                      schemaField->name);
    4726           0 :             return false;
    4727             :         }
    4728         715 :         const int nLength = atoi(arrowType + strlen("+w:"));
    4729         715 :         if( psChildArray->length < nLength * arrayField->length )
    4730             :         {
    4731           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    4732             :                      "Field %s: psChildArray->length < nLength * arrayField->length",
    4733           0 :                      schemaField->name);
    4734           0 :             return false;
    4735             :         }
    4736         715 :         numpyArray = PyArray_SimpleNew(1, &dims, NPY_OBJECT);
    4737        1936 :         for( npy_intp j = 0; j < dims; j++ )
    4738             :         {
    4739        1221 :             PyObject* subObj;
    4740        1221 :             npy_intp nvalues = nLength;
    4741        1221 :             if( typenum == NPY_BOOL )
    4742             :             {
    4743         111 :                 subObj = PyArray_SimpleNew(1, &nvalues, NPY_BOOL);
    4744         333 :                 for( npy_intp k = 0; k < nvalues; k++ )
    4745             :                 {
    4746         222 :                     size_t srcOffset = static_cast<size_t>(psChildArray->offset + (j + arrayField->offset) * nLength + k);
    4747         222 :                     uint8_t val = (((uint8_t*)psChildArray->buffers[1])[srcOffset / 8]  >> (srcOffset % 8)) & 1;
    4748         222 :                     *(uint8_t*)PyArray_GETPTR1((PyArrayObject *) subObj, k) = val;
    4749             :                 }
    4750             :             }
    4751             :             else
    4752             :             {
    4753        1110 :                 subObj = PyArray_SimpleNewFromData(
    4754             :                     1, &nvalues, typenum,
    4755             :                     (char*)psChildArray->buffers[1] + static_cast<size_t>((psChildArray->offset + (j + arrayField->offset) * nLength) * sizeOfType));
    4756             :                 /* Keep a reference to the owner object */
    4757             : #if NPY_API_VERSION >= 0x00000007
    4758        1110 :                 PyArray_SetBaseObject((PyArrayObject *) subObj, pointerArrayKeeper);
    4759             : #else
    4760             :                 PyArray_BASE((PyArrayObject *) subObj) = pointerArrayKeeper;
    4761             : #endif
    4762        1110 :                 Py_INCREF(pointerArrayKeeper);
    4763             :             }
    4764        1221 :             memcpy(PyArray_GETPTR1((PyArrayObject *) numpyArray, j),
    4765             :                    &subObj,
    4766             :                    sizeof(PyObject*));
    4767             :         }
    4768             :     }
    4769        3110 :     else if( (arrowType[0] == 'u' || /* string */
    4770        1285 :               arrowType[0] == 'z'    /* binary */) && arrowType[1] == '\0' &&
    4771        1285 :               schemaField->n_children == 0 )
    4772             :     {
    4773        1285 :         if( arrayField->n_buffers != 3 )
    4774             :         {
    4775           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    4776             :                      "Field %s: arrayField->n_buffers != 3",
    4777           0 :                      schemaField->name);
    4778           0 :             return false;
    4779             :         }
    4780        1285 :         const int32_t* offsets = (const int32_t*)arrayField->buffers[1] + static_cast<size_t>(arrayField->offset);
    4781             :         // numpy can't deal with zero length strings
    4782        1285 :         int32_t maxLength = 1;
    4783        1285 :         int32_t minLength = 0x7FFFFFFF;
    4784        1285 :         int64_t averageLength = 0;
    4785        8295 :         for( npy_intp j = 0; j < dims; j++ )
    4786             :         {
    4787        7010 :             const int32_t nLength = offsets[j+1] - offsets[j];
    4788        7010 :             if( nLength < minLength )
    4789             :                 minLength = nLength;
    4790        7010 :             if( nLength > maxLength )
    4791             :                 maxLength = nLength;
    4792        7010 :             averageLength += nLength;
    4793             :         }
    4794        1285 :         if( dims )
    4795        1285 :             averageLength /= dims;
    4796             : 
    4797             : 
    4798        1285 :         if( arrowType[0] == 'z' && (minLength == 0 || minLength != maxLength) )
    4799             :         {
    4800         816 :             const uint8_t* panNotNulls =
    4801         408 :                  arrayField->null_count == 0 ? NULL :
    4802             :                 (const uint8_t*)arrayField->buffers[0];
    4803         408 :             numpyArray = PyArray_SimpleNew(1, &dims, NPY_OBJECT);
    4804        1417 :             for( npy_intp j = 0; j < dims; j++ )
    4805             :             {
    4806        1009 :                 PyObject* subObj;
    4807        1009 :                 size_t srcOffset = static_cast<size_t>(arrayField->offset + j);
    4808        1009 :                 if( panNotNulls && (panNotNulls[srcOffset / 8] & (1 << (srcOffset%8))) == 0 )
    4809             :                 {
    4810         827 :                     subObj = Py_None;
    4811         827 :                     Py_INCREF(subObj);
    4812             :                 }
    4813             :                 else
    4814             :                 {
    4815         182 :                     const int32_t nLength = offsets[j+1] - offsets[j];
    4816         182 :                     subObj = PyBytes_FromStringAndSize(
    4817         182 :                         ((const char*)arrayField->buffers[2]) + offsets[j],
    4818             :                         nLength);
    4819             :                 }
    4820        1009 :                 memcpy(PyArray_GETPTR1((PyArrayObject *) numpyArray, j),
    4821             :                        &subObj,
    4822             :                        sizeof(PyObject*));
    4823             :             }
    4824             :         }
    4825         877 :         else if( arrowType[0] == 'u' && dims > 0 && maxLength > 32 &&
    4826          70 :                  maxLength > 100 * 1000 / dims &&
    4827           1 :                  maxLength > averageLength * 2 )
    4828             :         {
    4829             :             // If the maximum string size is significantly large, and
    4830             :             // larger than the average one, then do not use fixed size
    4831             :             // strings, but create an array of string objects to save memory
    4832           2 :             const uint8_t* panNotNulls =
    4833           1 :                  arrayField->null_count == 0 ? NULL :
    4834             :                 (const uint8_t*)arrayField->buffers[0];
    4835           1 :             numpyArray = PyArray_SimpleNew(1, &dims, NPY_OBJECT);
    4836           4 :             for( npy_intp j = 0; j < dims; j++ )
    4837             :             {
    4838           3 :                 PyObject* subObj;
    4839           3 :                 size_t srcOffset = static_cast<size_t>(arrayField->offset + j);
    4840           3 :                 if( panNotNulls && (panNotNulls[srcOffset / 8] & (1 << (srcOffset%8))) == 0 )
    4841             :                 {
    4842           1 :                     subObj = Py_None;
    4843           1 :                     Py_INCREF(subObj);
    4844             :                 }
    4845             :                 else
    4846             :                 {
    4847           2 :                     const int32_t nLength = offsets[j+1] - offsets[j];
    4848           2 :                     subObj = PyUnicode_FromStringAndSize(
    4849           2 :                         ((const char*)arrayField->buffers[2]) + offsets[j],
    4850             :                         nLength);
    4851             :                 }
    4852           3 :                 memcpy(PyArray_GETPTR1((PyArrayObject *) numpyArray, j),
    4853             :                        &subObj,
    4854             :                        sizeof(PyObject*));
    4855             :             }
    4856             :         }
    4857             :         else
    4858             :         {
    4859             :             // create the dtype string
    4860        1219 :             PyObject *pDTypeString = PyUnicode_FromFormat("%c%u",
    4861             :                 arrowType[0] == 'u' ? 'S' : 'V', maxLength);
    4862             :             // out type description object
    4863         876 :             PyArray_Descr *pDescr = NULL;
    4864         876 :             PyArray_DescrConverter(pDTypeString, &pDescr);
    4865         876 :             Py_DECREF(pDTypeString);
    4866             : 
    4867         876 :             if( minLength == maxLength )
    4868             :             {
    4869        1070 :                 numpyArray = PyArray_NewFromDescr(
    4870             :                     &PyArray_Type, pDescr, 1, &dims, NULL,
    4871         535 :                     (char*)arrayField->buffers[2] + offsets[0], 0, NULL);
    4872             : 
    4873             :                 /* Keep a reference to the owner object */
    4874             : #if NPY_API_VERSION >= 0x00000007
    4875         535 :                 PyArray_SetBaseObject((PyArrayObject *) numpyArray, pointerArrayKeeper);
    4876             : #else
    4877             :                 PyArray_BASE((PyArrayObject *) numpyArray) = pointerArrayKeeper;
    4878             : #endif
    4879         535 :                 Py_INCREF(pointerArrayKeeper);
    4880             :             }
    4881             :             else
    4882             :             {
    4883             :                 // create array
    4884         341 :                 numpyArray = PyArray_SimpleNewFromDescr(1, &dims, pDescr);
    4885        1308 :                 for( npy_intp j = 0; j < dims; j++ )
    4886             :                 {
    4887         967 :                     const int32_t nLength = offsets[j+1] - offsets[j];
    4888         967 :                     if( nLength > 0 )
    4889             :                     {
    4890        1453 :                         memcpy(PyArray_GETPTR1((PyArrayObject *) numpyArray, j),
    4891         486 :                                ((const char*)arrayField->buffers[2]) + offsets[j],
    4892             :                                nLength);
    4893             :                     }
    4894         967 :                     if( nLength < maxLength )
    4895             :                     {
    4896         967 :                         memset(((char*)PyArray_GETPTR1((PyArrayObject *) numpyArray, j)) + nLength,
    4897             :                                0,
    4898         803 :                                maxLength - nLength);
    4899             :                     }
    4900             :                 }
    4901             :             }
    4902             :         }
    4903             :     }
    4904        1825 :     else if( (arrowType[0] == 'U' || /* string */
    4905         228 :               arrowType[0] == 'Z'    /* binary */) && arrowType[1] == '\0' &&
    4906         228 :               schemaField->n_children == 0 )
    4907             :     {
    4908         228 :         if( arrayField->n_buffers != 3 )
    4909             :         {
    4910           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    4911             :                      "Field %s: arrayField->n_buffers != 3",
    4912           0 :                      schemaField->name);
    4913           0 :             return false;
    4914             :         }
    4915         228 :         const int64_t* offsets = (const int64_t*)arrayField->buffers[1] + static_cast<size_t>(arrayField->offset);
    4916             :         // numpy can't deal with zero length strings
    4917         228 :         int64_t maxLength = 1;
    4918         228 :         int64_t minLength = ((int64_t)0x7FFFFFFF << 32) | 0xFFFFFFFF;
    4919         228 :         int64_t averageLength = 0;
    4920         634 :         for( npy_intp j = 0; j < dims; j++ )
    4921             :         {
    4922         406 :             const int64_t nLength = offsets[j+1] - offsets[j];
    4923         406 :             if( nLength < minLength )
    4924             :                 minLength = nLength;
    4925         406 :             if( nLength > maxLength )
    4926             :                 maxLength = nLength;
    4927         406 :             averageLength += nLength;
    4928             :         }
    4929         228 :         if( dims )
    4930         208 :             averageLength /= dims;
    4931             : 
    4932         228 :         if( arrowType[0] == 'Z' && (minLength == 0 || minLength != maxLength || maxLength > 0x7FFFFFFF) )
    4933             :         {
    4934          90 :             const uint8_t* panNotNulls =
    4935          45 :                  arrayField->null_count == 0 ? NULL :
    4936             :                 (const uint8_t*)arrayField->buffers[0];
    4937          45 :             numpyArray = PyArray_SimpleNew(1, &dims, NPY_OBJECT);
    4938         141 :             for( npy_intp j = 0; j < dims; j++ )
    4939             :             {
    4940          96 :                 PyObject* subObj;
    4941          96 :                 size_t srcOffset = static_cast<size_t>(arrayField->offset + j);
    4942          96 :                 if( panNotNulls && (panNotNulls[srcOffset / 8] & (1 << (srcOffset%8))) == 0 )
    4943             :                 {
    4944           8 :                     subObj = Py_None;
    4945           8 :                     Py_INCREF(subObj);
    4946             :                 }
    4947             :                 else
    4948             :                 {
    4949          88 :                     const int64_t nLength = offsets[j+1] - offsets[j];
    4950          88 :                     subObj = PyBytes_FromStringAndSize(
    4951          88 :                         ((const char*)arrayField->buffers[2]) + offsets[j],
    4952             :                         static_cast<size_t>(nLength));
    4953             :                 }
    4954          96 :                 memcpy(PyArray_GETPTR1((PyArrayObject *) numpyArray, j),
    4955             :                        &subObj,
    4956             :                        sizeof(PyObject*));
    4957             :             }
    4958             :         }
    4959         183 :         else if( arrowType[0] == 'U' && dims > 0 && maxLength > 32 &&
    4960           0 :                  maxLength <= 0x7FFFFFFF &&
    4961           0 :                  maxLength > 100 * 1000 / dims &&
    4962           0 :                  maxLength > averageLength * 2 )
    4963             :         {
    4964             :             // If the maximum string size is significantly large, and
    4965             :             // larger than the average one, then do not use fixed size
    4966             :             // strings, but create an array of string objects to save memory
    4967           0 :             const uint8_t* panNotNulls =
    4968           0 :                  arrayField->null_count == 0 ? NULL :
    4969             :                 (const uint8_t*)arrayField->buffers[0];
    4970           0 :             numpyArray = PyArray_SimpleNew(1, &dims, NPY_OBJECT);
    4971           0 :             for( npy_intp j = 0; j < dims; j++ )
    4972             :             {
    4973           0 :                 PyObject* subObj;
    4974           0 :                 size_t srcOffset = static_cast<size_t>(arrayField->offset + j);
    4975           0 :                 if( panNotNulls && (panNotNulls[srcOffset / 8] & (1 << (srcOffset%8))) == 0 )
    4976             :                 {
    4977           0 :                     subObj = Py_None;
    4978           0 :                     Py_INCREF(subObj);
    4979             :                 }
    4980             :                 else
    4981             :                 {
    4982           0 :                     const int32_t nLength = int(offsets[j+1] - offsets[j]);
    4983           0 :                     subObj = PyUnicode_FromStringAndSize(
    4984           0 :                         ((const char*)arrayField->buffers[2]) + offsets[j],
    4985             :                         nLength);
    4986             :                 }
    4987           0 :                 memcpy(PyArray_GETPTR1((PyArrayObject *) numpyArray, j),
    4988             :                        &subObj,
    4989             :                        sizeof(PyObject*));
    4990             :             }
    4991             :         }
    4992             :         else
    4993             :         {
    4994             :             // We could possibly handle this...
    4995         183 :             if( maxLength > 0x7FFFFFFF )
    4996             :             {
    4997           0 :                 CPLError(CE_Failure, CPLE_AppDefined,
    4998             :                          "Field %s: too large value",
    4999           0 :                          schemaField->name);
    5000           0 :                 return false;
    5001             :             }
    5002             : 
    5003             :             // create the dtype string
    5004         272 :             PyObject *pDTypeString = PyUnicode_FromFormat("%c%u",
    5005             :                 arrowType[0] == 'U' ? 'S' : 'V', static_cast<int32_t>(maxLength));
    5006             :             // out type description object
    5007         183 :             PyArray_Descr *pDescr = NULL;
    5008         183 :             PyArray_DescrConverter(pDTypeString, &pDescr);
    5009         183 :             Py_DECREF(pDTypeString);
    5010             : 
    5011         183 :             if( minLength == maxLength )
    5012             :             {
    5013         262 :                 numpyArray = PyArray_NewFromDescr(
    5014             :                     &PyArray_Type, pDescr, 1, &dims, NULL,
    5015         131 :                     (char*)arrayField->buffers[2] + offsets[0], 0, NULL);
    5016             : 
    5017             :                 /* Keep a reference to the owner object */
    5018             : #if NPY_API_VERSION >= 0x00000007
    5019         131 :                 PyArray_SetBaseObject((PyArrayObject *) numpyArray, pointerArrayKeeper);
    5020             : #else
    5021             :                 PyArray_BASE((PyArrayObject *) numpyArray) = pointerArrayKeeper;
    5022             : #endif
    5023         131 :                 Py_INCREF(pointerArrayKeeper);
    5024             :             }
    5025             :             else
    5026             :             {
    5027             :                 // create array
    5028          52 :                 numpyArray = PyArray_SimpleNewFromDescr(1, &dims, pDescr);
    5029         159 :                 for( npy_intp j = 0; j < dims; j++ )
    5030             :                 {
    5031         107 :                     const int32_t nLength = static_cast<int32_t>(offsets[j+1] - offsets[j]);
    5032         107 :                     if( nLength > 0 )
    5033             :                     {
    5034         157 :                         memcpy(PyArray_GETPTR1((PyArrayObject *) numpyArray, j),
    5035          50 :                                ((const char*)arrayField->buffers[2]) + offsets[j],
    5036             :                                nLength);
    5037             :                     }
    5038         107 :                     if( nLength < maxLength )
    5039             :                     {
    5040         107 :                         memset(((char*)PyArray_GETPTR1((PyArrayObject *) numpyArray, j)) + nLength,
    5041             :                                0,
    5042          74 :                                static_cast<int32_t>(maxLength) - nLength);
    5043             :                     }
    5044             :                 }
    5045             :             }
    5046             :         }
    5047             :     }
    5048        1597 :     else if( arrowType[0] == 'w' && arrowType[1] == ':' &&
    5049          69 :              schemaField->n_children == 0 )
    5050             :     {
    5051             :         // Fixed width binary
    5052          69 :         if( arrayField->n_buffers != 2 )
    5053             :         {
    5054           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5055             :                      "field %s:arrayField->n_buffers != 2",
    5056           0 :                      schemaField->name);
    5057           0 :             return false;
    5058             :         }
    5059          69 :         const int nLength = atoi(arrowType + strlen("w:"));
    5060          69 :         numpyArray = PyArray_SimpleNew(1, &dims, NPY_OBJECT);
    5061         193 :         for( npy_intp j = 0; j < dims; j++ )
    5062             :         {
    5063         124 :             PyObject* subObj = PyBytes_FromStringAndSize(
    5064         124 :                     ((const char*)arrayField->buffers[1]) + static_cast<size_t>(arrayField->offset + j) * nLength,
    5065         124 :                     nLength);
    5066         124 :             memcpy(PyArray_GETPTR1((PyArrayObject *) numpyArray, j),
    5067             :                    &subObj,
    5068             :                    sizeof(PyObject*));
    5069             :         }
    5070             :     }
    5071        1528 :     else if( bIsList &&
    5072         351 :              schemaField->children[0]->format[0] == 'u' &&
    5073          91 :              schemaField->children[0]->format[1] == '\0' )
    5074             :     {
    5075             :         // List of strings
    5076          91 :         if( arrayField->n_buffers != 2 )
    5077             :         {
    5078           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5079             :                      "Field %s: arrayField->n_buffers != 2",
    5080           0 :                      schemaField->name);
    5081           0 :             return false;
    5082             :         }
    5083          91 :         if( arrayField->n_children != 1 )
    5084             :         {
    5085           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5086             :                      "Field %s: arrayField->n_children != 1",
    5087           0 :                      schemaField->name);
    5088           0 :             return false;
    5089             :         }
    5090          91 :         if( arrayField->children[0]->n_buffers != 3 )
    5091             :         {
    5092           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5093             :                      "Field %s: arrayField->children[0]->n_buffers != 3",
    5094           0 :                      schemaField->name);
    5095           0 :             return false;
    5096             :         }
    5097          91 :         const int32_t* offsets = (const int32_t*)arrayField->buffers[1] + static_cast<size_t>(arrayField->offset);
    5098          91 :         if( arrayField->children[0]->length < offsets[arrayField->length] )
    5099             :         {
    5100           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5101             :                      "Field %s: arrayField->children[0]->length = (%d) < offsets[arrayField->length] (=%d)",
    5102           0 :                      schemaField->name,
    5103             :                      int(arrayField->children[0]->length),
    5104             :                      int(offsets[arrayField->length]));
    5105           0 :             return false;
    5106             :         }
    5107          91 :         const int32_t* offsetsToBytes = (const int32_t*)arrayField->children[0]->buffers[1] + static_cast<size_t>(arrayField->children[0]->offset);
    5108          91 :         const char* bytes = (const char*)arrayField->children[0]->buffers[2];
    5109          91 :         numpyArray = PyArray_SimpleNew(1, &dims, NPY_OBJECT);
    5110         263 :         for( npy_intp j = 0; j < dims; j++ )
    5111             :         {
    5112         172 :             npy_intp nStrings = offsets[j+1] - offsets[j];
    5113         172 :             int32_t maxLength = 1;
    5114         352 :             for( npy_intp k = 0; k < nStrings; k++ )
    5115             :             {
    5116         180 :                 const int32_t nLength = offsetsToBytes[offsets[j] + k + 1] - offsetsToBytes[offsets[j] + k];
    5117         180 :                 if( nLength > maxLength )
    5118             :                     maxLength = nLength;
    5119             :             }
    5120             : 
    5121             :             // create the dtype string
    5122         172 :             PyObject *pDTypeString = PyUnicode_FromFormat("S%d", maxLength);
    5123             :             // out type description object
    5124         172 :             PyArray_Descr *pDescr = NULL;
    5125         172 :             PyArray_DescrConverter(pDTypeString, &pDescr);
    5126         172 :             Py_DECREF(pDTypeString);
    5127             : 
    5128         172 :             PyObject* subArray = PyArray_SimpleNewFromDescr(1, &nStrings, pDescr);
    5129         352 :             for( npy_intp k = 0; k < nStrings; k++ )
    5130             :             {
    5131         180 :                 const int32_t nLength = offsetsToBytes[offsets[j] + k + 1] - offsetsToBytes[offsets[j] + k];
    5132         180 :                 if( nLength > 0 )
    5133             :                 {
    5134         333 :                     memcpy(PyArray_GETPTR1((PyArrayObject *) subArray, k),
    5135         153 :                            bytes + offsetsToBytes[offsets[j] + k],
    5136             :                            nLength);
    5137             :                 }
    5138         180 :                 if( nLength < maxLength )
    5139             :                 {
    5140         180 :                     memset(((char*)PyArray_GETPTR1((PyArrayObject *) subArray, k)) + nLength,
    5141             :                            0,
    5142          90 :                            maxLength - nLength);
    5143             :                 }
    5144             :             }
    5145             : 
    5146         172 :             memcpy(PyArray_GETPTR1((PyArrayObject *) numpyArray, j),
    5147             :                    &subArray,
    5148             :                    sizeof(PyObject*));
    5149             :         }
    5150             :     }
    5151        1437 :     else if( bIsLargeList &&
    5152           0 :              schemaField->children[0]->format[0] == 'U' &&
    5153           0 :              schemaField->children[0]->format[1] == '\0' )
    5154             :     {
    5155             :         // List of strings
    5156           0 :         if( arrayField->n_buffers != 2 )
    5157             :         {
    5158           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5159             :                      "Field %s: arrayField->n_buffers != 2",
    5160           0 :                      schemaField->name);
    5161           0 :             return false;
    5162             :         }
    5163           0 :         if( arrayField->n_children != 1 )
    5164             :         {
    5165           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5166             :                      "Field %s: arrayField->n_children != 1",
    5167           0 :                      schemaField->name);
    5168           0 :             return false;
    5169             :         }
    5170           0 :         if( arrayField->children[0]->n_buffers != 3 )
    5171             :         {
    5172           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5173             :                      "Field %s: arrayField->children[0]->n_buffers != 3",
    5174           0 :                      schemaField->name);
    5175           0 :             return false;
    5176             :         }
    5177           0 :         const int64_t* offsets = (const int64_t*)arrayField->buffers[1] + static_cast<size_t>(arrayField->offset);
    5178           0 :         if( arrayField->children[0]->length < offsets[arrayField->length] )
    5179             :         {
    5180           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5181             :                      "Field %s: arrayField->children[0]->length = (%d) < offsets[arrayField->length] (=%d)",
    5182           0 :                      schemaField->name,
    5183             :                      int(arrayField->children[0]->length),
    5184             :                      int(offsets[arrayField->length]));
    5185           0 :             return false;
    5186             :         }
    5187           0 :         const int64_t* offsetsToBytes = (const int64_t*)arrayField->children[0]->buffers[1] + static_cast<size_t>(arrayField->children[0]->offset);
    5188           0 :         const char* bytes = (const char*)arrayField->children[0]->buffers[2];
    5189           0 :         numpyArray = PyArray_SimpleNew(1, &dims, NPY_OBJECT);
    5190           0 :         for( npy_intp j = 0; j < dims; j++ )
    5191             :         {
    5192           0 :             npy_intp nStrings = offsets[j+1] - offsets[j];
    5193           0 :             int64_t maxLength = 1;
    5194           0 :             for( npy_intp k = 0; k < nStrings; k++ )
    5195             :             {
    5196           0 :                 const int64_t nLength = offsetsToBytes[offsets[j] + k + 1] - offsetsToBytes[offsets[j] + k];
    5197           0 :                 if( nLength > maxLength )
    5198             :                     maxLength = nLength;
    5199             :             }
    5200           0 :             if( maxLength >= INT_MAX )
    5201             :             {
    5202           0 :                 CPLError(CE_Failure, CPLE_AppDefined, "Too large string");
    5203           0 :                 return false;
    5204             :             }
    5205             : 
    5206             :             // create the dtype string
    5207           0 :             PyObject *pDTypeString = PyUnicode_FromFormat("S%d", int(maxLength));
    5208             :             // out type description object
    5209           0 :             PyArray_Descr *pDescr = NULL;
    5210           0 :             PyArray_DescrConverter(pDTypeString, &pDescr);
    5211           0 :             Py_DECREF(pDTypeString);
    5212             : 
    5213           0 :             PyObject* subArray = PyArray_SimpleNewFromDescr(1, &nStrings, pDescr);
    5214           0 :             for( npy_intp k = 0; k < nStrings; k++ )
    5215             :             {
    5216           0 :                 const int64_t nLength = offsetsToBytes[offsets[j] + k + 1] - offsetsToBytes[offsets[j] + k];
    5217           0 :                 if( nLength > 0 )
    5218             :                 {
    5219           0 :                     memcpy(PyArray_GETPTR1((PyArrayObject *) subArray, k),
    5220           0 :                            bytes + offsetsToBytes[offsets[j] + k],
    5221             :                            int(nLength));
    5222             :                 }
    5223           0 :                 if( nLength < maxLength )
    5224             :                 {
    5225           0 :                     memset(((char*)PyArray_GETPTR1((PyArrayObject *) subArray, k)) + nLength,
    5226             :                            0,
    5227           0 :                            int(maxLength - nLength));
    5228             :                 }
    5229             :             }
    5230             : 
    5231           0 :             memcpy(PyArray_GETPTR1((PyArrayObject *) numpyArray, j),
    5232             :                    &subArray,
    5233             :                    sizeof(PyObject*));
    5234             :         }
    5235             :     }
    5236        1437 :     else if( bIsFixedSizeList &&
    5237          65 :              schemaField->children[0]->format[0] == 'u' &&
    5238          65 :              schemaField->children[0]->format[1] == '\0' )
    5239             :     {
    5240             :         // Fixed size list of strings
    5241          65 :         const int nStrings = atoi(arrowType + strlen("+w:"));
    5242          65 :         if( arrayField->n_buffers != 1 )
    5243             :         {
    5244           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5245             :                      "Field %s: arrayField->n_buffers != 1",
    5246           0 :                      schemaField->name);
    5247           0 :             return false;
    5248             :         }
    5249          65 :         if( arrayField->n_children != 1 )
    5250             :         {
    5251           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5252             :                      "Field %s: arrayField->n_children != 1",
    5253           0 :                      schemaField->name);
    5254           0 :             return false;
    5255             :         }
    5256          65 :         if( arrayField->children[0]->n_buffers != 3 )
    5257             :         {
    5258           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5259             :                      "Field %s: arrayField->children[0]->n_buffers != 3",
    5260           0 :                      schemaField->name);
    5261           0 :             return false;
    5262             :         }
    5263          65 :         if( arrayField->children[0]->length < nStrings * arrayField->length )
    5264             :         {
    5265           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5266             :                      "Field %s: arrayField->children[0]->length < nStrings * arrayField->length",
    5267           0 :                      schemaField->name);
    5268           0 :             return false;
    5269             :         }
    5270          65 :         const int32_t* offsetsToBytes = (const int32_t*)arrayField->children[0]->buffers[1] + arrayField->offset * nStrings + static_cast<size_t>(arrayField->children[0]->offset);
    5271          65 :         const char* bytes = (const char*)arrayField->children[0]->buffers[2];
    5272          65 :         numpyArray = PyArray_SimpleNew(1, &dims, NPY_OBJECT);
    5273         176 :         for( npy_intp j = 0; j < dims; j++ )
    5274             :         {
    5275             :             int32_t maxLength = 1;
    5276         333 :             for( int k = 0; k < nStrings; k++ )
    5277             :             {
    5278         222 :                 const int32_t nLength = offsetsToBytes[j * nStrings + k + 1] - offsetsToBytes[j * nStrings + k];
    5279         222 :                 if( nLength > maxLength )
    5280             :                     maxLength = nLength;
    5281             :             }
    5282             : 
    5283             :             // create the dtype string
    5284         111 :             PyObject *pDTypeString = PyUnicode_FromFormat("S%u", maxLength);
    5285             :             // out type description object
    5286         111 :             PyArray_Descr *pDescr = NULL;
    5287         111 :             PyArray_DescrConverter(pDTypeString, &pDescr);
    5288         111 :             Py_DECREF(pDTypeString);
    5289             : 
    5290         111 :             npy_intp nStringsNpyIntp = nStrings;
    5291         111 :             PyObject* subArray = PyArray_SimpleNewFromDescr(1, &nStringsNpyIntp, pDescr);
    5292         333 :             for( int k = 0; k < nStrings; k++ )
    5293             :             {
    5294         222 :                 const int32_t nLength = offsetsToBytes[j * nStrings + k + 1] - offsetsToBytes[j * nStrings + k];
    5295         222 :                 if( nLength > 0 )
    5296             :                 {
    5297         444 :                     memcpy(PyArray_GETPTR1((PyArrayObject *) subArray, k),
    5298         222 :                            bytes + offsetsToBytes[j * nStrings + k],
    5299             :                            nLength);
    5300             :                 }
    5301         222 :                 if( nLength < maxLength )
    5302             :                 {
    5303         222 :                     memset(((char*)PyArray_GETPTR1((PyArrayObject *) subArray, k)) + nLength,
    5304             :                            0,
    5305           0 :                            maxLength - nLength);
    5306             :                 }
    5307             :             }
    5308             : 
    5309         111 :             memcpy(PyArray_GETPTR1((PyArrayObject *) numpyArray, j),
    5310             :                    &subArray,
    5311             :                    sizeof(PyObject*));
    5312             :         }
    5313             :     }
    5314        1372 :     else if( strcmp(arrowType, "tdD") == 0 &&
    5315         205 :              schemaField->n_children == 0 )
    5316             :     {
    5317             :         // Date(32) in days since Epoch
    5318         205 :         if( arrayField->n_buffers != 2 )
    5319             :         {
    5320           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5321             :                      "Field %s: arrayField->n_buffers != 2",
    5322           0 :                      schemaField->name);
    5323           0 :             return false;
    5324             :         }
    5325             : 
    5326             :         // create the dtype string
    5327         205 :         PyObject *pDTypeString = PyUnicode_FromString("datetime64[D]");
    5328             :         // out type description object
    5329         205 :         PyArray_Descr *pDescr = NULL;
    5330         205 :         PyArray_DescrConverter(pDTypeString, &pDescr);
    5331         205 :         Py_DECREF(pDTypeString);
    5332         205 :         CPLAssert(pDescr);
    5333             : 
    5334             :         // create array
    5335         205 :         numpyArray = PyArray_SimpleNewFromDescr(1, &dims, pDescr);
    5336         569 :         for( npy_intp j = 0; j < dims; j++ )
    5337             :         {
    5338         364 :             *(int64_t*)PyArray_GETPTR1((PyArrayObject *) numpyArray, j) =
    5339         364 :                 ((int*)arrayField->buffers[1])[j + static_cast<size_t>(arrayField->offset)];
    5340         205 :         }
    5341             :     }
    5342        1167 :     else if( strcmp(arrowType, "ttm") == 0 &&
    5343         185 :              schemaField->n_children == 0 )
    5344             :     {
    5345             :         // Time(32) in milliseconds
    5346         185 :         if( arrayField->n_buffers != 2 )
    5347             :         {
    5348           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5349             :                      "Field %s: arrayField->n_buffers != 2",
    5350           0 :                      schemaField->name);
    5351           0 :             return false;
    5352             :         }
    5353             : #if 0
    5354             :         // create the dtype string
    5355             :         PyObject *pDTypeString = PyUnicode_FromString("datetime64[ms]");
    5356             :         // out type description object
    5357             :         PyArray_Descr *pDescr = NULL;
    5358             :         PyArray_DescrConverter(pDTypeString, &pDescr);
    5359             :         Py_DECREF(pDTypeString);
    5360             :         CPLAssert(pDescr);
    5361             : 
    5362             :         // create array
    5363             :         numpyArray = PyArray_SimpleNewFromDescr(1, &dims, pDescr);
    5364             :         for( npy_intp j = 0; j < dims; j++ )
    5365             :         {
    5366             :             *(int64_t*)PyArray_GETPTR1((PyArrayObject *) numpyArray, j) =
    5367             :                 ((int*)arrayField->buffers[1])[j + static_cast<size_t>(arrayField->offset)];
    5368             :         }
    5369             : #else
    5370             :         // create array
    5371         185 :         numpyArray = PyArray_SimpleNew(1, &dims, NPY_OBJECT);
    5372         520 :         for( npy_intp j = 0; j < dims; j++ )
    5373             :         {
    5374         335 :             int timeMs = ((int*)arrayField->buffers[1])[j + static_cast<size_t>(arrayField->offset)];
    5375         335 :             PyObject* subObj = PyTime_FromTime((timeMs / 1000) / 3600,
    5376             :                                                ((timeMs / 1000) % 3600) / 60,
    5377             :                                                ((timeMs / 1000) % 3600) % 60,
    5378             :                                                (timeMs % 1000) * 1000);
    5379         335 :             memcpy(PyArray_GETPTR1((PyArrayObject *) numpyArray, j),
    5380             :                    &subObj,
    5381             :                    sizeof(PyObject*));
    5382             :         }
    5383             : #endif
    5384             :     }
    5385         982 :     else if( strcmp(arrowType, "ttu") == 0 &&
    5386          65 :              schemaField->n_children == 0 )
    5387             :     {
    5388             :         // Time(64) in microseconds
    5389          65 :         if( arrayField->n_buffers != 2 )
    5390             :         {
    5391           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5392             :                      "Field %s: arrayField->n_buffers != 2",
    5393           0 :                      schemaField->name);
    5394           0 :             return false;
    5395             :         }
    5396             : 
    5397             :         // create array
    5398          65 :         numpyArray = PyArray_SimpleNew(1, &dims, NPY_OBJECT);
    5399         176 :         for( npy_intp j = 0; j < dims; j++ )
    5400             :         {
    5401         111 :             const int64_t timeUs = ((int64_t*)arrayField->buffers[1])[j + static_cast<size_t>(arrayField->offset)];
    5402         111 :             PyObject* subObj = PyTime_FromTime(static_cast<int>((timeUs / 1000000) / 3600),
    5403             :                                                static_cast<int>(((timeUs / 1000000) % 3600) / 60),
    5404             :                                                static_cast<int>(((timeUs / 1000000) % 3600) % 60),
    5405             :                                                static_cast<int>(timeUs % 1000000));
    5406         111 :             memcpy(PyArray_GETPTR1((PyArrayObject *) numpyArray, j),
    5407             :                    &subObj,
    5408             :                    sizeof(PyObject*));
    5409             :         }
    5410             :     }
    5411         917 :     else if( (strncmp(arrowType, "tsm:", 4) == 0 || // DateTime in milliseconds
    5412         562 :               strncmp(arrowType, "tsu:", 4) == 0 || // DateTime in microseconds
    5413         432 :               strncmp(arrowType, "tsn:", 4) == 0) &&  // DateTime in nanoseconds
    5414         485 :              schemaField->n_children == 0 )
    5415             :     {
    5416             :         // DateTime(64)
    5417         485 :         if( arrayField->n_buffers != 2 )
    5418             :         {
    5419           0 :             CPLError(CE_Failure, CPLE_AppDefined,
    5420             :                      "Field %s: arrayField->n_buffers != 2",
    5421           0 :                      schemaField->name);
    5422           0 :             return false;
    5423             :         }
    5424             : 
    5425             :         // create the dtype string
    5426         615 :         PyObject *pDTypeString = PyUnicode_FromString(
    5427             :             strncmp(arrowType, "tsm:", 4) == 0 ? "datetime64[ms]" :
    5428         130 :             strncmp(arrowType, "tsu:", 4) == 0 ? "datetime64[us]" :
    5429             :                                                  "datetime64[ns]");
    5430             :         // out type description object
    5431         485 :         PyArray_Descr *pDescr = NULL;
    5432         485 :         PyArray_DescrConverter(pDTypeString, &pDescr);
    5433         485 :         Py_DECREF(pDTypeString);
    5434         485 :         CPLAssert(pDescr);
    5435             : 
    5436             :         // create array
    5437         970 :         numpyArray = PyArray_NewFromDescr(
    5438             :                     &PyArray_Type, pDescr, 1, &dims, NULL,
    5439         485 :                     (int64_t*)arrayField->buffers[1] + static_cast<size_t>(arrayField->offset), 0, NULL);
    5440             : 
    5441             :         /* Keep a reference to the owner object */
    5442             : #if NPY_API_VERSION >= 0x00000007
    5443         485 :         PyArray_SetBaseObject((PyArrayObject *) numpyArray, pointerArrayKeeper);
    5444             : #else
    5445             :         PyArray_BASE((PyArrayObject *) numpyArray) = pointerArrayKeeper;
    5446             : #endif
    5447         485 :         Py_INCREF(pointerArrayKeeper);
    5448             :     }
    5449         432 :     else if( strcmp(arrowType, "+s") == 0 )
    5450             :     {
    5451         585 :         for( int iField = 0; iField < arrayField->n_children; iField++ )
    5452             :         {
    5453         455 :             const struct ArrowArray* childArray = arrayField ->children[iField];
    5454         455 :             const struct ArrowSchema* childSchema = schemaField->children[iField];
    5455             : 
    5456         455 :             if( !AddNumpyArrayToDict(dict, childSchema, childArray,
    5457         910 :                                      osPrefix + schemaField->name + ".",
    5458             :                                      pointerArrayKeeper) )
    5459             :             {
    5460             :                 return false;
    5461             :             }
    5462             :         }
    5463             :     }
    5464             :     else
    5465             :     {
    5466         302 :         if( strcmp(arrowType, "+l") == 0 || strcmp(arrowType, "+L") == 0 )
    5467             :         {
    5468         260 :             CPLError(CE_Warning, CPLE_AppDefined,
    5469             :                      "Field %s: Unhandled arrow type: %s %s",
    5470           0 :                      (osPrefix + schemaField->name).c_str(),
    5471         260 :                      arrowType, schemaField->children[0]->format);
    5472             :         }
    5473             :         else
    5474             :         {
    5475          42 :             CPLError(CE_Warning, CPLE_AppDefined,
    5476             :                      "Field %s: Unhandled arrow type: %s",
    5477          42 :                      (osPrefix + schemaField->name).c_str(),
    5478             :                      arrowType);
    5479             :         }
    5480             :     }
    5481             : 
    5482        7724 :     if( numpyArray )
    5483             :     {
    5484        7292 :         const uint8_t* panNotNulls = (const uint8_t*)arrayField->buffers[0];
    5485        7292 :         if( panNotNulls && arrayField->null_count != 0 )
    5486             :         {
    5487        2329 :             PyObject* maskArray = PyArray_SimpleNew(1, &dims, NPY_BOOL);
    5488        7345 :             for( npy_intp j = 0; j < dims; j++ )
    5489             :             {
    5490        5016 :                 size_t srcOffset = static_cast<size_t>(arrayField->offset + j);
    5491             :                 // Inverse convention between arrow not-null bitmap, where
    5492             :                 // 1 means valid, and numpy masks where 1 means invalid
    5493        5016 :                 *(char*)PyArray_GETPTR1((PyArrayObject *) maskArray, j) =
    5494        5016 :                     ((panNotNulls[srcOffset / 8] & (1 << (srcOffset%8))) == 0) ? 1 : 0;
    5495             :             }
    5496        2329 :             PyObject *subdict = PyDict_New();
    5497        2329 :             PyDict_SetItemString( subdict, "mask", maskArray );
    5498        2329 :             PyDict_SetItemString( subdict, "data", numpyArray );
    5499        2329 :             PyDict_SetItemString( dict, (osPrefix + schemaField->name).c_str(), subdict);
    5500        2329 :             Py_DECREF(maskArray);
    5501        2329 :             Py_DECREF(subdict);
    5502             :         }
    5503             :         else
    5504             :         {
    5505        9926 :             PyDict_SetItemString( dict, (osPrefix + schemaField->name).c_str(), numpyArray );
    5506             :         }
    5507        7724 :         Py_DECREF(numpyArray);
    5508             :     }
    5509             : 
    5510             :     return true;
    5511             : }
    5512             : 
    5513             : /* Internal method used by ogr.Layer.GetNextRecordBatchAsNumpy() */
    5514         475 : PyObject* _RecordBatchAsNumpy(VoidPtrAsLong recordBatchPtr,
    5515             :                               VoidPtrAsLong schemaPtr,
    5516             :                               PyObject* pointerArrayKeeper)
    5517             : {
    5518         475 :     const struct ArrowSchema* schema = (const struct ArrowSchema* )schemaPtr;
    5519         475 :     const struct ArrowArray* array = (const struct ArrowArray* )recordBatchPtr;
    5520         475 :     if( strcmp(schema->format, "+s") != 0 )
    5521             :     {
    5522           0 :       CPLError(CE_Failure, CPLE_AppDefined, "schema->format != '+s'");
    5523           0 :       Py_RETURN_NONE;
    5524             :     }
    5525         475 :     if( schema->n_children != array->n_children )
    5526             :     {
    5527           0 :       CPLError(CE_Failure, CPLE_AppDefined,
    5528             :                "schema->n_children(=%d) != array->n_children(=%d)",
    5529             :                static_cast<int>(schema->n_children),
    5530             :                static_cast<int>(array->n_children));
    5531           0 :       Py_RETURN_NONE;
    5532             :     }
    5533         475 :     PyObject *dict = PyDict_New();
    5534        7744 :     for( int iField = 0; iField < array->n_children; iField++ )
    5535             :     {
    5536        7269 :         const struct ArrowArray* childArray = array->children[iField];
    5537        7269 :         const struct ArrowSchema* childSchema = schema->children[iField];
    5538             : 
    5539        7269 :         if( !AddNumpyArrayToDict(dict, childSchema, childArray, std::string(), pointerArrayKeeper) )
    5540             :         {
    5541           0 :             Py_DECREF(dict);
    5542           0 :             Py_RETURN_NONE;
    5543             :         }
    5544             :     }
    5545             :     return dict;
    5546             : }
    5547             : 
    5548             : 
    5549             : 
    5550             : SWIGINTERNINLINE PyObject*
    5551           0 :   SWIG_From_bool  (bool value)
    5552             : {
    5553           0 :   return PyBool_FromLong(value ? 1 : 0);
    5554             : }
    5555             : 
    5556             : 
    5557          28 :     void VirtualMemGetArray(CPLVirtualMemShadow* virtualmem, CPLVirtualMemShadow** pvirtualmem, int numpytypemap)
    5558             :     {
    5559          28 :         *pvirtualmem = virtualmem;
    5560          28 :     }
    5561             : 
    5562             : 
    5563             :   // need different functions for read and write
    5564             :   // since reading strings requires us to know the
    5565             :   // length of the longest string before creating array
    5566          20 :   CPLErr RATValuesIONumPyWrite( GDALRasterAttributeTableShadow* poRAT, int nField, int nStart,
    5567             :                        PyArrayObject *psArray) {
    5568             : 
    5569          20 :     if( PyArray_NDIM(psArray) != 1 )
    5570             :     {
    5571           0 :         CPLError( CE_Failure, CPLE_AppDefined,
    5572             :                   "Illegal numpy array rank %d.\n",
    5573             :                   PyArray_NDIM(psArray) );
    5574           0 :         return CE_Failure;
    5575             :     }
    5576          20 :     if( PyArray_DIM(psArray, 0) > INT_MAX )
    5577             :     {
    5578           0 :         CPLError( CE_Failure, CPLE_NotSupported,
    5579             :                   "Too big array dimension");
    5580           0 :         return CE_Failure;
    5581             :     }
    5582             : 
    5583          20 :     int nLength = static_cast<int>(PyArray_DIM(psArray, 0));
    5584          20 :     int nType = PyArray_TYPE(psArray);
    5585          20 :     CPLErr retval = CE_None;
    5586             : 
    5587          20 :     if( nType == NPY_INT32 )
    5588             :     {
    5589           4 :         retval = GDALRATValuesIOAsInteger(poRAT, GF_Write, nField, nStart, nLength,
    5590           4 :                         (int*)PyArray_DATA(psArray) );
    5591             :     }
    5592          16 :     else if( nType == NPY_DOUBLE )
    5593             :     {
    5594           6 :         retval = GDALRATValuesIOAsDouble(poRAT, GF_Write, nField, nStart, nLength,
    5595           6 :                         (double*)PyArray_DATA(psArray) );
    5596             :     }
    5597          10 :     else if( nType == NPY_STRING )
    5598             :     {
    5599             :         // max size of string
    5600           5 :         const size_t nMaxLen = PyArray_ITEMSIZE(psArray);
    5601           5 :         char *pszBuffer = (char*)VSIMalloc(nMaxLen+1);
    5602           5 :         if (!pszBuffer)
    5603             :         {
    5604           0 :             CPLError( CE_Failure, CPLE_OutOfMemory,
    5605             :                       "Out of memory in RATValuesIONumPyWrite()" );
    5606           0 :             return CE_Failure;
    5607             :         }
    5608             :         // make sure there is a null char on the end
    5609             :         // as there won't be if this string is the maximum size
    5610           5 :         pszBuffer[nMaxLen] = '\0';
    5611             : 
    5612             :         // have to convert array of strings to a char **
    5613           5 :         char **papszStringData = (char**)CPLCalloc(sizeof(char*), nLength);
    5614             : 
    5615             :         // we can't just use the memory location in the array
    5616             :         // since long strings won't be null terminated
    5617          55 :         for( int i = 0; i < nLength; i++ )
    5618             :         {
    5619          50 :             strncpy(pszBuffer, (char*)PyArray_GETPTR1(psArray, i), nMaxLen);
    5620          50 :             papszStringData[i] = CPLStrdup(pszBuffer);
    5621             :         }
    5622           5 :         CPLFree(pszBuffer);
    5623             : 
    5624           5 :         retval = GDALRATValuesIOAsString(poRAT, GF_Write, nField, nStart, nLength,
    5625             :                                             papszStringData);
    5626             : 
    5627          55 :         for( int i = 0; i < nLength; i++ )
    5628             :         {
    5629          50 :             CPLFree(papszStringData[i]);
    5630             :         }
    5631           5 :         CPLFree(papszStringData);
    5632             :     }
    5633           5 :     else if( nType == NPY_BOOL )
    5634             :     {
    5635           1 :         retval = GDALRATValuesIOAsBoolean(poRAT, GF_Write, nField, nStart, nLength,
    5636           1 :                         (bool*)PyArray_DATA(psArray) );
    5637             :     }
    5638           4 :     else if( nType == NPY_OBJECT && GDALRATGetTypeOfCol(poRAT, nField) == GFT_DateTime )
    5639             :     {
    5640           2 :         GDALRATDateTime dt;
    5641           3 :         std::vector<GDALRATDateTime> asDateTimeValues(nLength, dt);
    5642           4 :         for( int i = 0; i < nLength; i++ )
    5643             :         {
    5644           3 :             PyObject* pyDateTime = *(PyObject**)PyArray_GETPTR1(psArray, i);
    5645           3 :             if (!pyDateTime || pyDateTime == Py_None)
    5646             :             {
    5647           1 :                 continue;
    5648             :             }
    5649           2 :             if (!PyDateTime_Check(pyDateTime))
    5650             :             {
    5651           1 :                 CPLError( CE_Failure, CPLE_AppDefined,
    5652             :                       "Non-datetime object found at index %d", i);
    5653           1 :                 return CE_Failure;
    5654             :             }
    5655           1 :             asDateTimeValues[i].nYear = PyDateTime_GET_YEAR(pyDateTime);
    5656           1 :             asDateTimeValues[i].nMonth = PyDateTime_GET_MONTH(pyDateTime);
    5657           1 :             asDateTimeValues[i].nDay = PyDateTime_GET_DAY(pyDateTime);
    5658           1 :             asDateTimeValues[i].nHour = PyDateTime_DATE_GET_HOUR(pyDateTime);
    5659           1 :             asDateTimeValues[i].nMinute = PyDateTime_DATE_GET_MINUTE(pyDateTime);
    5660           1 :             asDateTimeValues[i].fSecond = (float)(PyDateTime_DATE_GET_SECOND(pyDateTime) +
    5661           1 :                                             PyDateTime_DATE_GET_MICROSECOND(pyDateTime) * 1e-6);
    5662           1 :             asDateTimeValues[i].bPositiveTimeZone = true;
    5663           1 :             asDateTimeValues[i].bIsValid = true;
    5664           1 :             asDateTimeValues[i].nTimeZoneHour = 0;
    5665           1 :             asDateTimeValues[i].nTimeZoneMinute = 0;
    5666           1 :             PyObject *tzinfo = ((PyDateTime_DateTime *)pyDateTime)->tzinfo;
    5667           1 :             if (tzinfo && tzinfo != Py_None)
    5668             :             {
    5669           1 :                 PyObject *pyMethodName = PyUnicode_FromString("utcoffset");
    5670           1 :                 PyObject *pyDelta = PyObject_CallMethodObjArgs(
    5671             :                     tzinfo,
    5672             :                     pyMethodName,
    5673             :                     pyDateTime,
    5674             :                     NULL
    5675             :                 );
    5676           1 :                 Py_DECREF(pyMethodName);
    5677           1 :                 if (pyDelta && pyDelta != Py_None)
    5678             :                 {
    5679           1 :                     if (!PyDelta_Check(pyDelta)) {
    5680           0 :                         Py_DECREF(pyDelta);
    5681           0 :                         PyErr_SetString(PyExc_TypeError, "tzinfo.utcoffset() did not return timedelta");
    5682             :                         return CE_Failure;
    5683             :                     }
    5684           1 :                     int days = PyDateTime_DELTA_GET_DAYS(pyDelta);
    5685           1 :                     int seconds = PyDateTime_DELTA_GET_SECONDS(pyDelta);
    5686           1 :                     int minutes = days * 24 * 60 + seconds / 60;
    5687           1 :                     if (minutes < 0 )
    5688             :                     {
    5689           0 :                         asDateTimeValues[i].bPositiveTimeZone = false;
    5690           0 :                         minutes = -minutes;
    5691             :                     }
    5692           1 :                     asDateTimeValues[i].nTimeZoneHour = minutes / 60;
    5693           1 :                     asDateTimeValues[i].nTimeZoneMinute = minutes % 60;
    5694             :                 }
    5695           2 :                 Py_DECREF(pyDelta);
    5696             :             }
    5697             :         }
    5698           1 :         retval = GDALRATValuesIOAsDateTime(poRAT, GF_Write, nField, nStart, nLength,
    5699             :                                            asDateTimeValues.data());
    5700             :     }
    5701           2 :     else if( nType == NPY_OBJECT && GDALRATGetTypeOfCol(poRAT, nField) == GFT_WKBGeometry )
    5702             :     {
    5703           2 :         retval = CE_None;
    5704           4 :         std::vector<GByte*> apabyWKB(nLength);
    5705           4 :         std::vector<size_t> anWKBSize(nLength);
    5706           3 :         for( int i = 0; i < nLength; i++ )
    5707             :         {
    5708           2 :             PyObject* pyBytes = *(PyObject**)PyArray_GETPTR1(psArray, i);
    5709           2 :             if (!PyBytes_Check(pyBytes))
    5710             :             {
    5711           1 :                 CPLError( CE_Failure, CPLE_AppDefined,
    5712             :                       "Non-byte object found at index %d", i);
    5713             :                 retval = CE_Failure;
    5714             :                 break;
    5715             :             }
    5716           1 :             apabyWKB[i] = (GByte*)PyBytes_AsString(pyBytes);
    5717           1 :             anWKBSize[i] = PyBytes_Size(pyBytes);
    5718             :         }
    5719           1 :         if (retval == CE_None )
    5720             :         {
    5721           1 :             retval = GDALRATValuesIOAsWKBGeometry(poRAT, GF_Write, nField, nStart, nLength,
    5722             :                                                   apabyWKB.data(), anWKBSize.data());
    5723             :         }
    5724             :     }
    5725             :     else
    5726             :     {
    5727           0 :         CPLError( CE_Failure, CPLE_AppDefined,
    5728             :                   "Illegal numpy array type %d.\n",
    5729             :                   nType );
    5730           0 :         return CE_Failure;
    5731             :     }
    5732             :     return retval;
    5733             :   }
    5734             : 
    5735             : 
    5736             :   // need different functions for read and write
    5737             :   // since reading strings requires us to know the
    5738             :   // length of the longest string before creating array
    5739          55 :   PyObject *RATValuesIONumPyRead( GDALRasterAttributeTableShadow* poRAT, int nField, int nStart,
    5740             :                        int nLength) {
    5741             : 
    5742          55 :     const GDALRATFieldType colType = GDALRATGetTypeOfCol(poRAT, nField);
    5743          55 :     npy_intp dims = nLength;
    5744          55 :     PyObject *pOutArray = NULL;
    5745          55 :     switch (colType)
    5746             :     {
    5747          19 :         case GFT_Integer:
    5748          19 :         {
    5749          19 :             pOutArray = PyArray_SimpleNew(1, &dims, NPY_INT32);
    5750          19 :             if( GDALRATValuesIOAsInteger(poRAT, GF_Read, nField, nStart, nLength,
    5751          19 :                             (int*)PyArray_DATA((PyArrayObject *) pOutArray)) != CE_None)
    5752             :             {
    5753           1 :                 Py_DECREF(pOutArray);
    5754           1 :                 Py_RETURN_NONE;
    5755             :             }
    5756             :             break;
    5757             :         }
    5758             : 
    5759          16 :         case GFT_Real:
    5760          16 :         {
    5761          16 :             pOutArray = PyArray_SimpleNew(1, &dims, NPY_DOUBLE);
    5762          16 :             if( GDALRATValuesIOAsDouble(poRAT, GF_Read, nField, nStart, nLength,
    5763          16 :                             (double*)PyArray_DATA((PyArrayObject *) pOutArray)) != CE_None)
    5764             :             {
    5765           0 :                 Py_DECREF(pOutArray);
    5766           0 :                 Py_RETURN_NONE;
    5767             :             }
    5768             :             break;
    5769             :         }
    5770             : 
    5771          17 :         case GFT_String:
    5772          17 :         {
    5773             :             // must read the data first to work out max size
    5774             :             // of strings to create array
    5775          17 :             int n;
    5776          17 :             char **papszStringList = (char**)CPLCalloc(sizeof(char*), nLength);
    5777          17 :             if( GDALRATValuesIOAsString(poRAT, GF_Read, nField, nStart, nLength, papszStringList) != CE_None )
    5778             :             {
    5779           0 :                 CPLFree(papszStringList);
    5780           0 :                 Py_RETURN_NONE;
    5781             :             }
    5782             :             int nMaxLen = 0, nLen;
    5783         168 :             for( n = 0; n < nLength; n++ )
    5784             :             {
    5785             :                 // note strlen doesn't include null char
    5786             :                 // but that is what numpy expects so all good
    5787         151 :                 nLen = static_cast<int>(strlen(papszStringList[n]));
    5788         151 :                 if( nLen > nMaxLen )
    5789             :                     nMaxLen = nLen;
    5790             :             }
    5791          17 :             int bZeroLength = FALSE;
    5792             :             // numpy can't deal with zero length strings
    5793          17 :             if( nMaxLen == 0 )
    5794             :             {
    5795           0 :                 nMaxLen = 1;
    5796           0 :                 bZeroLength = TRUE;
    5797             :             }
    5798             : 
    5799             :             // create the dtype string
    5800          17 :             PyObject *pDTypeString = PyUnicode_FromFormat("S%d", nMaxLen);
    5801             :             // out type description object
    5802          17 :             PyArray_Descr *pDescr;
    5803          17 :             PyArray_DescrConverter(pDTypeString, &pDescr);
    5804          17 :             Py_DECREF(pDTypeString);
    5805             : 
    5806             :             // create array
    5807          17 :             pOutArray = PyArray_SimpleNewFromDescr(1, &dims, pDescr);
    5808             : 
    5809             :             // copy data in
    5810          17 :             if( !bZeroLength )
    5811             :             {
    5812         168 :                 for( n = 0; n < nLength; n++ )
    5813             :                 {
    5814             :                     // we use strncpy so that we don't go over nMaxLen
    5815             :                     // which we would if the null char is copied
    5816             :                     // (which we don't want as numpy 'knows' to interpret the string as nMaxLen long)
    5817         151 :                     strncpy((char*)PyArray_GETPTR1((PyArrayObject *) pOutArray, n), papszStringList[n], nMaxLen);
    5818             :                 }
    5819             :             }
    5820             :             else
    5821             :             {
    5822             :                 // so there isn't rubbish in the 1 char strings
    5823           0 :                 PyArray_FILLWBYTE((PyArrayObject *) pOutArray, 0);
    5824             :             }
    5825             : 
    5826             :             // free strings
    5827         168 :             for( n = 0; n < nLength; n++ )
    5828             :             {
    5829         151 :                 CPLFree(papszStringList[n]);
    5830             :             }
    5831          17 :             CPLFree(papszStringList);
    5832             : 
    5833          17 :             break;
    5834             :         }
    5835             : 
    5836           1 :         case GFT_Boolean:
    5837           1 :         {
    5838           1 :             pOutArray = PyArray_SimpleNew(1, &dims, NPY_BOOL);
    5839           1 :             if( GDALRATValuesIOAsBoolean(poRAT, GF_Read, nField, nStart, nLength,
    5840           1 :                             (bool*)PyArray_DATA((PyArrayObject *) pOutArray)) != CE_None)
    5841             :             {
    5842           0 :                 Py_DECREF(pOutArray);
    5843           0 :                 Py_RETURN_NONE;
    5844             :             }
    5845             :             break;
    5846             :         }
    5847             : 
    5848           1 :         case GFT_DateTime:
    5849           1 :         {
    5850           1 :             std::vector<GDALRATDateTime> asDateTimeValues(nLength);
    5851           1 :             if( GDALRATValuesIOAsDateTime(poRAT, GF_Read, nField, nStart, nLength,
    5852             :                                           asDateTimeValues.data()) != CE_None)
    5853             :             {
    5854           0 :                 Py_RETURN_NONE;
    5855             :             }
    5856           1 :             pOutArray = PyArray_SimpleNew(1, &dims, NPY_OBJECT);
    5857           3 :             for( int i = 0; i < nLength; i++ )
    5858             :             {
    5859           2 :                 PyObject* pyDateTime;
    5860           2 :                 if (asDateTimeValues[i].bIsValid )
    5861             :                 {
    5862           1 :                     struct tm brokendowntime;
    5863           1 :                     brokendowntime.tm_year = asDateTimeValues[i].nYear - 1900;
    5864           1 :                     brokendowntime.tm_mon = asDateTimeValues[i].nMonth - 1;
    5865           1 :                     brokendowntime.tm_mday = asDateTimeValues[i].nDay;
    5866           1 :                     brokendowntime.tm_hour = asDateTimeValues[i].nHour;
    5867           1 :                     brokendowntime.tm_min = asDateTimeValues[i].nMinute;
    5868           1 :                     brokendowntime.tm_sec = (int)asDateTimeValues[i].fSecond;
    5869           1 :                     GIntBig nTimestamp = CPLYMDHMSToUnixTime(&brokendowntime);
    5870           1 :                     double dfTimestamp = (double)nTimestamp + (double)fmod(asDateTimeValues[i].fSecond, 1.0f);
    5871           1 :                     int nTimeZoneOffset = asDateTimeValues[i].nTimeZoneHour * 3600 +
    5872           1 :                                           asDateTimeValues[i].nTimeZoneMinute * 60;
    5873           1 :                     if (!asDateTimeValues[i].bPositiveTimeZone)
    5874           0 :                         nTimeZoneOffset = -nTimeZoneOffset;
    5875           1 :                     dfTimestamp -= nTimeZoneOffset;
    5876           1 :                     PyObject* pyTimestamp = PyFloat_FromDouble(dfTimestamp);
    5877           1 :                     PyObject* pyDelta = PyDelta_FromDSU(0, nTimeZoneOffset, 0);
    5878           1 :                     PyObject* pyTimeZone = PyTimeZone_FromOffset(pyDelta);
    5879           1 :                     Py_DECREF(pyDelta);
    5880           1 :                     PyObject* pyArgs = PyTuple_Pack(2, pyTimestamp, pyTimeZone);
    5881           1 :                     pyDateTime = PyDateTime_FromTimestamp(pyArgs);
    5882           1 :                     Py_DECREF(pyArgs);
    5883           1 :                     Py_DECREF(pyTimestamp);
    5884           1 :                     Py_DECREF(pyTimeZone);
    5885             :                 }
    5886             :                 else
    5887             :                 {
    5888           1 :                     pyDateTime = Py_None;
    5889           1 :                     Py_INCREF(pyDateTime);
    5890             :                 }
    5891           2 :                 memcpy(PyArray_GETPTR1((PyArrayObject *) pOutArray, i),
    5892             :                    &pyDateTime,
    5893             :                    sizeof(PyObject*));
    5894             :             }
    5895           2 :             break;
    5896             :         }
    5897             : 
    5898           1 :         case GFT_WKBGeometry:
    5899           1 :         {
    5900           1 :             std::vector<GByte*> apabyWKB(nLength);
    5901           1 :             std::vector<size_t> anWKBSize(nLength);
    5902           1 :             if( GDALRATValuesIOAsWKBGeometry(poRAT, GF_Read, nField, nStart, nLength,
    5903             :                                              apabyWKB.data(), anWKBSize.data()) != CE_None)
    5904             :             {
    5905           0 :                 Py_RETURN_NONE;
    5906             :             }
    5907           1 :             pOutArray = PyArray_SimpleNew(1, &dims, NPY_OBJECT);
    5908           2 :             for( int i = 0; i < nLength; i++ )
    5909             :             {
    5910           1 :                 PyObject* pyWKB = PyBytes_FromStringAndSize((const char*)apabyWKB[i], anWKBSize[i]);
    5911           1 :                 CPLFree(apabyWKB[i]);
    5912           1 :                 memcpy(PyArray_GETPTR1((PyArrayObject *) pOutArray, i),
    5913             :                    &pyWKB,
    5914             :                    sizeof(PyObject*));
    5915             :             }
    5916           2 :             break;
    5917             :         }
    5918             :     }
    5919             : 
    5920             :     return pOutArray;
    5921             :   }
    5922             : 
    5923             : #ifdef __cplusplus
    5924             : extern "C" {
    5925             : #endif
    5926          28 : SWIGINTERN PyObject *_wrap_delete_VirtualMem(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    5927          28 :   PyObject *resultobj = 0;
    5928          28 :   CPLVirtualMemShadow *arg1 = (CPLVirtualMemShadow *) 0 ;
    5929          28 :   void *argp1 = 0 ;
    5930          28 :   int res1 = 0 ;
    5931          28 :   PyObject *swig_obj[1] ;
    5932             :   
    5933          28 :   if (!args) SWIG_fail;
    5934          28 :   swig_obj[0] = args;
    5935          28 :   res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_CPLVirtualMemShadow, SWIG_POINTER_DISOWN |  0 );
    5936          28 :   if (!SWIG_IsOK(res1)) {
    5937           0 :     SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_VirtualMem" "', argument " "1"" of type '" "CPLVirtualMemShadow *""'"); 
    5938             :   }
    5939          28 :   arg1 = reinterpret_cast< CPLVirtualMemShadow * >(argp1);
    5940          28 :   {
    5941          28 :     SWIG_PYTHON_THREAD_BEGIN_ALLOW;
    5942          28 :     delete_CPLVirtualMemShadow(arg1);
    5943          28 :     SWIG_PYTHON_THREAD_END_ALLOW;
    5944             :   }
    5945          28 :   resultobj = SWIG_Py_Void();
    5946          28 :   return resultobj;
    5947             : fail:
    5948             :   return NULL;
    5949             : }
    5950             : 
    5951             : 
    5952           0 : SWIGINTERN PyObject *_wrap_VirtualMem_GetAddr(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    5953           0 :   PyObject *resultobj = 0;
    5954           0 :   CPLVirtualMemShadow *arg1 = (CPLVirtualMemShadow *) 0 ;
    5955           0 :   void **arg2 = (void **) 0 ;
    5956           0 :   size_t *arg3 = (size_t *) 0 ;
    5957           0 :   GDALDataType *arg4 = (GDALDataType *) 0 ;
    5958           0 :   int *arg5 = (int *) 0 ;
    5959           0 :   void *argp1 = 0 ;
    5960           0 :   int res1 = 0 ;
    5961           0 :   void *ptr2 ;
    5962           0 :   size_t nsize2 ;
    5963           0 :   GDALDataType datatype2 ;
    5964           0 :   int readonly2 ;
    5965           0 :   PyObject *swig_obj[1] ;
    5966             :   
    5967           0 :   {
    5968             :     /* %typemap(in,numinputs=0) (void** pptr, size_t* pnsize, GDALDataType* pdatatype, int* preadonly) */
    5969           0 :     arg2 = &ptr2;
    5970           0 :     arg3 = &nsize2;
    5971           0 :     arg4 = &datatype2;
    5972           0 :     arg5 = &readonly2;
    5973             :   }
    5974           0 :   if (!args) SWIG_fail;
    5975           0 :   swig_obj[0] = args;
    5976           0 :   res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_CPLVirtualMemShadow, 0 |  0 );
    5977           0 :   if (!SWIG_IsOK(res1)) {
    5978           0 :     SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "VirtualMem_GetAddr" "', argument " "1"" of type '" "CPLVirtualMemShadow *""'"); 
    5979             :   }
    5980           0 :   arg1 = reinterpret_cast< CPLVirtualMemShadow * >(argp1);
    5981           0 :   {
    5982           0 :     SWIG_PYTHON_THREAD_BEGIN_ALLOW;
    5983           0 :     CPLVirtualMemShadow_GetAddr(arg1,arg2,arg3,arg4,arg5);
    5984           0 :     SWIG_PYTHON_THREAD_END_ALLOW;
    5985             :   }
    5986           0 :   resultobj = SWIG_Py_Void();
    5987           0 :   {
    5988             :     /* %typemap(argout) (void** pptr, size_t* pnsize, GDALDataType* pdatatype, int* preadonly)*/
    5989           0 :     Py_buffer *buf=(Py_buffer*)malloc(sizeof(Py_buffer));
    5990             :     
    5991           0 :     if (PyBuffer_FillInfo(buf, swig_obj[0], *(arg2), *(arg3), *(arg5), PyBUF_ND)) {
    5992             :       // error, handle
    5993             :     }
    5994           0 :     if( *(arg4) == GDT_Byte )
    5995             :     {
    5996           0 :       buf->format = (char*) "B";
    5997           0 :       buf->itemsize = 1;
    5998             :     }
    5999           0 :     else if( *(arg4) == GDT_Int16 )
    6000             :     {
    6001           0 :       buf->format = (char*) "h";
    6002           0 :       buf->itemsize = 2;
    6003             :     }
    6004           0 :     else if( *(arg4) == GDT_UInt16 )
    6005             :     {
    6006           0 :       buf->format = (char*) "H";
    6007           0 :       buf->itemsize = 2;
    6008             :     }
    6009           0 :     else if( *(arg4) == GDT_Int32 )
    6010             :     {
    6011           0 :       buf->format = (char*) "i";
    6012           0 :       buf->itemsize = 4;
    6013             :     }
    6014           0 :     else if( *(arg4) == GDT_UInt32 )
    6015             :     {
    6016           0 :       buf->format = (char*) "I";
    6017           0 :       buf->itemsize = 4;
    6018             :     }
    6019           0 :     else if( *(arg4) == GDT_Float16 )
    6020             :     {
    6021           0 :       buf->format = (char*) "f";
    6022           0 :       buf->itemsize = 2;
    6023             :     }
    6024           0 :     else if( *(arg4) == GDT_Float32 )
    6025             :     {
    6026           0 :       buf->format = (char*) "f";
    6027           0 :       buf->itemsize = 4;
    6028             :     }
    6029           0 :     else if( *(arg4) == GDT_Float64 )
    6030             :     {
    6031           0 :       buf->format = (char*) "F";
    6032           0 :       buf->itemsize = 8;
    6033             :     }
    6034             :     else
    6035             :     {
    6036           0 :       buf->format = (char*) "B";
    6037           0 :       buf->itemsize = 1;
    6038             :     }
    6039           0 :     Py_DECREF(resultobj);
    6040           0 :     resultobj = PyMemoryView_FromBuffer(buf);
    6041             :   }
    6042             :   return resultobj;
    6043             : fail:
    6044             :   return NULL;
    6045             : }
    6046             : 
    6047             : 
    6048             : SWIGINTERN PyObject *_wrap_VirtualMem_Pin__SWIG_0(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
    6049             :   PyObject *resultobj = 0;
    6050             :   CPLVirtualMemShadow *arg1 = (CPLVirtualMemShadow *) 0 ;
    6051             :   size_t arg2 ;
    6052             :   size_t arg3 ;
    6053             :   int arg4 ;
    6054             :   void *argp1 = 0 ;
    6055             :   int res1 = 0 ;
    6056             :   size_t val2 ;
    6057             :   int ecode2 = 0 ;
    6058             :   size_t val3 ;
    6059             :   int ecode3 = 0 ;
    6060             :   int val4 ;
    6061             :   int ecode4 = 0 ;
    6062             :   
    6063             :   if ((nobjs < 4) || (nobjs > 4)) SWIG_fail;
    6064             :   res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_CPLVirtualMemShadow, 0 |  0 );
    6065             :   if (!SWIG_IsOK(res1)) {
    6066             :     SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "VirtualMem_Pin" "', argument " "1"" of type '" "CPLVirtualMemShadow *""'"); 
    6067             :   }
    6068             :   arg1 = reinterpret_cast< CPLVirtualMemShadow * >(argp1);
    6069             :   ecode2 = SWIG_AsVal_size_t(swig_obj[1], &val2);
    6070             :   if (!SWIG_IsOK(ecode2)) {
    6071             :     SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "VirtualMem_Pin" "', argument " "2"" of type '" "size_t""'");
    6072             :   } 
    6073             :   arg2 = static_cast< size_t >(val2);
    6074             :   ecode3 = SWIG_AsVal_size_t(swig_obj[2], &val3);
    6075             :   if (!SWIG_IsOK(ecode3)) {
    6076             :     SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "VirtualMem_Pin" "', argument " "3"" of type '" "size_t""'");
    6077             :   } 
    6078             :   arg3 = static_cast< size_t >(val3);
    6079             :   ecode4 = SWIG_AsVal_int(swig_obj[3], &val4);
    6080             :   if (!SWIG_IsOK(ecode4)) {
    6081             :     SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "VirtualMem_Pin" "', argument " "4"" of type '" "int""'");
    6082             :   } 
    6083             :   arg4 = static_cast< int >(val4);
    6084             :   {
    6085             :     SWIG_PYTHON_THREAD_BEGIN_ALLOW;
    6086             :     CPLVirtualMemShadow_Pin__SWIG_0(arg1,arg2,arg3,arg4);
    6087             :     SWIG_PYTHON_THREAD_END_ALLOW;
    6088             :   }
    6089             :   resultobj = SWIG_Py_Void();
    6090             :   return resultobj;
    6091             : fail:
    6092             :   return NULL;
    6093             : }
    6094             : 
    6095             : 
    6096             : SWIGINTERN PyObject *_wrap_VirtualMem_Pin__SWIG_1(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
    6097             :   PyObject *resultobj = 0;
    6098             :   CPLVirtualMemShadow *arg1 = (CPLVirtualMemShadow *) 0 ;
    6099             :   size_t arg2 ;
    6100             :   size_t arg3 ;
    6101             :   void *argp1 = 0 ;
    6102             :   int res1 = 0 ;
    6103             :   size_t val2 ;
    6104             :   int ecode2 = 0 ;
    6105             :   size_t val3 ;
    6106             :   int ecode3 = 0 ;
    6107             :   
    6108             :   if ((nobjs < 3) || (nobjs > 3)) SWIG_fail;
    6109             :   res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_CPLVirtualMemShadow, 0 |  0 );
    6110             :   if (!SWIG_IsOK(res1)) {
    6111             :     SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "VirtualMem_Pin" "', argument " "1"" of type '" "CPLVirtualMemShadow *""'"); 
    6112             :   }
    6113             :   arg1 = reinterpret_cast< CPLVirtualMemShadow * >(argp1);
    6114             :   ecode2 = SWIG_AsVal_size_t(swig_obj[1], &val2);
    6115             :   if (!SWIG_IsOK(ecode2)) {
    6116             :     SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "VirtualMem_Pin" "', argument " "2"" of type '" "size_t""'");
    6117             :   } 
    6118             :   arg2 = static_cast< size_t >(val2);
    6119             :   ecode3 = SWIG_AsVal_size_t(swig_obj[2], &val3);
    6120             :   if (!SWIG_IsOK(ecode3)) {
    6121             :     SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "VirtualMem_Pin" "', argument " "3"" of type '" "size_t""'");
    6122             :   } 
    6123             :   arg3 = static_cast< size_t >(val3);
    6124             :   {
    6125             :     SWIG_PYTHON_THREAD_BEGIN_ALLOW;
    6126             :     CPLVirtualMemShadow_Pin__SWIG_0(arg1,arg2,arg3);
    6127             :     SWIG_PYTHON_THREAD_END_ALLOW;
    6128             :   }
    6129             :   resultobj = SWIG_Py_Void();
    6130             :   return resultobj;
    6131             : fail:
    6132             :   return NULL;
    6133             : }
    6134             : 
    6135             : 
    6136             : SWIGINTERN PyObject *_wrap_VirtualMem_Pin__SWIG_2(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
    6137             :   PyObject *resultobj = 0;
    6138             :   CPLVirtualMemShadow *arg1 = (CPLVirtualMemShadow *) 0 ;
    6139             :   size_t arg2 ;
    6140             :   void *argp1 = 0 ;
    6141             :   int res1 = 0 ;
    6142             :   size_t val2 ;
    6143             :   int ecode2 = 0 ;
    6144             :   
    6145             :   if ((nobjs < 2) || (nobjs > 2)) SWIG_fail;
    6146             :   res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_CPLVirtualMemShadow, 0 |  0 );
    6147             :   if (!SWIG_IsOK(res1)) {
    6148             :     SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "VirtualMem_Pin" "', argument " "1"" of type '" "CPLVirtualMemShadow *""'"); 
    6149             :   }
    6150             :   arg1 = reinterpret_cast< CPLVirtualMemShadow * >(argp1);
    6151             :   ecode2 = SWIG_AsVal_size_t(swig_obj[1], &val2);
    6152             :   if (!SWIG_IsOK(ecode2)) {
    6153             :     SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "VirtualMem_Pin" "', argument " "2"" of type '" "size_t""'");
    6154             :   } 
    6155             :   arg2 = static_cast< size_t >(val2);
    6156             :   {
    6157             :     SWIG_PYTHON_THREAD_BEGIN_ALLOW;
    6158             :     CPLVirtualMemShadow_Pin__SWIG_0(arg1,arg2);
    6159             :     SWIG_PYTHON_THREAD_END_ALLOW;
    6160             :   }
    6161             :   resultobj = SWIG_Py_Void();
    6162             :   return resultobj;
    6163             : fail:
    6164             :   return NULL;
    6165             : }
    6166             : 
    6167             : 
    6168             : SWIGINTERN PyObject *_wrap_VirtualMem_Pin__SWIG_3(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
    6169             :   PyObject *resultobj = 0;
    6170             :   CPLVirtualMemShadow *arg1 = (CPLVirtualMemShadow *) 0 ;
    6171             :   void *argp1 = 0 ;
    6172             :   int res1 = 0 ;
    6173             :   
    6174             :   if ((nobjs < 1) || (nobjs > 1)) SWIG_fail;
    6175             :   res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_CPLVirtualMemShadow, 0 |  0 );
    6176             :   if (!SWIG_IsOK(res1)) {
    6177             :     SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "VirtualMem_Pin" "', argument " "1"" of type '" "CPLVirtualMemShadow *""'"); 
    6178             :   }
    6179             :   arg1 = reinterpret_cast< CPLVirtualMemShadow * >(argp1);
    6180             :   {
    6181             :     SWIG_PYTHON_THREAD_BEGIN_ALLOW;
    6182             :     CPLVirtualMemShadow_Pin__SWIG_0(arg1);
    6183             :     SWIG_PYTHON_THREAD_END_ALLOW;
    6184             :   }
    6185             :   resultobj = SWIG_Py_Void();
    6186             :   return resultobj;
    6187             : fail:
    6188             :   return NULL;
    6189             : }
    6190             : 
    6191             : 
    6192           0 : SWIGINTERN PyObject *_wrap_VirtualMem_Pin(PyObject *self, PyObject *args) {
    6193           0 :   Py_ssize_t argc;
    6194           0 :   PyObject *argv[5] = {
    6195             :     0
    6196             :   };
    6197             :   
    6198           0 :   if (!(argc = SWIG_Python_UnpackTuple(args, "VirtualMem_Pin", 0, 4, argv))) SWIG_fail;
    6199           0 :   --argc;
    6200           0 :   if (argc == 1) {
    6201           0 :     int _v;
    6202           0 :     void *vptr = 0;
    6203           0 :     int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_CPLVirtualMemShadow, 0);
    6204           0 :     _v = SWIG_CheckState(res);
    6205           0 :     if (_v) {
    6206           0 :       return _wrap_VirtualMem_Pin__SWIG_3(self, argc, argv);
    6207             :     }
    6208             :   }
    6209           0 :   if (argc == 2) {
    6210           0 :     int _v;
    6211           0 :     void *vptr = 0;
    6212           0 :     int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_CPLVirtualMemShadow, 0);
    6213           0 :     _v = SWIG_CheckState(res);
    6214           0 :     if (_v) {
    6215           0 :       {
    6216           0 :         int res = SWIG_AsVal_size_t(argv[1], NULL);
    6217           0 :         _v = SWIG_CheckState(res);
    6218             :       }
    6219           0 :       if (_v) {
    6220           0 :         return _wrap_VirtualMem_Pin__SWIG_2(self, argc, argv);
    6221             :       }
    6222             :     }
    6223             :   }
    6224           0 :   if (argc == 3) {
    6225           0 :     int _v;
    6226           0 :     void *vptr = 0;
    6227           0 :     int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_CPLVirtualMemShadow, 0);
    6228           0 :     _v = SWIG_CheckState(res);
    6229           0 :     if (_v) {
    6230           0 :       {
    6231           0 :         int res = SWIG_AsVal_size_t(argv[1], NULL);
    6232           0 :         _v = SWIG_CheckState(res);
    6233             :       }
    6234           0 :       if (_v) {
    6235           0 :         {
    6236           0 :           int res = SWIG_AsVal_size_t(argv[2], NULL);
    6237           0 :           _v = SWIG_CheckState(res);
    6238             :         }
    6239           0 :         if (_v) {
    6240           0 :           return _wrap_VirtualMem_Pin__SWIG_1(self, argc, argv);
    6241             :         }
    6242             :       }
    6243             :     }
    6244             :   }
    6245           0 :   if (argc == 4) {
    6246           0 :     int _v;
    6247           0 :     void *vptr = 0;
    6248           0 :     int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_CPLVirtualMemShadow, 0);
    6249           0 :     _v = SWIG_CheckState(res);
    6250           0 :     if (_v) {
    6251           0 :       {
    6252           0 :         int res = SWIG_AsVal_size_t(argv[1], NULL);
    6253           0 :         _v = SWIG_CheckState(res);
    6254             :       }
    6255           0 :       if (_v) {
    6256           0 :         {
    6257           0 :           int res = SWIG_AsVal_size_t(argv[2], NULL);
    6258           0 :           _v = SWIG_CheckState(res);
    6259             :         }
    6260           0 :         if (_v) {
    6261           0 :           {
    6262           0 :             int res = SWIG_AsVal_int(argv[3], NULL);
    6263           0 :             _v = SWIG_CheckState(res);
    6264             :           }
    6265           0 :           if (_v) {
    6266           0 :             return _wrap_VirtualMem_Pin__SWIG_0(self, argc, argv);
    6267             :           }
    6268             :         }
    6269             :       }
    6270             :     }
    6271             :   }
    6272             :   
    6273           0 : fail:
    6274           0 :   SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'VirtualMem_Pin'.\n"
    6275             :     "  Possible C/C++ prototypes are:\n"
    6276             :     "    CPLVirtualMemShadow::Pin(size_t,size_t,int)\n"
    6277             :     "    CPLVirtualMemShadow::Pin(size_t,size_t)\n"
    6278             :     "    CPLVirtualMemShadow::Pin(size_t)\n"
    6279             :     "    CPLVirtualMemShadow::Pin()\n");
    6280             :   return 0;
    6281             : }
    6282             : 
    6283             : 
    6284         233 : SWIGINTERN PyObject *VirtualMem_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    6285         233 :   PyObject *obj;
    6286         233 :   if (!SWIG_Python_UnpackTuple(args, "swigregister", 1, 1, &obj)) return NULL;
    6287         233 :   SWIG_TypeNewClientData(SWIGTYPE_p_CPLVirtualMemShadow, SWIG_NewClientData(obj));
    6288         233 :   return SWIG_Py_Void();
    6289             : }
    6290             : 
    6291           0 : SWIGINTERN PyObject *_wrap_GetUseExceptions(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    6292           0 :   PyObject *resultobj = 0;
    6293           0 :   int result;
    6294             :   
    6295           0 :   if (!SWIG_Python_UnpackTuple(args, "GetUseExceptions", 0, 0, 0)) SWIG_fail;
    6296           0 :   {
    6297             : #ifdef SED_HACKS
    6298             :     if( ReturnSame(TRUE) ) bLocalUseExceptionsCode = FALSE;
    6299             : #endif
    6300           0 :     result = GetUseExceptions();
    6301             :   }
    6302           0 :   resultobj = SWIG_From_int(static_cast< int >(result));
    6303           0 :   return resultobj;
    6304           0 : fail:
    6305           0 :   return NULL;
    6306             : }
    6307             : 
    6308             : 
    6309           0 : SWIGINTERN PyObject *_wrap__GetExceptionsLocal(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    6310           0 :   PyObject *resultobj = 0;
    6311           0 :   int result;
    6312             :   
    6313           0 :   if (!SWIG_Python_UnpackTuple(args, "_GetExceptionsLocal", 0, 0, 0)) SWIG_fail;
    6314           0 :   {
    6315             : #ifdef SED_HACKS
    6316             :     if( ReturnSame(TRUE) ) bLocalUseExceptionsCode = FALSE;
    6317             : #endif
    6318           0 :     {
    6319           0 :       SWIG_PYTHON_THREAD_BEGIN_ALLOW;
    6320           0 :       result = (int)_GetExceptionsLocal();
    6321           0 :       SWIG_PYTHON_THREAD_END_ALLOW;
    6322             :     }
    6323             :   }
    6324           0 :   resultobj = SWIG_From_int(static_cast< int >(result));
    6325           0 :   return resultobj;
    6326           0 : fail:
    6327           0 :   return NULL;
    6328             : }
    6329             : 
    6330             : 
    6331       25146 : SWIGINTERN PyObject *_wrap__SetExceptionsLocal(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    6332       25146 :   PyObject *resultobj = 0;
    6333       25146 :   int arg1 ;
    6334       25146 :   int val1 ;
    6335       25146 :   int ecode1 = 0 ;
    6336       25146 :   PyObject *swig_obj[1] ;
    6337             :   
    6338       25146 :   if (!args) SWIG_fail;
    6339       25146 :   swig_obj[0] = args;
    6340       25146 :   ecode1 = SWIG_AsVal_int(swig_obj[0], &val1);
    6341       25146 :   if (!SWIG_IsOK(ecode1)) {
    6342           0 :     SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "_SetExceptionsLocal" "', argument " "1"" of type '" "int""'");
    6343             :   } 
    6344       25146 :   arg1 = static_cast< int >(val1);
    6345       25146 :   {
    6346             : #ifdef SED_HACKS
    6347             :     if( ReturnSame(TRUE) ) bLocalUseExceptionsCode = FALSE;
    6348             : #endif
    6349       25146 :     {
    6350       25146 :       SWIG_PYTHON_THREAD_BEGIN_ALLOW;
    6351       25146 :       _SetExceptionsLocal(arg1);
    6352       25146 :       SWIG_PYTHON_THREAD_END_ALLOW;
    6353             :     }
    6354             :   }
    6355       25146 :   resultobj = SWIG_Py_Void();
    6356       25146 :   return resultobj;
    6357             : fail:
    6358             :   return NULL;
    6359             : }
    6360             : 
    6361             : 
    6362          32 : SWIGINTERN PyObject *_wrap__UseExceptions(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    6363          32 :   PyObject *resultobj = 0;
    6364             :   
    6365          32 :   if (!SWIG_Python_UnpackTuple(args, "_UseExceptions", 0, 0, 0)) SWIG_fail;
    6366          32 :   {
    6367          32 :     SWIG_PYTHON_THREAD_BEGIN_ALLOW;
    6368          32 :     _UseExceptions();
    6369          32 :     SWIG_PYTHON_THREAD_END_ALLOW;
    6370             :   }
    6371          32 :   resultobj = SWIG_Py_Void();
    6372          32 :   return resultobj;
    6373           0 : fail:
    6374           0 :   return NULL;
    6375             : }
    6376             : 
    6377             : 
    6378           5 : SWIGINTERN PyObject *_wrap__DontUseExceptions(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    6379           5 :   PyObject *resultobj = 0;
    6380             :   
    6381           5 :   if (!SWIG_Python_UnpackTuple(args, "_DontUseExceptions", 0, 0, 0)) SWIG_fail;
    6382           5 :   {
    6383           5 :     SWIG_PYTHON_THREAD_BEGIN_ALLOW;
    6384           5 :     _DontUseExceptions();
    6385           5 :     SWIG_PYTHON_THREAD_END_ALLOW;
    6386             :   }
    6387           5 :   resultobj = SWIG_Py_Void();
    6388           5 :   return resultobj;
    6389           0 : fail:
    6390           0 :   return NULL;
    6391             : }
    6392             : 
    6393             : 
    6394           0 : SWIGINTERN PyObject *_wrap__UserHasSpecifiedIfUsingExceptions(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    6395           0 :   PyObject *resultobj = 0;
    6396           0 :   int result;
    6397             :   
    6398           0 :   if (!SWIG_Python_UnpackTuple(args, "_UserHasSpecifiedIfUsingExceptions", 0, 0, 0)) SWIG_fail;
    6399           0 :   {
    6400             : #ifdef SED_HACKS
    6401             :     if( ReturnSame(TRUE) ) bLocalUseExceptionsCode = FALSE;
    6402             : #endif
    6403           0 :     {
    6404           0 :       SWIG_PYTHON_THREAD_BEGIN_ALLOW;
    6405           0 :       result = (int)_UserHasSpecifiedIfUsingExceptions();
    6406           0 :       SWIG_PYTHON_THREAD_END_ALLOW;
    6407             :     }
    6408             :   }
    6409           0 :   resultobj = SWIG_From_int(static_cast< int >(result));
    6410           0 :   return resultobj;
    6411           0 : fail:
    6412           0 :   return NULL;
    6413             : }
    6414             : 
    6415             : 
    6416           0 : SWIGINTERN PyObject *_wrap_TermProgress_nocb(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
    6417           0 :   PyObject *resultobj = 0;
    6418           0 :   double arg1 ;
    6419           0 :   char *arg2 = (char *) NULL ;
    6420           0 :   void *arg3 = (void *) NULL ;
    6421           0 :   double val1 ;
    6422           0 :   int ecode1 = 0 ;
    6423           0 :   int res2 ;
    6424           0 :   char *buf2 = 0 ;
    6425           0 :   int alloc2 = 0 ;
    6426           0 :   int res3 ;
    6427           0 :   PyObject * obj0 = 0 ;
    6428           0 :   PyObject * obj1 = 0 ;
    6429           0 :   PyObject * obj2 = 0 ;
    6430           0 :   char * kwnames[] = {
    6431             :     (char *)"dfProgress",  (char *)"pszMessage",  (char *)"pData",  NULL 
    6432             :   };
    6433           0 :   int result;
    6434             :   
    6435           0 :   if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|OO:TermProgress_nocb", kwnames, &obj0, &obj1, &obj2)) SWIG_fail;
    6436           0 :   ecode1 = SWIG_AsVal_double(obj0, &val1);
    6437           0 :   if (!SWIG_IsOK(ecode1)) {
    6438           0 :     SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "TermProgress_nocb" "', argument " "1"" of type '" "double""'");
    6439             :   } 
    6440           0 :   arg1 = static_cast< double >(val1);
    6441           0 :   if (obj1) {
    6442           0 :     res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2);
    6443           0 :     if (!SWIG_IsOK(res2)) {
    6444           0 :       SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "TermProgress_nocb" "', argument " "2"" of type '" "char const *""'");
    6445             :     }
    6446           0 :     arg2 = reinterpret_cast< char * >(buf2);
    6447             :   }
    6448           0 :   if (obj2) {
    6449           0 :     res3 = SWIG_ConvertPtr(obj2,SWIG_as_voidptrptr(&arg3), 0, 0);
    6450           0 :     if (!SWIG_IsOK(res3)) {
    6451           0 :       SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "TermProgress_nocb" "', argument " "3"" of type '" "void *""'"); 
    6452             :     }
    6453             :   }
    6454           0 :   {
    6455           0 :     const int bLocalUseExceptions = GetUseExceptions();
    6456           0 :     if ( bLocalUseExceptions ) {
    6457           0 :       pushErrorHandler();
    6458             :     }
    6459           0 :     result = (int)GDALTermProgress_nocb(arg1,(char const *)arg2,arg3);
    6460           0 :     if ( bLocalUseExceptions ) {
    6461           0 :       popErrorHandler();
    6462             :     }
    6463             : #ifndef SED_HACKS
    6464           0 :     if ( bLocalUseExceptions ) {
    6465           0 :       CPLErr eclass = CPLGetLastErrorType();
    6466           0 :       if ( eclass == CE_Failure || eclass == CE_Fatal ) {
    6467           0 :         SWIG_exception( SWIG_RuntimeError, CPLGetLastErrorMsg() );
    6468             :       }
    6469             :     }
    6470             : #endif
    6471             :   }
    6472           0 :   resultobj = SWIG_From_int(static_cast< int >(result));
    6473           0 :   if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
    6474             :   return resultobj;
    6475           0 : fail:
    6476           0 :   if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
    6477             :   return NULL;
    6478             : }
    6479             : 
    6480             : 
    6481          30 : SWIGINTERN PyObject *_wrap_OpenNumPyArray(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    6482          30 :   PyObject *resultobj = 0;
    6483          30 :   PyArrayObject *arg1 = (PyArrayObject *) 0 ;
    6484          30 :   bool arg2 ;
    6485          30 :   bool val2 ;
    6486          30 :   int ecode2 = 0 ;
    6487          30 :   PyObject *swig_obj[2] ;
    6488          30 :   GDALDatasetShadow *result = 0 ;
    6489             :   
    6490          30 :   if (!SWIG_Python_UnpackTuple(args, "OpenNumPyArray", 2, 2, swig_obj)) SWIG_fail;
    6491          30 :   {
    6492             :     /* %typemap(in,numinputs=1) (PyArrayObject  *psArray) */
    6493          30 :     if (swig_obj[0] != NULL && PyArray_Check(swig_obj[0]))
    6494             :     {
    6495          30 :       arg1 = (PyArrayObject*)(swig_obj[0]);
    6496             :     }
    6497             :     else
    6498             :     {
    6499           0 :       PyErr_SetString(PyExc_TypeError, "not a numpy array");
    6500           0 :       SWIG_fail;
    6501             :     }
    6502             :   }
    6503          30 :   ecode2 = SWIG_AsVal_bool(swig_obj[1], &val2);
    6504          30 :   if (!SWIG_IsOK(ecode2)) {
    6505           0 :     SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "OpenNumPyArray" "', argument " "2"" of type '" "bool""'");
    6506             :   } 
    6507          30 :   arg2 = static_cast< bool >(val2);
    6508          30 :   {
    6509          30 :     const int bLocalUseExceptions = GetUseExceptions();
    6510          30 :     if ( bLocalUseExceptions ) {
    6511           4 :       pushErrorHandler();
    6512             :     }
    6513          30 :     result = (GDALDatasetShadow *)OpenNumPyArray(arg1,arg2);
    6514          30 :     if ( bLocalUseExceptions ) {
    6515           4 :       popErrorHandler();
    6516             :     }
    6517             : #ifndef SED_HACKS
    6518          30 :     if( result == NULL && bLocalUseExceptions ) {
    6519           1 :       CPLErr eclass = CPLGetLastErrorType();
    6520           1 :       if ( eclass == CE_Failure || eclass == CE_Fatal ) {
    6521           1 :         SWIG_exception( SWIG_RuntimeError, CPLGetLastErrorMsg() );
    6522             :       }
    6523             :     }
    6524             : #endif
    6525          29 :     if( result != NULL && bLocalUseExceptions ) {
    6526             : #ifdef SED_HACKS
    6527             :       bLocalUseExceptionsCode = FALSE;
    6528             : #endif
    6529             :     }
    6530             :   }
    6531          29 :   resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_GDALDatasetShadow, SWIG_POINTER_OWN |  0 );
    6532             :   return resultobj;
    6533             : fail:
    6534             :   return NULL;
    6535             : }
    6536             : 
    6537             : 
    6538          21 : SWIGINTERN PyObject *_wrap_OpenMultiDimensionalNumPyArray(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    6539          21 :   PyObject *resultobj = 0;
    6540          21 :   PyArrayObject *arg1 = (PyArrayObject *) 0 ;
    6541          21 :   PyObject *swig_obj[1] ;
    6542          21 :   GDALDatasetShadow *result = 0 ;
    6543             :   
    6544          21 :   if (!args) SWIG_fail;
    6545          21 :   swig_obj[0] = args;
    6546          21 :   {
    6547             :     /* %typemap(in,numinputs=1) (PyArrayObject  *psArray) */
    6548          21 :     if (swig_obj[0] != NULL && PyArray_Check(swig_obj[0]))
    6549             :     {
    6550          21 :       arg1 = (PyArrayObject*)(swig_obj[0]);
    6551             :     }
    6552             :     else
    6553             :     {
    6554           0 :       PyErr_SetString(PyExc_TypeError, "not a numpy array");
    6555           0 :       SWIG_fail;
    6556             :     }
    6557             :   }
    6558          21 :   {
    6559          21 :     const int bLocalUseExceptions = GetUseExceptions();
    6560          21 :     if ( bLocalUseExceptions ) {
    6561          21 :       pushErrorHandler();
    6562             :     }
    6563          21 :     result = (GDALDatasetShadow *)OpenMultiDimensionalNumPyArray(arg1);
    6564          21 :     if ( bLocalUseExceptions ) {
    6565          21 :       popErrorHandler();
    6566             :     }
    6567             : #ifndef SED_HACKS
    6568          21 :     if( result == NULL && bLocalUseExceptions ) {
    6569           1 :       CPLErr eclass = CPLGetLastErrorType();
    6570           1 :       if ( eclass == CE_Failure || eclass == CE_Fatal ) {
    6571           1 :         SWIG_exception( SWIG_RuntimeError, CPLGetLastErrorMsg() );
    6572             :       }
    6573             :     }
    6574             : #endif
    6575          20 :     if( result != NULL && bLocalUseExceptions ) {
    6576             : #ifdef SED_HACKS
    6577             :       bLocalUseExceptionsCode = FALSE;
    6578             : #endif
    6579             :     }
    6580             :   }
    6581          20 :   resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_GDALDatasetShadow, SWIG_POINTER_OWN |  0 );
    6582             :   return resultobj;
    6583             : fail:
    6584             :   return NULL;
    6585             : }
    6586             : 
    6587             : 
    6588           2 : SWIGINTERN PyObject *_wrap_GetArrayFilename(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    6589           2 :   PyObject *resultobj = 0;
    6590           2 :   PyArrayObject *arg1 = (PyArrayObject *) 0 ;
    6591           2 :   PyObject *swig_obj[1] ;
    6592           2 :   retStringAndCPLFree *result = 0 ;
    6593             :   
    6594           2 :   if (!args) SWIG_fail;
    6595           2 :   swig_obj[0] = args;
    6596           2 :   {
    6597             :     /* %typemap(in,numinputs=1) (PyArrayObject  *psArray) */
    6598           2 :     if (swig_obj[0] != NULL && PyArray_Check(swig_obj[0]))
    6599             :     {
    6600           2 :       arg1 = (PyArrayObject*)(swig_obj[0]);
    6601             :     }
    6602             :     else
    6603             :     {
    6604           0 :       PyErr_SetString(PyExc_TypeError, "not a numpy array");
    6605           0 :       SWIG_fail;
    6606             :     }
    6607             :   }
    6608           2 :   {
    6609           2 :     const int bLocalUseExceptions = GetUseExceptions();
    6610           2 :     if ( bLocalUseExceptions ) {
    6611           0 :       pushErrorHandler();
    6612             :     }
    6613           2 :     result = (retStringAndCPLFree *)GetArrayFilename(arg1);
    6614           2 :     if ( bLocalUseExceptions ) {
    6615           0 :       popErrorHandler();
    6616             :     }
    6617             : #ifndef SED_HACKS
    6618           2 :     if ( bLocalUseExceptions ) {
    6619           0 :       CPLErr eclass = CPLGetLastErrorType();
    6620           0 :       if ( eclass == CE_Failure || eclass == CE_Fatal ) {
    6621           0 :         SWIG_exception( SWIG_RuntimeError, CPLGetLastErrorMsg() );
    6622             :       }
    6623             :     }
    6624             : #endif
    6625             :   }
    6626           2 :   {
    6627             :     /* %typemap(out) (retStringAndCPLFree*) */
    6628           2 :     Py_XDECREF(resultobj);
    6629           2 :     if(result)
    6630             :     {
    6631           2 :       resultobj = GDALPythonObjectFromCStr( (const char *)result);
    6632           2 :       CPLFree(result);
    6633             :     }
    6634             :     else
    6635             :     {
    6636           0 :       resultobj = Py_None;
    6637           0 :       Py_INCREF(resultobj);
    6638             :     }
    6639             :   }
    6640             :   return resultobj;
    6641             : fail:
    6642             :   return NULL;
    6643             : }
    6644             : 
    6645             : 
    6646       19396 : SWIGINTERN PyObject *_wrap_BandRasterIONumPy(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
    6647       19396 :   PyObject *resultobj = 0;
    6648       19396 :   GDALRasterBandShadow *arg1 = (GDALRasterBandShadow *) 0 ;
    6649       19396 :   int arg2 ;
    6650       19396 :   double arg3 ;
    6651       19396 :   double arg4 ;
    6652       19396 :   double arg5 ;
    6653       19396 :   double arg6 ;
    6654       19396 :   PyArrayObject *arg7 = (PyArrayObject *) 0 ;
    6655       19396 :   GDALDataType arg8 ;
    6656       19396 :   GDALRIOResampleAlg arg9 ;
    6657       19396 :   int arg10 ;
    6658       19396 :   GDALProgressFunc arg11 = (GDALProgressFunc) NULL ;
    6659       19396 :   void *arg12 = (void *) NULL ;
    6660       19396 :   void *argp1 = 0 ;
    6661       19396 :   int res1 = 0 ;
    6662       19396 :   int val2 ;
    6663       19396 :   int ecode2 = 0 ;
    6664       19396 :   double val3 ;
    6665       19396 :   int ecode3 = 0 ;
    6666       19396 :   double val4 ;
    6667       19396 :   int ecode4 = 0 ;
    6668       19396 :   double val5 ;
    6669       19396 :   int ecode5 = 0 ;
    6670       19396 :   double val6 ;
    6671       19396 :   int ecode6 = 0 ;
    6672       19396 :   int val10 ;
    6673       19396 :   int ecode10 = 0 ;
    6674       19396 :   PyObject * obj0 = 0 ;
    6675       19396 :   PyObject * obj1 = 0 ;
    6676       19396 :   PyObject * obj2 = 0 ;
    6677       19396 :   PyObject * obj3 = 0 ;
    6678       19396 :   PyObject * obj4 = 0 ;
    6679       19396 :   PyObject * obj5 = 0 ;
    6680       19396 :   PyObject * obj6 = 0 ;
    6681       19396 :   PyObject * obj7 = 0 ;
    6682       19396 :   PyObject * obj8 = 0 ;
    6683       19396 :   PyObject * obj9 = 0 ;
    6684       19396 :   PyObject * obj10 = 0 ;
    6685       19396 :   PyObject * obj11 = 0 ;
    6686       19396 :   char * kwnames[] = {
    6687             :     (char *)"band",  (char *)"bWrite",  (char *)"xoff",  (char *)"yoff",  (char *)"xsize",  (char *)"ysize",  (char *)"psArray",  (char *)"buf_type",  (char *)"resample_alg",  (char *)"operate_in_buf_type",  (char *)"callback",  (char *)"callback_data",  NULL 
    6688             :   };
    6689       19396 :   CPLErr result;
    6690             :   
    6691             :   /* %typemap(arginit) ( const char* callback_data=NULL)  */
    6692       19396 :   PyProgressData *psProgressInfo;
    6693       19396 :   psProgressInfo = (PyProgressData *) CPLCalloc(1,sizeof(PyProgressData));
    6694       19396 :   psProgressInfo->nLastReported = -1;
    6695       19396 :   psProgressInfo->psPyCallback = NULL;
    6696       19396 :   psProgressInfo->psPyCallbackData = NULL;
    6697       19396 :   arg12 = psProgressInfo;
    6698       19396 :   if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOOOOOOOOO|OO:BandRasterIONumPy", kwnames, &obj0, &obj1, &obj2, &obj3, &obj4, &obj5, &obj6, &obj7, &obj8, &obj9, &obj10, &obj11)) SWIG_fail;
    6699       19396 :   res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_GDALRasterBandShadow, 0 |  0 );
    6700       19396 :   if (!SWIG_IsOK(res1)) {
    6701           0 :     SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "BandRasterIONumPy" "', argument " "1"" of type '" "GDALRasterBandShadow *""'"); 
    6702             :   }
    6703       19396 :   arg1 = reinterpret_cast< GDALRasterBandShadow * >(argp1);
    6704       19396 :   ecode2 = SWIG_AsVal_int(obj1, &val2);
    6705       19396 :   if (!SWIG_IsOK(ecode2)) {
    6706           0 :     SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "BandRasterIONumPy" "', argument " "2"" of type '" "int""'");
    6707             :   } 
    6708       19396 :   arg2 = static_cast< int >(val2);
    6709       19396 :   ecode3 = SWIG_AsVal_double(obj2, &val3);
    6710       19396 :   if (!SWIG_IsOK(ecode3)) {
    6711           0 :     SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "BandRasterIONumPy" "', argument " "3"" of type '" "double""'");
    6712             :   } 
    6713       19396 :   arg3 = static_cast< double >(val3);
    6714       19396 :   ecode4 = SWIG_AsVal_double(obj3, &val4);
    6715       19396 :   if (!SWIG_IsOK(ecode4)) {
    6716           0 :     SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "BandRasterIONumPy" "', argument " "4"" of type '" "double""'");
    6717             :   } 
    6718       19396 :   arg4 = static_cast< double >(val4);
    6719       19396 :   ecode5 = SWIG_AsVal_double(obj4, &val5);
    6720       19396 :   if (!SWIG_IsOK(ecode5)) {
    6721           0 :     SWIG_exception_fail(SWIG_ArgError(ecode5), "in method '" "BandRasterIONumPy" "', argument " "5"" of type '" "double""'");
    6722             :   } 
    6723       19396 :   arg5 = static_cast< double >(val5);
    6724       19396 :   ecode6 = SWIG_AsVal_double(obj5, &val6);
    6725       19396 :   if (!SWIG_IsOK(ecode6)) {
    6726           0 :     SWIG_exception_fail(SWIG_ArgError(ecode6), "in method '" "BandRasterIONumPy" "', argument " "6"" of type '" "double""'");
    6727             :   } 
    6728       19396 :   arg6 = static_cast< double >(val6);
    6729       19396 :   {
    6730             :     /* %typemap(in,numinputs=1) (PyArrayObject  *psArray) */
    6731       19396 :     if (obj6 != NULL && PyArray_Check(obj6))
    6732             :     {
    6733       19396 :       arg7 = (PyArrayObject*)(obj6);
    6734             :     }
    6735             :     else
    6736             :     {
    6737           0 :       PyErr_SetString(PyExc_TypeError, "not a numpy array");
    6738           0 :       SWIG_fail;
    6739             :     }
    6740             :   }
    6741       19396 :   {
    6742             :     // %typemap(in) GDALDataType
    6743       19396 :     int val = 0;
    6744       19396 :     int ecode = SWIG_AsVal_int(obj7, &val);
    6745       19396 :     if (!SWIG_IsOK(ecode)) {
    6746           0 :       SWIG_exception_fail(SWIG_ArgError(ecode), "invalid value for GDALDataType");
    6747             :     }
    6748       19396 :     if( val < GDT_Unknown || val >= GDT_TypeCount )
    6749             :     {
    6750           0 :       SWIG_exception_fail(SWIG_ValueError, "Invalid value for GDALDataType");
    6751             :     }
    6752       19396 :     arg8 = static_cast<GDALDataType>(val);
    6753             :   }
    6754       19396 :   {
    6755             :     // %typemap(in) GDALRIOResampleAlg
    6756       19396 :     int val = 0;
    6757       19396 :     int ecode = SWIG_AsVal_int(obj8, &val);
    6758       19396 :     if (!SWIG_IsOK(ecode)) {
    6759           2 :       SWIG_exception_fail(SWIG_ArgError(ecode), "invalid value for GDALRIOResampleAlg");
    6760             :     }
    6761       19394 :     if( val < 0 ||
    6762       19392 :       ( val >= static_cast<int>(GRIORA_RESERVED_START) &&
    6763       19390 :         val <= static_cast<int>(GRIORA_RESERVED_END) ) ||
    6764             :       val > static_cast<int>(GRIORA_LAST) )
    6765             :     {
    6766           4 :       SWIG_exception_fail(SWIG_ValueError, "Invalid value for resample_alg");
    6767             :     }
    6768       19390 :     arg9 = static_cast< GDALRIOResampleAlg >(val);
    6769             :   }
    6770       19390 :   ecode10 = SWIG_AsVal_int(obj9, &val10);
    6771       19390 :   if (!SWIG_IsOK(ecode10)) {
    6772           0 :     SWIG_exception_fail(SWIG_ArgError(ecode10), "in method '" "BandRasterIONumPy" "', argument " "10"" of type '" "int""'");
    6773             :   } 
    6774       19390 :   arg10 = static_cast< int >(val10);
    6775       19390 :   if (obj10) {
    6776       19390 :     {
    6777             :       /* %typemap(in) (GDALProgressFunc callback = NULL) */
    6778             :       /* callback_func typemap */
    6779             :       
    6780             :       /* In some cases 0 is passed instead of None. */
    6781             :       /* See https://github.com/OSGeo/gdal/pull/219 */
    6782       19390 :       if ( PyLong_Check(obj10) || PyInt_Check(obj10) )
    6783             :       {
    6784           0 :         if( PyLong_AsLong(obj10) == 0 )
    6785             :         {
    6786           0 :           obj10 = Py_None;
    6787             :         }
    6788             :       }
    6789             :       
    6790       19390 :       if (obj10 && obj10 != Py_None ) {
    6791           4 :         void* cbfunction = NULL;
    6792           4 :         CPL_IGNORE_RET_VAL(SWIG_ConvertPtr( obj10,
    6793             :             (void**)&cbfunction,
    6794             :             SWIGTYPE_p_f_double_p_q_const__char_p_void__int,
    6795             :             SWIG_POINTER_EXCEPTION | 0 ));
    6796             :         
    6797           4 :         if ( cbfunction == GDALTermProgress ) {
    6798             :           arg11 = GDALTermProgress;
    6799             :         } else {
    6800           4 :           if (!PyCallable_Check(obj10)) {
    6801           0 :             PyErr_SetString( PyExc_RuntimeError,
    6802             :               "Object given is not a Python function" );
    6803           0 :             SWIG_fail;
    6804             :           }
    6805           4 :           psProgressInfo->psPyCallback = obj10;
    6806           4 :           arg11 = PyProgressProxy;
    6807             :         }
    6808             :         
    6809             :       }
    6810             :       
    6811             :     }
    6812             :   }
    6813       19390 :   if (obj11) {
    6814       19390 :     {
    6815             :       /* %typemap(in) ( void* callback_data=NULL)  */
    6816       19390 :       psProgressInfo->psPyCallbackData = obj11 ;
    6817             :     }
    6818             :   }
    6819       19390 :   {
    6820       19390 :     const int bLocalUseExceptions = GetUseExceptions();
    6821       19390 :     if ( bLocalUseExceptions ) {
    6822       16480 :       pushErrorHandler();
    6823             :     }
    6824       19390 :     {
    6825       19390 :       SWIG_PYTHON_THREAD_BEGIN_ALLOW;
    6826       19390 :       result = (CPLErr)BandRasterIONumPy(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12);
    6827       19390 :       SWIG_PYTHON_THREAD_END_ALLOW;
    6828             :     }
    6829       19390 :     if ( bLocalUseExceptions ) {
    6830       16480 :       popErrorHandler();
    6831             :     }
    6832             : #ifndef SED_HACKS
    6833       19390 :     if ( bLocalUseExceptions ) {
    6834       16480 :       CPLErr eclass = CPLGetLastErrorType();
    6835       16480 :       if ( eclass == CE_Failure || eclass == CE_Fatal ) {
    6836          21 :         SWIG_exception( SWIG_RuntimeError, CPLGetLastErrorMsg() );
    6837             :       }
    6838             :     }
    6839             : #endif
    6840             :   }
    6841       19369 :   resultobj = SWIG_From_int(static_cast< int >(result));
    6842       19369 :   {
    6843             :     /* %typemap(freearg) ( void* callback_data=NULL)  */
    6844             :     
    6845       19369 :     CPLFree(psProgressInfo);
    6846             :     
    6847             :   }
    6848             :   return resultobj;
    6849          27 : fail:
    6850          27 :   {
    6851             :     /* %typemap(freearg) ( void* callback_data=NULL)  */
    6852             :     
    6853          27 :     CPLFree(psProgressInfo);
    6854             :     
    6855             :   }
    6856             :   return NULL;
    6857             : }
    6858             : 
    6859             : 
    6860         108 : SWIGINTERN PyObject *_wrap_DatasetIONumPy(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
    6861         108 :   PyObject *resultobj = 0;
    6862         108 :   GDALDatasetShadow *arg1 = (GDALDatasetShadow *) 0 ;
    6863         108 :   int arg2 ;
    6864         108 :   double arg3 ;
    6865         108 :   double arg4 ;
    6866         108 :   double arg5 ;
    6867         108 :   double arg6 ;
    6868         108 :   PyArrayObject *arg7 = (PyArrayObject *) 0 ;
    6869         108 :   GDALDataType arg8 ;
    6870         108 :   GDALRIOResampleAlg arg9 ;
    6871         108 :   int arg10 ;
    6872         108 :   GDALProgressFunc arg11 = (GDALProgressFunc) NULL ;
    6873         108 :   void *arg12 = (void *) NULL ;
    6874         108 :   bool arg13 = (bool) true ;
    6875         108 :   int arg14 = (int) 0 ;
    6876         108 :   int *arg15 = (int *) 0 ;
    6877         108 :   void *argp1 = 0 ;
    6878         108 :   int res1 = 0 ;
    6879         108 :   int val2 ;
    6880         108 :   int ecode2 = 0 ;
    6881         108 :   double val3 ;
    6882         108 :   int ecode3 = 0 ;
    6883         108 :   double val4 ;
    6884         108 :   int ecode4 = 0 ;
    6885         108 :   double val5 ;
    6886         108 :   int ecode5 = 0 ;
    6887         108 :   double val6 ;
    6888         108 :   int ecode6 = 0 ;
    6889         108 :   int val10 ;
    6890         108 :   int ecode10 = 0 ;
    6891         108 :   bool val13 ;
    6892         108 :   int ecode13 = 0 ;
    6893         108 :   PyObject * obj0 = 0 ;
    6894         108 :   PyObject * obj1 = 0 ;
    6895         108 :   PyObject * obj2 = 0 ;
    6896         108 :   PyObject * obj3 = 0 ;
    6897         108 :   PyObject * obj4 = 0 ;
    6898         108 :   PyObject * obj5 = 0 ;
    6899         108 :   PyObject * obj6 = 0 ;
    6900         108 :   PyObject * obj7 = 0 ;
    6901         108 :   PyObject * obj8 = 0 ;
    6902         108 :   PyObject * obj9 = 0 ;
    6903         108 :   PyObject * obj10 = 0 ;
    6904         108 :   PyObject * obj11 = 0 ;
    6905         108 :   PyObject * obj12 = 0 ;
    6906         108 :   PyObject * obj13 = 0 ;
    6907         108 :   char * kwnames[] = {
    6908             :     (char *)"ds",  (char *)"bWrite",  (char *)"xoff",  (char *)"yoff",  (char *)"xsize",  (char *)"ysize",  (char *)"psArray",  (char *)"buf_type",  (char *)"resample_alg",  (char *)"operate_in_buf_type",  (char *)"callback",  (char *)"callback_data",  (char *)"binterleave",  (char *)"band_list",  NULL 
    6909             :   };
    6910         108 :   CPLErr result;
    6911             :   
    6912             :   /* %typemap(arginit) ( const char* callback_data=NULL)  */
    6913         108 :   PyProgressData *psProgressInfo;
    6914         108 :   psProgressInfo = (PyProgressData *) CPLCalloc(1,sizeof(PyProgressData));
    6915         108 :   psProgressInfo->nLastReported = -1;
    6916         108 :   psProgressInfo->psPyCallback = NULL;
    6917         108 :   psProgressInfo->psPyCallbackData = NULL;
    6918         108 :   arg12 = psProgressInfo;
    6919         108 :   if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOOOOOOOOO|OOOO:DatasetIONumPy", kwnames, &obj0, &obj1, &obj2, &obj3, &obj4, &obj5, &obj6, &obj7, &obj8, &obj9, &obj10, &obj11, &obj12, &obj13)) SWIG_fail;
    6920         108 :   res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_GDALDatasetShadow, 0 |  0 );
    6921         108 :   if (!SWIG_IsOK(res1)) {
    6922           0 :     SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "DatasetIONumPy" "', argument " "1"" of type '" "GDALDatasetShadow *""'"); 
    6923             :   }
    6924         108 :   arg1 = reinterpret_cast< GDALDatasetShadow * >(argp1);
    6925         108 :   ecode2 = SWIG_AsVal_int(obj1, &val2);
    6926         108 :   if (!SWIG_IsOK(ecode2)) {
    6927           0 :     SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "DatasetIONumPy" "', argument " "2"" of type '" "int""'");
    6928             :   } 
    6929         108 :   arg2 = static_cast< int >(val2);
    6930         108 :   ecode3 = SWIG_AsVal_double(obj2, &val3);
    6931         108 :   if (!SWIG_IsOK(ecode3)) {
    6932           0 :     SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "DatasetIONumPy" "', argument " "3"" of type '" "double""'");
    6933             :   } 
    6934         108 :   arg3 = static_cast< double >(val3);
    6935         108 :   ecode4 = SWIG_AsVal_double(obj3, &val4);
    6936         108 :   if (!SWIG_IsOK(ecode4)) {
    6937           0 :     SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "DatasetIONumPy" "', argument " "4"" of type '" "double""'");
    6938             :   } 
    6939         108 :   arg4 = static_cast< double >(val4);
    6940         108 :   ecode5 = SWIG_AsVal_double(obj4, &val5);
    6941         108 :   if (!SWIG_IsOK(ecode5)) {
    6942           0 :     SWIG_exception_fail(SWIG_ArgError(ecode5), "in method '" "DatasetIONumPy" "', argument " "5"" of type '" "double""'");
    6943             :   } 
    6944         108 :   arg5 = static_cast< double >(val5);
    6945         108 :   ecode6 = SWIG_AsVal_double(obj5, &val6);
    6946         108 :   if (!SWIG_IsOK(ecode6)) {
    6947           0 :     SWIG_exception_fail(SWIG_ArgError(ecode6), "in method '" "DatasetIONumPy" "', argument " "6"" of type '" "double""'");
    6948             :   } 
    6949         108 :   arg6 = static_cast< double >(val6);
    6950         108 :   {
    6951             :     /* %typemap(in,numinputs=1) (PyArrayObject  *psArray) */
    6952         108 :     if (obj6 != NULL && PyArray_Check(obj6))
    6953             :     {
    6954         108 :       arg7 = (PyArrayObject*)(obj6);
    6955             :     }
    6956             :     else
    6957             :     {
    6958           0 :       PyErr_SetString(PyExc_TypeError, "not a numpy array");
    6959           0 :       SWIG_fail;
    6960             :     }
    6961             :   }
    6962         108 :   {
    6963             :     // %typemap(in) GDALDataType
    6964         108 :     int val = 0;
    6965         108 :     int ecode = SWIG_AsVal_int(obj7, &val);
    6966         108 :     if (!SWIG_IsOK(ecode)) {
    6967           0 :       SWIG_exception_fail(SWIG_ArgError(ecode), "invalid value for GDALDataType");
    6968             :     }
    6969         108 :     if( val < GDT_Unknown || val >= GDT_TypeCount )
    6970             :     {
    6971           0 :       SWIG_exception_fail(SWIG_ValueError, "Invalid value for GDALDataType");
    6972             :     }
    6973         108 :     arg8 = static_cast<GDALDataType>(val);
    6974             :   }
    6975         108 :   {
    6976             :     // %typemap(in) GDALRIOResampleAlg
    6977         108 :     int val = 0;
    6978         108 :     int ecode = SWIG_AsVal_int(obj8, &val);
    6979         108 :     if (!SWIG_IsOK(ecode)) {
    6980           0 :       SWIG_exception_fail(SWIG_ArgError(ecode), "invalid value for GDALRIOResampleAlg");
    6981             :     }
    6982         108 :     if( val < 0 ||
    6983         108 :       ( val >= static_cast<int>(GRIORA_RESERVED_START) &&
    6984         108 :         val <= static_cast<int>(GRIORA_RESERVED_END) ) ||
    6985             :       val > static_cast<int>(GRIORA_LAST) )
    6986             :     {
    6987           0 :       SWIG_exception_fail(SWIG_ValueError, "Invalid value for resample_alg");
    6988             :     }
    6989         108 :     arg9 = static_cast< GDALRIOResampleAlg >(val);
    6990             :   }
    6991         108 :   ecode10 = SWIG_AsVal_int(obj9, &val10);
    6992         108 :   if (!SWIG_IsOK(ecode10)) {
    6993           0 :     SWIG_exception_fail(SWIG_ArgError(ecode10), "in method '" "DatasetIONumPy" "', argument " "10"" of type '" "int""'");
    6994             :   } 
    6995         108 :   arg10 = static_cast< int >(val10);
    6996         108 :   if (obj10) {
    6997         108 :     {
    6998             :       /* %typemap(in) (GDALProgressFunc callback = NULL) */
    6999             :       /* callback_func typemap */
    7000             :       
    7001             :       /* In some cases 0 is passed instead of None. */
    7002             :       /* See https://github.com/OSGeo/gdal/pull/219 */
    7003         108 :       if ( PyLong_Check(obj10) || PyInt_Check(obj10) )
    7004             :       {
    7005           0 :         if( PyLong_AsLong(obj10) == 0 )
    7006             :         {
    7007           0 :           obj10 = Py_None;
    7008             :         }
    7009             :       }
    7010             :       
    7011         108 :       if (obj10 && obj10 != Py_None ) {
    7012           3 :         void* cbfunction = NULL;
    7013           3 :         CPL_IGNORE_RET_VAL(SWIG_ConvertPtr( obj10,
    7014             :             (void**)&cbfunction,
    7015             :             SWIGTYPE_p_f_double_p_q_const__char_p_void__int,
    7016             :             SWIG_POINTER_EXCEPTION | 0 ));
    7017             :         
    7018           3 :         if ( cbfunction == GDALTermProgress ) {
    7019             :           arg11 = GDALTermProgress;
    7020             :         } else {
    7021           3 :           if (!PyCallable_Check(obj10)) {
    7022           0 :             PyErr_SetString( PyExc_RuntimeError,
    7023             :               "Object given is not a Python function" );
    7024           0 :             SWIG_fail;
    7025             :           }
    7026           3 :           psProgressInfo->psPyCallback = obj10;
    7027           3 :           arg11 = PyProgressProxy;
    7028             :         }
    7029             :         
    7030             :       }
    7031             :       
    7032             :     }
    7033             :   }
    7034         108 :   if (obj11) {
    7035         108 :     {
    7036             :       /* %typemap(in) ( void* callback_data=NULL)  */
    7037         108 :       psProgressInfo->psPyCallbackData = obj11 ;
    7038             :     }
    7039             :   }
    7040         108 :   if (obj12) {
    7041         108 :     ecode13 = SWIG_AsVal_bool(obj12, &val13);
    7042         108 :     if (!SWIG_IsOK(ecode13)) {
    7043           0 :       SWIG_exception_fail(SWIG_ArgError(ecode13), "in method '" "DatasetIONumPy" "', argument " "13"" of type '" "bool""'");
    7044             :     } 
    7045             :     arg13 = static_cast< bool >(val13);
    7046             :   }
    7047         108 :   if (obj13) {
    7048         108 :     {
    7049             :       /* %typemap(in,numinputs=1) (int nList, int* pList)*/
    7050         108 :       arg15 = CreateCIntListFromSequence(obj13, &arg14);
    7051         108 :       if( arg14 < 0 ) {
    7052           0 :         SWIG_fail;
    7053             :       }
    7054             :     }
    7055             :   }
    7056         108 :   {
    7057         108 :     const int bLocalUseExceptions = GetUseExceptions();
    7058         108 :     if ( bLocalUseExceptions ) {
    7059          76 :       pushErrorHandler();
    7060             :     }
    7061         108 :     {
    7062         108 :       SWIG_PYTHON_THREAD_BEGIN_ALLOW;
    7063         108 :       result = (CPLErr)DatasetIONumPy(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12,arg13,arg14,arg15);
    7064         108 :       SWIG_PYTHON_THREAD_END_ALLOW;
    7065             :     }
    7066         108 :     if ( bLocalUseExceptions ) {
    7067          76 :       popErrorHandler();
    7068             :     }
    7069             : #ifndef SED_HACKS
    7070         108 :     if ( bLocalUseExceptions ) {
    7071          76 :       CPLErr eclass = CPLGetLastErrorType();
    7072          76 :       if ( eclass == CE_Failure || eclass == CE_Fatal ) {
    7073           5 :         SWIG_exception( SWIG_RuntimeError, CPLGetLastErrorMsg() );
    7074             :       }
    7075             :     }
    7076             : #endif
    7077             :   }
    7078         103 :   resultobj = SWIG_From_int(static_cast< int >(result));
    7079         103 :   {
    7080             :     /* %typemap(freearg) ( void* callback_data=NULL)  */
    7081             :     
    7082         103 :     CPLFree(psProgressInfo);
    7083             :     
    7084             :   }
    7085         103 :   {
    7086             :     /* %typemap(freearg) (int nList, int* pList) */
    7087         103 :     free(arg15);
    7088             :   }
    7089         103 :   return resultobj;
    7090           5 : fail:
    7091           5 :   {
    7092             :     /* %typemap(freearg) ( void* callback_data=NULL)  */
    7093             :     
    7094           5 :     CPLFree(psProgressInfo);
    7095             :     
    7096             :   }
    7097           5 :   {
    7098             :     /* %typemap(freearg) (int nList, int* pList) */
    7099           5 :     free(arg15);
    7100             :   }
    7101           5 :   return NULL;
    7102             : }
    7103             : 
    7104             : 
    7105          84 : SWIGINTERN PyObject *_wrap_MDArrayIONumPy(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    7106          84 :   PyObject *resultobj = 0;
    7107          84 :   bool arg1 ;
    7108          84 :   GDALMDArrayHS *arg2 = (GDALMDArrayHS *) 0 ;
    7109          84 :   PyArrayObject *arg3 = (PyArrayObject *) 0 ;
    7110          84 :   int arg4 ;
    7111          84 :   GUIntBig *arg5 = (GUIntBig *) 0 ;
    7112          84 :   int arg6 ;
    7113          84 :   GIntBig *arg7 = (GIntBig *) 0 ;
    7114          84 :   GDALExtendedDataTypeHS *arg8 = (GDALExtendedDataTypeHS *) 0 ;
    7115          84 :   bool val1 ;
    7116          84 :   int ecode1 = 0 ;
    7117          84 :   void *argp2 = 0 ;
    7118          84 :   int res2 = 0 ;
    7119          84 :   void *argp8 = 0 ;
    7120          84 :   int res8 = 0 ;
    7121          84 :   PyObject *swig_obj[6] ;
    7122          84 :   CPLErr result;
    7123             :   
    7124          84 :   if (!SWIG_Python_UnpackTuple(args, "MDArrayIONumPy", 6, 6, swig_obj)) SWIG_fail;
    7125          84 :   ecode1 = SWIG_AsVal_bool(swig_obj[0], &val1);
    7126          84 :   if (!SWIG_IsOK(ecode1)) {
    7127           0 :     SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "MDArrayIONumPy" "', argument " "1"" of type '" "bool""'");
    7128             :   } 
    7129          84 :   arg1 = static_cast< bool >(val1);
    7130          84 :   res2 = SWIG_ConvertPtr(swig_obj[1], &argp2,SWIGTYPE_p_GDALMDArrayHS, 0 |  0 );
    7131          84 :   if (!SWIG_IsOK(res2)) {
    7132           0 :     SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "MDArrayIONumPy" "', argument " "2"" of type '" "GDALMDArrayHS *""'"); 
    7133             :   }
    7134          84 :   arg2 = reinterpret_cast< GDALMDArrayHS * >(argp2);
    7135          84 :   {
    7136             :     /* %typemap(in,numinputs=1) (PyArrayObject  *psArray) */
    7137          84 :     if (swig_obj[2] != NULL && PyArray_Check(swig_obj[2]))
    7138             :     {
    7139          84 :       arg3 = (PyArrayObject*)(swig_obj[2]);
    7140             :     }
    7141             :     else
    7142             :     {
    7143           0 :       PyErr_SetString(PyExc_TypeError, "not a numpy array");
    7144           0 :       SWIG_fail;
    7145             :     }
    7146             :   }
    7147          84 :   {
    7148             :     /* %typemap(in,numinputs=1) (int nList, GUIntBig* pList)*/
    7149          84 :     arg5 = CreateCGUIntBigListFromSequence(swig_obj[3], &arg4);
    7150          84 :     if( arg4 < 0 ) {
    7151           0 :       SWIG_fail;
    7152             :     }
    7153             :   }
    7154          84 :   {
    7155             :     /* %typemap(in,numinputs=1) (int nList, GIntBig* pList)*/
    7156          84 :     arg7 = CreateCGIntBigListFromSequence(swig_obj[4], &arg6);
    7157          84 :     if( arg6 < 0 ) {
    7158           0 :       SWIG_fail;
    7159             :     }
    7160             :   }
    7161          84 :   res8 = SWIG_ConvertPtr(swig_obj[5], &argp8,SWIGTYPE_p_GDALExtendedDataTypeHS, 0 |  0 );
    7162          84 :   if (!SWIG_IsOK(res8)) {
    7163           0 :     SWIG_exception_fail(SWIG_ArgError(res8), "in method '" "MDArrayIONumPy" "', argument " "8"" of type '" "GDALExtendedDataTypeHS *""'"); 
    7164             :   }
    7165          84 :   arg8 = reinterpret_cast< GDALExtendedDataTypeHS * >(argp8);
    7166          84 :   {
    7167          84 :     const int bLocalUseExceptions = GetUseExceptions();
    7168          84 :     if ( bLocalUseExceptions ) {
    7169          82 :       pushErrorHandler();
    7170             :     }
    7171          84 :     {
    7172          84 :       SWIG_PYTHON_THREAD_BEGIN_ALLOW;
    7173          84 :       result = (CPLErr)MDArrayIONumPy(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8);
    7174          84 :       SWIG_PYTHON_THREAD_END_ALLOW;
    7175             :     }
    7176          84 :     if ( bLocalUseExceptions ) {
    7177          82 :       popErrorHandler();
    7178             :     }
    7179             : #ifndef SED_HACKS
    7180          84 :     if ( bLocalUseExceptions ) {
    7181          82 :       CPLErr eclass = CPLGetLastErrorType();
    7182          82 :       if ( eclass == CE_Failure || eclass == CE_Fatal ) {
    7183           0 :         SWIG_exception( SWIG_RuntimeError, CPLGetLastErrorMsg() );
    7184             :       }
    7185             :     }
    7186             : #endif
    7187             :   }
    7188          84 :   resultobj = SWIG_From_int(static_cast< int >(result));
    7189          84 :   {
    7190             :     /* %typemap(freearg) (int nList, GUIntBig* pList) */
    7191          84 :     free(arg5);
    7192             :   }
    7193          84 :   {
    7194             :     /* %typemap(freearg) (int nList, GIntBig* pList) */
    7195          84 :     free(arg7);
    7196             :   }
    7197          84 :   return resultobj;
    7198           0 : fail:
    7199           0 :   {
    7200             :     /* %typemap(freearg) (int nList, GUIntBig* pList) */
    7201           0 :     free(arg5);
    7202             :   }
    7203           0 :   {
    7204             :     /* %typemap(freearg) (int nList, GIntBig* pList) */
    7205           0 :     free(arg7);
    7206             :   }
    7207           0 :   return NULL;
    7208             : }
    7209             : 
    7210             : 
    7211           0 : SWIGINTERN PyObject *_wrap_AddNumpyArrayToDict(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    7212           0 :   PyObject *resultobj = 0;
    7213           0 :   PyObject *arg1 = (PyObject *) 0 ;
    7214           0 :   ArrowSchema *arg2 = (ArrowSchema *) 0 ;
    7215           0 :   ArrowArray *arg3 = (ArrowArray *) 0 ;
    7216           0 :   std::string *arg4 = 0 ;
    7217           0 :   PyObject *arg5 = (PyObject *) 0 ;
    7218           0 :   void *argp2 = 0 ;
    7219           0 :   int res2 = 0 ;
    7220           0 :   void *argp3 = 0 ;
    7221           0 :   int res3 = 0 ;
    7222           0 :   void *argp4 = 0 ;
    7223           0 :   int res4 = 0 ;
    7224           0 :   PyObject *swig_obj[5] ;
    7225           0 :   bool result;
    7226             :   
    7227           0 :   if (!SWIG_Python_UnpackTuple(args, "AddNumpyArrayToDict", 5, 5, swig_obj)) SWIG_fail;
    7228           0 :   arg1 = swig_obj[0];
    7229           0 :   res2 = SWIG_ConvertPtr(swig_obj[1], &argp2,SWIGTYPE_p_ArrowSchema, 0 |  0 );
    7230           0 :   if (!SWIG_IsOK(res2)) {
    7231           0 :     SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "AddNumpyArrayToDict" "', argument " "2"" of type '" "ArrowSchema const *""'"); 
    7232             :   }
    7233           0 :   arg2 = reinterpret_cast< ArrowSchema * >(argp2);
    7234           0 :   res3 = SWIG_ConvertPtr(swig_obj[2], &argp3,SWIGTYPE_p_ArrowArray, 0 |  0 );
    7235           0 :   if (!SWIG_IsOK(res3)) {
    7236           0 :     SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "AddNumpyArrayToDict" "', argument " "3"" of type '" "ArrowArray const *""'"); 
    7237             :   }
    7238           0 :   arg3 = reinterpret_cast< ArrowArray * >(argp3);
    7239           0 :   res4 = SWIG_ConvertPtr(swig_obj[3], &argp4, SWIGTYPE_p_std__string,  0  | 0);
    7240           0 :   if (!SWIG_IsOK(res4)) {
    7241           0 :     SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "AddNumpyArrayToDict" "', argument " "4"" of type '" "std::string const &""'"); 
    7242             :   }
    7243           0 :   if (!argp4) {
    7244           0 :     SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "AddNumpyArrayToDict" "', argument " "4"" of type '" "std::string const &""'"); 
    7245             :   }
    7246           0 :   arg4 = reinterpret_cast< std::string * >(argp4);
    7247           0 :   arg5 = swig_obj[4];
    7248           0 :   {
    7249           0 :     const int bLocalUseExceptions = GetUseExceptions();
    7250           0 :     if ( bLocalUseExceptions ) {
    7251           0 :       pushErrorHandler();
    7252             :     }
    7253           0 :     result = (bool)AddNumpyArrayToDict(arg1,(ArrowSchema const *)arg2,(ArrowArray const *)arg3,(std::string const &)*arg4,arg5);
    7254           0 :     if ( bLocalUseExceptions ) {
    7255           0 :       popErrorHandler();
    7256             :     }
    7257             : #ifndef SED_HACKS
    7258           0 :     if ( bLocalUseExceptions ) {
    7259           0 :       CPLErr eclass = CPLGetLastErrorType();
    7260           0 :       if ( eclass == CE_Failure || eclass == CE_Fatal ) {
    7261           0 :         SWIG_exception( SWIG_RuntimeError, CPLGetLastErrorMsg() );
    7262             :       }
    7263             :     }
    7264             : #endif
    7265             :   }
    7266           0 :   resultobj = SWIG_From_bool(static_cast< bool >(result));
    7267             :   return resultobj;
    7268             : fail:
    7269             :   return NULL;
    7270             : }
    7271             : 
    7272             : 
    7273         475 : SWIGINTERN PyObject *_wrap__RecordBatchAsNumpy(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    7274         475 :   PyObject *resultobj = 0;
    7275         475 :   VoidPtrAsLong arg1 = (VoidPtrAsLong) 0 ;
    7276         475 :   VoidPtrAsLong arg2 = (VoidPtrAsLong) 0 ;
    7277         475 :   PyObject *arg3 = (PyObject *) 0 ;
    7278         475 :   PyObject *swig_obj[3] ;
    7279         475 :   PyObject *result = 0 ;
    7280             :   
    7281         475 :   if (!SWIG_Python_UnpackTuple(args, "_RecordBatchAsNumpy", 3, 3, swig_obj)) SWIG_fail;
    7282         475 :   {
    7283         475 :     arg1 = PyLong_AsVoidPtr(swig_obj[0]);
    7284             :   }
    7285         475 :   {
    7286         475 :     arg2 = PyLong_AsVoidPtr(swig_obj[1]);
    7287             :   }
    7288         475 :   arg3 = swig_obj[2];
    7289         475 :   {
    7290         475 :     const int bLocalUseExceptions = GetUseExceptions();
    7291         475 :     if ( bLocalUseExceptions ) {
    7292         160 :       pushErrorHandler();
    7293             :     }
    7294         475 :     result = (PyObject *)_RecordBatchAsNumpy(arg1,arg2,arg3);
    7295         475 :     if ( bLocalUseExceptions ) {
    7296         160 :       popErrorHandler();
    7297             :     }
    7298             : #ifndef SED_HACKS
    7299         475 :     if ( bLocalUseExceptions ) {
    7300         160 :       CPLErr eclass = CPLGetLastErrorType();
    7301         160 :       if ( eclass == CE_Failure || eclass == CE_Fatal ) {
    7302           0 :         SWIG_exception( SWIG_RuntimeError, CPLGetLastErrorMsg() );
    7303             :       }
    7304             :     }
    7305             : #endif
    7306             :   }
    7307         475 :   resultobj = result;
    7308             :   return resultobj;
    7309             : fail:
    7310             :   return NULL;
    7311             : }
    7312             : 
    7313             : 
    7314          28 : SWIGINTERN PyObject *_wrap_VirtualMemGetArray(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
    7315          28 :   PyObject *resultobj = 0;
    7316          28 :   CPLVirtualMemShadow *arg1 = (CPLVirtualMemShadow *) 0 ;
    7317          28 :   CPLVirtualMemShadow **arg2 = (CPLVirtualMemShadow **) 0 ;
    7318          28 :   int arg3 ;
    7319          28 :   void *argp1 = 0 ;
    7320          28 :   int res1 = 0 ;
    7321          28 :   CPLVirtualMemShadow *virtualmem2 ;
    7322          28 :   PyObject *swig_obj[1] ;
    7323             :   
    7324          28 :   {
    7325          28 :     arg2 = &virtualmem2;
    7326          28 :     arg3 = 0;
    7327             :   }
    7328          28 :   if (!args) SWIG_fail;
    7329          28 :   swig_obj[0] = args;
    7330          28 :   res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_CPLVirtualMemShadow, 0 |  0 );
    7331          28 :   if (!SWIG_IsOK(res1)) {
    7332           0 :     SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "VirtualMemGetArray" "', argument " "1"" of type '" "CPLVirtualMemShadow *""'"); 
    7333             :   }
    7334          28 :   arg1 = reinterpret_cast< CPLVirtualMemShadow * >(argp1);
    7335          28 :   {
    7336          28 :     if (!arg1) {
    7337           0 :       SWIG_exception(SWIG_ValueError,"Received a NULL pointer.");
    7338             :     }
    7339             :   }
    7340          28 :   {
    7341          28 :     const int bLocalUseExceptions = GetUseExceptions();
    7342          28 :     if ( bLocalUseExceptions ) {
    7343          28 :       pushErrorHandler();
    7344             :     }
    7345          28 :     VirtualMemGetArray(arg1,arg2,arg3);
    7346          28 :     if ( bLocalUseExceptions ) {
    7347          28 :       popErrorHandler();
    7348             :     }
    7349             : #ifndef SED_HACKS
    7350          28 :     if ( bLocalUseExceptions ) {
    7351          28 :       CPLErr eclass = CPLGetLastErrorType();
    7352          28 :       if ( eclass == CE_Failure || eclass == CE_Fatal ) {
    7353           0 :         SWIG_exception( SWIG_RuntimeError, CPLGetLastErrorMsg() );
    7354             :       }
    7355             :     }
    7356             : #endif
    7357             :   }
    7358          28 :   resultobj = SWIG_Py_Void();
    7359          28 :   {
    7360          28 :     CPLVirtualMemShadow* virtualmem = *(arg2);
    7361          28 :     void* ptr = CPLVirtualMemGetAddr( virtualmem->vmem );
    7362             :     /*size_t nsize = CPLVirtualMemGetSize( virtualmem->vmem );*/
    7363          28 :     GDALDataType datatype = virtualmem->eBufType;
    7364          28 :     int readonly = virtualmem->bReadOnly;
    7365          28 :     GIntBig nBufXSize = virtualmem->nBufXSize;
    7366          28 :     GIntBig nBufYSize = virtualmem->nBufYSize;
    7367          28 :     int nBandCount = virtualmem->nBandCount;
    7368          28 :     int bIsBandSequential = virtualmem->bIsBandSequential;
    7369          28 :     GDALTileOrganization eTileOrganization = virtualmem->eTileOrganization;
    7370          28 :     int nTileXSize = virtualmem->nTileXSize;
    7371          28 :     int nTileYSize = virtualmem->nTileYSize;
    7372          28 :     int bAuto = virtualmem->bAuto;
    7373          28 :     int            nPixelSpace = virtualmem->nPixelSpace; /* if bAuto == TRUE */
    7374          28 :     GIntBig        nLineSpace = virtualmem->nLineSpace; /* if bAuto == TRUE */
    7375          28 :     int numpytype;
    7376             :     
    7377          28 :     if( datatype == GDT_CInt16 || datatype == GDT_CInt32 || datatype == GDT_CFloat16 )
    7378             :     {
    7379           0 :       PyErr_SetString( PyExc_RuntimeError, "GDT_CInt16, GDT_CInt32, and GDT_CFloat16 not supported for now" );
    7380           0 :       SWIG_fail;
    7381             :     }
    7382             :     
    7383          28 :     switch(datatype)
    7384             :     {
    7385             :       case GDT_Byte: numpytype = NPY_UBYTE; break;
    7386             :       case GDT_Int8: numpytype = NPY_INT8; break;
    7387             :       case GDT_Int16: numpytype = NPY_INT16; break;
    7388             :       case GDT_UInt16: numpytype = NPY_UINT16; break;
    7389             :       case GDT_Int32: numpytype = NPY_INT32; break;
    7390             :       case GDT_UInt32: numpytype = NPY_UINT32; break;
    7391             :       case GDT_Int64: numpytype = NPY_INT64; break;
    7392             :       case GDT_UInt64: numpytype = NPY_UINT64; break;
    7393             :       case GDT_Float16: numpytype = NPY_FLOAT16; break;
    7394             :       case GDT_Float32: numpytype = NPY_FLOAT32; break;
    7395             :       case GDT_Float64: numpytype = NPY_FLOAT64; break;
    7396             :       //case GDT_CInt16: numpytype = NPY_INT16; break;
    7397             :       //case GDT_CInt32: numpytype = NPY_INT32; break;
    7398             :       //case GDT_CFloat16: numpytype = NPY_CHALF; break;
    7399             :       case GDT_CFloat32: numpytype = NPY_CFLOAT; break;
    7400             :       case GDT_CFloat64: numpytype = NPY_CDOUBLE; break;
    7401             :       default: numpytype = NPY_UBYTE; break;
    7402             :     }
    7403          28 :     PyArrayObject* ar;
    7404          28 :     int flags = (readonly) ? 0x1 : 0x1 | 0x0400;
    7405          28 :     int nDataTypeSize = GDALGetDataTypeSizeBytes(datatype);
    7406          28 :     if( bAuto )
    7407             :     {
    7408          20 :       if( nBandCount == 1 )
    7409             :       {
    7410          20 :         npy_intp shape[2], stride[2];
    7411          20 :         shape[0] = nBufYSize;
    7412          20 :         shape[1] = nBufXSize;
    7413          20 :         stride[1] = nPixelSpace;
    7414          20 :         stride[0] = nLineSpace;
    7415          20 :         ar = (PyArrayObject*) PyArray_New(&PyArray_Type, 2, shape,
    7416             :           numpytype, stride, ptr, 0, flags , NULL);
    7417             :       }
    7418             :       else
    7419             :       {
    7420           0 :         PyErr_SetString( PyExc_RuntimeError, "Code update needed for bAuto and nBandCount > 1 !" );
    7421           0 :         SWIG_fail;
    7422             :       }
    7423             :     }
    7424           8 :     else if( bIsBandSequential >= 0 )
    7425             :     {
    7426           4 :       if( nBandCount == 1 )
    7427             :       {
    7428           2 :         npy_intp shape[2], stride[2];
    7429           2 :         shape[0] = nBufYSize;
    7430           2 :         shape[1] = nBufXSize;
    7431           2 :         stride[1] = nDataTypeSize;
    7432           2 :         stride[0] = stride[1] * nBufXSize;
    7433           2 :         ar = (PyArrayObject*) PyArray_New(&PyArray_Type, 2, shape,
    7434             :           numpytype, stride, ptr, 0, flags , NULL);
    7435             :       }
    7436             :       else
    7437             :       {
    7438           2 :         npy_intp shape[3], stride[3];
    7439           2 :         if( bIsBandSequential )
    7440             :         {
    7441           1 :           shape[0] = nBandCount;
    7442           1 :           shape[1] = nBufYSize;
    7443           1 :           shape[2] = nBufXSize;
    7444           1 :           stride[2] = nDataTypeSize;
    7445           1 :           stride[1] = stride[2] * nBufXSize;
    7446           1 :           stride[0] = stride[1] * nBufYSize;
    7447             :         }
    7448             :         else
    7449             :         {
    7450           1 :           shape[0] = nBufYSize;
    7451           1 :           shape[1] = nBufXSize;
    7452           1 :           shape[2] = nBandCount;
    7453           1 :           stride[2] = nDataTypeSize;
    7454           1 :           stride[1] = stride[2] * nBandCount;
    7455           1 :           stride[0] = stride[1] * nBufXSize;
    7456             :         }
    7457           2 :         ar = (PyArrayObject*) PyArray_New(&PyArray_Type, 3, shape,
    7458             :           numpytype, stride, ptr, 0, flags , NULL);
    7459             :       }
    7460             :     }
    7461             :     else
    7462             :     {
    7463           4 :       npy_intp nTilesPerRow = static_cast<npy_intp>(DIV_ROUND_UP(nBufXSize, nTileXSize));
    7464           4 :       npy_intp nTilesPerCol = static_cast<npy_intp>(DIV_ROUND_UP(nBufYSize, nTileYSize));
    7465           4 :       npy_intp shape[5], stride[5];
    7466           4 :       if( nBandCount == 1 )
    7467             :       {
    7468           1 :         shape[0] = nTilesPerCol;
    7469           1 :         shape[1] = nTilesPerRow;
    7470           1 :         shape[2] = nTileYSize;
    7471           1 :         shape[3] = nTileXSize;
    7472           1 :         stride[3] = nDataTypeSize;
    7473           1 :         stride[2] = stride[3] * nTileXSize;
    7474           1 :         stride[1] = stride[2] * nTileYSize;
    7475           1 :         stride[0] = stride[1] * nTilesPerRow;
    7476           1 :         ar = (PyArrayObject*) PyArray_New(&PyArray_Type, 4, shape,
    7477             :           numpytype, stride, ptr, 0, flags , NULL);
    7478             :       }
    7479           3 :       else if( eTileOrganization == GTO_TIP )
    7480             :       {
    7481           1 :         shape[0] = nTilesPerCol;
    7482           1 :         shape[1] = nTilesPerRow;
    7483           1 :         shape[2] = nTileYSize;
    7484           1 :         shape[3] = nTileXSize;
    7485           1 :         shape[4] = nBandCount;
    7486           1 :         stride[4] = nDataTypeSize;
    7487           1 :         stride[3] = stride[4] * nBandCount;
    7488           1 :         stride[2] = stride[3] * nTileXSize;
    7489           1 :         stride[1] = stride[2] * nTileYSize;
    7490           1 :         stride[0] = stride[1] * nTilesPerRow;
    7491           1 :         ar = (PyArrayObject*) PyArray_New(&PyArray_Type, 5, shape,
    7492             :           numpytype, stride, ptr, 0, flags , NULL);
    7493             :       }
    7494           2 :       else if( eTileOrganization == GTO_BIT )
    7495             :       {
    7496           1 :         shape[0] = nTilesPerCol;
    7497           1 :         shape[1] = nTilesPerRow;
    7498           1 :         shape[2] = nBandCount;
    7499           1 :         shape[3] = nTileYSize;
    7500           1 :         shape[4] = nTileXSize;
    7501           1 :         stride[4] = nDataTypeSize;
    7502           1 :         stride[3] = stride[4] * nTileXSize;
    7503           1 :         stride[2] = stride[3] * nTileYSize;
    7504           1 :         stride[1] = stride[2] * nBandCount;
    7505           1 :         stride[0] = stride[1] * nTilesPerRow;
    7506           1 :         ar = (PyArrayObject*) PyArray_New(&PyArray_Type, 5, shape,
    7507             :           numpytype, stride, ptr, 0, flags , NULL);
    7508             :       }
    7509             :       else /* GTO_BSQ */
    7510             :       {
    7511           1 :         shape[0] = nBandCount;
    7512           1 :         shape[1] = nTilesPerCol;
    7513           1 :         shape[2] = nTilesPerRow;
    7514           1 :         shape[3] = nTileYSize;
    7515           1 :         shape[4] = nTileXSize;
    7516           1 :         stride[4] = nDataTypeSize;
    7517           1 :         stride[3] = stride[4] * nTileXSize;
    7518           1 :         stride[2] = stride[3] * nTileYSize;
    7519           1 :         stride[1] = stride[2] * nTilesPerRow;
    7520           1 :         stride[0] = stride[1] * nTilesPerCol;
    7521           1 :         ar = (PyArrayObject*) PyArray_New(&PyArray_Type, 5, shape,
    7522             :           numpytype, stride, ptr, 0, flags , NULL);
    7523             :       }
    7524             :     }
    7525             :     
    7526             :     /* Keep a reference to the VirtualMem object */
    7527             : #if NPY_API_VERSION >= 0x00000007
    7528          28 :     PyArray_SetBaseObject(ar, swig_obj[0]);
    7529             : #else
    7530             :     PyArray_BASE(ar) = swig_obj[0];
    7531             : #endif
    7532          28 :     Py_INCREF(swig_obj[0]);
    7533          28 :     Py_DECREF(resultobj);
    7534          28 :     resultobj = (PyObject*) ar;
    7535             :   }
    7536             :   return resultobj;
    7537             : fail:
    7538             :   return NULL;
    7539             : }
    7540             : 
    7541             : 
    7542          20 : SWIGINTERN PyObject *_wrap_RATValuesIONumPyWrite(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
    7543          20 :   PyObject *resultobj = 0;
    7544          20 :   GDALRasterAttributeTableShadow *arg1 = (GDALRasterAttributeTableShadow *) 0 ;
    7545          20 :   int arg2 ;
    7546          20 :   int arg3 ;
    7547          20 :   PyArrayObject *arg4 = (PyArrayObject *) 0 ;
    7548          20 :   void *argp1 = 0 ;
    7549          20 :   int res1 = 0 ;
    7550          20 :   int val2 ;
    7551          20 :   int ecode2 = 0 ;
    7552          20 :   int val3 ;
    7553          20 :   int ecode3 = 0 ;
    7554          20 :   PyObject * obj0 = 0 ;
    7555          20 :   PyObject * obj1 = 0 ;
    7556          20 :   PyObject * obj2 = 0 ;
    7557          20 :   PyObject * obj3 = 0 ;
    7558          20 :   char * kwnames[] = {
    7559             :     (char *)"poRAT",  (char *)"nField",  (char *)"nStart",  (char *)"psArray",  NULL 
    7560             :   };
    7561          20 :   CPLErr result;
    7562             :   
    7563          20 :   if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOOO:RATValuesIONumPyWrite", kwnames, &obj0, &obj1, &obj2, &obj3)) SWIG_fail;
    7564          20 :   res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_GDALRasterAttributeTableShadow, 0 |  0 );
    7565          20 :   if (!SWIG_IsOK(res1)) {
    7566           0 :     SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "RATValuesIONumPyWrite" "', argument " "1"" of type '" "GDALRasterAttributeTableShadow *""'"); 
    7567             :   }
    7568          20 :   arg1 = reinterpret_cast< GDALRasterAttributeTableShadow * >(argp1);
    7569          20 :   ecode2 = SWIG_AsVal_int(obj1, &val2);
    7570          20 :   if (!SWIG_IsOK(ecode2)) {
    7571           0 :     SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "RATValuesIONumPyWrite" "', argument " "2"" of type '" "int""'");
    7572             :   } 
    7573          20 :   arg2 = static_cast< int >(val2);
    7574          20 :   ecode3 = SWIG_AsVal_int(obj2, &val3);
    7575          20 :   if (!SWIG_IsOK(ecode3)) {
    7576           0 :     SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "RATValuesIONumPyWrite" "', argument " "3"" of type '" "int""'");
    7577             :   } 
    7578          20 :   arg3 = static_cast< int >(val3);
    7579          20 :   {
    7580             :     /* %typemap(in,numinputs=1) (PyArrayObject  *psArray) */
    7581          20 :     if (obj3 != NULL && PyArray_Check(obj3))
    7582             :     {
    7583          20 :       arg4 = (PyArrayObject*)(obj3);
    7584             :     }
    7585             :     else
    7586             :     {
    7587           0 :       PyErr_SetString(PyExc_TypeError, "not a numpy array");
    7588           0 :       SWIG_fail;
    7589             :     }
    7590             :   }
    7591          20 :   {
    7592          20 :     const int bLocalUseExceptions = GetUseExceptions();
    7593          20 :     if ( bLocalUseExceptions ) {
    7594          20 :       pushErrorHandler();
    7595             :     }
    7596          20 :     result = (CPLErr)RATValuesIONumPyWrite(arg1,arg2,arg3,arg4);
    7597          20 :     if ( bLocalUseExceptions ) {
    7598          20 :       popErrorHandler();
    7599             :     }
    7600             : #ifndef SED_HACKS
    7601          20 :     if ( bLocalUseExceptions ) {
    7602          20 :       CPLErr eclass = CPLGetLastErrorType();
    7603          20 :       if ( eclass == CE_Failure || eclass == CE_Fatal ) {
    7604           4 :         SWIG_exception( SWIG_RuntimeError, CPLGetLastErrorMsg() );
    7605             :       }
    7606             :     }
    7607             : #endif
    7608             :   }
    7609          16 :   resultobj = SWIG_From_int(static_cast< int >(result));
    7610             :   return resultobj;
    7611             : fail:
    7612             :   return NULL;
    7613             : }
    7614             : 
    7615             : 
    7616          55 : SWIGINTERN PyObject *_wrap_RATValuesIONumPyRead(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
    7617          55 :   PyObject *resultobj = 0;
    7618          55 :   GDALRasterAttributeTableShadow *arg1 = (GDALRasterAttributeTableShadow *) 0 ;
    7619          55 :   int arg2 ;
    7620          55 :   int arg3 ;
    7621          55 :   int arg4 ;
    7622          55 :   void *argp1 = 0 ;
    7623          55 :   int res1 = 0 ;
    7624          55 :   int val2 ;
    7625          55 :   int ecode2 = 0 ;
    7626          55 :   int val3 ;
    7627          55 :   int ecode3 = 0 ;
    7628          55 :   int val4 ;
    7629          55 :   int ecode4 = 0 ;
    7630          55 :   PyObject * obj0 = 0 ;
    7631          55 :   PyObject * obj1 = 0 ;
    7632          55 :   PyObject * obj2 = 0 ;
    7633          55 :   PyObject * obj3 = 0 ;
    7634          55 :   char * kwnames[] = {
    7635             :     (char *)"poRAT",  (char *)"nField",  (char *)"nStart",  (char *)"nLength",  NULL 
    7636             :   };
    7637          55 :   PyObject *result = 0 ;
    7638             :   
    7639          55 :   if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOOO:RATValuesIONumPyRead", kwnames, &obj0, &obj1, &obj2, &obj3)) SWIG_fail;
    7640          55 :   res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_GDALRasterAttributeTableShadow, 0 |  0 );
    7641          55 :   if (!SWIG_IsOK(res1)) {
    7642           0 :     SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "RATValuesIONumPyRead" "', argument " "1"" of type '" "GDALRasterAttributeTableShadow *""'"); 
    7643             :   }
    7644          55 :   arg1 = reinterpret_cast< GDALRasterAttributeTableShadow * >(argp1);
    7645          55 :   ecode2 = SWIG_AsVal_int(obj1, &val2);
    7646          55 :   if (!SWIG_IsOK(ecode2)) {
    7647           0 :     SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "RATValuesIONumPyRead" "', argument " "2"" of type '" "int""'");
    7648             :   } 
    7649          55 :   arg2 = static_cast< int >(val2);
    7650          55 :   ecode3 = SWIG_AsVal_int(obj2, &val3);
    7651          55 :   if (!SWIG_IsOK(ecode3)) {
    7652           0 :     SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "RATValuesIONumPyRead" "', argument " "3"" of type '" "int""'");
    7653             :   } 
    7654          55 :   arg3 = static_cast< int >(val3);
    7655          55 :   ecode4 = SWIG_AsVal_int(obj3, &val4);
    7656          55 :   if (!SWIG_IsOK(ecode4)) {
    7657           0 :     SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "RATValuesIONumPyRead" "', argument " "4"" of type '" "int""'");
    7658             :   } 
    7659          55 :   arg4 = static_cast< int >(val4);
    7660          55 :   {
    7661          55 :     const int bLocalUseExceptions = GetUseExceptions();
    7662          55 :     if ( bLocalUseExceptions ) {
    7663          55 :       pushErrorHandler();
    7664             :     }
    7665          55 :     result = (PyObject *)RATValuesIONumPyRead(arg1,arg2,arg3,arg4);
    7666          55 :     if ( bLocalUseExceptions ) {
    7667          55 :       popErrorHandler();
    7668             :     }
    7669             : #ifndef SED_HACKS
    7670          55 :     if ( bLocalUseExceptions ) {
    7671          55 :       CPLErr eclass = CPLGetLastErrorType();
    7672          55 :       if ( eclass == CE_Failure || eclass == CE_Fatal ) {
    7673           5 :         SWIG_exception( SWIG_RuntimeError, CPLGetLastErrorMsg() );
    7674             :       }
    7675             :     }
    7676             : #endif
    7677             :   }
    7678          55 :   resultobj = result;
    7679             :   return resultobj;
    7680             : fail:
    7681             :   return NULL;
    7682             : }
    7683             : 
    7684             : 
    7685             : static PyMethodDef SwigMethods[] = {
    7686             :    { "SWIG_PyInstanceMethod_New", SWIG_PyInstanceMethod_New, METH_O, NULL},
    7687             :    { "delete_VirtualMem", _wrap_delete_VirtualMem, METH_O, "delete_VirtualMem(VirtualMem self)"},
    7688             :    { "VirtualMem_GetAddr", _wrap_VirtualMem_GetAddr, METH_O, "VirtualMem_GetAddr(VirtualMem self)"},
    7689             :    { "VirtualMem_Pin", _wrap_VirtualMem_Pin, METH_VARARGS, "VirtualMem_Pin(VirtualMem self, size_t start_offset=0, size_t nsize=0, int bWriteOp=0)"},
    7690             :    { "VirtualMem_swigregister", VirtualMem_swigregister, METH_O, NULL},
    7691             :    { "GetUseExceptions", _wrap_GetUseExceptions, METH_NOARGS, "GetUseExceptions() -> int"},
    7692             :    { "_GetExceptionsLocal", _wrap__GetExceptionsLocal, METH_NOARGS, "_GetExceptionsLocal() -> int"},
    7693             :    { "_SetExceptionsLocal", _wrap__SetExceptionsLocal, METH_O, "_SetExceptionsLocal(int bVal)"},
    7694             :    { "_UseExceptions", _wrap__UseExceptions, METH_NOARGS, "_UseExceptions()"},
    7695             :    { "_DontUseExceptions", _wrap__DontUseExceptions, METH_NOARGS, "_DontUseExceptions()"},
    7696             :    { "_UserHasSpecifiedIfUsingExceptions", _wrap__UserHasSpecifiedIfUsingExceptions, METH_NOARGS, "_UserHasSpecifiedIfUsingExceptions() -> int"},
    7697             :    { "TermProgress_nocb", (PyCFunction)(void(*)(void))_wrap_TermProgress_nocb, METH_VARARGS|METH_KEYWORDS, "TermProgress_nocb(double dfProgress, char const * pszMessage=None, void * pData=None) -> int"},
    7698             :    { "OpenNumPyArray", _wrap_OpenNumPyArray, METH_VARARGS, "OpenNumPyArray(PyArrayObject * psArray, bool binterleave) -> Dataset"},
    7699             :    { "OpenMultiDimensionalNumPyArray", _wrap_OpenMultiDimensionalNumPyArray, METH_O, "OpenMultiDimensionalNumPyArray(PyArrayObject * psArray) -> Dataset"},
    7700             :    { "GetArrayFilename", _wrap_GetArrayFilename, METH_O, "GetArrayFilename(PyArrayObject * psArray) -> retStringAndCPLFree *"},
    7701             :    { "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, int operate_in_buf_type, GDALProgressFunc callback=0, void * callback_data=None) -> CPLErr"},
    7702             :    { "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, int operate_in_buf_type, GDALProgressFunc callback=0, void * callback_data=None, bool binterleave=True, int band_list=0) -> CPLErr"},
    7703             :    { "MDArrayIONumPy", _wrap_MDArrayIONumPy, METH_VARARGS, "MDArrayIONumPy(bool bWrite, GDALMDArrayHS * mdarray, PyArrayObject * psArray, int nDims1, int nDims3, GDALExtendedDataTypeHS * buffer_datatype) -> CPLErr"},
    7704             :    { "AddNumpyArrayToDict", _wrap_AddNumpyArrayToDict, METH_VARARGS, "AddNumpyArrayToDict(PyObject * dict, ArrowSchema const * schemaField, ArrowArray const * arrayField, std::string const & osPrefix, PyObject * pointerArrayKeeper) -> bool"},
    7705             :    { "_RecordBatchAsNumpy", _wrap__RecordBatchAsNumpy, METH_VARARGS, "_RecordBatchAsNumpy(VoidPtrAsLong recordBatchPtr, VoidPtrAsLong schemaPtr, PyObject * pointerArrayKeeper) -> PyObject *"},
    7706             :    { "VirtualMemGetArray", _wrap_VirtualMemGetArray, METH_O, "VirtualMemGetArray(VirtualMem virtualmem)"},
    7707             :    { "RATValuesIONumPyWrite", (PyCFunction)(void(*)(void))_wrap_RATValuesIONumPyWrite, METH_VARARGS|METH_KEYWORDS, "RATValuesIONumPyWrite(RasterAttributeTable poRAT, int nField, int nStart, PyArrayObject * psArray) -> CPLErr"},
    7708             :    { "RATValuesIONumPyRead", (PyCFunction)(void(*)(void))_wrap_RATValuesIONumPyRead, METH_VARARGS|METH_KEYWORDS, "RATValuesIONumPyRead(RasterAttributeTable poRAT, int nField, int nStart, int nLength) -> PyObject *"},
    7709             :    { NULL, NULL, 0, NULL }
    7710             : };
    7711             : 
    7712             : static PyMethodDef SwigMethods_proxydocs[] = {
    7713             :    { NULL, NULL, 0, NULL }
    7714             : };
    7715             : 
    7716             : 
    7717             : /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */
    7718             : 
    7719           0 : static void *_p_GDALComputedRasterBandShadowTo_p_GDALRasterBandShadow(void *x, int *SWIGUNUSEDPARM(newmemory)) {
    7720           0 :     return (void *)((GDALRasterBandShadow *)  ((GDALComputedRasterBandShadow *) x));
    7721             : }
    7722             : static swig_type_info _swigt__p_ArrowArray = {"_p_ArrowArray", "ArrowArray *", 0, 0, (void*)0, 0};
    7723             : static swig_type_info _swigt__p_ArrowSchema = {"_p_ArrowSchema", "ArrowSchema *", 0, 0, (void*)0, 0};
    7724             : static swig_type_info _swigt__p_CPLVirtualMemShadow = {"_p_CPLVirtualMemShadow", "CPLVirtualMemShadow *", 0, 0, (void*)0, 0};
    7725             : static swig_type_info _swigt__p_GDALDataType = {"_p_GDALDataType", "GDALDataType *", 0, 0, (void*)0, 0};
    7726             : static swig_type_info _swigt__p_GDALDatasetShadow = {"_p_GDALDatasetShadow", "GDALDatasetShadow *", 0, 0, (void*)0, 0};
    7727             : static swig_type_info _swigt__p_GDALExtendedDataTypeHS = {"_p_GDALExtendedDataTypeHS", "GDALExtendedDataTypeHS *", 0, 0, (void*)0, 0};
    7728             : static swig_type_info _swigt__p_GDALMDArrayHS = {"_p_GDALMDArrayHS", "GDALMDArrayHS *", 0, 0, (void*)0, 0};
    7729             : static swig_type_info _swigt__p_GDALProgressFunc = {"_p_GDALProgressFunc", "GDALProgressFunc *", 0, 0, (void*)0, 0};
    7730             : static swig_type_info _swigt__p_GDALRATDateTime = {"_p_GDALRATDateTime", "GDALRATDateTime *", 0, 0, (void*)0, 0};
    7731             : static swig_type_info _swigt__p_GDALRasterAttributeTableShadow = {"_p_GDALRasterAttributeTableShadow", "GDALRasterAttributeTableShadow *", 0, 0, (void*)0, 0};
    7732             : static swig_type_info _swigt__p_GDALRasterBandShadow = {"_p_GDALRasterBandShadow", "GDALRasterBandShadow *", 0, 0, (void*)0, 0};
    7733             : static swig_type_info _swigt__p_GDALComputedRasterBandShadow = {"_p_GDALComputedRasterBandShadow", 0, 0, 0, 0, 0};
    7734             : static swig_type_info _swigt__p_GIntBig = {"_p_GIntBig", "GIntBig *", 0, 0, (void*)0, 0};
    7735             : static swig_type_info _swigt__p_GUIntBig = {"_p_GUIntBig", "GUIntBig *", 0, 0, (void*)0, 0};
    7736             : static swig_type_info _swigt__p_PyArrayObject = {"_p_PyArrayObject", "PyArrayObject *", 0, 0, (void*)0, 0};
    7737             : static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0};
    7738             : 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};
    7739             : static swig_type_info _swigt__p_int = {"_p_int", "GDALRATFieldType *|CPLErr *|int *|GDALRATTableType *|GDALRATFieldUsage *|GDALRIOResampleAlg *", 0, 0, (void*)0, 0};
    7740             : static swig_type_info _swigt__p_p_CPLVirtualMemShadow = {"_p_p_CPLVirtualMemShadow", "CPLVirtualMemShadow **", 0, 0, (void*)0, 0};
    7741             : static swig_type_info _swigt__p_p_void = {"_p_p_void", "void **", 0, 0, (void*)0, 0};
    7742             : static swig_type_info _swigt__p_size_t = {"_p_size_t", "size_t *", 0, 0, (void*)0, 0};
    7743             : static swig_type_info _swigt__p_std__string = {"_p_std__string", "std::string *", 0, 0, (void*)0, 0};
    7744             : 
    7745             : static swig_type_info *swig_type_initial[] = {
    7746             :   &_swigt__p_ArrowArray,
    7747             :   &_swigt__p_ArrowSchema,
    7748             :   &_swigt__p_CPLVirtualMemShadow,
    7749             :   &_swigt__p_GDALComputedRasterBandShadow,
    7750             :   &_swigt__p_GDALDataType,
    7751             :   &_swigt__p_GDALDatasetShadow,
    7752             :   &_swigt__p_GDALExtendedDataTypeHS,
    7753             :   &_swigt__p_GDALMDArrayHS,
    7754             :   &_swigt__p_GDALProgressFunc,
    7755             :   &_swigt__p_GDALRATDateTime,
    7756             :   &_swigt__p_GDALRasterAttributeTableShadow,
    7757             :   &_swigt__p_GDALRasterBandShadow,
    7758             :   &_swigt__p_GIntBig,
    7759             :   &_swigt__p_GUIntBig,
    7760             :   &_swigt__p_PyArrayObject,
    7761             :   &_swigt__p_char,
    7762             :   &_swigt__p_f_double_p_q_const__char_p_void__int,
    7763             :   &_swigt__p_int,
    7764             :   &_swigt__p_p_CPLVirtualMemShadow,
    7765             :   &_swigt__p_p_void,
    7766             :   &_swigt__p_size_t,
    7767             :   &_swigt__p_std__string,
    7768             : };
    7769             : 
    7770             : static swig_cast_info _swigc__p_ArrowArray[] = {  {&_swigt__p_ArrowArray, 0, 0, 0},{0, 0, 0, 0}};
    7771             : static swig_cast_info _swigc__p_ArrowSchema[] = {  {&_swigt__p_ArrowSchema, 0, 0, 0},{0, 0, 0, 0}};
    7772             : static swig_cast_info _swigc__p_CPLVirtualMemShadow[] = {  {&_swigt__p_CPLVirtualMemShadow, 0, 0, 0},{0, 0, 0, 0}};
    7773             : static swig_cast_info _swigc__p_GDALDataType[] = {  {&_swigt__p_GDALDataType, 0, 0, 0},{0, 0, 0, 0}};
    7774             : static swig_cast_info _swigc__p_GDALDatasetShadow[] = {  {&_swigt__p_GDALDatasetShadow, 0, 0, 0},{0, 0, 0, 0}};
    7775             : static swig_cast_info _swigc__p_GDALExtendedDataTypeHS[] = {  {&_swigt__p_GDALExtendedDataTypeHS, 0, 0, 0},{0, 0, 0, 0}};
    7776             : static swig_cast_info _swigc__p_GDALMDArrayHS[] = {  {&_swigt__p_GDALMDArrayHS, 0, 0, 0},{0, 0, 0, 0}};
    7777             : static swig_cast_info _swigc__p_GDALProgressFunc[] = {  {&_swigt__p_GDALProgressFunc, 0, 0, 0},{0, 0, 0, 0}};
    7778             : static swig_cast_info _swigc__p_GDALRATDateTime[] = {  {&_swigt__p_GDALRATDateTime, 0, 0, 0},{0, 0, 0, 0}};
    7779             : static swig_cast_info _swigc__p_GDALRasterAttributeTableShadow[] = {  {&_swigt__p_GDALRasterAttributeTableShadow, 0, 0, 0},{0, 0, 0, 0}};
    7780             : static swig_cast_info _swigc__p_GDALComputedRasterBandShadow[] = {{&_swigt__p_GDALComputedRasterBandShadow, 0, 0, 0},{0, 0, 0, 0}};
    7781             : 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}};
    7782             : static swig_cast_info _swigc__p_GIntBig[] = {  {&_swigt__p_GIntBig, 0, 0, 0},{0, 0, 0, 0}};
    7783             : static swig_cast_info _swigc__p_GUIntBig[] = {  {&_swigt__p_GUIntBig, 0, 0, 0},{0, 0, 0, 0}};
    7784             : static swig_cast_info _swigc__p_PyArrayObject[] = {  {&_swigt__p_PyArrayObject, 0, 0, 0},{0, 0, 0, 0}};
    7785             : static swig_cast_info _swigc__p_char[] = {  {&_swigt__p_char, 0, 0, 0},{0, 0, 0, 0}};
    7786             : 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}};
    7787             : static swig_cast_info _swigc__p_int[] = {  {&_swigt__p_int, 0, 0, 0},{0, 0, 0, 0}};
    7788             : static swig_cast_info _swigc__p_p_CPLVirtualMemShadow[] = {  {&_swigt__p_p_CPLVirtualMemShadow, 0, 0, 0},{0, 0, 0, 0}};
    7789             : static swig_cast_info _swigc__p_p_void[] = {  {&_swigt__p_p_void, 0, 0, 0},{0, 0, 0, 0}};
    7790             : static swig_cast_info _swigc__p_size_t[] = {  {&_swigt__p_size_t, 0, 0, 0},{0, 0, 0, 0}};
    7791             : static swig_cast_info _swigc__p_std__string[] = {  {&_swigt__p_std__string, 0, 0, 0},{0, 0, 0, 0}};
    7792             : 
    7793             : static swig_cast_info *swig_cast_initial[] = {
    7794             :   _swigc__p_ArrowArray,
    7795             :   _swigc__p_ArrowSchema,
    7796             :   _swigc__p_CPLVirtualMemShadow,
    7797             :   _swigc__p_GDALComputedRasterBandShadow,
    7798             :   _swigc__p_GDALDataType,
    7799             :   _swigc__p_GDALDatasetShadow,
    7800             :   _swigc__p_GDALExtendedDataTypeHS,
    7801             :   _swigc__p_GDALMDArrayHS,
    7802             :   _swigc__p_GDALProgressFunc,
    7803             :   _swigc__p_GDALRATDateTime,
    7804             :   _swigc__p_GDALRasterAttributeTableShadow,
    7805             :   _swigc__p_GDALRasterBandShadow,
    7806             :   _swigc__p_GIntBig,
    7807             :   _swigc__p_GUIntBig,
    7808             :   _swigc__p_PyArrayObject,
    7809             :   _swigc__p_char,
    7810             :   _swigc__p_f_double_p_q_const__char_p_void__int,
    7811             :   _swigc__p_int,
    7812             :   _swigc__p_p_CPLVirtualMemShadow,
    7813             :   _swigc__p_p_void,
    7814             :   _swigc__p_size_t,
    7815             :   _swigc__p_std__string,
    7816             : };
    7817             : 
    7818             : 
    7819             : /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */
    7820             : 
    7821             : static swig_const_info swig_const_table[] = {
    7822             : { SWIG_PY_POINTER, "TermProgress", 0, 0, (void *)((int (*)(double,char const *,void *))(GDALTermProgress)), &SWIGTYPE_p_f_double_p_q_const__char_p_void__int },
    7823             : {0, 0, 0, 0.0, 0, 0}};
    7824             : 
    7825             : #ifdef __cplusplus
    7826             : }
    7827             : #endif
    7828             : /* -----------------------------------------------------------------------------
    7829             :  * Type initialization:
    7830             :  * This problem is tough by the requirement that no dynamic
    7831             :  * memory is used. Also, since swig_type_info structures store pointers to
    7832             :  * swig_cast_info structures and swig_cast_info structures store pointers back
    7833             :  * to swig_type_info structures, we need some lookup code at initialization.
    7834             :  * The idea is that swig generates all the structures that are needed.
    7835             :  * The runtime then collects these partially filled structures.
    7836             :  * The SWIG_InitializeModule function takes these initial arrays out of
    7837             :  * swig_module, and does all the lookup, filling in the swig_module.types
    7838             :  * array with the correct data and linking the correct swig_cast_info
    7839             :  * structures together.
    7840             :  *
    7841             :  * The generated swig_type_info structures are assigned statically to an initial
    7842             :  * array. We just loop through that array, and handle each type individually.
    7843             :  * First we lookup if this type has been already loaded, and if so, use the
    7844             :  * loaded structure instead of the generated one. Then we have to fill in the
    7845             :  * cast linked list. The cast data is initially stored in something like a
    7846             :  * two-dimensional array. Each row corresponds to a type (there are the same
    7847             :  * number of rows as there are in the swig_type_initial array). Each entry in
    7848             :  * a column is one of the swig_cast_info structures for that type.
    7849             :  * The cast_initial array is actually an array of arrays, because each row has
    7850             :  * a variable number of columns. So to actually build the cast linked list,
    7851             :  * we find the array of casts associated with the type, and loop through it
    7852             :  * adding the casts to the list. The one last trick we need to do is making
    7853             :  * sure the type pointer in the swig_cast_info struct is correct.
    7854             :  *
    7855             :  * First off, we lookup the cast->type name to see if it is already loaded.
    7856             :  * There are three cases to handle:
    7857             :  *  1) If the cast->type has already been loaded AND the type we are adding
    7858             :  *     casting info to has not been loaded (it is in this module), THEN we
    7859             :  *     replace the cast->type pointer with the type pointer that has already
    7860             :  *     been loaded.
    7861             :  *  2) If BOTH types (the one we are adding casting info to, and the
    7862             :  *     cast->type) are loaded, THEN the cast info has already been loaded by
    7863             :  *     the previous module so we just ignore it.
    7864             :  *  3) Finally, if cast->type has not already been loaded, then we add that
    7865             :  *     swig_cast_info to the linked list (because the cast->type) pointer will
    7866             :  *     be correct.
    7867             :  * ----------------------------------------------------------------------------- */
    7868             : 
    7869             : #ifdef __cplusplus
    7870             : extern "C" {
    7871             : #if 0
    7872             : } /* c-mode */
    7873             : #endif
    7874             : #endif
    7875             : 
    7876             : #if 0
    7877             : #define SWIGRUNTIME_DEBUG
    7878             : #endif
    7879             : 
    7880             : 
    7881             : SWIGRUNTIME void
    7882             : SWIG_InitializeModule(void *clientdata) {
    7883             :   size_t i;
    7884             :   swig_module_info *module_head, *iter;
    7885             :   int init;
    7886             :   
    7887             :   /* check to see if the circular list has been setup, if not, set it up */
    7888             :   if (swig_module.next==0) {
    7889             :     /* Initialize the swig_module */
    7890             :     swig_module.type_initial = swig_type_initial;
    7891             :     swig_module.cast_initial = swig_cast_initial;
    7892             :     swig_module.next = &swig_module;
    7893             :     init = 1;
    7894             :   } else {
    7895             :     init = 0;
    7896             :   }
    7897             :   
    7898             :   /* Try and load any already created modules */
    7899             :   module_head = SWIG_GetModule(clientdata);
    7900             :   if (!module_head) {
    7901             :     /* This is the first module loaded for this interpreter */
    7902             :     /* so set the swig module into the interpreter */
    7903             :     SWIG_SetModule(clientdata, &swig_module);
    7904             :   } else {
    7905             :     /* the interpreter has loaded a SWIG module, but has it loaded this one? */
    7906             :     iter=module_head;
    7907             :     do {
    7908             :       if (iter==&swig_module) {
    7909             :         /* Our module is already in the list, so there's nothing more to do. */
    7910             :         return;
    7911             :       }
    7912             :       iter=iter->next;
    7913             :     } while (iter!= module_head);
    7914             :     
    7915             :     /* otherwise we must add our module into the list */
    7916             :     swig_module.next = module_head->next;
    7917             :     module_head->next = &swig_module;
    7918             :   }
    7919             :   
    7920             :   /* When multiple interpreters are used, a module could have already been initialized in
    7921             :        a different interpreter, but not yet have a pointer in this interpreter.
    7922             :        In this case, we do not want to continue adding types... everything should be
    7923             :        set up already */
    7924             :   if (init == 0) return;
    7925             :   
    7926             :   /* Now work on filling in swig_module.types */
    7927             : #ifdef SWIGRUNTIME_DEBUG
    7928             :   printf("SWIG_InitializeModule: size %lu\n", (unsigned long)swig_module.size);
    7929             : #endif
    7930             :   for (i = 0; i < swig_module.size; ++i) {
    7931             :     swig_type_info *type = 0;
    7932             :     swig_type_info *ret;
    7933             :     swig_cast_info *cast;
    7934             :     
    7935             : #ifdef SWIGRUNTIME_DEBUG
    7936             :     printf("SWIG_InitializeModule: type %lu %s\n", (unsigned long)i, swig_module.type_initial[i]->name);
    7937             : #endif
    7938             :     
    7939             :     /* if there is another module already loaded */
    7940             :     if (swig_module.next != &swig_module) {
    7941             :       type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name);
    7942             :     }
    7943             :     if (type) {
    7944             :       /* Overwrite clientdata field */
    7945             : #ifdef SWIGRUNTIME_DEBUG
    7946             :       printf("SWIG_InitializeModule: found type %s\n", type->name);
    7947             : #endif
    7948             :       if (swig_module.type_initial[i]->clientdata) {
    7949             :         type->clientdata = swig_module.type_initial[i]->clientdata;
    7950             : #ifdef SWIGRUNTIME_DEBUG
    7951             :         printf("SWIG_InitializeModule: found and overwrite type %s \n", type->name);
    7952             : #endif
    7953             :       }
    7954             :     } else {
    7955             :       type = swig_module.type_initial[i];
    7956             :     }
    7957             :     
    7958             :     /* Insert casting types */
    7959             :     cast = swig_module.cast_initial[i];
    7960             :     while (cast->type) {
    7961             :       /* Don't need to add information already in the list */
    7962             :       ret = 0;
    7963             : #ifdef SWIGRUNTIME_DEBUG
    7964             :       printf("SWIG_InitializeModule: look cast %s\n", cast->type->name);
    7965             : #endif
    7966             :       if (swig_module.next != &swig_module) {
    7967             :         ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name);
    7968             : #ifdef SWIGRUNTIME_DEBUG
    7969             :         if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name);
    7970             : #endif
    7971             :       }
    7972             :       if (ret) {
    7973             :         if (type == swig_module.type_initial[i]) {
    7974             : #ifdef SWIGRUNTIME_DEBUG
    7975             :           printf("SWIG_InitializeModule: skip old type %s\n", ret->name);
    7976             : #endif
    7977             :           cast->type = ret;
    7978             :           ret = 0;
    7979             :         } else {
    7980             :           /* Check for casting already in the list */
    7981             :           swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type);
    7982             : #ifdef SWIGRUNTIME_DEBUG
    7983             :           if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name);
    7984             : #endif
    7985             :           if (!ocast) ret = 0;
    7986             :         }
    7987             :       }
    7988             :       
    7989             :       if (!ret) {
    7990             : #ifdef SWIGRUNTIME_DEBUG
    7991             :         printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name);
    7992             : #endif
    7993             :         if (type->cast) {
    7994             :           type->cast->prev = cast;
    7995             :           cast->next = type->cast;
    7996             :         }
    7997             :         type->cast = cast;
    7998             :       }
    7999             :       cast++;
    8000             :     }
    8001             :     /* Set entry in modules->types array equal to the type */
    8002             :     swig_module.types[i] = type;
    8003             :   }
    8004             :   swig_module.types[i] = 0;
    8005             :   
    8006             : #ifdef SWIGRUNTIME_DEBUG
    8007             :   printf("**** SWIG_InitializeModule: Cast List ******\n");
    8008             :   for (i = 0; i < swig_module.size; ++i) {
    8009             :     int j = 0;
    8010             :     swig_cast_info *cast = swig_module.cast_initial[i];
    8011             :     printf("SWIG_InitializeModule: type %lu %s\n", (unsigned long)i, swig_module.type_initial[i]->name);
    8012             :     while (cast->type) {
    8013             :       printf("SWIG_InitializeModule: cast type %s\n", cast->type->name);
    8014             :       cast++;
    8015             :       ++j;
    8016             :     }
    8017             :     printf("---- Total casts: %d\n",j);
    8018             :   }
    8019             :   printf("**** SWIG_InitializeModule: Cast List ******\n");
    8020             : #endif
    8021             : }
    8022             : 
    8023             : /* This function will propagate the clientdata field of type to
    8024             : * any new swig_type_info structures that have been added into the list
    8025             : * of equivalent types.  It is like calling
    8026             : * SWIG_TypeClientData(type, clientdata) a second time.
    8027             : */
    8028             : SWIGRUNTIME void
    8029             : SWIG_PropagateClientData(void) {
    8030             :   size_t i;
    8031             :   swig_cast_info *equiv;
    8032             :   static int init_run = 0;
    8033             :   
    8034             :   if (init_run) return;
    8035             :   init_run = 1;
    8036             :   
    8037             :   for (i = 0; i < swig_module.size; i++) {
    8038             :     if (swig_module.types[i]->clientdata) {
    8039             :       equiv = swig_module.types[i]->cast;
    8040             :       while (equiv) {
    8041             :         if (!equiv->converter) {
    8042             :           if (equiv->type && !equiv->type->clientdata)
    8043             :           SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata);
    8044             :         }
    8045             :         equiv = equiv->next;
    8046             :       }
    8047             :     }
    8048             :   }
    8049             : }
    8050             : 
    8051             : #ifdef __cplusplus
    8052             : #if 0
    8053             : {
    8054             :   /* c-mode */
    8055             : #endif
    8056             : }
    8057             : #endif
    8058             : 
    8059             : 
    8060             : 
    8061             : #ifdef __cplusplus
    8062             : extern "C" {
    8063             : #endif
    8064             :   
    8065             :   /* Python-specific SWIG API */
    8066             : #define SWIG_newvarlink()                             SWIG_Python_newvarlink()
    8067             : #define SWIG_addvarlink(p, name, get_attr, set_attr)  SWIG_Python_addvarlink(p, name, get_attr, set_attr)
    8068             : #define SWIG_InstallConstants(d, constants)           SWIG_Python_InstallConstants(d, constants)
    8069             :   
    8070             :   /* -----------------------------------------------------------------------------
    8071             :    * global variable support code.
    8072             :    * ----------------------------------------------------------------------------- */
    8073             :   
    8074             :   typedef struct swig_globalvar {
    8075             :     char       *name;                  /* Name of global variable */
    8076             :     PyObject *(*get_attr)(void);       /* Return the current value */
    8077             :     int       (*set_attr)(PyObject *); /* Set the value */
    8078             :     struct swig_globalvar *next;
    8079             :   } swig_globalvar;
    8080             :   
    8081             :   typedef struct swig_varlinkobject {
    8082             :     PyObject_HEAD
    8083             :     swig_globalvar *vars;
    8084             :   } swig_varlinkobject;
    8085             :   
    8086             :   SWIGINTERN PyObject *
    8087             :   swig_varlink_repr(swig_varlinkobject *SWIGUNUSEDPARM(v)) {
    8088             : #if PY_VERSION_HEX >= 0x03000000
    8089             :     return PyUnicode_InternFromString("<Swig global variables>");
    8090             : #else
    8091             :     return PyString_FromString("<Swig global variables>");
    8092             : #endif
    8093             :   }
    8094             :   
    8095             :   SWIGINTERN PyObject *
    8096             :   swig_varlink_str(swig_varlinkobject *v) {
    8097             : #if PY_VERSION_HEX >= 0x03000000
    8098             :     PyObject *str = PyUnicode_InternFromString("(");
    8099             :     PyObject *tail;
    8100             :     PyObject *joined;
    8101             :     swig_globalvar *var;
    8102             :     for (var = v->vars; var; var=var->next) {
    8103             :       tail = PyUnicode_FromString(var->name);
    8104             :       joined = PyUnicode_Concat(str, tail);
    8105             :       Py_DecRef(str);
    8106             :       Py_DecRef(tail);
    8107             :       str = joined;
    8108             :       if (var->next) {
    8109             :         tail = PyUnicode_InternFromString(", ");
    8110             :         joined = PyUnicode_Concat(str, tail);
    8111             :         Py_DecRef(str);
    8112             :         Py_DecRef(tail);
    8113             :         str = joined;
    8114             :       }
    8115             :     }
    8116             :     tail = PyUnicode_InternFromString(")");
    8117             :     joined = PyUnicode_Concat(str, tail);
    8118             :     Py_DecRef(str);
    8119             :     Py_DecRef(tail);
    8120             :     str = joined;
    8121             : #else
    8122             :     PyObject *str = PyString_FromString("(");
    8123             :     swig_globalvar *var;
    8124             :     for (var = v->vars; var; var=var->next) {
    8125             :       PyString_ConcatAndDel(&str,PyString_FromString(var->name));
    8126             :       if (var->next) PyString_ConcatAndDel(&str,PyString_FromString(", "));
    8127             :     }
    8128             :     PyString_ConcatAndDel(&str,PyString_FromString(")"));
    8129             : #endif
    8130             :     return str;
    8131             :   }
    8132             :   
    8133             :   SWIGINTERN void
    8134             :   swig_varlink_dealloc(swig_varlinkobject *v) {
    8135             :     swig_globalvar *var = v->vars;
    8136             :     while (var) {
    8137             :       swig_globalvar *n = var->next;
    8138             :       free(var->name);
    8139             :       free(var);
    8140             :       var = n;
    8141             :     }
    8142             :   }
    8143             :   
    8144             :   SWIGINTERN PyObject *
    8145             :   swig_varlink_getattr(swig_varlinkobject *v, char *n) {
    8146             :     PyObject *res = NULL;
    8147             :     swig_globalvar *var = v->vars;
    8148             :     while (var) {
    8149             :       if (strcmp(var->name,n) == 0) {
    8150             :         res = (*var->get_attr)();
    8151             :         break;
    8152             :       }
    8153             :       var = var->next;
    8154             :     }
    8155             :     if (res == NULL && !PyErr_Occurred()) {
    8156             :       PyErr_Format(PyExc_AttributeError, "Unknown C global variable '%s'", n);
    8157             :     }
    8158             :     return res;
    8159             :   }
    8160             :   
    8161             :   SWIGINTERN int
    8162             :   swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p) {
    8163             :     int res = 1;
    8164             :     swig_globalvar *var = v->vars;
    8165             :     while (var) {
    8166             :       if (strcmp(var->name,n) == 0) {
    8167             :         res = (*var->set_attr)(p);
    8168             :         break;
    8169             :       }
    8170             :       var = var->next;
    8171             :     }
    8172             :     if (res == 1 && !PyErr_Occurred()) {
    8173             :       PyErr_Format(PyExc_AttributeError, "Unknown C global variable '%s'", n);
    8174             :     }
    8175             :     return res;
    8176             :   }
    8177             :   
    8178             :   SWIGINTERN PyTypeObject*
    8179             :   swig_varlink_type(void) {
    8180             :     static char varlink__doc__[] = "Swig var link object";
    8181             :     static PyTypeObject varlink_type;
    8182             :     static int type_init = 0;
    8183             :     if (!type_init) {
    8184             :       const PyTypeObject tmp = {
    8185             : #if PY_VERSION_HEX >= 0x03000000
    8186             :         PyVarObject_HEAD_INIT(NULL, 0)
    8187             : #else
    8188             :         PyObject_HEAD_INIT(NULL)
    8189             :         0,                                  /* ob_size */
    8190             : #endif
    8191             :         "swigvarlink",                      /* tp_name */
    8192             :         sizeof(swig_varlinkobject),         /* tp_basicsize */
    8193             :         0,                                  /* tp_itemsize */
    8194             :         (destructor) swig_varlink_dealloc,  /* tp_dealloc */
    8195             :         0,                                  /* tp_print */
    8196             :         (getattrfunc) swig_varlink_getattr, /* tp_getattr */
    8197             :         (setattrfunc) swig_varlink_setattr, /* tp_setattr */
    8198             :         0,                                  /* tp_compare */
    8199             :         (reprfunc) swig_varlink_repr,       /* tp_repr */
    8200             :         0,                                  /* tp_as_number */
    8201             :         0,                                  /* tp_as_sequence */
    8202             :         0,                                  /* tp_as_mapping */
    8203             :         0,                                  /* tp_hash */
    8204             :         0,                                  /* tp_call */
    8205             :         (reprfunc) swig_varlink_str,        /* tp_str */
    8206             :         0,                                  /* tp_getattro */
    8207             :         0,                                  /* tp_setattro */
    8208             :         0,                                  /* tp_as_buffer */
    8209             :         0,                                  /* tp_flags */
    8210             :         varlink__doc__,                     /* tp_doc */
    8211             :         0,                                  /* tp_traverse */
    8212             :         0,                                  /* tp_clear */
    8213             :         0,                                  /* tp_richcompare */
    8214             :         0,                                  /* tp_weaklistoffset */
    8215             :         0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */
    8216             :         0,                                  /* tp_del */
    8217             :         0,                                  /* tp_version_tag */
    8218             : #if PY_VERSION_HEX >= 0x03040000
    8219             :         0,                                  /* tp_finalize */
    8220             : #endif
    8221             : #ifdef COUNT_ALLOCS
    8222             :         0,                                  /* tp_allocs */
    8223             :         0,                                  /* tp_frees */
    8224             :         0,                                  /* tp_maxalloc */
    8225             :         0,                                  /* tp_prev */
    8226             :         0                                   /* tp_next */
    8227             : #endif
    8228             :       };
    8229             :       varlink_type = tmp;
    8230             :       type_init = 1;
    8231             :       if (PyType_Ready(&varlink_type) < 0)
    8232             :       return NULL;
    8233             :     }
    8234             :     return &varlink_type;
    8235             :   }
    8236             :   
    8237             :   /* Create a variable linking object for use later */
    8238             :   SWIGINTERN PyObject *
    8239             :   SWIG_Python_newvarlink(void) {
    8240             :     swig_varlinkobject *result = PyObject_NEW(swig_varlinkobject, swig_varlink_type());
    8241             :     if (result) {
    8242             :       result->vars = 0;
    8243             :     }
    8244             :     return ((PyObject*) result);
    8245             :   }
    8246             :   
    8247             :   SWIGINTERN void 
    8248             :   SWIG_Python_addvarlink(PyObject *p, const char *name, PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p)) {
    8249             :     swig_varlinkobject *v = (swig_varlinkobject *) p;
    8250             :     swig_globalvar *gv = (swig_globalvar *) malloc(sizeof(swig_globalvar));
    8251             :     if (gv) {
    8252             :       size_t size = strlen(name)+1;
    8253             :       gv->name = (char *)malloc(size);
    8254             :       if (gv->name) {
    8255             :         memcpy(gv->name, name, size);
    8256             :         gv->get_attr = get_attr;
    8257             :         gv->set_attr = set_attr;
    8258             :         gv->next = v->vars;
    8259             :       }
    8260             :     }
    8261             :     v->vars = gv;
    8262             :   }
    8263             :   
    8264             :   SWIGINTERN PyObject *
    8265             :   SWIG_globals(void) {
    8266             :     static PyObject *globals = 0;
    8267             :     if (!globals) {
    8268             :       globals = SWIG_newvarlink();
    8269             :     }
    8270             :     return globals;
    8271             :   }
    8272             :   
    8273             :   /* -----------------------------------------------------------------------------
    8274             :    * constants/methods manipulation
    8275             :    * ----------------------------------------------------------------------------- */
    8276             :   
    8277             :   /* Install Constants */
    8278             :   SWIGINTERN void
    8279         233 :   SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) {
    8280         233 :     PyObject *obj = 0;
    8281         233 :     size_t i;
    8282         466 :     for (i = 0; constants[i].type; ++i) {
    8283         233 :       switch(constants[i].type) {
    8284         233 :       case SWIG_PY_POINTER:
    8285         233 :         obj = SWIG_InternalNewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0);
    8286         233 :         break;
    8287           0 :       case SWIG_PY_BINARY:
    8288           0 :         obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype));
    8289             :         break;
    8290             :       default:
    8291             :         obj = 0;
    8292             :         break;
    8293             :       }
    8294         233 :       if (obj) {
    8295         233 :         PyDict_SetItemString(d, constants[i].name, obj);
    8296         233 :         Py_DECREF(obj);
    8297             :       }
    8298             :     }
    8299         233 :   }
    8300             :   
    8301             :   /* -----------------------------------------------------------------------------*/
    8302             :   /* Fix SwigMethods to carry the callback ptrs when needed */
    8303             :   /* -----------------------------------------------------------------------------*/
    8304             :   
    8305             :   SWIGINTERN void
    8306         233 :   SWIG_Python_FixMethods(PyMethodDef *methods,
    8307             :     swig_const_info *const_table,
    8308             :     swig_type_info **types,
    8309             :     swig_type_info **types_initial) {
    8310         233 :     size_t i;
    8311        5592 :     for (i = 0; methods[i].ml_name; ++i) {
    8312        5359 :       const char *c = methods[i].ml_doc;
    8313        5359 :       if (!c) continue;
    8314        4893 :       c = strstr(c, "swig_ptr: ");
    8315        4893 :       if (c) {
    8316           0 :         int j;
    8317           0 :         swig_const_info *ci = 0;
    8318           0 :         const char *name = c + 10;
    8319           0 :         for (j = 0; const_table[j].type; ++j) {
    8320           0 :           if (strncmp(const_table[j].name, name, 
    8321             :               strlen(const_table[j].name)) == 0) {
    8322             :             ci = &(const_table[j]);
    8323             :             break;
    8324             :           }
    8325             :         }
    8326           0 :         if (ci) {
    8327        5359 :           void *ptr = (ci->type == SWIG_PY_POINTER) ? ci->pvalue : 0;
    8328           0 :           if (ptr) {
    8329           0 :             size_t shift = (ci->ptype) - types;
    8330           0 :             swig_type_info *ty = types_initial[shift];
    8331           0 :             size_t ldoc = (c - methods[i].ml_doc);
    8332           0 :             size_t lptr = strlen(ty->name)+2*sizeof(void*)+2;
    8333           0 :             char *ndoc = (char*)malloc(ldoc + lptr + 10);
    8334           0 :             if (ndoc) {
    8335           0 :               char *buff = ndoc;
    8336           0 :               memcpy(buff, methods[i].ml_doc, ldoc);
    8337           0 :               buff += ldoc;
    8338           0 :               memcpy(buff, "swig_ptr: ", 10);
    8339           0 :               buff += 10;
    8340           0 :               SWIG_PackVoidPtr(buff, ptr, ty->name, lptr);
    8341           0 :               methods[i].ml_doc = ndoc;
    8342             :             }
    8343             :           }
    8344             :         }
    8345             :       }
    8346             :     }
    8347         233 :   } 
    8348             :   
    8349             :   /* -----------------------------------------------------------------------------
    8350             :    * Method creation and docstring support functions
    8351             :    * ----------------------------------------------------------------------------- */
    8352             :   
    8353             :   /* -----------------------------------------------------------------------------
    8354             :    * Function to find the method definition with the correct docstring for the
    8355             :    * proxy module as opposed to the low-level API
    8356             :    * ----------------------------------------------------------------------------- */
    8357             :   
    8358           0 :   SWIGINTERN PyMethodDef *SWIG_PythonGetProxyDoc(const char *name) {
    8359             :     /* Find the function in the modified method table */
    8360           0 :     size_t offset = 0;
    8361           0 :     int found = 0;
    8362           0 :     while (SwigMethods_proxydocs[offset].ml_meth != NULL) {
    8363           0 :       if (strcmp(SwigMethods_proxydocs[offset].ml_name, name) == 0) {
    8364             :         found = 1;
    8365             :         break;
    8366             :       }
    8367           0 :       offset++;
    8368             :     }
    8369             :     /* Use the copy with the modified docstring if available */
    8370           0 :     return found ? &SwigMethods_proxydocs[offset] : NULL;
    8371             :   }
    8372             :   
    8373             :   /* -----------------------------------------------------------------------------
    8374             :    * Wrapper of PyInstanceMethod_New() used in Python 3
    8375             :    * It is exported to the generated module, used for -fastproxy
    8376             :    * ----------------------------------------------------------------------------- */
    8377             :   
    8378           0 :   SWIGINTERN PyObject *SWIG_PyInstanceMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *func) {
    8379           0 :     if (PyCFunction_Check(func)) {
    8380           0 :       PyCFunctionObject *funcobj = (PyCFunctionObject *)func;
    8381           0 :       PyMethodDef *ml = SWIG_PythonGetProxyDoc(funcobj->m_ml->ml_name);
    8382           0 :       if (ml)
    8383           0 :       func = PyCFunction_NewEx(ml, funcobj->m_self, funcobj->m_module);
    8384             :     }
    8385             : #if PY_VERSION_HEX >= 0x03000000
    8386           0 :     return PyInstanceMethod_New(func);
    8387             : #else
    8388             :     return PyMethod_New(func, NULL, NULL);
    8389             : #endif
    8390             :   }
    8391             :   
    8392             :   /* -----------------------------------------------------------------------------
    8393             :    * Wrapper of PyStaticMethod_New()
    8394             :    * It is exported to the generated module, used for -fastproxy
    8395             :    * ----------------------------------------------------------------------------- */
    8396             :   
    8397             :   SWIGINTERN PyObject *SWIG_PyStaticMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *func) {
    8398             :     if (PyCFunction_Check(func)) {
    8399             :       PyCFunctionObject *funcobj = (PyCFunctionObject *)func;
    8400             :       PyMethodDef *ml = SWIG_PythonGetProxyDoc(funcobj->m_ml->ml_name);
    8401             :       if (ml)
    8402             :       func = PyCFunction_NewEx(ml, funcobj->m_self, funcobj->m_module);
    8403             :     }
    8404             :     return PyStaticMethod_New(func);
    8405             :   }
    8406             :   
    8407             : #ifdef __cplusplus
    8408             : }
    8409             : #endif
    8410             : 
    8411             : /* -----------------------------------------------------------------------------*
    8412             :  *  Partial Init method
    8413             :  * -----------------------------------------------------------------------------*/
    8414             : 
    8415             : #ifdef __cplusplus
    8416             : extern "C"
    8417             : #endif
    8418             : 
    8419             : SWIGEXPORT 
    8420             : #if PY_VERSION_HEX >= 0x03000000
    8421             : PyObject*
    8422             : #else
    8423             : void
    8424             : #endif
    8425         233 : SWIG_init(void) {
    8426         233 :   PyObject *m, *d, *md, *globals;
    8427             :   
    8428             : #if PY_VERSION_HEX >= 0x03000000
    8429         233 :   static struct PyModuleDef SWIG_module = {
    8430             :     PyModuleDef_HEAD_INIT,
    8431             :     SWIG_name,
    8432             :     NULL,
    8433             :     -1,
    8434             :     SwigMethods,
    8435             :     NULL,
    8436             :     NULL,
    8437             :     NULL,
    8438             :     NULL
    8439             :   };
    8440             : #endif
    8441             :   
    8442             : #if defined(SWIGPYTHON_BUILTIN)
    8443             :   static SwigPyClientData SwigPyObject_clientdata = {
    8444             :     0, 0, 0, 0, 0, 0, 0
    8445             :   };
    8446             :   static PyGetSetDef this_getset_def = {
    8447             :     (char *)"this", &SwigPyBuiltin_ThisClosure, NULL, NULL, NULL
    8448             :   };
    8449             :   static SwigPyGetSet thisown_getset_closure = {
    8450             :     SwigPyObject_own,
    8451             :     SwigPyObject_own
    8452             :   };
    8453             :   static PyGetSetDef thisown_getset_def = {
    8454             :     (char *)"thisown", SwigPyBuiltin_GetterClosure, SwigPyBuiltin_SetterClosure, NULL, &thisown_getset_closure
    8455             :   };
    8456             :   PyTypeObject *builtin_pytype;
    8457             :   int builtin_base_count;
    8458             :   swig_type_info *builtin_basetype;
    8459             :   PyObject *tuple;
    8460             :   PyGetSetDescrObject *static_getset;
    8461             :   PyTypeObject *metatype;
    8462             :   PyTypeObject *swigpyobject;
    8463             :   SwigPyClientData *cd;
    8464             :   PyObject *public_interface, *public_symbol;
    8465             :   PyObject *this_descr;
    8466             :   PyObject *thisown_descr;
    8467             :   PyObject *self = 0;
    8468             :   int i;
    8469             :   
    8470             :   (void)builtin_pytype;
    8471             :   (void)builtin_base_count;
    8472             :   (void)builtin_basetype;
    8473             :   (void)tuple;
    8474             :   (void)static_getset;
    8475             :   (void)self;
    8476             :   
    8477             :   /* Metaclass is used to implement static member variables */
    8478             :   metatype = SwigPyObjectType();
    8479             :   assert(metatype);
    8480             : #endif
    8481             :   
    8482         233 :   (void)globals;
    8483             :   
    8484             :   /* Create singletons now to avoid potential deadlocks with multi-threaded usage after module initialization */
    8485         233 :   SWIG_This();
    8486         233 :   SWIG_Python_TypeCache();
    8487         233 :   SwigPyPacked_type();
    8488             : #ifndef SWIGPYTHON_BUILTIN
    8489         233 :   SwigPyObject_type();
    8490             : #endif
    8491             :   
    8492             :   /* Fix SwigMethods to carry the callback ptrs when needed */
    8493         233 :   SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_type_initial);
    8494             :   
    8495             : #if PY_VERSION_HEX >= 0x03000000
    8496         233 :   m = PyModule_Create(&SWIG_module);
    8497             : #else
    8498             :   m = Py_InitModule(SWIG_name, SwigMethods);
    8499             : #endif
    8500             :   
    8501         233 :   md = d = PyModule_GetDict(m);
    8502         233 :   (void)md;
    8503             :   
    8504         233 :   SWIG_InitializeModule(0);
    8505             :   
    8506             : #ifdef SWIGPYTHON_BUILTIN
    8507             :   swigpyobject = SwigPyObject_TypeOnce();
    8508             :   
    8509             :   SwigPyObject_stype = SWIG_MangledTypeQuery("_p_SwigPyObject");
    8510             :   assert(SwigPyObject_stype);
    8511             :   cd = (SwigPyClientData*) SwigPyObject_stype->clientdata;
    8512             :   if (!cd) {
    8513             :     SwigPyObject_stype->clientdata = &SwigPyObject_clientdata;
    8514             :     SwigPyObject_clientdata.pytype = swigpyobject;
    8515             :   } else if (swigpyobject->tp_basicsize != cd->pytype->tp_basicsize) {
    8516             :     PyErr_SetString(PyExc_RuntimeError, "Import error: attempted to load two incompatible swig-generated modules.");
    8517             : # if PY_VERSION_HEX >= 0x03000000
    8518             :     return NULL;
    8519             : # else
    8520             :     return;
    8521             : # endif
    8522             :   }
    8523             :   
    8524             :   /* All objects have a 'this' attribute */
    8525             :   this_descr = PyDescr_NewGetSet(SwigPyObject_type(), &this_getset_def);
    8526             :   (void)this_descr;
    8527             :   
    8528             :   /* All objects have a 'thisown' attribute */
    8529             :   thisown_descr = PyDescr_NewGetSet(SwigPyObject_type(), &thisown_getset_def);
    8530             :   (void)thisown_descr;
    8531             :   
    8532             :   public_interface = PyList_New(0);
    8533             :   public_symbol = 0;
    8534             :   (void)public_symbol;
    8535             :   
    8536             :   PyDict_SetItemString(md, "__all__", public_interface);
    8537             :   Py_DECREF(public_interface);
    8538             :   for (i = 0; SwigMethods[i].ml_name != NULL; ++i)
    8539             :   SwigPyBuiltin_AddPublicSymbol(public_interface, SwigMethods[i].ml_name);
    8540             :   for (i = 0; swig_const_table[i].name != 0; ++i)
    8541             :   SwigPyBuiltin_AddPublicSymbol(public_interface, swig_const_table[i].name);
    8542             : #endif
    8543             :   
    8544         233 :   SWIG_InstallConstants(d,swig_const_table);
    8545             :   
    8546             :   
    8547             : #if SWIG_VERSION >= 0x040400
    8548             :   import_array1(-1);
    8549             : #else
    8550         233 :   import_array();
    8551             : #endif
    8552         233 :   PyDateTime_IMPORT;
    8553         233 :   GDALRegister_NUMPY();
    8554             :   
    8555             :   
    8556             :   
    8557             :   /* Initialize threading */
    8558         233 :   SWIG_PYTHON_INITIALIZE_THREADS;
    8559             : #if PY_VERSION_HEX >= 0x03000000
    8560         233 :   return m;
    8561             : #else
    8562             :   return;
    8563             : #endif
    8564             : }
    8565             : 

Generated by: LCOV version 1.14