VirtualBox

Changeset 80835 in vbox for trunk/include/VBox/com


Ignore:
Timestamp:
Sep 16, 2019 8:30:40 PM (5 years ago)
Author:
vboxsync
Message:

Main/glue: Added bstr testcase and fixed printf bugs. Introduced jolt, joltNoThrow, reserve and reserveNoThrow for the low level allocation operations needed by printf.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/com/string.h

    r80793 r80835  
    386386
    387387    /**
    388      *  Returns a non-const raw pointer that allows to modify the string directly.
    389      *  As opposed to raw(), this DOES return NULL if the member string is empty
    390      *  because we cannot return a mutable pointer to the global variable with the
    391      *  empty string.
    392      *
    393      *  @warning
    394      *      Be sure not to modify data beyond the allocated memory! The
    395      *      guaranteed size of the allocated memory is at least #length()
    396      *      bytes after creation and after every assignment operation.
     388     * Returns a non-const raw pointer that allows modifying the string directly.
     389     *
     390     * @note As opposed to raw(), this DOES return NULL if the member string is
     391     *       empty because we cannot return a mutable pointer to the global variable
     392     *       with the empty string.
     393     *
     394     * @note If modifying the string size (only shrinking it is allows), #jolt() or
     395     *       #joltNoThrow() must be called!
     396     *
     397     * @note Do not modify memory beyond the #length() of the string!
     398     *
     399     * @sa   joltNoThrow(), mutalbleRaw(), reserve(), reserveNoThrow()
    397400     */
    398401    BSTR mutableRaw() { return m_bstr; }
     402
     403    /**
     404     * Correct the embedded length after using mutableRaw().
     405     *
     406     * This is needed on COM (Windows) to update the embedded string length.  It is
     407     * a stub on hosts using XPCOM.
     408     *
     409     * @param   cwcNew      The new string length, if handy, otherwise a negative
     410     *                      number.
     411     * @sa      joltNoThrow(), mutalbleRaw(), reserve(), reserveNoThrow()
     412     */
     413#ifndef VBOX_WITH_XPCOM
     414    void jolt(ssize_t cwcNew = -1);
     415#else
     416    void jolt(ssize_t cwcNew = -1)
     417    {
     418        Assert(cwcNew < 0 || (cwcNew == 0 && !m_bstr) || m_bstr[cwcNew] == '\0'); RT_NOREF(cwcNew);
     419    }
     420#endif
     421
     422    /**
     423     * Correct the embedded length after using mutableRaw().
     424     *
     425     * This is needed on COM (Windows) to update the embedded string length.  It is
     426     * a stub on hosts using XPCOM.
     427     *
     428     * @returns S_OK on success, E_OUTOFMEMORY if shrinking the string failed.
     429     * @param   cwcNew      The new string length, if handy, otherwise a negative
     430     *                      number.
     431     * @sa      jolt(), mutalbleRaw(), reserve(), reserveNoThrow()
     432     */
     433#ifndef VBOX_WITH_XPCOM
     434    HRESULT joltNoThrow(ssize_t cwcNew = -1) RT_NOEXCEPT;
     435#else
     436    HRESULT joltNoThrow(ssize_t cwcNew = -1) RT_NOEXCEPT
     437    {
     438        Assert(cwcNew < 0 || (cwcNew == 0 && !m_bstr) || m_bstr[cwcNew] == '\0'); RT_NOREF(cwcNew);
     439        return S_OK;
     440    }
     441#endif
     442
     443    /**
     444     * Make sure at that least @a cwc of buffer space is reserved.
     445     *
     446     * Requests that the contained memory buffer have at least cb bytes allocated.
     447     * This may expand or shrink the string's storage, but will never truncate the
     448     * contained string.  In other words, cb will be ignored if it's smaller than
     449     * length() + 1.
     450     *
     451     * @param   cwcMin  The new minimum string length that the can be stored. This
     452     *                  does not include the terminator.
     453     * @param   fForce  Force this size.
     454     *
     455     * @throws  std::bad_alloc  On allocation error.  The object is left unchanged.
     456     */
     457    void reserve(size_t cwcMin, bool fForce = false);
     458
     459    /**
     460     * A C like version of the #reserve() method, i.e. return code instead of throw.
     461     *
     462     * @returns S_OK or E_OUTOFMEMORY.
     463     * @param   cwcMin  The new minimum string length that the can be stored.  This
     464     *                  does not include the terminator.
     465    * @param   fForce  Force this size.
     466     */
     467    HRESULT reserveNoThrow(size_t cwcMin, bool fForce = false) RT_NOEXCEPT;
    399468
    400469    /**
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette