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

Fix Objective-C build failures #1496

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions cpp/src/slice2objc/Gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)";
Expand Down
40 changes: 40 additions & 0 deletions cpp/src/slice2objc/ObjCUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions cpp/src/slice2objc/ObjCUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ObjCGenerator : private ::IceUtil::noncopyable
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&);
Expand Down
2 changes: 1 addition & 1 deletion objective-c/test/Ice/defaultValue/Client.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#import <DefaultValueTest.h>

static int
run()
run(void)
{
void defaultValueAllTests(void);
defaultValueAllTests();
Expand Down
2 changes: 1 addition & 1 deletion objective-c/test/Ice/dispatcher/AllTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion objective-c/test/Ice/hash/Client.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#import <HashTest.h>

static int
run()
run(void)
{
void hashAllTests(void);
hashAllTests();
Expand Down
4 changes: 2 additions & 2 deletions objective-c/test/Ice/services/AllTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ -(void)tick:(NSString*)time current:(ICECurrent*)__unused current
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"];
Expand Down
2 changes: 1 addition & 1 deletion objective-c/test/Slice/escape/Client.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ @interface andfriendI : ICELocalObject<andfriend>
// are named correctly. It is not expected to run.
//
static void
testSymbols()
testSymbols(void)
{
andbreakPrx* prx1 = 0;
[prx1 case_:0 try:0];
Expand Down
Loading