[segyio] 192/376: Use signed int for offset and line numbers

Jørgen Kvalsvik jokva-guest at moszumanska.debian.org
Wed Sep 20 08:04:31 UTC 2017


This is an automated email from the git hooks/post-receive script.

jokva-guest pushed a commit to branch debian
in repository segyio.

commit b6941b235237e321e6aa9802a3d8da39128536cc
Author: Jørgen Kvalsvik <jokva at statoil.com>
Date:   Tue Feb 14 13:23:29 2017 +0100

    Use signed int for offset and line numbers
    
    These are often used in arithmetic, and have no inherent need for
    unsignedness (no wrap-around semantics). Negative values are for the
    most part nonsensical and can be detected and treated as bugs.
---
 applications/segyinspect.c | 12 +++---
 lib/include/segyio/segy.h  | 58 ++++++++++++++-------------
 lib/src/segy.c             | 92 +++++++++++++++++++++---------------------
 lib/test/segy.c            | 41 ++++++++++---------
 mex/segy_get_offsets_mex.c |  2 +-
 mex/segy_get_ps_line_mex.c |  2 +-
 mex/segyutil.c             | 24 +++++------
 mex/segyutil.h             | 22 +++++------
 python/segyio/_segyio.c    | 99 +++++++++++++++++++++++-----------------------
 python/segyio/create.py    |  4 +-
 python/segyio/open.py      |  6 +--
 python/test/segyio_c.py    | 22 +++++------
 12 files changed, 194 insertions(+), 190 deletions(-)

diff --git a/applications/segyinspect.c b/applications/segyinspect.c
index a2e7584..58615dc 100644
--- a/applications/segyinspect.c
+++ b/applications/segyinspect.c
@@ -94,14 +94,14 @@ int main(int argc, char* argv[]) {
         exit( err );
     }
 
-    unsigned int offsets;
+    int offsets;
     err = segy_offsets( fp, il_field, xl_field, traces, &offsets, trace0, trace_bsize );
     if( err != 0 ) {
         perror( "Could not determine offsets" );
         exit( err );
     }
 
