Commit 3da701525850cbe4c7761b414e10bb4bf91bb595

Authored by Jürgen Knödlseder
1 parent 37e9373c

Add %inline function PythonSlice_GetIndices for handling of slices in Python 2 and 3

inst/cta/pyext/GCTAEventList.i
... ... @@ -110,11 +110,7 @@ public:
110 110 Py_ssize_t stop = 0;
111 111 Py_ssize_t step = 0;
112 112 Py_ssize_t len = self->size();
113   - #if PY_VERSION_HEX >= 0x03020000
114   - if (PySlice_GetIndices(param, len, &start, &stop, &step) == 0) {
115   - #else
116   - if (PySlice_GetIndices((PySliceObject*)param, len, &start, &stop, &step) == 0) {
117   - #endif
  113 + if (PythonSlice_GetIndices(param, len, &start, &stop, &step) == 0) {
118 114 GCTAEventList* list = new GCTAEventList;
119 115 if (step > 0) {
120 116 for (int i = (int)start; i < (int)stop; i += (int)step) {
... ...
inst/cta/pyext/cta.i
1 1 /***************************************************************************
2 2 * cta.i - Cherenkov Telescope Array module *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2011-2016 by Juergen Knoedlseder *
  4 + * copyright (C) 2011-2017 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -41,6 +41,7 @@
41 41  
42 42 /* __ Include GammaLib typemaps __________________________________________ */
43 43 %include typemap_GFilename.i
  44 +%include typemap_slices.i
44 45  
45 46 /* __ Include interface classes __________________________________________ */
46 47 %import(module="gammalib.base") "GBase.i";
... ...
inst/lat/pyext/GLATEventList.i
... ... @@ -88,11 +88,7 @@ public:
88 88 Py_ssize_t stop = 0;
89 89 Py_ssize_t step = 0;
90 90 Py_ssize_t len = self->size();
91   - #if PY_VERSION_HEX >= 0x03020000
92   - if (PySlice_GetIndices(param, len, &start, &stop, &step) == 0) {
93   - #else
94   - if (PySlice_GetIndices((PySliceObject*)param, len, &start, &stop, &step) == 0) {
95   - #endif
  91 + if (PythonSlice_GetIndices(param, len, &start, &stop, &step) == 0) {
96 92 GLATEventList* list = new GLATEventList;
97 93 if (step > 0) {
98 94 for (int i = (int)start; i < (int)stop; i += (int)step) {
... ...
inst/lat/pyext/lat.i
1 1 /***************************************************************************
2 2 * lat.i - Fermi/LAT module *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2011-2016 by Juergen Knoedlseder *
  4 + * copyright (C) 2011-2017 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -41,6 +41,7 @@
41 41  
42 42 /* __ Include GammaLib typemaps __________________________________________ */
43 43 %include typemap_GFilename.i
  44 +%include typemap_slices.i
44 45  
45 46 /* __ Include interface classes __________________________________________ */
46 47 %import(module="gammalib.base") "GBase.i";
... ...
pyext/GApplicationPars.i
... ... @@ -28,7 +28,6 @@
28 28 #include "GApplicationPars.hpp"
29 29 #include "GException.hpp"
30 30 #include "GFilename.hpp"
31   -#include "Python.h"
32 31 %}
33 32  
34 33  
... ... @@ -98,11 +97,7 @@ public:
98 97 Py_ssize_t stop = 0;
99 98 Py_ssize_t step = 0;
100 99 Py_ssize_t len = self->size();
101   - #if PY_VERSION_HEX >= 0x03020000
102   - if (PySlice_GetIndices(param, len, &start, &stop, &step) == 0) {
103   - #else
104   - if (PySlice_GetIndices((PySliceObject*)param, len, &start, &stop, &step) == 0) {
105   - #endif
  100 + if (PythonSlice_GetIndices(param, len, &start, &stop, &step) == 0) {
106 101 GApplicationPars* pars = new GApplicationPars;
107 102 if (step > 0) {
108 103 for (int i = (int)start; i < (int)stop; i += (int)step) {
... ...
pyext/GEbounds.i
... ... @@ -99,11 +99,7 @@ public:
99 99 Py_ssize_t stop = 0;
100 100 Py_ssize_t step = 0;
101 101 Py_ssize_t len = self->size();
102   - #if PY_VERSION_HEX >= 0x03020000
103   - if (PySlice_GetIndices(param, len, &start, &stop, &step) == 0) {
104   - #else
105   - if (PySlice_GetIndices((PySliceObject*)param, len, &start, &stop, &step) == 0) {
106   - #endif
  102 + if (PythonSlice_GetIndices(param, len, &start, &stop, &step) == 0) {
107 103 GEbounds* ebounds = new GEbounds;
108 104 if (step > 0) {
109 105 for (int i = (int)start; i < (int)stop; i += (int)step) {
... ...
pyext/GEnergies.i
... ... @@ -97,11 +97,7 @@ public:
97 97 Py_ssize_t stop = 0;
98 98 Py_ssize_t step = 0;
99 99 Py_ssize_t len = self->size();
100   - #if PY_VERSION_HEX >= 0x03020000
101   - if (PySlice_GetIndices(param, len, &start, &stop, &step) == 0) {
102   - #else
103   - if (PySlice_GetIndices((PySliceObject*)param, len, &start, &stop, &step) == 0) {
104   - #endif
  100 + if (PythonSlice_GetIndices(param, len, &start, &stop, &step) == 0) {
105 101 GEnergies* energies = new GEnergies;
106 102 if (step > 0) {
107 103 for (int i = (int)start; i < (int)stop; i += (int)step) {
... ...
pyext/GFits.i
... ... @@ -123,11 +123,7 @@ public:
123 123 Py_ssize_t stop = 0;
124 124 Py_ssize_t step = 0;
125 125 Py_ssize_t len = self->size();
126   - #if PY_VERSION_HEX >= 0x03020000
127   - if (PySlice_GetIndices(param, len, &start, &stop, &step) == 0) {
128   - #else
129   - if (PySlice_GetIndices((PySliceObject*)param, len, &start, &stop, &step) == 0) {
130   - #endif
  126 + if (PythonSlice_GetIndices(param, len, &start, &stop, &step) == 0) {
131 127 GFits* fits = new GFits;
132 128 if (step > 0) {
133 129 for (int i = (int)start; i < (int)stop; i += (int)step) {
... ...
pyext/GFitsHeader.i
... ... @@ -98,11 +98,7 @@ public:
98 98 Py_ssize_t stop = 0;
99 99 Py_ssize_t step = 0;
100 100 Py_ssize_t len = self->size();
101   - #if PY_VERSION_HEX >= 0x03020000
102   - if (PySlice_GetIndices(param, len, &start, &stop, &step) == 0) {
103   - #else
104   - if (PySlice_GetIndices((PySliceObject*)param, len, &start, &stop, &step) == 0) {
105   - #endif
  101 + if (PythonSlice_GetIndices(param, len, &start, &stop, &step) == 0) {
106 102 GFitsHeader* header = new GFitsHeader;
107 103 if (step > 0) {
108 104 for (int i = (int)start; i < (int)stop; i += (int)step) {
... ...
pyext/GGti.i
... ... @@ -91,11 +91,7 @@ public:
91 91 Py_ssize_t stop = 0;
92 92 Py_ssize_t step = 0;
93 93 Py_ssize_t len = self->size();
94   - #if PY_VERSION_HEX >= 0x03020000
95   - if (PySlice_GetIndices(param, len, &start, &stop, &step) == 0) {
96   - #else
97   - if (PySlice_GetIndices((PySliceObject*)param, len, &start, &stop, &step) == 0) {
98   - #endif
  94 + if (PythonSlice_GetIndices(param, len, &start, &stop, &step) == 0) {
99 95 GGti* gti = new GGti;
100 96 if (step > 0) {
101 97 for (int i = (int)start; i < (int)stop; i += (int)step) {
... ...
pyext/GModels.i
... ... @@ -101,11 +101,7 @@ public:
101 101 Py_ssize_t stop = 0;
102 102 Py_ssize_t step = 0;
103 103 Py_ssize_t len = self->size();
104   - #if PY_VERSION_HEX >= 0x03020000
105   - if (PySlice_GetIndices(param, len, &start, &stop, &step) == 0) {
106   - #else
107   - if (PySlice_GetIndices((PySliceObject*)param, len, &start, &stop, &step) == 0) {
108   - #endif
  104 + if (PythonSlice_GetIndices(param, len, &start, &stop, &step) == 0) {
109 105 GModels* models = new GModels;
110 106 if (step > 0) {
111 107 for (int i = (int)start; i < (int)stop; i += (int)step) {
... ...
pyext/GNodeArray.i
... ... @@ -104,11 +104,7 @@ public:
104 104 Py_ssize_t stop = 0;
105 105 Py_ssize_t step = 0;
106 106 Py_ssize_t len = self->size();
107   - #if PY_VERSION_HEX >= 0x03020000
108   - if (PySlice_GetIndices(param, len, &start, &stop, &step) == 0) {
109   - #else
110   - if (PySlice_GetIndices((PySliceObject*)param, len, &start, &stop, &step) == 0) {
111   - #endif
  107 + if (PythonSlice_GetIndices(param, len, &start, &stop, &step) == 0) {
112 108 GNodeArray* nodes = new GNodeArray;
113 109 if (step > 0) {
114 110 for (int i = (int)start; i < (int)stop; i += (int)step) {
... ...
pyext/GObservations.i
... ... @@ -126,11 +126,7 @@ typedef GObservations::likelihood likelihood;
126 126 Py_ssize_t stop = 0;
127 127 Py_ssize_t step = 0;
128 128 Py_ssize_t len = self->size();
129   - #if PY_VERSION_HEX >= 0x03020000
130   - if (PySlice_GetIndices(param, len, &start, &stop, &step) == 0) {
131   - #else
132   - if (PySlice_GetIndices((PySliceObject*)param, len, &start, &stop, &step) == 0) {
133   - #endif
  129 + if (PythonSlice_GetIndices(param, len, &start, &stop, &step) == 0) {
134 130 GObservations* obs = new GObservations;
135 131 obs->models(self->models()); // Copy over model container
136 132 if (step > 0) {
... ...
pyext/GOptimizerPars.i
... ... @@ -93,11 +93,7 @@ public:
93 93 Py_ssize_t stop = 0;
94 94 Py_ssize_t step = 0;
95 95 Py_ssize_t len = self->size();
96   - #if PY_VERSION_HEX >= 0x03020000
97   - if (PySlice_GetIndices(param, len, &start, &stop, &step) == 0) {
98   - #else
99   - if (PySlice_GetIndices((PySliceObject*)param, len, &start, &stop, &step) == 0) {
100   - #endif
  96 + if (PythonSlice_GetIndices(param, len, &start, &stop, &step) == 0) {
101 97 GOptimizerPars* pars = new GOptimizerPars;
102 98 if (step > 0) {
103 99 for (int i = (int)start; i < (int)stop; i += (int)step) {
... ...
pyext/GPhases.i
... ... @@ -69,11 +69,7 @@ public:
69 69 Py_ssize_t stop = 0;
70 70 Py_ssize_t step = 0;
71 71 Py_ssize_t len = self->size();
72   - #if PY_VERSION_HEX >= 0x03020000
73   - if (PySlice_GetIndices(param, len, &start, &stop, &step) == 0) {
74   - #else
75   - if (PySlice_GetIndices((PySliceObject*)param, len, &start, &stop, &step) == 0) {
76   - #endif
  72 + if (PythonSlice_GetIndices(param, len, &start, &stop, &step) == 0) {
77 73 GPhases* phases = new GPhases;
78 74 if (step > 0) {
79 75 for (int i = (int)start; i < (int)stop; i += (int)step) {
... ...
pyext/GPhotons.i
... ... @@ -78,11 +78,7 @@ public:
78 78 Py_ssize_t stop = 0;
79 79 Py_ssize_t step = 0;
80 80 Py_ssize_t len = self->size();
81   - #if PY_VERSION_HEX >= 0x03020000
82   - if (PySlice_GetIndices(param, len, &start, &stop, &step) == 0) {
83   - #else
84   - if (PySlice_GetIndices((PySliceObject*)param, len, &start, &stop, &step) == 0) {
85   - #endif
  81 + if (PythonSlice_GetIndices(param, len, &start, &stop, &step) == 0) {
86 82 GPhotons* photons = new GPhotons;
87 83 if (step > 0) {
88 84 for (int i = (int)start; i < (int)stop; i += (int)step) {
... ...
pyext/GSkyRegions.i
... ... @@ -86,11 +86,7 @@ public:
86 86 Py_ssize_t stop = 0;
87 87 Py_ssize_t step = 0;
88 88 Py_ssize_t len = self->size();
89   - #if PY_VERSION_HEX >= 0x03020000
90   - if (PySlice_GetIndices(param, len, &start, &stop, &step) == 0) {
91   - #else
92   - if (PySlice_GetIndices((PySliceObject*)param, len, &start, &stop, &step) == 0) {
93   - #endif
  89 + if (PythonSlice_GetIndices(param, len, &start, &stop, &step) == 0) {
94 90 GSkyRegions* regions = new GSkyRegions;
95 91 if (step > 0) {
96 92 for (int i = (int)start; i < (int)stop; i += (int)step) {
... ...
pyext/GTestSuites.i
... ... @@ -91,11 +91,7 @@ public:
91 91 Py_ssize_t stop = 0;
92 92 Py_ssize_t step = 0;
93 93 Py_ssize_t len = self->size();
94   - #if PY_VERSION_HEX >= 0x03020000
95   - if (PySlice_GetIndices(param, len, &start, &stop, &step) == 0) {
96   - #else
97   - if (PySlice_GetIndices((PySliceObject*)param, len, &start, &stop, &step) == 0) {
98   - #endif
  94 + if (PythonSlice_GetIndices(param, len, &start, &stop, &step) == 0) {
99 95 GTestSuites* tests = new GTestSuites(self->name());
100 96 if (step > 0) {
101 97 for (int i = (int)start; i < (int)stop; i += (int)step) {
... ...
pyext/GTimes.i
... ... @@ -80,11 +80,7 @@ public:
80 80 Py_ssize_t stop = 0;
81 81 Py_ssize_t step = 0;
82 82 Py_ssize_t len = self->size();
83   - #if PY_VERSION_HEX >= 0x03020000
84   - if (PySlice_GetIndices(param, len, &start, &stop, &step) == 0) {
85   - #else
86   - if (PySlice_GetIndices((PySliceObject*)param, len, &start, &stop, &step) == 0) {
87   - #endif
  83 + if (PythonSlice_GetIndices(param, len, &start, &stop, &step) == 0) {
88 84 GTimes* times = new GTimes;
89 85 if (step > 0) {
90 86 for (int i = (int)start; i < (int)stop; i += (int)step) {
... ...
pyext/GXml.i
... ... @@ -92,11 +92,7 @@ public:
92 92 Py_ssize_t stop = 0;
93 93 Py_ssize_t step = 0;
94 94 Py_ssize_t len = self->size();
95   - #if PY_VERSION_HEX >= 0x03020000
96   - if (PySlice_GetIndices(param, len, &start, &stop, &step) == 0) {
97   - #else
98   - if (PySlice_GetIndices((PySliceObject*)param, len, &start, &stop, &step) == 0) {
99   - #endif
  95 + if (PythonSlice_GetIndices(param, len, &start, &stop, &step) == 0) {
100 96 GXml* xml = new GXml;
101 97 if (step > 0) {
102 98 for (int i = (int)start; i < (int)stop; i += (int)step) {
... ...
pyext/GXmlElement.i
... ... @@ -93,11 +93,7 @@ public:
93 93 Py_ssize_t stop = 0;
94 94 Py_ssize_t step = 0;
95 95 Py_ssize_t len = self->size();
96   - #if PY_VERSION_HEX >= 0x03020000
97   - if (PySlice_GetIndices(param, len, &start, &stop, &step) == 0) {
98   - #else
99   - if (PySlice_GetIndices((PySliceObject*)param, len, &start, &stop, &step) == 0) {
100   - #endif
  96 + if (PythonSlice_GetIndices(param, len, &start, &stop, &step) == 0) {
101 97 GXmlElement* element = new GXmlElement;
102 98 if (step > 0) {
103 99 for (int i = (int)start; i < (int)stop; i += (int)step) {
... ...
pyext/gammalib/app.i
1 1 /***************************************************************************
2 2 * app.i - Application module *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2011-2016 by Juergen Knoedlseder *
  4 + * copyright (C) 2011-2017 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -41,6 +41,7 @@
41 41  
42 42 /* __ Include GammaLib typemaps __________________________________________ */
43 43 %include typemap_GFilename.i
  44 +%include typemap_slices.i
44 45  
45 46 /* __ Include interface classes __________________________________________ */
46 47 %import(module="gammalib.base") "GBase.i";
... ...
pyext/gammalib/fits.i
1 1 /***************************************************************************
2 2 * fits.i - FITS module *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2011-2016 by Juergen Knoedlseder *
  4 + * copyright (C) 2011-2017 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -46,6 +46,7 @@ namespace std {
46 46  
47 47 /* __ Include GammaLib typemaps __________________________________________ */
48 48 %include typemap_GFilename.i
  49 +%include typemap_slices.i
49 50  
50 51 /* __ Include interface classes __________________________________________ */
51 52 %import(module="gammalib.base") "GBase.i";
... ...
pyext/gammalib/model.i
... ... @@ -41,6 +41,7 @@
41 41  
42 42 /* __ Include GammaLib typemaps __________________________________________ */
43 43 %include typemap_GFilename.i
  44 +%include typemap_slices.i
44 45  
45 46 /* __ Include interface classes __________________________________________ */
46 47 %import(module="gammalib.base") "GBase.i";
... ...
pyext/gammalib/obs.i
... ... @@ -41,6 +41,7 @@
41 41  
42 42 /* __ Include GammaLib typemaps __________________________________________ */
43 43 %include typemap_GFilename.i
  44 +%include typemap_slices.i
44 45  
45 46 /* __ Include interface classes __________________________________________ */
46 47 %import(module="gammalib.base") "GBase.i";
... ...
pyext/gammalib/opt.i
1 1 /***************************************************************************
2 2 * opt.i - Optimization module *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2011-2016 by Juergen Knoedlseder *
  4 + * copyright (C) 2011-2017 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -41,6 +41,7 @@
41 41  
42 42 /* __ Include GammaLib typemaps __________________________________________ */
43 43 %include typemap_GFilename.i
  44 +%include typemap_slices.i
44 45  
45 46 /* __ Include interface classes __________________________________________ */
46 47 %import(module="gammalib.base") "GBase.i";
... ...
pyext/gammalib/sky.i
1 1 /***************************************************************************
2 2 * sky.i - Sky module *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2011-2016 by Jurgen Knodlseder *
  4 + * copyright (C) 2011-2017 by Jurgen Knodlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -48,6 +48,7 @@ namespace std {
48 48  
49 49 /* __ Include GammaLib typemaps __________________________________________ */
50 50 %include typemap_GFilename.i
  51 +%include typemap_slices.i
51 52  
52 53 /* __ Include interface classes __________________________________________ */
53 54 %import(module="gammalib.base") "GBase.i";
... ...
pyext/gammalib/support.i
1 1 /***************************************************************************
2 2 * support.i - Support module *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2011-2016 by Jurgen Knodlseder *
  4 + * copyright (C) 2011-2017 by Jurgen Knodlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -45,6 +45,7 @@
45 45  
46 46 /* __ Include GammaLib typemaps __________________________________________ */
47 47 %include typemap_GFilename.i
  48 +%include typemap_slices.i
48 49  
49 50 /* __ Include interface classes __________________________________________ */
50 51 %import(module="gammalib.base") "GBase.i";
... ...
pyext/gammalib/test.i
1 1 /***************************************************************************
2 2 * test.i - Test module *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2012-2016 by Jean-Baptiste Cayrou *
  4 + * copyright (C) 2012-2017 by Jean-Baptiste Cayrou *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -41,6 +41,7 @@
41 41  
42 42 /* __ Include GammaLib typemaps __________________________________________ */
43 43 %include typemap_GFilename.i
  44 +%include typemap_slices.i
44 45  
45 46 /* __ Include interface classes __________________________________________ */
46 47 %import(module="gammalib.base") "GBase.i";
... ...
pyext/gammalib/xml.i
1 1 /***************************************************************************
2 2 * xml.i - XML module *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2011-2016 by Juergen Knoedlseder *
  4 + * copyright (C) 2011-2017 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -41,6 +41,7 @@
41 41  
42 42 /* __ Include GammaLib typemaps __________________________________________ */
43 43 %include typemap_GFilename.i
  44 +%include typemap_slices.i
44 45  
45 46 /* __ Include interface classes __________________________________________ */
46 47 %import(module="gammalib.base") "GBase.i";
... ...