Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Update QhullUser.cpp#68

Closed
stephanmg wants to merge 1 commit into
qhull:masterfrom
stephanmg:patch-2
Closed

Update QhullUser.cpp#68
stephanmg wants to merge 1 commit into
qhull:masterfrom
stephanmg:patch-2

Conversation

@stephanmg
Copy link
Copy Markdown
Contributor

Getting rid of uintptr_t to make the code C++98 compatible.

Getting rid of uintptr_t to make the code C++98 compatible.
@SpaceIm
Copy link
Copy Markdown
Contributor

SpaceIm commented Jul 17, 2020

This modification fails on Visual Studio with QhullUser.cpp(101,170): error C2440: '<function-style-cast>': cannot convert from 'initializer list' to 'orgQhull::QhullError'. It very likely fails with all compilers.

Anyway, behind compilation issue, there is something fondamentaly wrong trying to cast a pointer to int.

}
if(qh()->cpp_user!=this){
throw QhullError(10081, "Qhull error: conflicting QhullUser (0x%llx) for QhullUser::captureOff(). Does not match 'this' (0x...%X)", int((uintptr_t)this), 0, 0.0, qh()->cpp_user);
throw QhullError(10081, "Qhull error: conflicting QhullUser (0x%llx) for QhullUser::captureOff(). Does not match 'this' (0x...%X)", this, 0, 0.0, qh()->cpp_user);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw QhullError(10081, "Qhull error: conflicting QhullUser (0x%llx) for QhullUser::captureOff(). Does not match 'this' (0x...%X)", this, 0, 0.0, qh()->cpp_user);
throw QhullError(10081, "Qhull error: conflicting QhullUser (0x%llx) for QhullUser::captureOff(). Does not match 'this' (0x...%X)", *(int *)this, 0, 0.0, qh()->cpp_user);

@SpaceIm
Copy link
Copy Markdown
Contributor

SpaceIm commented Jul 17, 2020

There is also C++11 in QhullUser.h

Fix:

--- a/src/libqhullcpp/QhullUser.h
+++ b/src/libqhullcpp/QhullUser.h
@@ -36,8 +36,8 @@ namespace orgQhull{
 #//!\name Fields
         QhullQh *       qh_qh;          //!< QhullQh/qhT for access to libqhull_r
         void *          previous_user;  //!< previous qh.cpp_user, restored on deconstruction
-        std::vector< std::vector< double>> doubles_vector;  //! vectors for capturing ints and doubles
-        std::vector< std::vector< int>> ints_vector;
+        std::vector< std::vector< double> > doubles_vector;  //! vectors for capturing ints and doubles
+        std::vector< std::vector< int> > ints_vector;
         std::vector< int>               fprintf_ints;
         std::vector< double>            fprintf_doubles;
         std::vector< int>               fprintf_codes;
@@ -77,11 +77,11 @@ namespace orgQhull{
         void            clearIntsVector() { ints_vector.clear(); }
         const std::vector< int> &codes() const { return fprintf_codes; }
         int             delaunayDim() const { return delaunay_dim; }
-        const std::vector< std::vector< double>> &doublesVector() const { return doubles_vector; }
+        const std::vector< std::vector< double> > &doublesVector() const { return doubles_vector; }
         const std::vector< double> &doubles() const { return fprintf_doubles; }
         int             firstCode() const { return (fprintf_codes.size() == 0 ? -1 : fprintf_codes[0]); }
         const std::vector< int> &ints() const { return fprintf_ints; }
-        const std::vector< std::vector< int>> &intsVector() const { return ints_vector; }
+        const std::vector< std::vector< int> > &intsVector() const { return ints_vector; }
         int             numDoubles() const { return (int)doubles_vector.size();  }
         int             numFacets() const { return num_facets; }
         int             numInts() const { return (int)ints_vector.size(); }

and also range for loop to replace in src/user_eg3/user_eg3_r.cpp

@cbbarber
Copy link
Copy Markdown
Collaborator

The third argument to QhullError should be the low order bits of 'this' to aid in debugging the reported error. '__intptr_t' would allow the cast to int. It was suggested in #65
note: suggested alternative: ‘__intptr_t’

Thanks for fixing the other C++11 issues.

@cbbarber
Copy link
Copy Markdown
Collaborator

cbbarber commented Aug 5, 2020

Fixed in Qhull 8.0.1. Many thanks for reporting these problems.

@cbbarber cbbarber closed this Aug 5, 2020
cbbarber added a commit that referenced this pull request Aug 5, 2020
- Removed Java-style iterators for Coordinates and PointCoordinates.
  std::vector has an expensive copy constructor and copy assignment.
  A pointer to std::vector is vulnerable to mysterious overwrites (e.g., deleting
  a returned value and reusing its memory).  Qt's 'foreach' should not be used for
  Coordinates and PointCoordinates.  It copies std::vector.
- QHULL_DECLARE_SEQUENTIAL_ITERATOR: allow temporary results
  The Jave-style iterator copies the container.  Same as Qt's Q_DECLARE_SEQUENTIAL_ITERATOR
- QhullHyperplaneIterator,QhullPointIterator,QhullPointsIterator: allow temporary results
  These Java-style iterators copy the container instead of pointing to the container
- QhullLinkedListIterator,QhullFacetListIterator,QhullVertexListIterator: allow temporary results
  These Java-style iterators copy the container instead of pointing to the container
- QhullSetIterator,QhullFacetSetIterator,QhullPointSetIterator,QhullVertexSetIterator: add documentation about temporary results
  These Java-style iterators have always copied the container
- QhullUser.h, user_eg3_r.cpp: Removed C++11 dependencies [S. Grein #66,#67]
  QhullUser.cpp: Use intptr_t to avoid C++11 dependencies  [S. Grein, Spacelm #68]
- QhullVertex.cpp: moved the copy constructor to the code file.  It was inline.

Testing and example programs
- user_eg3_r.cpp: Renamed 'inputSites' to 'voronoiRegions' in qvoronoi_o/qvoronoi_pfn [M. Konecny #72]
- user_eg3_r.cpp: Replaced C++11's range-based for loops with Qhull's Java-style iterators
- qh-code.html: Updated qhullcpp code example [M. Konecny #71]
- QhullFacet_test.cpp: fixed hyperplane epsilon test in t_getSet. The epsilon due to rotation is unknown.
- Qhull*List_test.cpp,Qhull*Set_test.cpp,QhullRidge_test,QhullVertex_test: test Qt's 'foreach' in t_foreach
- Qhull*List_test.cpp,Qhull*Set_test.cpp,QhullRidge_test,QhullVertex_test: test C++11 range for in t_foreach
- Qhull*List_test.cpp,Qhull*Set_test.cpp: test Java-style iterator in t_java_iterator
- Coordinates_test.cpp,PointCoordinates_test.cpp,QhullHyperplane_test.cpp,QhullPoint_test.cpp,QhullPoints_test.cpp,RboxPoints_test.cpp
  test C++11 range for, Qt's 'foreach', and Java-style iterators (if available)

Builds
- README.txt: Fixed "cmake -G" for "Installing Qhull with CMake"
- README.txt: Added a note on 'make install' to "Installing Qhull on Unix"
- README.txt: Added 'make test' to "Installing Qhull on Unix"
- README.txt: Added 'ctest' to "Installing Qhull with CMake"
- README.txt: Added pkg-config notes to "Installing Qhull with CMake"
- README.txt: Added usage notes for Windows to "Installing Qhull with CMake"
- README.txt: Added instructions for downloading MinGW-W64-install.exe
- build/qhull_p.pc.in,qhull_r.pc.in: Delete obsolete files [T. Roehling #63]
- build/qhull.pc.in: move qhull.pc.in into the build/ directory [T. Roehling #63]

Documentation
- qh-code.htm, qhull-news.html: Add Toronto and McCarthy, "Practically accurate floating-point math".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants