summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJose <pepone@users.noreply.github.com>2023-08-09 09:27:00 +0200
committerGitHub <noreply@github.com>2023-08-09 09:27:00 +0200
commitbadafe8b848181a720ab96b48da6abc170fd918c (patch)
tree4b24dbf02f578cb6c68a43fa45a71b4cb8f2405b
parentFix GCC13 build failure - #1489 (#1490) (diff)
downloadice-badafe8b848181a720ab96b48da6abc170fd918c.tar.bz2
ice-badafe8b848181a720ab96b48da6abc170fd918c.tar.xz
ice-badafe8b848181a720ab96b48da6abc170fd918c.zip
Fix Objective-C build failures (#1496)
-rw-r--r--cpp/src/slice2objc/Gen.cpp15
-rw-r--r--cpp/src/slice2objc/ObjCUtil.cpp40
-rw-r--r--cpp/src/slice2objc/ObjCUtil.h1
-rw-r--r--objective-c/test/Ice/defaultValue/Client.m2
-rw-r--r--objective-c/test/Ice/dispatcher/AllTests.m2
-rw-r--r--objective-c/test/Ice/hash/Client.m2
-rw-r--r--objective-c/test/Ice/services/AllTests.m4
-rw-r--r--objective-c/test/Slice/escape/Client.m2
8 files changed, 50 insertions, 18 deletions
diff --git a/cpp/src/slice2objc/Gen.cpp b/cpp/src/slice2objc/Gen.cpp
index c52ea9bbf17..3923e3fabaf 100644
--- a/cpp/src/slice2objc/Gen.cpp
+++ b/cpp/src/slice2objc/Gen.cpp
@@ -3106,23 +3106,14 @@ Slice::Gen::DelegateMVisitor::visitOperation(const OperationPtr& p)
if(returnType)
{
_M << nl << outTypeToString(returnType, p->returnIsOptional(), true) << " ret";
- if(!isValueType(returnType))
- {
- _M << " = nil;";
- }
- else
- {
- _M << ";";
- }
+ _M << " = " << defaultValue(returnType, p->returnIsOptional()) << ";";
}
if(p->returnsData())
{
for(ParamDeclList::const_iterator op = outParams.begin(); op != outParams.end(); ++op)
{
- if(!isValueType((*op)->type()))
- {
- _M << nl << "*" << getParamName(*op, true) << " = nil;";
- }
+ _M << nl << "*" << getParamName(*op, true) << " = " << defaultValue((*op)->type(), (*op)->optional())
+ << ";";
}
}
_M << nl << "if(!ok)";
diff --git a/cpp/src/slice2objc/ObjCUtil.cpp b/cpp/src/slice2objc/ObjCUtil.cpp
index 1848cbcbf4d..cf7e34fd5f0 100644
--- a/cpp/src/slice2objc/ObjCUtil.cpp
+++ b/cpp/src/slice2objc/ObjCUtil.cpp
@@ -427,6 +427,46 @@ Slice::ObjCGenerator::typeToObjCTypeString(const TypePtr& type)
}
}
+string
+Slice::ObjCGenerator::defaultValue(const TypePtr& type, bool isOptional)
+{
+ if(isValueType(type) && !isOptional)
+ {
+ if(EnumPtr::dynamicCast(type))
+ {
+ return "0";
+ }
+ BuiltinPtr builtin = BuiltinPtr::dynamicCast(type);
+ if(builtin)
+ {
+ switch(builtin->kind())
+ {
+ case Builtin::KindBool:
+ return "NO";
+ case Builtin::KindByte:
+ case Builtin::KindShort:
+ case Builtin::KindInt:
+ case Builtin::KindLong:
+ return "0";
+ case Builtin::KindFloat:
+ case Builtin::KindDouble:
+ return "0.0";
+ default:
+ {
+ assert(false);
+ return "???";
+ }
+ }
+ }
+ assert(false);
+ return "???";
+ }
+ else
+ {
+ return "nil";
+ }
+}
+
bool
Slice::ObjCGenerator::isValueType(const TypePtr& type)
{
diff --git a/cpp/src/slice2objc/ObjCUtil.h b/cpp/src/slice2objc/ObjCUtil.h
index 0c5176d67d8..4520ee7082a 100644
--- a/cpp/src/slice2objc/ObjCUtil.h
+++ b/cpp/src/slice2objc/ObjCUtil.h
@@ -52,6 +52,7 @@ protected:
static std::string inTypeToString(const TypePtr&, bool, bool = false, bool = false);
static std::string outTypeToString(const TypePtr&, bool, bool = false, bool = false);
static std::string typeToObjCTypeString(const TypePtr&);
+ static std::string defaultValue(const TypePtr&, bool);
static bool isValueType(const TypePtr&);
static bool isString(const TypePtr&);
static bool isClass(const TypePtr&);
diff --git a/objective-c/test/Ice/defaultValue/Client.m b/objective-c/test/Ice/defaultValue/Client.m
index bc36e6977ee..9983d7030c0 100644
--- a/objective-c/test/Ice/defaultValue/Client.m
+++ b/objective-c/test/Ice/defaultValue/Client.m
@@ -7,7 +7,7 @@
#import <DefaultValueTest.h>
static int
-run()
+run(void)
{
void defaultValueAllTests(void);
defaultValueAllTests();
diff --git a/objective-c/test/Ice/dispatcher/AllTests.m b/objective-c/test/Ice/dispatcher/AllTests.m
index f237c0492c8..a46e22f6414 100644
--- a/objective-c/test/Ice/dispatcher/AllTests.m
+++ b/objective-c/test/Ice/dispatcher/AllTests.m
@@ -8,7 +8,7 @@
#import <Foundation/Foundation.h>
-static BOOL isDispatcherThread()
+static BOOL isDispatcherThread(void)
{
return strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), "Dispatcher") == 0;
}
diff --git a/objective-c/test/Ice/hash/Client.m b/objective-c/test/Ice/hash/Client.m
index 867593665b6..e942196b4f3 100644
--- a/objective-c/test/Ice/hash/Client.m
+++ b/objective-c/test/Ice/hash/Client.m
@@ -7,7 +7,7 @@
#import <HashTest.h>
static int
-run()
+run(void)
{
void hashAllTests(void);
hashAllTests();
diff --git a/objective-c/test/Ice/services/AllTests.m b/objective-c/test/Ice/services/AllTests.m
index 44102d01730..11d47dab75a 100644
--- a/objective-c/test/Ice/services/AllTests.m
+++ b/objective-c/test/Ice/services/AllTests.m
@@ -50,8 +50,8 @@ servicesAllTests(id<ICECommunicator> communicator)
ICESTORMTopicManagerPrx* manager =
[ICESTORMTopicManagerPrx uncheckedCast:[communicator stringToProxy:@"test:default -p 12010"]];
- ICESTORMQoS* qos;
- ICESTORMTopicPrx* topic;
+ ICESTORMQoS* qos = nil;
+ ICESTORMTopicPrx* topic = nil;
NSString* topicName = @"time";
id<ICEObjectAdapter> adapter = [communicator createObjectAdapterWithEndpoints:@"subscriber" endpoints:@"tcp"];
diff --git a/objective-c/test/Slice/escape/Client.m b/objective-c/test/Slice/escape/Client.m
index bc18968677e..805c417dfd6 100644
--- a/objective-c/test/Slice/escape/Client.m
+++ b/objective-c/test/Slice/escape/Client.m
@@ -29,7 +29,7 @@
// are named correctly. It is not expected to run.
//
static void
-testSymbols()
+testSymbols(void)
{
andbreakPrx* prx1 = 0;
[prx1 case_:0 try:0];