Skip to content

Commit

Permalink
Python bindings: turn on exceptions by default (refs OSGeo#7452)
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Mar 17, 2023
1 parent 244956f commit 335468e
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 22 deletions.
22 changes: 0 additions & 22 deletions swig/include/gdal_array.i
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,6 @@ typedef int GDALRIOResampleAlg;

%include "python_strings.i"

%{
#include "cpl_conv.h"
%}

%inline %{
// Note: copied&pasted from python_exceptions.i
static void _StoreLastException()
{
const char* pszLastErrorMessage =
CPLGetThreadLocalConfigOption("__last_error_message", NULL);
const char* pszLastErrorCode =
CPLGetThreadLocalConfigOption("__last_error_code", NULL);
if( pszLastErrorMessage != NULL && pszLastErrorCode != NULL )
{
CPLErrorSetState( CE_Failure,
static_cast<CPLErrorNum>(atoi(pszLastErrorCode)),
pszLastErrorMessage);
}
}
%}

%{
#include <vector>
#include "gdal_priv.h"
Expand Down Expand Up @@ -2087,7 +2066,6 @@ def GDALTypeCodeToNumericTypeCode(gdal_code):

def _RaiseException():
if gdal.GetUseExceptions():
_StoreLastException()
raise RuntimeError(gdal.GetLastErrorMsg())

def LoadFile(filename, xoff=0, yoff=0, xsize=None, ysize=None,
Expand Down
1 change: 1 addition & 0 deletions swig/include/python/gdal_python.i
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
/* gdal_python.i %init code */
if ( GDALGetDriverCount() == 0 ) {
GDALAllRegister();
UseExceptions();
}
%}

Expand Down
1 change: 1 addition & 0 deletions swig/include/python/gnm_python.i
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

if ( OGRGetDriverCount() == 0 ) {
OGRRegisterAll();
UseExceptions();
}

%}
Expand Down
1 change: 1 addition & 0 deletions swig/include/python/ogr_python.i
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

if ( OGRGetDriverCount() == 0 ) {
OGRRegisterAll();
UseExceptions();
}

%}
Expand Down
4 changes: 4 additions & 0 deletions swig/include/python/osr_python.i
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

%feature("autodoc");

%init %{
UseExceptions();
%}

#ifndef FROM_GDAL_I
%{
#define MODULE_NAME "osr"
Expand Down

0 comments on commit 335468e

Please sign in to comment.