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 18, 2023
1 parent e90d65e commit 3b8eb4f
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 @@ -12,6 +12,7 @@
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 @@ -12,6 +12,7 @@
if ( OGRGetDriverCount() == 0 ) {
OGRRegisterAll();
}
UseExceptions();

%}
#endif
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 @@ -12,6 +12,7 @@
if ( OGRGetDriverCount() == 0 ) {
OGRRegisterAll();
}
UseExceptions();

%}
#endif
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 3b8eb4f

Please sign in to comment.