Author: wyoung
Date: Wed Nov 28 03:57:03 2007
New Revision: 1899

URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1899&view=rev
Log:
No longer possible to do a delayed initialization of ResUse's internal
FieldNames and FieldTypes objects: whatever value they get on object
creation, that's what they keep.  No change to test suite results, but
it's possible that end user code is abusing the library in some way, and
current weirdness in the way ResUse handles copy construction and
assignment may be the "cure" to this abuse.  Next up: fix the weirdness
to make this unnecessary.

Modified:
    trunk/Wishlist
    trunk/lib/result.cpp
    trunk/lib/result.h

Modified: trunk/Wishlist
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/Wishlist?rev=1899&r1=1898&r2=1899&view=diff
==============================================================================
--- trunk/Wishlist (original)
+++ trunk/Wishlist Wed Nov 28 03:57:03 2007
@@ -22,13 +22,6 @@
 
     o Classes Connection, Query, String, Result and Row all have
       operator bool() as well.  Use "safe bool" here too, as needed.
-
-    o Allocation of RefCountedPointers in places like ResUse::field_*()
-      isn't thread safe.  If possible, just allocate these things on
-      ResUse/Result object creation.  If they really do need delayed
-      creation, put this test-and-allocate stuff in an accessor,
-      and guard this function with a mutex.  Otherwise, there's a
-      risk of double-allocation.
 
     o Apply Jonathan Wakely's patch to RefCountedPointer.
 

Modified: trunk/lib/result.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/result.cpp?rev=1899&r1=1898&r2=1899&view=diff
==============================================================================
--- trunk/lib/result.cpp (original)
+++ trunk/lib/result.cpp Wed Nov 28 03:57:03 2007
@@ -30,15 +30,15 @@
 
 ResUse::ResUse(MYSQL_RES* result, bool te) :
 OptionalExceptions(te),
+result_(0),
 initialized_(false),
 types_(0),
 fields_(this)
 {
-       if ((result_ = result) != 0) {
+       if (result) {
+               result_ = result;
                names_ = new FieldNames(this);
-               if (names_) {
-                       types_ = new FieldTypes(this);
-               }
+               types_ = new FieldTypes(this);
                initialized_ = true;
        }
 }
@@ -85,56 +85,12 @@
 int
 ResUse::field_num(const std::string& i) const
 {
-       if (!names_) {
-               names_ = new FieldNames(this);
-       }
-
        size_t index = (*names_)[i];
        if ((index >= names_->size()) && throw_exceptions()) {
                throw BadFieldName(i.c_str());
        }
        
        return int(index);
-}
-
-
-const std::string&
-ResUse::field_name(int i) const
-{
-       if (!names_) {
-               names_ = new FieldNames(this);
-       }
-       return names_->at(i);
-}
-
-
-const RefCountedPointer<FieldNames>
-ResUse::field_names() const
-{
-       if (!names_) {
-               names_ = new FieldNames(this);
-       }
-       return names_;
-}
-
-
-const mysql_type_info&
-ResUse::field_type(int i) const
-{
-       if (!types_) {
-               types_ = new FieldTypes(this);
-       }
-       return (*types_)[i];
-}
-
-
-const FieldTypes&
-ResUse::field_types() const
-{
-       if (!types_) {
-               types_ = new FieldTypes(this);
-       }
-       return *types_;
 }
 
 

Modified: trunk/lib/result.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/result.h?rev=1899&r1=1898&r2=1899&view=diff
==============================================================================
--- trunk/lib/result.h (original)
+++ trunk/lib/result.h Wed Nov 28 03:57:03 2007
@@ -161,17 +161,20 @@
        int field_num(const std::string&) const;
 
        /// \brief Get the name of the field at the given index.
-       const std::string& field_name(int) const;
+       const std::string& field_name(int i) const
+                       { return names_->at(i); }
 
        /// \brief Get the names of the fields within this result set.
-       const RefCountedPointer<FieldNames> field_names() const;
+       const RefCountedPointer<FieldNames> field_names() const
+                       { return names_; }
 
        /// \brief Get the MySQL type for a field given its index.
-       const mysql_type_info& field_type(int) const;
+       const mysql_type_info& field_type(int i) const
+                       { return (*types_)[i]; }
 
        /// \brief Get a list of the types of the fields within this
        /// result set.
-       const FieldTypes& field_types() const;
+       const FieldTypes& field_types() const { return *types_; }
 
        /// \brief Get the underlying Fields structure.
        const Fields& fields() const { return fields_; }
@@ -195,11 +198,11 @@
 protected:
        mutable MYSQL_RES* result_;     ///< underlying C API result set
        bool initialized_;                      ///< if true, object is fully 
initted
-       mutable FieldTypes* types_;     ///< list of field types in result
+       FieldTypes* types_;                     ///< list of field types in 
result
        Fields fields_;                         ///< list of fields in result
 
        /// \brief list of field names in result
-       mutable RefCountedPointer<FieldNames> names_;
+       RefCountedPointer<FieldNames> names_;
 
        /// \brief Copy another ResUse object's contents into this one.
        ///


_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits

Reply via email to