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

Add support for default property values #2100

Merged
merged 19 commits into from
May 2, 2024

Conversation

externl
Copy link
Member

@externl externl commented May 1, 2024

This PR adds support for setting default property values in PropertyNames.xml.

I've only added a handful of defaults for now, we can add more in follow-up PRs.

In addition it also adds three new property functions for fetching these properties:

  • getIceProperty
  • getIcePropertyAsInt
  • getIcePropertyAsList

Additionally, JavaScript's setProperty validation was broken. I fixed it for this PR and will open an issue to fix 3.7.

Fixe #2072

- getIceProperty
- getIcePropertyAsInt
- getIcePropertyAsList
@externl externl changed the title Add new property functions Add Ice property functions May 1, 2024
@externl externl changed the title Add Ice property functions Add support for default property values May 1, 2024
self.srcFile.write(
r' new Property("/^%s\.%s/", false, null),\n'
% (self.currentSection, self.fix(propertyName))
line = 'new Property("^{section}\\.{name}$", {defaultValue}, {deprecated}, {deprecatedBy})'.format(
Copy link
Member Author

@externl externl May 1, 2024

Choose a reason for hiding this comment

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

The regex for JavaScript was broken. The /XXX/ wrapping is incorrect.

/// @param key The property name.
/// @param logWarnings Whether to log relevant warnings.
/// @return The property if found, nullopt otherwise.
optional<Property> findProperty(string_view key, bool logWarnings)
Copy link
Member Author

@externl externl May 1, 2024

Choose a reason for hiding this comment

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

In the various languages, this lookup logic was only found in setProperty. I've moved this code into a new function.



class PropertiesTestSuite(TestSuite):
def setup(self, current):
if isinstance(self.getMapping(), PhpMapping) or isinstance(
Copy link
Member Author

Choose a reason for hiding this comment

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

PHP and Matlab don't have any config file tests

cpp/include/Ice/Properties.h Outdated Show resolved Hide resolved
/// @param key The ice property name.
/// @return The default value for the property.
/// @throws std::invalid_argument if the property is unknown.
string getDefaultValue(string_view key)
Copy link
Member

Choose a reason for hiding this comment

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

Return a string_view since the backing type is a const char*?

cpp/src/Ice/Properties.cpp Outdated Show resolved Hide resolved
@@ -89,6 +106,12 @@ public string[] getPropertyAsList(string key)
return getPropertyAsListWithDefault(key, null);
}

public string[] getIcePropertyAsList(string key)
{
string[] defaultList = IceUtilInternal.StringUtil.splitString(getDefaultProperty(key), ", \t\r\n");
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not the same as our splitSting deals with "quoted" properties.

@@ -4,9 +4,10 @@ namespace IceInternal;

public sealed class Property
{
public Property(string pattern, bool deprecated, string deprecatedBy)
public Property(string pattern, string defaultValue, bool deprecated, string deprecatedBy)
Copy link
Member

Choose a reason for hiding this comment

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

What about using a readonly record class?

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's do that in a follow-up PR.

@@ -17,6 +18,12 @@ public string
return _pattern;
}

public string
defaultValue()
Copy link
Member

Choose a reason for hiding this comment

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

This should be a C# property.

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'll clean up this class in a follow-up pr.

@externl externl removed the request for review from InsertCreativityHere May 2, 2024 14:56
@externl externl marked this pull request as ready for review May 2, 2024 15:17
Copy link
Member

@pepone pepone 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

// Check for case-insensitive match.

if (IceUtilInternal::match(
IceUtilInternal::toUpper(string{key}),
Copy link
Member

Choose a reason for hiding this comment

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

I think we can update toUpper/toLower to work with string_view in a follow up PR, what do you think?

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 think we should get rid of this check entirely

cpp/src/Ice/Properties.cpp Outdated Show resolved Hide resolved
cpp/src/Ice/Properties.cpp Outdated Show resolved Hide resolved
// Copyright (c) ZeroC, Inc. All rights reserved.
//
// Generated by makeprops.py from file ../config/PropertyNames.xml, Fri Apr 26 11:24:58 2024
// Copyright (c) ZeroC, Inc. All rights reserved.// Generated by makeprops.py from file ./config/PropertyNames.xml, Wed
Copy link
Member

Choose a reason for hiding this comment

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

Seems there is a missing new line in the generator for this file.

// Copyright (c) ZeroC, Inc. All rights reserved.
//
// Generated by makeprops.py from file ../config/PropertyNames.xml, Fri Apr 26 11:24:58 2024
// Copyright (c) ZeroC, Inc. All rights reserved.// Generated by makeprops.py from file ./config/PropertyNames.xml, Wed
Copy link
Member

Choose a reason for hiding this comment

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

missing new line in the generator

test(retryIntervals.size() == 1);
test(retryIntervals[0] == "0");
cout << "ok" << endl;
}
Copy link
Member

Choose a reason for hiding this comment

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

To be complete we should also test that you don't get the default when the property is set to a different value. But maybe not worth because the code is simple enough?

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 don't think it's needed. The rest of the tests will cover this when we start using it.

Ice::PropertiesPtr _this = Wrapper<Ice::PropertiesPtr>::value(getThis());
assert(_this);

string propName(name, nameLen);
Copy link
Member

Choose a reason for hiding this comment

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

Can we create a string_view?

@externl externl force-pushed the 2072-default-props branch from 5e368df to 41bebb1 Compare May 2, 2024 16:35
* Get an Ice property by key. If the property is not set, its default value is returned.
* @param key The property key.
* @return The property value or the default value.
* @see #setProperty
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 document @throws std::invalid_argument for getIceXxx methods.

Comment on lines +182 to +185
// If the property is deprecated by another property, use the new property key
if (prop != null && prop.deprecatedBy() != null)
{
key = prop.deprecatedBy();
Copy link
Member

Choose a reason for hiding this comment

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

This is unrelated to your changes, but the behavior here seems odd. The code assumes the new property values are compatible with the deprecated property.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I want to get rid of this code as well.

@externl externl merged commit 6f9de65 into zeroc-ice:main May 2, 2024
17 checks passed
@externl externl deleted the 2072-default-props branch May 2, 2024 18:43
InsertCreativityHere pushed a commit to InsertCreativityHere/compiler-comparison that referenced this pull request Jan 1, 2025
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