[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master c62b01e 031/125: Corrected incrementation issu
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master c62b01e 031/125: Corrected incrementation issue with and and or operators |
Date: |
Sun, 23 Apr 2017 22:36:31 -0400 (EDT) |
branch: master
commit c62b01e539f5ad2f19bc425b35eaf9188aed2c88
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>
Corrected incrementation issue with and and or operators
The `&&' and `||' operators will not necessarily read their second
operand. So the default `BINARY_OP_OT_RT_LT_SET' wouldn't read the second
array sometimes and this caused unsynchronized incrementations. So with
this commit we have a new `BINARY_OP_INCR_OT_RT_LT_SET' macro specially for
these types of operators. In this new macro, the second operand is
incremented in a a separate expression.
Also, the freeing of the keys linked list after reading keywords in
`gal_fits_read_img_hdu' was moved after `gal_data_alloc' so the values are
freed. In the old way, the two strings were left unfreed until the end of
the program, because they were artificially set to NULL (mistakenly
assuming that we won't need to copy them, while `gal_data_alloc' copies
them).
---
lib/data-arithmetic-binary.c | 18 ++++++++++++++++--
lib/fits.c | 15 ++++++++-------
2 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/lib/data-arithmetic-binary.c b/lib/data-arithmetic-binary.c
index 1bd24e7..4accfd1 100644
--- a/lib/data-arithmetic-binary.c
+++ b/lib/data-arithmetic-binary.c
@@ -265,6 +265,20 @@ along with Gnuastro. If not, see
<http://www.gnu.org/licenses/>.
+/* This is for operators like `&&' and `||', where the right operator is
+ not necessarily read (and thus incremented) incremented. */
+#define BINARY_OP_INCR_OT_RT_LT_SET(OP, OT, RT, LT) { \
+ LT *la=l->array; \
+ RT *ra=r->array; \
+ OT *oa=o->array, *of=oa + o->size; \
+ if(l->size==r->size) do {*oa = *la++ OP *ra; ++ra;} while(++oa<of); \
+ else if(l->size==1) do {*oa = *la OP *ra; ++ra;} while(++oa<of); \
+ else do *oa = *la++ OP *ra; while(++oa<of); \
+ }
+
+
+
+
/* For operators whose type may be any of the given inputs. */
#define BINARY_OP_RT_LT_SET(OP, RT, LT) \
@@ -312,10 +326,10 @@ along with Gnuastro. If not, see
<http://www.gnu.org/licenses/>.
BINARY_OP_OT_RT_LT_SET(!=, unsigned char, RT, LT); \
break; \
case GAL_DATA_OPERATOR_AND: \
- BINARY_OP_OT_RT_LT_SET(&&, unsigned char, RT, LT); \
+ BINARY_OP_INCR_OT_RT_LT_SET(&&, unsigned char, RT, LT); \
break; \
case GAL_DATA_OPERATOR_OR: \
- BINARY_OP_OT_RT_LT_SET(||, unsigned char, RT, LT); \
+ BINARY_OP_INCR_OT_RT_LT_SET(||, unsigned char, RT, LT); \
break; \
default: \
error(EXIT_FAILURE, 0, "operator code %d not recognized in " \
diff --git a/lib/fits.c b/lib/fits.c
index 96f60e6..44b4cd8 100644
--- a/lib/fits.c
+++ b/lib/fits.c
@@ -1275,23 +1275,24 @@ gal_fits_read_img_hdu(char *filename, char *hdu, char
*maskname,
/* Read the possibly existing useful keywords. Note that the values are
- in allocated strings in the keys[i] data structures. We don't want to
- allocated them again, so we will just copy the pointers within the
- `img' data structure and set the original value to NULL so it isn't
- freed. */
+ in allocated strings in the keys[i] data structures. Note that we need
+ the linked list of keys to keep the `name' and `unit' pointers. We can
+ free the linked list after `gal_data_alloc' has read/copied the
+ values.*/
gal_data_add_to_ll(&keysll, NULL, GAL_DATA_TYPE_STRING, 1, &dsize_key,
NULL, 0, -1, "EXTNAME", NULL, NULL);
gal_data_add_to_ll(&keysll, NULL, GAL_DATA_TYPE_STRING, 1, &dsize_key,
NULL, 0, -1, "BUNIT", NULL, NULL);
gal_fits_read_keywords_fptr(fptr, keysll, 0, 0);
- if(keysll->status==0) {str=keysll->array; unit=*str; *str=NULL;}
- if(keysll->next->status==0) {str=keysll->next->array; name=*str; *str=NULL;}
- gal_data_free_ll(keysll);
+ if(keysll->status==0) {str=keysll->array; unit=*str; }
+ if(keysll->next->status==0) {str=keysll->next->array; name=*str; }
+
/* Allocate the space for the array and for the blank values. */
img=gal_data_alloc(NULL, type, (long)ndim, dsize, NULL, 0, minmapsize,
name, unit, NULL);
blank=gal_data_alloc_blank(type);
+ gal_data_free_ll(keysll);
free(dsize);
- [gnuastro-commits] master c2fcb3e 020/125: Absolute value operator in gal_data_arithmetic, (continued)
- [gnuastro-commits] master c2fcb3e 020/125: Absolute value operator in gal_data_arithmetic, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master fdb6183 019/125: Where operator implemented in gal_data_arithmetic, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 493bc6f 001/125: Defined new gnuastro/data.h header, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master c6462d1 016/125: Type conversion operators in Arithmetic, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master c10c4be 002/125: Moved type code and alloc functions into data.h, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master a4c5b9d 012/125: Binary operator arithmetic works on uncompiled types, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master ad2810d 029/125: Work started on getting text table information, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master bc57ade 021/125: Minimum and maximum value operators implemented, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 2dea9a7 011/125: All binary operator types set at configure time, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master ff0b76d 018/125: New Data types section in book, bitwise not added, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master c62b01e 031/125: Corrected incrementation issue with and and or operators,
Mohammad Akhlaghi <=
- [gnuastro-commits] master 0a32a82 027/125: Any number of searched columns from FITS are read, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master d0aa78e 005/125: Arithmetic operation on data structures in library, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 0ad0906 014/125: Bitwise operators available in arithmetic operations, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 3ad83a4 010/125: data-arithmetic and data-copy separated from data.c, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 6c6382a 013/125: Use of function instead of macros for binary operators, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master ce73959 030/125: Reading FITS keywords into linked list not array, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master e0e8679 017/125: Removed `anyblank' from datastructure, several new operators, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 6d68470 033/125: Column info format for writing ASCII tables, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 0fd75fe 040/125: With no columns, Table program will print all columns, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 8090e6d 038/125: Corrections to FITS table reading, Mohammad Akhlaghi, 2017/04/23