-    unsigned int inline_count, crossline_count;
+    int inline_count, crossline_count;
     if( sorting == SEGY_INLINE_SORTING ) {
         err = segy_count_lines( fp, xl_field, offsets, &inline_count, &crossline_count, trace0, trace_bsize );
     } else {
@@ -114,8 +114,8 @@ int main(int argc, char* argv[]) {
         exit( err );
     }
 
-    unsigned int* inline_indices = malloc( sizeof( unsigned int ) * inline_count );
-    unsigned int* crossline_indices = malloc( sizeof( unsigned int ) * crossline_count );
+    int* inline_indices = malloc( sizeof( int ) * inline_count );
+    int* crossline_indices = malloc( sizeof( int ) * crossline_count );
 
     err = segy_inline_indices( fp, il_field, sorting, inline_count, crossline_count, offsets, inline_indices, trace0, trace_bsize );
     if( err != 0 ) {
@@ -143,14 +143,14 @@ int main(int argc, char* argv[]) {
     puts("");
     puts("Crossline indexes:");
 
-    for( unsigned int i = 0; i < crossline_count; i++ ) {
+    for( int i = 0; i < crossline_count; i++ ) {
         printf( "%d ", crossline_indices[i] );
     }
 
     puts("\n");
     puts("Inline indexes:");
 
-    for( unsigned int i = 0; i < inline_count; i++ ) {
+    for( int i = 0; i < inline_count; i++ ) {
         printf( "%d ", inline_indices[i] );
     }
 
diff --git a/lib/include/segyio/segy.h b/lib/include/segyio/segy.h
index 7e87995..b94b75f 100644
--- a/lib/include/segyio/segy.h
+++ b/lib/include/segyio/segy.h
@@ -112,7 +112,7 @@ int segy_offsets( segy_file*,
                   int il,
                   int xl,
                   int traces,
-                  unsigned int* offsets,
+                  int* offsets,
                   long trace0,
                   int trace_bsize );
 
@@ -155,8 +155,8 @@ int segy_from_native( int format,
 
 int segy_read_line( segy_file* fp,
                     int line_trace0,
-                    unsigned int line_length,
-                    unsigned int stride,
+                    int line_length,
+                    int stride,
                     int offsets,
                     float* buf,
                     long trace0,
@@ -164,8 +164,8 @@ int segy_read_line( segy_file* fp,
 
 int segy_write_line( segy_file* fp,
                     int line_trace0,
-                    unsigned int line_length,
-                    unsigned int stride,
+                    int line_length,
+                    int stride,
                     int offsets,
                     const float* buf,
                     long trace0,
@@ -185,9 +185,9 @@ int segy_write_line( segy_file* fp,
  */
 int segy_count_lines( segy_file*,
                       int field,
-                      unsigned int offsets,
-                      unsigned int* l1out,
-                      unsigned int* l2out,
+                      int offsets,
+                      int* l1out,
+                      int* l2out,
                       long trace0,
                       int trace_bsize );
 
@@ -209,13 +209,15 @@ int segy_lines_count( segy_file*,
 /*
  * Find the `line_length` for the inlines. Assumes all inlines, crosslines and
  * traces don't vary in length.
- * *
+ *
  * `inline_count` and `crossline_count` are the two values obtained with
  * `segy_count_lines`.
+ *
+ * These functions cannot fail and return the length, not an error code.
  */
-unsigned int segy_inline_length(unsigned int crossline_count);
+int segy_inline_length(int crossline_count);
 
-unsigned int segy_crossline_length(unsigned int inline_count);
+int segy_crossline_length(int inline_count);
 
 /*
  * Find the indices of the inlines and write to `buf`. `offsets` are the number
@@ -224,20 +226,20 @@ unsigned int segy_crossline_length(unsigned int inline_count);
 int segy_inline_indices( segy_file*,
                          int il,
                          int sorting,
-                         unsigned int inline_count,
-                         unsigned int crossline_count,
-                         unsigned int offsets,
-                         unsigned int* buf,
+                         int inline_count,
+                         int crossline_count,
+                         int offsets,
+                         int* buf,
                          long trace0,
                          int trace_bsize );
 
 int segy_crossline_indices( segy_file*,
                             int xl,
                             int sorting,
-                            unsigned int inline_count,
-                            unsigned int crossline_count,
-                            unsigned int offsets,
-                            unsigned int* buf,
+                            int inline_count,
+                            int crossline_count,
+                            int offsets,
+                            int* buf,
                             long trace0,
                             int trace_bsize );
 
@@ -253,24 +255,24 @@ int segy_crossline_indices( segy_file*,
  * To read/write an inline, read `line_length` starting at `traceno`,
  * incrementing `traceno` with `stride` `line_length` times.
  */
-int segy_line_trace0( unsigned int lineno,
-                      unsigned int line_length,
-                      unsigned int stride,
+int segy_line_trace0( int lineno,
+                      int line_length,
+                      int stride,
                       int offsets,
-                      const unsigned int* linenos,
-                      const unsigned int linenos_sz,
+                      const int* linenos,
+                      int linenos_sz,
                       int* traceno );
 
 /*
  * Find the stride needed for an inline/crossline traversal.
  */
 int segy_inline_stride( int sorting,
-                        unsigned int inline_count,
-                        unsigned int* stride );
+                        int inline_count,
+                        int* stride );
 
 int segy_crossline_stride( int sorting,
-                           unsigned int crossline_count,
-                           unsigned int* stride );
+                           int crossline_count,
+                           int* stride );
 
 typedef enum {
     SEGY_TR_SEQ_LINE                = 1,
diff --git a/lib/src/segy.c b/lib/src/segy.c
index a58d714..b2a7fac 100644
--- a/lib/src/segy.c
+++ b/lib/src/segy.c
@@ -824,13 +824,13 @@ int segy_offsets( segy_file* fp,
                   int il,
                   int xl,
                   int traces,
-                  unsigned int* out,
+                  int* out,
                   long trace0,
                   int trace_bsize ) {
     int err;
     int il0, il1, xl0, xl1;
     char header[ SEGY_TRACE_HEADER_SIZE ];
-    unsigned int offsets = 0;
+    int offsets = 0;
 
     if( traces == 1 ) {
         *out = 1;
@@ -890,10 +890,10 @@ int segy_offset_indices( segy_file* fp,
 
 static int segy_line_indices( segy_file* fp,
                               int field,
-                              unsigned int traceno,
-                              unsigned int stride,
-                              unsigned int num_indices,
-                              unsigned int* buf,
+                              int traceno,
+                              int stride,
+                              int num_indices,
+                              int* buf,
                               long trace0,
                               int trace_bsize ) {
 
@@ -906,7 +906,7 @@ static int segy_line_indices( segy_file* fp,
         int err = segy_traceheader( fp, traceno, header, trace0, trace_bsize );
         if( err != 0 ) return SEGY_FREAD_ERROR;
 
-        segy_get_field( header, field, (int*)buf );
+        segy_get_field( header, field, buf );
     }
 
     return SEGY_OK;
@@ -914,8 +914,8 @@ static int segy_line_indices( segy_file* fp,
 
 static int count_lines( segy_file* fp,
                         int field,
-                        unsigned int offsets,
-                        unsigned int* out,
+                        int offsets,
+                        int* out,
                         long trace0,
                         int trace_bsize ) {
 
@@ -932,8 +932,8 @@ static int count_lines( segy_file* fp,
     err = segy_get_field( header, 37, &first_offset );
     if( err != 0 ) return err;
 
-    unsigned int lines = 1;
-    unsigned int curr = offsets;
+    int lines = 1;
+    int curr = offsets;
 
     while( true ) {
         err = segy_traceheader( fp, curr, header, trace0, trace_bsize );
@@ -954,14 +954,14 @@ static int count_lines( segy_file* fp,
 
 int segy_count_lines( segy_file* fp,
                       int field,
-                      unsigned int offsets,
-                      unsigned int* l1out,
-                      unsigned int* l2out,
+                      int offsets,
+                      int* l1out,
+                      int* l2out,
                       long trace0,
                       int trace_bsize ) {
 
     int err;
-    unsigned int l2count;
+    int l2count;
     err = count_lines( fp, field, offsets, &l2count, trace0, trace_bsize );
     if( err != 0 ) return err;
 
@@ -969,8 +969,8 @@ int segy_count_lines( segy_file* fp,
     err = segy_traces( fp, &traces, trace0, trace_bsize );
     if( err != 0 ) return err;
 
-    const unsigned int line_length = l2count * offsets;
-    const unsigned int l1count = traces / line_length;
+    const int line_length = l2count * offsets;
+    const int l1count = traces / line_length;
 
     *l1out = l1count;
     *l2out = l2count;
@@ -991,7 +991,7 @@ int segy_lines_count( segy_file* fp,
     if( sorting == SEGY_UNKNOWN_SORTING ) return SEGY_INVALID_SORTING;
 
     int field;
-    unsigned int l1out, l2out;
+    int l1out, l2out;
 
     if( sorting == SEGY_INLINE_SORTING ) field = xl;
     else field = il;
@@ -1013,26 +1013,30 @@ int segy_lines_count( segy_file* fp,
     return SEGY_OK;
 }
 
-unsigned int segy_inline_length(unsigned int crossline_count) {
+/* 
+ * segy_*line_length is rather pointless as a computation, but serve a purpose
+ * as an abstraction as the detail on how exactly a length is defined is usually uninteresting
+ */
+int segy_inline_length( int crossline_count ) {
     return crossline_count;
 }
 
-unsigned int segy_crossline_length(unsigned int inline_count) {
+int segy_crossline_length( int inline_count ) {
     return inline_count;
 }
 
 int segy_inline_indices( segy_file* fp,
                          int il,
                          int sorting,
-                         unsigned int inline_count,
-                         unsigned int crossline_count,
-                         unsigned int offsets,
-                         unsigned int* buf,
+                         int inline_count,
+                         int crossline_count,
+                         int offsets,
+                         int* buf,
                          long trace0,
                          int trace_bsize) {
 
     if( sorting == SEGY_INLINE_SORTING ) {
-        unsigned int stride = crossline_count * offsets;
+        int stride = crossline_count * offsets;
         return segy_line_indices( fp, il, 0, stride, inline_count, buf, trace0, trace_bsize );
     }
 
@@ -1046,10 +1050,10 @@ int segy_inline_indices( segy_file* fp,
 int segy_crossline_indices( segy_file* fp,
                             int xl,
                             int sorting,
-                            unsigned int inline_count,
-                            unsigned int crossline_count,
-                            unsigned int offsets,
-                            unsigned int* buf,
+                            int inline_count,
+                            int crossline_count,
+                            int offsets,
+                            int* buf,
                             long trace0,
                             int trace_bsize ) {
 
@@ -1058,7 +1062,7 @@ int segy_crossline_indices( segy_file* fp,
     }
 
     if( sorting == SEGY_CROSSLINE_SORTING ) {
-        unsigned int stride = inline_count * offsets;
+        int stride = inline_count * offsets;
         return segy_line_indices( fp, xl, 0, stride, crossline_count, buf, trace0, trace_bsize );
     }
 
@@ -1183,7 +1187,7 @@ int segy_from_native( int format,
  * Returns -1 if the value cannot be found
  */
 static int index_of( int x,
-                     const unsigned int* xs,
+                     const int* xs,
                      int sz ) {
     for( int i = 0; i < sz; i++ ) {
         if( xs[i] == x )
@@ -1207,8 +1211,8 @@ static int index_of( int x,
  */
 int segy_read_line( segy_file* fp,
                     int line_trace0,
-                    unsigned int line_length,
-                    unsigned int stride,
+                    int line_length,
+                    int stride,
                     int offsets,
                     float* buf,
                     long trace0,
@@ -1241,8 +1245,8 @@ int segy_read_line( segy_file* fp,
  */
 int segy_write_line( segy_file* fp,
                      int line_trace0,
-                     unsigned int line_length,
-                     unsigned int stride,
+                     int line_length,
+                     int stride,
                      int offsets,
                      const float* buf,
                      long trace0,
@@ -1263,12 +1267,12 @@ int segy_write_line( segy_file* fp,
     return SEGY_OK;
 }
 
-int segy_line_trace0( unsigned int lineno,
-                      unsigned int line_length,
-                      unsigned int stride,
+int segy_line_trace0( int lineno,
+                      int line_length,
+                      int stride,
                       int offsets,
-                      const unsigned int* linenos,
-                      const unsigned int linenos_sz,
+                      const int* linenos,
+                      int linenos_sz,
                       int* traceno ) {
 
     int index = index_of( lineno, linenos, linenos_sz );
@@ -1283,8 +1287,8 @@ int segy_line_trace0( unsigned int lineno,
 }
 
 int segy_inline_stride( int sorting,
-                        unsigned int inline_count,
-                        unsigned int* stride ) {
+                        int inline_count,
+                        int* stride ) {
     switch( sorting ) {
         case SEGY_CROSSLINE_SORTING:
             *stride = inline_count;
@@ -1300,8 +1304,8 @@ int segy_inline_stride( int sorting,
 }
 
 int segy_crossline_stride( int sorting,
-                           unsigned int crossline_count,
-                           unsigned int* stride ) {
+                           int crossline_count,
+                           int* stride ) {
     switch( sorting ) {
         case SEGY_CROSSLINE_SORTING:
             *stride = 1;
diff --git a/lib/test/segy.c b/lib/test/segy.c
index a73410f..581d017 100644
--- a/lib/test/segy.c
+++ b/lib/test/segy.c
@@ -18,9 +18,9 @@ static void test_interpret_file() {
     char header[ SEGY_BINARY_HEADER_SIZE ];
     int sorting;
     int traces;
-    unsigned int inlines_sz, crosslines_sz;
-    unsigned int offsets, stride;
-    unsigned int line_trace0, line_length;
+    int inlines_sz, crosslines_sz;
+    int offsets, stride;
+    int line_trace0, line_length;
     const int il = SEGY_TR_INLINE;
     const int xl = SEGY_TR_CROSSLINE;
 
@@ -68,10 +68,10 @@ static void test_interpret_file() {
     assertTrue( crosslines_sz == 5, "Expected 5 crosslines." );
 
     /* Inline-specific information */
-    unsigned int inline_indices[ 5 ];
+    int inline_indices[ 5 ];
     err = segy_inline_indices( fp, il, sorting, inlines_sz, crosslines_sz, offsets, inline_indices, trace0, trace_bsize );
     assertTrue( err == 0, "Could not determine inline linenos." );
-    for( unsigned int i = 0, ref = 1; i < 5; ++i, ++ref )
+    for( int i = 0, ref = 1; i < 5; ++i, ++ref )
         assertTrue( inline_indices[ i ] == ref,
                     "Inline lineno mismatch, should be [1..5]." );
 
@@ -87,10 +87,10 @@ static void test_interpret_file() {
     assertTrue( line_length == 5, "Inline length should be 5." );
 
     /* Crossline-specific information */
-    unsigned int crossline_indices[ 5 ];
+    int crossline_indices[ 5 ];
     err = segy_crossline_indices( fp, xl, sorting, inlines_sz, crosslines_sz, offsets, crossline_indices, trace0, trace_bsize );
     assertTrue( err == 0, "Could not determine crossline linenos." );
-    for( unsigned int i = 0, ref = 20; i < 5; ++i, ++ref )
+    for( int i = 0, ref = 20; i < 5; ++i, ++ref )
         assertTrue( crossline_indices[ i ] == ref,
                     "Crossline lineno mismatch, should be [20..24]." );
 
@@ -209,10 +209,9 @@ static void testReadInLine_4(){
 
     int sorting;
     int traces;
-    unsigned int inlines_sz, crosslines_sz;
-    int offsets, line_trace0;
-    unsigned int stride;
-    unsigned int line_length;
+    int inlines_sz, crosslines_sz;
+    int offsets, stride;
+    int line_trace0, line_length;
 
     /* test specific consts */
     const int il = SEGY_TR_INLINE, xl = SEGY_TR_CROSSLINE;
@@ -226,8 +225,8 @@ static void testReadInLine_4(){
     const int trace_bsize = segy_trace_bsize( samples );
     const int format = segy_format( header );
 
-    unsigned int inline_indices[ 5 ];
-    const unsigned int inline_length = 5;
+    int inline_indices[ 5 ];
+    const int inline_length = 5;
     float* data = malloc( inline_length * samples * sizeof( float ) );
 
     int ok = 0;
@@ -285,9 +284,9 @@ static void testReadCrossLine_22(){
 
     int sorting;
     int traces;
-    unsigned int inlines_sz, crosslines_sz;
-    unsigned int offsets, stride;
-    unsigned int line_trace0, line_length;
+    int inlines_sz, crosslines_sz;
+    int offsets, stride;
+    int line_length, line_trace0;
 
     /* test specific consts */
     const int il = SEGY_TR_INLINE, xl = SEGY_TR_CROSSLINE;
@@ -301,8 +300,8 @@ static void testReadCrossLine_22(){
     const int trace_bsize = segy_trace_bsize( samples );
     const int format = segy_format( header );
 
-    unsigned int crossline_indices[ 5 ];
-    const unsigned int crossline_length = 5;
+    int crossline_indices[ 5 ];
+    const int crossline_length = 5;
     float* data = malloc( crossline_length * samples * sizeof(float) );
 
     int ok = 0;
@@ -550,7 +549,7 @@ static void test_file_error_codes() {
     err = segy_writetrace( fp, 0, NULL, 3600, 350 );
     assertTrue( err == SEGY_FSEEK_ERROR, "Could seek in invalid file." );
 
-    unsigned int l1, l2;
+    int l1, l2;
     err = segy_count_lines( fp, 0, 1, &l1, &l2, 3600, 350 );
     assertTrue( err == SEGY_FSEEK_ERROR, "Could seek in invalid file." );
 }
@@ -558,12 +557,12 @@ static void test_file_error_codes() {
 static void test_error_codes_sans_file() {
     int err;
 
-    unsigned int linenos[] = { 0, 1, 2 };
+    int linenos[] = { 0, 1, 2 };
     err = segy_line_trace0( 10, 3, 1, 1, linenos, 3, NULL );
     assertTrue( err == SEGY_MISSING_LINE_INDEX,
                 "Found line number that shouldn't exist." );
 
-    unsigned int stride;
+    int stride;
     err = segy_inline_stride( SEGY_INLINE_SORTING + 3, 10, &stride );
     assertTrue( err == SEGY_INVALID_SORTING,
                 "Expected sorting to be invalid." );
diff --git a/mex/segy_get_offsets_mex.c b/mex/segy_get_offsets_mex.c
index 00713ad..cb31908 100644
--- a/mex/segy_get_offsets_mex.c
+++ b/mex/segy_get_offsets_mex.c
@@ -43,7 +43,7 @@ void mexFunction(int nlhs, mxArray *plhs[],
     if( errc != SEGY_OK ) goto CLEANUP;
 
     int32_t* plhs0 = (int32_t*)mxGetData(plhs[0]);
-    for( unsigned int i = 0; i < spec.offset_count; ++i )
+    for( int i = 0; i < spec.offset_count; ++i )
         plhs0[i] = int_offsets[i];
 
     mxFree( int_offsets );
diff --git a/mex/segy_get_ps_line_mex.c b/mex/segy_get_ps_line_mex.c
index cafdf43..8e3b4eb 100644
--- a/mex/segy_get_ps_line_mex.c
+++ b/mex/segy_get_ps_line_mex.c
@@ -43,7 +43,7 @@ void mexFunction(int nlhs, mxArray *plhs[],
     if( err != SEGY_OK ) goto CLEANUP;
 
     int32_t* plhs0 = (int32_t*)mxGetScalar(plhs[0]);
-    for( unsigned int i = 0; i < spec.sample_count; ++i )
+    for( int i = 0; i < spec.sample_count; ++i )
         plhs0[i] = int_offsets[i];
 
     segy_close(fp);
diff --git a/mex/segyutil.c b/mex/segyutil.c
index 20b654f..cb6cff3 100644
--- a/mex/segyutil.c
+++ b/mex/segyutil.c
@@ -62,9 +62,9 @@ int segyCreateSpec(SegySpec* spec, const char* file, unsigned int inline_field,
         goto CLEANUP;
     }
 
-    unsigned int* l1;
-    unsigned int* l2;
-    unsigned int field;
+    int* l1;
+    int* l2;
+    int field;
     if (spec->trace_sorting_format == SEGY_INLINE_SORTING) {
         field = crossline_field;
         l1 = &spec->inline_count;
@@ -83,8 +83,8 @@ int segyCreateSpec(SegySpec* spec, const char* file, unsigned int inline_field,
         goto CLEANUP;
     }
 
-    spec->inline_indexes = malloc(sizeof(unsigned int) * spec->inline_count);
-    spec->crossline_indexes = malloc(sizeof(unsigned int) * spec->crossline_count);
+    spec->inline_indexes = malloc(sizeof(int) * spec->inline_count);
+    spec->crossline_indexes = malloc(sizeof(int) * spec->crossline_count);
 
     errc = segy_inline_indices(fp, inline_field, spec->trace_sorting_format,
                         spec->inline_count, spec->crossline_count, spec->offset_count, spec->inline_indexes,
@@ -143,13 +143,13 @@ static int getMaxDim(mxArray* arr){
 void recreateSpec(SegySpec *spec, const mxArray* mex_spec) {
 
     spec->filename = mxArrayToString(mxGetProperty(mex_spec, 0, "filename"));
-    spec->sample_format = (unsigned int)mxGetScalar(mxGetProperty(mex_spec, 0, "sample_format"));
-    spec->trace_sorting_format = (unsigned int)mxGetScalar(mxGetProperty(mex_spec, 0, "trace_sorting_format"));
-    spec->offset_count = (unsigned int)mxGetScalar(mxGetProperty(mex_spec, 0, "offset_count"));
-    spec->first_trace_pos = (unsigned int)mxGetScalar(mxGetProperty(mex_spec, 0, "first_trace_pos"));
-    spec->il_stride = (unsigned int)mxGetScalar(mxGetProperty(mex_spec, 0, "il_stride"));
-    spec->xl_stride = (unsigned int)mxGetScalar(mxGetProperty(mex_spec, 0, "xl_stride"));
-    spec->trace_bsize = (unsigned int)mxGetScalar(mxGetProperty(mex_spec, 0, "trace_bsize"));
+    spec->sample_format = (int)mxGetScalar(mxGetProperty(mex_spec, 0, "sample_format"));
+    spec->trace_sorting_format = (int)mxGetScalar(mxGetProperty(mex_spec, 0, "trace_sorting_format"));
+    spec->offset_count = (int)mxGetScalar(mxGetProperty(mex_spec, 0, "offset_count"));
+    spec->first_trace_pos = (int)mxGetScalar(mxGetProperty(mex_spec, 0, "first_trace_pos"));
+    spec->il_stride = (int)mxGetScalar(mxGetProperty(mex_spec, 0, "il_stride"));
+    spec->xl_stride = (int)mxGetScalar(mxGetProperty(mex_spec, 0, "xl_stride"));
+    spec->trace_bsize = (int)mxGetScalar(mxGetProperty(mex_spec, 0, "trace_bsize"));
 
     mxArray* crossline_indexes = mxGetProperty(mex_spec, 0, "crossline_indexes");
     spec->crossline_count = getMaxDim(crossline_indexes);
diff --git a/mex/segyutil.h b/mex/segyutil.h
index a2bdef0..98fe1a5 100644
--- a/mex/segyutil.h
+++ b/mex/segyutil.h
@@ -11,25 +11,25 @@
 typedef struct {
     char* filename;
 
-    unsigned int sample_format;
+    int sample_format;
 
-    unsigned int* crossline_indexes;
-    unsigned int crossline_count;
+    int* crossline_indexes;
+    int crossline_count;
 
-    unsigned int* inline_indexes;
-    unsigned int inline_count;
+    int* inline_indexes;
+    int inline_count;
 
-    unsigned int offset_count;
+    int offset_count;
 
     double* sample_indexes;
     int sample_count;
 
     int trace_sorting_format;
 
-    unsigned int il_stride;
-    unsigned int xl_stride;
-    unsigned int first_trace_pos;
-    unsigned int trace_bsize;
+    int il_stride;
+    int xl_stride;
+    long first_trace_pos;
+    int trace_bsize;
 
 } SegySpec;
 
@@ -40,7 +40,7 @@ void recreateSpec(SegySpec* spec, const mxArray* mex_spec);
 struct segy_file_format {
     int samples;
     long trace0;
-    unsigned int trace_bsize;
+    int trace_bsize;
     int traces;
     int format;
 };
diff --git a/python/segyio/_segyio.c b/python/segyio/_segyio.c
index 389a8d0..aa39749 100644
--- a/python/segyio/_segyio.c
+++ b/python/segyio/_segyio.c
@@ -283,7 +283,7 @@ static PyObject *py_write_texthdr(PyObject *self, PyObject *args) {
 }
 
 // ------------ Binary and Trace Header ------------
-static char *get_header_pointer_from_capsule(PyObject *capsule, unsigned int *length) {
+static char *get_header_pointer_from_capsule(PyObject *capsule, int *length) {
     if (PyCapsule_IsValid(capsule, "BinaryHeader=char*")) {
         if (length) {
             *length = segy_binheader_size();
@@ -308,7 +308,7 @@ static PyObject *py_get_field(PyObject *self, PyObject *args) {
 
     PyArg_ParseTuple(args, "Oi", &header_capsule, &field);
 
-    unsigned int length;
+    int length;
     char *header = get_header_pointer_from_capsule(header_capsule, &length);
 
     if (PyErr_Occurred()) { return NULL; }
@@ -336,7 +336,7 @@ static PyObject *py_set_field(PyObject *self, PyObject *args) {
 
     PyArg_ParseTuple(args, "Oii", &header_capsule, &field, &value);
 
-    unsigned int length;
+    int length;
     char *header = get_header_pointer_from_capsule(header_capsule, &length);
 
     if (PyErr_Occurred()) { return NULL; }
@@ -523,29 +523,29 @@ static PyObject *py_init_line_metrics(PyObject *self, PyObject *args) {
     errno = 0;
     SEGY_SORTING sorting;
     int trace_count;
-    unsigned int inline_count;
-    unsigned int crossline_count;
-    unsigned int offset_count;
+    int inline_count;
+    int crossline_count;
+    int offset_count;
 
-    PyArg_ParseTuple(args, "iiIII", &sorting, &trace_count, &inline_count, &crossline_count, &offset_count);
+    PyArg_ParseTuple(args, "iiiii", &sorting, &trace_count, &inline_count, &crossline_count, &offset_count);
 
-    unsigned int iline_length = segy_inline_length(crossline_count);
+    int iline_length = segy_inline_length(crossline_count);
 
-    unsigned int xline_length = segy_crossline_length(inline_count);
+    int xline_length = segy_crossline_length(inline_count);
 
-    unsigned int iline_stride;
+    int iline_stride;
     int error = segy_inline_stride(sorting, inline_count, &iline_stride);
     //Only check first call since the only error that can occur is SEGY_INVALID_SORTING
     if( error ) { return py_handle_segy_error( error, errno ); }
 
-    unsigned int xline_stride;
+    int xline_stride;
     segy_crossline_stride(sorting, crossline_count, &xline_stride);
 
     PyObject *dict = PyDict_New();
-    PyDict_SetItemString(dict, "xline_length", Py_BuildValue("I", xline_length));
-    PyDict_SetItemString(dict, "xline_stride", Py_BuildValue("I", xline_stride));
-    PyDict_SetItemString(dict, "iline_length", Py_BuildValue("I", iline_length));
-    PyDict_SetItemString(dict, "iline_stride", Py_BuildValue("I", iline_stride));
+    PyDict_SetItemString(dict, "xline_length", Py_BuildValue("i", xline_length));
+    PyDict_SetItemString(dict, "xline_stride", Py_BuildValue("i", xline_stride));
+    PyDict_SetItemString(dict, "iline_length", Py_BuildValue("i", iline_length));
+    PyDict_SetItemString(dict, "iline_stride", Py_BuildValue("i", iline_stride));
 
     return Py_BuildValue("O", dict);
 }
@@ -587,7 +587,7 @@ static PyObject *py_init_metrics(PyObject *self, PyObject *args) {
         return py_handle_segy_error(error, errno);
     }
 
-    unsigned int offset_count;
+    int offset_count;
     error = segy_offsets(p_FILE, il_field, xl_field, trace_count, &offset_count, trace0, trace_bsize);
 
     if (error != 0) {
@@ -595,10 +595,10 @@ static PyObject *py_init_metrics(PyObject *self, PyObject *args) {
     }
 
     int field;
-    unsigned int xl_count;
-    unsigned int il_count;
-    unsigned int *l1out;
-    unsigned int *l2out;
+    int xl_count;
+    int il_count;
+    int *l1out;
+    int *l2out;
 
     if (sorting == SEGY_CROSSLINE_SORTING) {
         field = il_field;
@@ -632,14 +632,14 @@ static PyObject *py_init_metrics(PyObject *self, PyObject *args) {
     PyDict_SetItemString(dict, "trace_bsize", Py_BuildValue("i", trace_bsize));
     PyDict_SetItemString(dict, "sorting", Py_BuildValue("i", sorting));
     PyDict_SetItemString(dict, "trace_count", Py_BuildValue("i", trace_count));
-    PyDict_SetItemString(dict, "offset_count", Py_BuildValue("I", offset_count));
-    PyDict_SetItemString(dict, "iline_count", Py_BuildValue("I", il_count));
-    PyDict_SetItemString(dict, "xline_count", Py_BuildValue("I", xl_count));
+    PyDict_SetItemString(dict, "offset_count", Py_BuildValue("i", offset_count));
+    PyDict_SetItemString(dict, "iline_count", Py_BuildValue("i", il_count));
+    PyDict_SetItemString(dict, "xline_count", Py_BuildValue("i", xl_count));
 
     return Py_BuildValue("O", dict);
 }
 
-static Py_buffer check_and_get_buffer(PyObject *object, const char *name, unsigned int expected, const char* fmt) {
+static Py_buffer check_and_get_buffer(PyObject *object, const char *name, unsigned int expected) {
     static const Py_buffer zero_buffer;
     Py_buffer buffer = zero_buffer;
     if (!PyObject_CheckBuffer(object)) {
@@ -648,14 +648,13 @@ static Py_buffer check_and_get_buffer(PyObject *object, const char *name, unsign
     }
     PyObject_GetBuffer(object, &buffer, PyBUF_FORMAT | PyBUF_C_CONTIGUOUS | PyBUF_WRITEABLE);
 
-    if (strcmp(buffer.format, fmt) != 0) {
-        const char* target = strcmp(fmt, "I") == 0 ? "uintc" : "intc";
-        PyErr_Format(PyExc_TypeError, "The destination for %s is not a buffer object of type '%s'", name, target);
+    if (strcmp(buffer.format, "i") != 0) {
+        PyErr_Format(PyExc_TypeError, "The destination for %s is not a buffer object of type 'intc'", name);
         PyBuffer_Release(&buffer);
         return buffer;
     }
 
-    size_t buffer_len = buffer.len;
+    size_t buffer_len = (size_t)buffer.len;
     if (buffer_len < expected * sizeof(unsigned int)) {
         PyErr_Format(PyExc_ValueError, "The destination for %s is too small. ", name);
         PyBuffer_Release(&buffer);
@@ -686,27 +685,27 @@ static PyObject *py_init_indices(PyObject *self, PyObject *args) {
         return NULL;
     }
 
-    unsigned int iline_count;
-    unsigned int xline_count;
-    unsigned int offset_count;
-    PyArg_Parse(PyDict_GetItemString(metrics, "iline_count"), "I", &iline_count);
-    PyArg_Parse(PyDict_GetItemString(metrics, "xline_count"), "I", &xline_count);
-    PyArg_Parse(PyDict_GetItemString(metrics, "offset_count"), "I", &offset_count);
+    int iline_count;
+    int xline_count;
+    int offset_count;
+    PyArg_Parse(PyDict_GetItemString(metrics, "iline_count"), "i", &iline_count);
+    PyArg_Parse(PyDict_GetItemString(metrics, "xline_count"), "i", &xline_count);
+    PyArg_Parse(PyDict_GetItemString(metrics, "offset_count"), "i", &offset_count);
 
     if (PyErr_Occurred()) { return NULL; }
 
-    Py_buffer iline_buffer = check_and_get_buffer(iline_out, "inline", iline_count, "I");
+    Py_buffer iline_buffer = check_and_get_buffer(iline_out, "inline", iline_count);
 
     if (PyErr_Occurred()) { return NULL; }
 
-    Py_buffer xline_buffer = check_and_get_buffer(xline_out, "crossline", xline_count, "I");
+    Py_buffer xline_buffer = check_and_get_buffer(xline_out, "crossline", xline_count);
 
     if (PyErr_Occurred()) {
         PyBuffer_Release(&iline_buffer);
         return NULL;
     }
 
-    Py_buffer offsets_buffer = check_and_get_buffer(offset_out, "offsets", offset_count, "i");
+    Py_buffer offsets_buffer = check_and_get_buffer(offset_out, "offsets", offset_count);
 
     if (PyErr_Occurred()) {
         PyBuffer_Release(&iline_buffer);
@@ -759,14 +758,14 @@ static PyObject *py_init_indices(PyObject *self, PyObject *args) {
 
 static PyObject *py_fread_trace0(PyObject *self, PyObject *args) {
     errno = 0;
-    unsigned int lineno;
-    unsigned int other_line_length;
-    unsigned int stride;
+    int lineno;
+    int other_line_length;
+    int stride;
     int offsets;
     PyObject *indices_object;
     char *type_name;
 
-    PyArg_ParseTuple(args, "IIIiOs", &lineno, &other_line_length, &stride, &offsets, &indices_object, &type_name);
+    PyArg_ParseTuple(args, "iiiiOs", &lineno, &other_line_length, &stride, &offsets, &indices_object, &type_name);
 
     Py_buffer buffer;
     if (!PyObject_CheckBuffer(indices_object)) {
@@ -776,7 +775,7 @@ static PyObject *py_fread_trace0(PyObject *self, PyObject *args) {
     PyObject_GetBuffer(indices_object, &buffer, PyBUF_FORMAT | PyBUF_C_CONTIGUOUS);
 
     int trace_no;
-    unsigned int linenos_sz = (unsigned int) PyObject_Length(indices_object);
+    int linenos_sz = PyObject_Length(indices_object);
     int error = segy_line_trace0(lineno, other_line_length, stride, offsets, buffer.buf, linenos_sz, &trace_no);
     PyBuffer_Release( &buffer );
 
@@ -796,9 +795,9 @@ static PyObject *py_read_trace(PyObject *self, PyObject *args) {
     long trace0;
     int trace_bsize;
     int format;
-    unsigned int samples;
+    int samples;
 
-    PyArg_ParseTuple(args, "OOiOlIiI", &file_capsule, &trace_no, &trace_count, &buffer_out, &trace0, &trace_bsize, &format, &samples);
+    PyArg_ParseTuple(args, "OOiOliii", &file_capsule, &trace_no, &trace_count, &buffer_out, &trace0, &trace_bsize, &format, &samples);
 
     segy_file *p_FILE = get_FILE_pointer_from_capsule(file_capsule);
 
@@ -871,9 +870,9 @@ static PyObject *py_write_trace(PyObject *self, PyObject *args) {
     long trace0;
     int trace_bsize;
     int format;
-    unsigned int samples;
+    int samples;
 
-    PyArg_ParseTuple(args, "OiOlIiI", &file_capsule, &trace_no, &buffer_in, &trace0, &trace_bsize, &format, &samples);
+    PyArg_ParseTuple(args, "OiOliii", &file_capsule, &trace_no, &buffer_in, &trace0, &trace_bsize, &format, &samples);
 
     segy_file *p_FILE = get_FILE_pointer_from_capsule(file_capsule);
 
@@ -913,16 +912,16 @@ static PyObject *py_read_line(PyObject *self, PyObject *args) {
     errno = 0;
     PyObject *file_capsule = NULL;
     int line_trace0;
-    unsigned int line_length;
-    unsigned int stride;
+    int line_length;
+    int stride;
     int offsets;
     PyObject *buffer_in;
     long trace0;
     int trace_bsize;
     int format;
-    unsigned int samples;
+    int samples;
 
-    PyArg_ParseTuple(args, "OiIIiOlIiI", &file_capsule,
+    PyArg_ParseTuple(args, "OiiiiOliii", &file_capsule,
                                          &line_trace0,
                                          &line_length, &stride, &offsets,
                                          &buffer_in,
diff --git a/python/segyio/create.py b/python/segyio/create.py
index 29a5a67..edd0840 100644
--- a/python/segyio/create.py
+++ b/python/segyio/create.py
@@ -82,10 +82,10 @@ def create(filename, spec):
     f._tracecount    = len(spec.ilines) * len(spec.xlines) * len(spec.offsets)
 
     f._il            = int(spec.iline)
-    f._ilines        = numpy.copy(numpy.asarray(spec.ilines, dtype=numpy.uintc))
+    f._ilines        = numpy.copy(numpy.asarray(spec.ilines, dtype=numpy.intc))
 
     f._xl            = int(spec.xline)
-    f._xlines        = numpy.copy(numpy.asarray(spec.xlines, dtype=numpy.uintc))
+    f._xlines        = numpy.copy(numpy.asarray(spec.xlines, dtype=numpy.intc))
 
     line_metrics = _segyio.init_line_metrics(f.sorting, f.tracecount, len(f.ilines), len(f.xlines), len(f.offsets))
 
diff --git a/python/segyio/open.py b/python/segyio/open.py
index 1f8d5cf..0871ce0 100644
--- a/python/segyio/open.py
+++ b/python/segyio/open.py
@@ -67,9 +67,9 @@ def open(filename, mode="r", iline=189, xline=193):
         line_metrics = segyio._segyio.init_line_metrics(f.sorting, f.tracecount,
                                                         iline_count, xline_count, offset_count)
 
-        f._ilines  = numpy.zeros(iline_count, dtype=numpy.uintc)
-        f._xlines  = numpy.zeros(xline_count, dtype=numpy.uintc)
-        f._offsets = numpy.zeros(offset_count, dtype = numpy.uintc)
+        f._ilines  = numpy.zeros(iline_count, dtype=numpy.intc)
+        f._xlines  = numpy.zeros(xline_count, dtype=numpy.intc)
+        f._offsets = numpy.zeros(offset_count, dtype = numpy.intc)
         segyio._segyio.init_indices(f.xfd, metrics, f.ilines, f.xlines, f.offsets)
 
         f._iline_length = line_metrics['iline_length']
diff --git a/python/test/segyio_c.py b/python/test/segyio_c.py
index e4ba307..a573586 100644
--- a/python/test/segyio_c.py
+++ b/python/test/segyio_c.py
@@ -196,7 +196,7 @@ class _segyioTests(TestCase):
         ilb = 189
         xlb = 193
         metrics = _segyio.init_metrics(f, binary_header, ilb, xlb)
-        dmy = numpy.zeros(2, dtype=numpy.uintc)
+        dmy = numpy.zeros(2, dtype=numpy.intc)
 
         dummy_metrics = {'xline_count':   2,
                          'iline_count':   2,
@@ -224,9 +224,9 @@ class _segyioTests(TestCase):
             fdmy = numpy.zeros(1, dtype=numpy.single)
             _segyio.init_indices(f, dummy_metrics, fdmy, dmy, dmy)
 
-        one = numpy.zeros(1, dtype=numpy.uintc)
-        two = numpy.zeros(2, dtype=numpy.uintc)
-        off = numpy.zeros(1, dtype=numpy.uintc)
+        one = numpy.zeros(1, dtype=numpy.intc)
+        two = numpy.zeros(2, dtype=numpy.intc)
+        off = numpy.zeros(1, dtype=numpy.intc)
         with self.assertRaises(ValueError):
             _segyio.init_indices(f, dummy_metrics, one, two, off)
 
@@ -234,8 +234,8 @@ class _segyioTests(TestCase):
             _segyio.init_indices(f, dummy_metrics, two, one, off)
 
         # Happy Path
-        iline_indexes = numpy.zeros(metrics['iline_count'], dtype=numpy.uintc)
-        xline_indexes = numpy.zeros(metrics['xline_count'], dtype=numpy.uintc)
+        iline_indexes = numpy.zeros(metrics['iline_count'], dtype=numpy.intc)
+        xline_indexes = numpy.zeros(metrics['xline_count'], dtype=numpy.intc)
         offsets       = numpy.zeros(metrics['offset_count'], dtype=numpy.intc)
         _segyio.init_indices(f, metrics, iline_indexes, xline_indexes, offsets)
 
@@ -262,8 +262,8 @@ class _segyioTests(TestCase):
 
         line_metrics = _segyio.init_line_metrics(sorting, trace_count, inline_count, crossline_count, offset_count)
 
-        iline_indexes = numpy.zeros(metrics['iline_count'], dtype=numpy.uintc)
-        xline_indexes = numpy.zeros(metrics['xline_count'], dtype=numpy.uintc)
+        iline_indexes = numpy.zeros(metrics['iline_count'], dtype=numpy.intc)
+        xline_indexes = numpy.zeros(metrics['xline_count'], dtype=numpy.intc)
         offsets       = numpy.zeros(metrics['offset_count'], dtype=numpy.intc)
         _segyio.init_indices(f, metrics, iline_indexes, xline_indexes, offsets)
 
@@ -396,8 +396,8 @@ class _segyioTests(TestCase):
 
         metrics.update(line_metrics)
 
-        iline_indexes = numpy.zeros(metrics['iline_count'], dtype=numpy.uintc)
-        xline_indexes = numpy.zeros(metrics['xline_count'], dtype=numpy.uintc)
+        iline_indexes = numpy.zeros(metrics['iline_count'], dtype=numpy.intc)
+        xline_indexes = numpy.zeros(metrics['xline_count'], dtype=numpy.intc)
         offsets       = numpy.zeros(metrics['offset_count'], dtype=numpy.intc)
         _segyio.init_indices(f, metrics, iline_indexes, xline_indexes, offsets)
 
@@ -451,7 +451,7 @@ class _segyioTests(TestCase):
 
     def test_fread_trace0_for_depth(self):
         elements = list(range(25))
-        indices = numpy.asarray(elements, dtype=numpy.uintc)
+        indices = numpy.asarray(elements, dtype=numpy.intc)
 
         for index in indices:
             d = _segyio.fread_trace0(index, 1, 1, 1, indices, "depth")

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/segyio.git



More information about the debian-science-commits mailing list