From fd363c300c1767681ac6b03f05132d9e6d8a6884 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 19 Jan 2024 12:59:47 +0100 Subject: Fix incorrect uses of cell_free This also gets rid of crystal_copy_deep. From now on, all crystal_copy calls also copy the UnitCell. --- libcrystfel/src/crystal.c | 28 ++-------------------------- libcrystfel/src/crystal.h | 1 - libcrystfel/src/image.c | 6 +----- libcrystfel/src/index.c | 1 - libcrystfel/src/indexers/fromfile.c | 2 +- 5 files changed, 4 insertions(+), 34 deletions(-) (limited to 'libcrystfel/src') diff --git a/libcrystfel/src/crystal.c b/libcrystfel/src/crystal.c index a21283f9..f0022fcc 100644 --- a/libcrystfel/src/crystal.c +++ b/libcrystfel/src/crystal.c @@ -88,41 +88,17 @@ Crystal *crystal_new() } -/** - * \param cryst: A \ref Crystal to copy. - * - * Creates a new \ref Crystal which is a copy of \p cryst. The copy is a "shallow - * copy", which means that copies are NOT made of the data structures which - * \p cryst contains references to, for example its \ref RefList. - * - * \returns A (shallow) copy of \p cryst, or NULL on failure. - * - */ -Crystal *crystal_copy(const Crystal *cryst) -{ - Crystal *c; - - c = crystal_new(); - if ( c == NULL ) return NULL; - - memcpy(c, cryst, sizeof(Crystal)); - if ( c->notes != NULL ) c->notes = cfstrdup(c->notes); - - return c; -} - - /** * \param cryst: A \ref Crystal to copy. * * Creates a new \ref Crystal which is a copy of \p cryst. The copy is a "deep * copy", which means that copies ARE made of the data structures which - * \p cryst contains references to, for example its \ref RefList. + * \p cryst contains references to, for example its \ref UnitCell. * * \returns A (deep) copy of \p cryst, or NULL on failure. * */ -Crystal *crystal_copy_deep(const Crystal *cryst) +Crystal *crystal_copy(const Crystal *cryst) { Crystal *c; diff --git a/libcrystfel/src/crystal.h b/libcrystfel/src/crystal.h index 3f19386c..7147111f 100644 --- a/libcrystfel/src/crystal.h +++ b/libcrystfel/src/crystal.h @@ -49,7 +49,6 @@ extern "C" { extern Crystal *crystal_new(void); extern Crystal *crystal_copy(const Crystal *cryst); -extern Crystal *crystal_copy_deep(const Crystal *cryst); extern void crystal_free(Crystal *cryst); extern UnitCell *crystal_get_cell(Crystal *cryst); diff --git a/libcrystfel/src/image.c b/libcrystfel/src/image.c index 142598e3..3b4e04df 100644 --- a/libcrystfel/src/image.c +++ b/libcrystfel/src/image.c @@ -352,9 +352,7 @@ int remove_flagged_crystals(struct image *image) for ( i=0; in_crystals; i++ ) { if ( crystal_get_user_flag(image->crystals[i].cr) ) { int j; - Crystal *deleteme = image->crystals[i].cr; - cell_free(crystal_get_cell(deleteme)); - crystal_free(deleteme); + crystal_free(image->crystals[i].cr); reflist_free(image->crystals[i].refls); for ( j=i; jn_crystals-1; j++ ) { image->crystals[j] = image->crystals[j+1]; @@ -375,8 +373,6 @@ void free_all_crystals(struct image *image) int i; if ( image->crystals == NULL ) return; for ( i=0; in_crystals; i++ ) { - Crystal *cr = image->crystals[i].cr; - cell_free(crystal_get_cell(cr)); crystal_free(image->crystals[i].cr); reflist_free(image->crystals[i].refls); } diff --git a/libcrystfel/src/index.c b/libcrystfel/src/index.c index 7aea3b59..2a2542f5 100644 --- a/libcrystfel/src/index.c +++ b/libcrystfel/src/index.c @@ -552,7 +552,6 @@ static int check_cell(IndexingFlags flags, Crystal *cr, UnitCell *target, if ( out != NULL ) { /* Replace crystal's cell with new one */ - cell_free(crystal_get_cell(cr)); crystal_set_cell(cr, out); rtnl_mtx_free(rm); if ( !right_handed(out) ) STATUS("WARNING: left handed\n"); diff --git a/libcrystfel/src/indexers/fromfile.c b/libcrystfel/src/indexers/fromfile.c index c7f1d1ba..30305b21 100644 --- a/libcrystfel/src/indexers/fromfile.c +++ b/libcrystfel/src/indexers/fromfile.c @@ -337,7 +337,7 @@ int fromfile_index(struct image *image, void *mpriv) for ( i=0; in_crystals; i++ ) { Crystal *cr; - cr = crystal_copy_deep(p->crystals[i]); + cr = crystal_copy(p->crystals[i]); image_add_crystal(image, cr); } -- cgit v1.2.3