Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
djinni
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
djinni
Commits
3e817fcb
Commit
3e817fcb
authored
Sep 16, 2015
by
Jacob Potter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent copying of Handle objects
parent
143fb84c
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
72 additions
and
65 deletions
+72
-65
example/generated-src/objc/TXSSortItems+Private.mm
example/generated-src/objc/TXSSortItems+Private.mm
+9
-9
src/source/ObjcppGenerator.scala
src/source/ObjcppGenerator.scala
+12
-9
support-lib/objc/DJICppWrapperCache+Private.h
support-lib/objc/DJICppWrapperCache+Private.h
+2
-0
support-lib/objc/DJIObjcWrapperCache+Private.h
support-lib/objc/DJIObjcWrapperCache+Private.h
+3
-1
test-suite/generated-src/objc/DBConstantsInterface+Private.mm
...-suite/generated-src/objc/DBConstantsInterface+Private.mm
+8
-8
test-suite/generated-src/objc/DBCppException+Private.mm
test-suite/generated-src/objc/DBCppException+Private.mm
+8
-8
test-suite/generated-src/objc/DBExternInterface1+Private.mm
test-suite/generated-src/objc/DBExternInterface1+Private.mm
+8
-8
test-suite/generated-src/objc/DBTestDuration+Private.mm
test-suite/generated-src/objc/DBTestDuration+Private.mm
+7
-7
test-suite/generated-src/objc/DBTestHelpers+Private.mm
test-suite/generated-src/objc/DBTestHelpers+Private.mm
+7
-7
test-suite/generated-src/objc/DBUserToken+Private.mm
test-suite/generated-src/objc/DBUserToken+Private.mm
+8
-8
No files found.
example/generated-src/objc/TXSSortItems+Private.mm
View file @
3e817fcb
...
...
@@ -16,18 +16,18 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
@interface
TXSSortItems
()
@property
(
nonatomic
,
readonly
)
::
djinni
::
DbxCppWrapperCache
<::
textsort
::
SortItems
>::
Handle
cppRef
;
-
(
id
)
initWithCpp
:(
const
std
::
shared_ptr
<::
textsort
::
SortItems
>&
)
cppRef
;
@end
@implementation
TXSSortItems
@implementation
TXSSortItems
{
::
djinni
::
DbxCppWrapperCache
<::
textsort
::
SortItems
>::
Handle
_cppRefHandle
;
}
-
(
id
)
initWithCpp
:(
const
std
::
shared_ptr
<::
textsort
::
SortItems
>&
)
cppRef
{
if
(
self
=
[
super
init
])
{
_cppRef
.
assign
(
cppRef
);
_cppRef
Handle
.
assign
(
cppRef
);
}
return
self
;
}
...
...
@@ -35,8 +35,8 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
-
(
void
)
sort
:(
TXSSortOrder
)
order
items
:(
nonnull
TXSItemList
*
)
items
{
try
{
_cppRef
.
get
()
->
sort
(
::
djinni
::
Enum
<::
textsort
::
sort_order
,
TXSSortOrder
>::
toCpp
(
order
),
::
djinni_generated
::
ItemList
::
toCpp
(
items
));
_cppRef
Handle
.
get
()
->
sort
(
::
djinni
::
Enum
<::
textsort
::
sort_order
,
TXSSortOrder
>::
toCpp
(
order
),
::
djinni_generated
::
ItemList
::
toCpp
(
items
));
}
DJINNI_TRANSLATE_EXCEPTIONS
()
}
...
...
@@ -47,8 +47,6 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
}
DJINNI_TRANSLATE_EXCEPTIONS
()
}
@end
namespace
djinni_generated
{
auto
SortItems
::
toCpp
(
ObjcType
objc
)
->
CppType
...
...
@@ -56,7 +54,7 @@ auto SortItems::toCpp(ObjcType objc) -> CppType
if
(
!
objc
)
{
return
nullptr
;
}
return
objc
.
cppRef
.
get
();
return
objc
->
_cppRefHandle
.
get
();
}
auto
SortItems
::
fromCpp
(
const
CppType
&
cpp
)
->
ObjcType
...
...
@@ -70,3 +68,5 @@ auto SortItems::fromCpp(const CppType& cpp) -> ObjcType
}
}
// namespace djinni_generated
@end
src/source/ObjcppGenerator.scala
View file @
3e817fcb
...
...
@@ -128,18 +128,18 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) {
else
w
.
wl
(
s
"@interface $objcSelf ()"
)
w
.
wl
w
.
wl
(
s
"@property (nonatomic, readonly) ::djinni::DbxCppWrapperCache<$cppSelf>::Handle cppRef;"
)
w
.
wl
w
.
wl
(
s
"- (id)initWithCpp:(const std::shared_ptr<$cppSelf>&)cppRef;"
)
w
.
wl
w
.
wl
(
"@end"
)
w
.
wl
w
.
wl
(
s
"@implementation $objcSelf"
)
w
.
wl
(
s
"@implementation $objcSelf {"
)
w
.
wl
(
s
" ::djinni::DbxCppWrapperCache<$cppSelf>::Handle _cppRefHandle;"
)
w
.
wl
(
"}"
)
w
.
wl
w
.
wl
(
s
"- (id)initWithCpp:(const std::shared_ptr<$cppSelf>&)cppRef"
)
w
.
braced
{
w
.
w
(
"if (self = [super init])"
).
braced
{
w
.
wl
(
"_cppRef.assign(cppRef);"
)
w
.
wl
(
"_cppRef
Handle
.assign(cppRef);"
)
}
w
.
wl
(
"return self;"
)
}
...
...
@@ -149,15 +149,13 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) {
w
.
braced
{
w
.
w
(
"try"
).
bracedEnd
(
" DJINNI_TRANSLATE_EXCEPTIONS()"
)
{
val
ret
=
m
.
ret
.
fold
(
""
)(
_
=>
"auto r = "
)
val
call
=
ret
+
(
if
(!
m
.
static
)
"_cppRef.get()->"
else
cppSelf
+
"::"
)
+
idCpp
.
method
(
m
.
ident
)
+
"("
val
call
=
ret
+
(
if
(!
m
.
static
)
"_cppRef
Handle
.get()->"
else
cppSelf
+
"::"
)
+
idCpp
.
method
(
m
.
ident
)
+
"("
writeAlignedCall
(
w
,
call
,
m
.
params
,
")"
,
p
=>
objcppMarshal
.
toCpp
(
p
.
ty
,
idObjc
.
local
(
p
.
ident
.
name
)))
w
.
wl
(
";"
)
m
.
ret
.
fold
()(
r
=>
w
.
wl
(
s
"return ${objcppMarshal.fromCpp(r, "
r
")};"
))
}
}
}
w
.
wl
w
.
wl
(
"@end"
)
}
if
(
i
.
ext
.
objc
)
{
...
...
@@ -198,14 +196,14 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) {
if
(
i
.
ext
.
cpp
&&
!
i
.
ext
.
objc
)
{
// C++ only. In this case we generate a class instead of a protocol, so
// we don't have to do any casting at all, just access cppRef directly.
w
.
wl
(
s
"return objc
.cppRef
.get();"
)
w
.
wl
(
s
"return objc
->_cppRefHandle
.get();"
)
}
else
{
// ObjC only, or ObjC and C++.
val
objcExtSelf
=
objcppMarshal
.
helperClass
(
"objc_proxy"
)
if
(
i
.
ext
.
cpp
)
{
// If it could be implemented in C++, we might have to unwrap a proxy object.
w
.
w
(
s
"if ([(id)objc isKindOfClass:[$objcSelf class]])"
).
braced
{
w
.
wl
(
s
"return (($objcSelf*)objc)
.cppRef
.get();"
)
w
.
wl
(
s
"return (($objcSelf*)objc)
->_cppRefHandle
.get();"
)
}
}
w
.
wl
(
s
"return ::djinni::DbxObjcWrapperCache<$objcExtSelf>::getInstance()->get(objc);"
)
...
...
@@ -237,6 +235,11 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) {
}
}
})
if
(
i
.
ext
.
cpp
)
{
w
.
wl
w
.
wl
(
"@end"
)
}
})
}
...
...
support-lib/objc/DJICppWrapperCache+Private.h
View file @
3e817fcb
...
...
@@ -63,6 +63,8 @@ public:
class
Handle
{
public:
Handle
()
=
default
;
Handle
(
const
Handle
&
)
=
delete
;
Handle
&
operator
=
(
const
Handle
&
)
=
delete
;
~
Handle
()
{
if
(
_ptr
)
{
_cache
->
remove
(
_ptr
);
...
...
support-lib/objc/DJIObjcWrapperCache+Private.h
View file @
3e817fcb
...
...
@@ -55,7 +55,9 @@ public:
class
Handle
{
public:
Handle
(
id
obj
)
:
_obj
(
obj
)
{
};
Handle
(
id
obj
)
:
_obj
(
obj
)
{
}
Handle
(
const
Handle
&
)
=
delete
;
Handle
&
operator
=
(
const
Handle
&
)
=
delete
;
~
Handle
()
{
if
(
_obj
)
{
_cache
->
remove
(
_obj
);
...
...
test-suite/generated-src/objc/DBConstantsInterface+Private.mm
View file @
3e817fcb
...
...
@@ -13,30 +13,28 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
@interface
DBConstantsInterface
()
@property
(
nonatomic
,
readonly
)
::
djinni
::
DbxCppWrapperCache
<::
ConstantsInterface
>::
Handle
cppRef
;
-
(
id
)
initWithCpp
:(
const
std
::
shared_ptr
<::
ConstantsInterface
>&
)
cppRef
;
@end
@implementation
DBConstantsInterface
@implementation
DBConstantsInterface
{
::
djinni
::
DbxCppWrapperCache
<::
ConstantsInterface
>::
Handle
_cppRefHandle
;
}
-
(
id
)
initWithCpp
:(
const
std
::
shared_ptr
<::
ConstantsInterface
>&
)
cppRef
{
if
(
self
=
[
super
init
])
{
_cppRef
.
assign
(
cppRef
);
_cppRef
Handle
.
assign
(
cppRef
);
}
return
self
;
}
-
(
void
)
dummy
{
try
{
_cppRef
.
get
()
->
dummy
();
_cppRef
Handle
.
get
()
->
dummy
();
}
DJINNI_TRANSLATE_EXCEPTIONS
()
}
@end
namespace
djinni_generated
{
auto
ConstantsInterface
::
toCpp
(
ObjcType
objc
)
->
CppType
...
...
@@ -44,7 +42,7 @@ auto ConstantsInterface::toCpp(ObjcType objc) -> CppType
if
(
!
objc
)
{
return
nullptr
;
}
return
objc
.
cppRef
.
get
();
return
objc
->
_cppRefHandle
.
get
();
}
auto
ConstantsInterface
::
fromCpp
(
const
CppType
&
cpp
)
->
ObjcType
...
...
@@ -58,3 +56,5 @@ auto ConstantsInterface::fromCpp(const CppType& cpp) -> ObjcType
}
}
// namespace djinni_generated
@end
test-suite/generated-src/objc/DBCppException+Private.mm
View file @
3e817fcb
...
...
@@ -14,25 +14,25 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
@interface
DBCppException
()
@property
(
nonatomic
,
readonly
)
::
djinni
::
DbxCppWrapperCache
<::
CppException
>::
Handle
cppRef
;
-
(
id
)
initWithCpp
:(
const
std
::
shared_ptr
<::
CppException
>&
)
cppRef
;
@end
@implementation
DBCppException
@implementation
DBCppException
{
::
djinni
::
DbxCppWrapperCache
<::
CppException
>::
Handle
_cppRefHandle
;
}
-
(
id
)
initWithCpp
:(
const
std
::
shared_ptr
<::
CppException
>&
)
cppRef
{
if
(
self
=
[
super
init
])
{
_cppRef
.
assign
(
cppRef
);
_cppRef
Handle
.
assign
(
cppRef
);
}
return
self
;
}
-
(
int32_t
)
throwAnException
{
try
{
auto
r
=
_cppRef
.
get
()
->
throw_an_exception
();
auto
r
=
_cppRef
Handle
.
get
()
->
throw_an_exception
();
return
::
djinni
::
I32
::
fromCpp
(
r
);
}
DJINNI_TRANSLATE_EXCEPTIONS
()
}
...
...
@@ -44,8 +44,6 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
}
DJINNI_TRANSLATE_EXCEPTIONS
()
}
@end
namespace
djinni_generated
{
auto
CppException
::
toCpp
(
ObjcType
objc
)
->
CppType
...
...
@@ -53,7 +51,7 @@ auto CppException::toCpp(ObjcType objc) -> CppType
if
(
!
objc
)
{
return
nullptr
;
}
return
objc
.
cppRef
.
get
();
return
objc
->
_cppRefHandle
.
get
();
}
auto
CppException
::
fromCpp
(
const
CppType
&
cpp
)
->
ObjcType
...
...
@@ -67,3 +65,5 @@ auto CppException::fromCpp(const CppType& cpp) -> ObjcType
}
}
// namespace djinni_generated
@end
test-suite/generated-src/objc/DBExternInterface1+Private.mm
View file @
3e817fcb
...
...
@@ -14,31 +14,29 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
@interface
DBExternInterface1
()
@property
(
nonatomic
,
readonly
)
::
djinni
::
DbxCppWrapperCache
<::
ExternInterface1
>::
Handle
cppRef
;
-
(
id
)
initWithCpp
:(
const
std
::
shared_ptr
<::
ExternInterface1
>&
)
cppRef
;
@end
@implementation
DBExternInterface1
@implementation
DBExternInterface1
{
::
djinni
::
DbxCppWrapperCache
<::
ExternInterface1
>::
Handle
_cppRefHandle
;
}
-
(
id
)
initWithCpp
:(
const
std
::
shared_ptr
<::
ExternInterface1
>&
)
cppRef
{
if
(
self
=
[
super
init
])
{
_cppRef
.
assign
(
cppRef
);
_cppRef
Handle
.
assign
(
cppRef
);
}
return
self
;
}
-
(
nonnull
DBClientReturnedRecord
*
)
foo
:(
nullable
id
<
DBClientInterface
>
)
i
{
try
{
auto
r
=
_cppRef
.
get
()
->
foo
(
::
djinni_generated
::
ClientInterface
::
toCpp
(
i
));
auto
r
=
_cppRef
Handle
.
get
()
->
foo
(
::
djinni_generated
::
ClientInterface
::
toCpp
(
i
));
return
::
djinni_generated
::
ClientReturnedRecord
::
fromCpp
(
r
);
}
DJINNI_TRANSLATE_EXCEPTIONS
()
}
@end
namespace
djinni_generated
{
auto
ExternInterface1
::
toCpp
(
ObjcType
objc
)
->
CppType
...
...
@@ -46,7 +44,7 @@ auto ExternInterface1::toCpp(ObjcType objc) -> CppType
if
(
!
objc
)
{
return
nullptr
;
}
return
objc
.
cppRef
.
get
();
return
objc
->
_cppRefHandle
.
get
();
}
auto
ExternInterface1
::
fromCpp
(
const
CppType
&
cpp
)
->
ObjcType
...
...
@@ -60,3 +58,5 @@ auto ExternInterface1::fromCpp(const CppType& cpp) -> ObjcType
}
}
// namespace djinni_generated
@end
test-suite/generated-src/objc/DBTestDuration+Private.mm
View file @
3e817fcb
...
...
@@ -14,18 +14,18 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
@interface
DBTestDuration
()
@property
(
nonatomic
,
readonly
)
::
djinni
::
DbxCppWrapperCache
<::
TestDuration
>::
Handle
cppRef
;
-
(
id
)
initWithCpp
:(
const
std
::
shared_ptr
<::
TestDuration
>&
)
cppRef
;
@end
@implementation
DBTestDuration
@implementation
DBTestDuration
{
::
djinni
::
DbxCppWrapperCache
<::
TestDuration
>::
Handle
_cppRefHandle
;
}
-
(
id
)
initWithCpp
:(
const
std
::
shared_ptr
<::
TestDuration
>&
)
cppRef
{
if
(
self
=
[
super
init
])
{
_cppRef
.
assign
(
cppRef
);
_cppRef
Handle
.
assign
(
cppRef
);
}
return
self
;
}
...
...
@@ -170,8 +170,6 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
}
DJINNI_TRANSLATE_EXCEPTIONS
()
}
@end
namespace
djinni_generated
{
auto
TestDuration
::
toCpp
(
ObjcType
objc
)
->
CppType
...
...
@@ -179,7 +177,7 @@ auto TestDuration::toCpp(ObjcType objc) -> CppType
if
(
!
objc
)
{
return
nullptr
;
}
return
objc
.
cppRef
.
get
();
return
objc
->
_cppRefHandle
.
get
();
}
auto
TestDuration
::
fromCpp
(
const
CppType
&
cpp
)
->
ObjcType
...
...
@@ -193,3 +191,5 @@ auto TestDuration::fromCpp(const CppType& cpp) -> ObjcType
}
}
// namespace djinni_generated
@end
test-suite/generated-src/objc/DBTestHelpers+Private.mm
View file @
3e817fcb
...
...
@@ -20,18 +20,18 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
@interface
DBTestHelpers
()
@property
(
nonatomic
,
readonly
)
::
djinni
::
DbxCppWrapperCache
<::
TestHelpers
>::
Handle
cppRef
;
-
(
id
)
initWithCpp
:(
const
std
::
shared_ptr
<::
TestHelpers
>&
)
cppRef
;
@end
@implementation
DBTestHelpers
@implementation
DBTestHelpers
{
::
djinni
::
DbxCppWrapperCache
<::
TestHelpers
>::
Handle
_cppRefHandle
;
}
-
(
id
)
initWithCpp
:(
const
std
::
shared_ptr
<::
TestHelpers
>&
)
cppRef
{
if
(
self
=
[
super
init
])
{
_cppRef
.
assign
(
cppRef
);
_cppRef
Handle
.
assign
(
cppRef
);
}
return
self
;
}
...
...
@@ -200,8 +200,6 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
}
DJINNI_TRANSLATE_EXCEPTIONS
()
}
@end
namespace
djinni_generated
{
auto
TestHelpers
::
toCpp
(
ObjcType
objc
)
->
CppType
...
...
@@ -209,7 +207,7 @@ auto TestHelpers::toCpp(ObjcType objc) -> CppType
if
(
!
objc
)
{
return
nullptr
;
}
return
objc
.
cppRef
.
get
();
return
objc
->
_cppRefHandle
.
get
();
}
auto
TestHelpers
::
fromCpp
(
const
CppType
&
cpp
)
->
ObjcType
...
...
@@ -223,3 +221,5 @@ auto TestHelpers::fromCpp(const CppType& cpp) -> ObjcType
}
}
// namespace djinni_generated
@end
test-suite/generated-src/objc/DBUserToken+Private.mm
View file @
3e817fcb
...
...
@@ -14,31 +14,29 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
@interface
DBUserTokenCppProxy
:
NSObject
<
DBUserToken
>
@property
(
nonatomic
,
readonly
)
::
djinni
::
DbxCppWrapperCache
<::
UserToken
>::
Handle
cppRef
;
-
(
id
)
initWithCpp
:(
const
std
::
shared_ptr
<::
UserToken
>&
)
cppRef
;
@end
@implementation
DBUserTokenCppProxy
@implementation
DBUserTokenCppProxy
{
::
djinni
::
DbxCppWrapperCache
<::
UserToken
>::
Handle
_cppRefHandle
;
}
-
(
id
)
initWithCpp
:(
const
std
::
shared_ptr
<::
UserToken
>&
)
cppRef
{
if
(
self
=
[
super
init
])
{
_cppRef
.
assign
(
cppRef
);
_cppRef
Handle
.
assign
(
cppRef
);
}
return
self
;
}
-
(
nonnull
NSString
*
)
whoami
{
try
{
auto
r
=
_cppRef
.
get
()
->
whoami
();
auto
r
=
_cppRef
Handle
.
get
()
->
whoami
();
return
::
djinni
::
String
::
fromCpp
(
r
);
}
DJINNI_TRANSLATE_EXCEPTIONS
()
}
@end
namespace
djinni_generated
{
class
UserToken
::
ObjcProxy
final
...
...
@@ -66,7 +64,7 @@ auto UserToken::toCpp(ObjcType objc) -> CppType
return
nullptr
;
}
if
([(
id
)
objc
isKindOfClass
:[
DBUserTokenCppProxy
class
]])
{
return
((
DBUserTokenCppProxy
*
)
objc
)
.
cppRef
.
get
();
return
((
DBUserTokenCppProxy
*
)
objc
)
->
_cppRefHandle
.
get
();
}
return
::
djinni
::
DbxObjcWrapperCache
<
ObjcProxy
>::
getInstance
()
->
get
(
objc
);
}
...
...
@@ -85,3 +83,5 @@ auto UserToken::fromCpp(const CppType& cpp) -> ObjcType
}
}
// namespace djinni_generated
@end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment