Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continue making Ice::Value the same for the Original and New mappings #1666

Merged
merged 21 commits into from
Jan 15, 2024

Conversation

bernardnormier
Copy link
Member

@bernardnormier bernardnormier commented Jan 12, 2024

This PR updates Ice::Value to be almost identical with the Original and New mappings.

In particular, InputStream and OutputStream always encodes and decodes shared_ptr<Ice::Value>. More generally, the Ice core longer uses "Ice::ValuePtr" anywhere.

@@ -70,7 +21,34 @@ namespace Ice
* @param type The value type.
* @return The value created for the given type, or nil if the factory is unable to create the value.
*/
using ValueFactory = ::std::function<::std::shared_ptr<Value>(const ::std::string& type)>;
using ValueFactoryFunc = ::std::function<::std::shared_ptr<Value>(const ::std::string& type)>;
Copy link
Member Author

Choose a reason for hiding this comment

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

I reworked ValueFactory and ValueFactoryManager to be a hybrid of the Old and New mappings:

  • you can add and find a ValueFactoryFunc (= new mapping API)
  • you can also add a ValueFactoryPtr = shared_ptr, where ValueFactory is an abstract base class with a pure virtual create function.
  • find only returns the ValueFactoryFunc

virtual std::shared_ptr<Value> create(const std::string& type) = 0;
};

using ValueFactoryPtr = std::shared_ptr<ValueFactory>;
Copy link
Member Author

Choose a reason for hiding this comment

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

The ultimate goal is for all Ptr in the public API to be shared_ptr all the time, with a few exceptions:

  • generated mapped classes (Ptr = SharedPtr or shared_ptr depending on the mapping)
  • generated mapped servants
  • ValuePtr and ObjectPtr

Since I was updating ValueFactory and ValueFactoryManager, I switched them to the new API.

ValueFactoryManager() = default;
ValueFactoryManager(const ValueFactoryManager&) = default;
ValueFactoryManager& operator=(const ValueFactoryManager&) = default;
virtual void add(ValueFactoryFunc factory, const ::std::string& id) = 0;
Copy link
Member Author

Choose a reason for hiding this comment

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

That's the only API we use in cpp/.

The ValueFactoryPtr API is used by other language mappings based on C++ like python.

@@ -16,19 +16,14 @@ struct SliceInfo;
class SlicedData;
class UnknownSlicedValue;

#ifdef ICE_CPP11_MAPPING
/// \cond INTERNAL
using SliceInfoPtr = ::std::shared_ptr<SliceInfo>;
Copy link
Member Author

Choose a reason for hiding this comment

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

SliceInfoPtr and SlicedDataPtr are now shared_ptr all the time.

@@ -66,14 +64,24 @@ class ICE_API Value
* Returns a shallow copy of the object.
* @return The cloned value.
*/
std::shared_ptr<Value> ice_clone() const;
#if defined ICE_CPP11_MAPPING
inline std::shared_ptr<Value> ice_clone() const
Copy link
Member Author

Choose a reason for hiding this comment

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

inline ice_clone is one of the very few mapping-specific functions.

<< getUnqualified("::Ice::ValuePtr&", scope) << ");";
H << nl << "/// \\endcond";
bool
Slice::Gen::DeclVisitor::visitClassDefStart(const ClassDefPtr& p)
Copy link
Member Author

Choose a reason for hiding this comment

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

Most of the changes in this file are copying the Cpp11 visitors for classes to the Cpp98 with minimal changes.

At a later point--when the implementation of both mappings is closer--we should clean up this code and use the same visitors for both mappings.

}
-(void) dealloc
{
[valueFactoryManager_ release];
[objectFactories_ release];
Copy link
Member Author

Choose a reason for hiding this comment

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

I believe this was a left over of the object factories removed in an earlier PR

#include <Ice/SlicedData.h>

@interface ICESlicedData : NSObject<ICESlicedData>
{
@private
Ice::SlicedData* slicedData_;
Ice::SlicedDataPtr slicedData_;
Copy link
Member Author

Choose a reason for hiding this comment

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

My understanding here:
we can use a C++ data member with a destructor because the type (shared_ptr) has no virtual function. And the cleanup of ICESlicedData will run the C++ destructors. Would be good to double-check with a small test.

In the previous version, we were using a pointer to the Ptr and made calls to __incRef and __decRef.

void
clear(const BPtr& b)
{
// No GC with the C++11 mapping
if(dynamic_pointer_cast<B>(b->theA))
if(ICE_DYNAMIC_CAST(B, b->theA))
Copy link
Member Author

Choose a reason for hiding this comment

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

Macros like ICE_DYNAMIC_CAST are and should remain useful for the tests.

@@ -647,25 +647,20 @@ class PNodeI : public virtual PNode

int PNodeI::counter = 0;

#ifndef ICE_CPP11_MAPPING
// TODO: this class is not used anywhere
Copy link
Member Author

Choose a reason for hiding this comment

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

It's not immediately clear from which test it comes. Maybe a GC test?

void
IceInternal::ValueFactoryManagerI::add(const ValueFactoryPtr& factory, const string& id)
{
IceUtil::Mutex::Lock sync(*this);
Copy link
Member

Choose a reason for hiding this comment

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

We should review this code in a separate PR, the "_factoryFuncMapHint` optimization doesn't seem worth it, because the insertion order is not predictable. Adding value factories is also not a critical code path.

Copy link
Member

@externl externl left a comment

Choose a reason for hiding this comment

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

Looks good!

cpp/include/Ice/ValueFactory.h Outdated Show resolved Hide resolved
cpp/include/Ice/ValueFactory.h Outdated Show resolved Hide resolved
cpp/src/Ice/Value.cpp Show resolved Hide resolved
cpp/src/Ice/ValueFactoryManagerI.h Outdated Show resolved Hide resolved
cpp/src/Ice/ValueFactoryManagerI.h Outdated Show resolved Hide resolved
cpp/test/Ice/slicing/objects/AllTests.cpp Outdated Show resolved Hide resolved
php/src/Communicator.cpp Show resolved Hide resolved
python/modules/IcePy/ValueFactoryManager.h Outdated Show resolved Hide resolved
@bernardnormier bernardnormier merged commit 3344a70 into zeroc-ice:main Jan 15, 2024
1 check passed
@bernardnormier bernardnormier deleted the common-value2 branch May 10, 2024 23:40
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