Skip to content

Commit 21fb92e

Browse files
committed
- Remove global placement new operator
- Add macros for defining placement new within derived classes (and use them in the example) - Fix copy errors on Windows when the temp DLL existed - Fix Bindings.h being included by Bindings.cpp on behalf of Game.h - Git-ignore Unity upgrade logs - Upgrade project to Unity 2019.2.0f1 and change the JSON config to add a newly-required type
1 parent d2be4ef commit 21fb92e

15 files changed

+444
-178
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# Rider IDE
2-
.idea
2+
.idea
3+
4+
# Unity upgrade logs
5+
Unity/Logs

Unity/Assets/CppSource/Game/Game.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace MyGame
1616
{
1717
struct BallScript : MyGame::BaseBallScript
1818
{
19+
MY_GAME_BALL_SCRIPT_DEFAULT_CONTENTS
1920
MY_GAME_BALL_SCRIPT_DEFAULT_CONSTRUCTOR
2021
void Update() override;
2122
};

Unity/Assets/CppSource/NativeScript/Bindings.cpp

Lines changed: 120 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,18 @@
99
/// MIT
1010
/// </license>
1111

12-
// Type definitions
13-
#include "Bindings.h"
14-
1512
// Game type definitions
1613
#include "Game.h"
1714

15+
// Type definitions
16+
#include "Bindings.h"
17+
1818
// For assert()
1919
#include <assert.h>
2020

21-
// For int32_t, etc.
22-
#include <stdint.h>
23-
24-
// For malloc(), etc.
25-
#include <stdlib.h>
26-
2721
// For memset(), etc.
2822
#include <string.h>
2923

30-
// Support placement new
31-
void* operator new(size_t, void* p)
32-
{
33-
return p;
34-
}
35-
3624
// Macro to put before functions that need to be exposed to C#
3725
#ifdef _WIN32
3826
#define DLLEXPORT extern "C" __declspec(dllexport)
@@ -3624,6 +3612,93 @@ namespace System
36243612
}
36253613
}
36263614

3615+
namespace System
3616+
{
3617+
namespace Runtime
3618+
{
3619+
namespace Serialization
3620+
{
3621+
IDeserializationCallback::IDeserializationCallback(decltype(nullptr))
3622+
{
3623+
}
3624+
3625+
IDeserializationCallback::IDeserializationCallback(Plugin::InternalUse, int32_t handle)
3626+
{
3627+
Handle = handle;
3628+
if (handle)
3629+
{
3630+
Plugin::ReferenceManagedClass(handle);
3631+
}
3632+
}
3633+
3634+
IDeserializationCallback::IDeserializationCallback(const IDeserializationCallback& other)
3635+
: IDeserializationCallback(Plugin::InternalUse::Only, other.Handle)
3636+
{
3637+
}
3638+
3639+
IDeserializationCallback::IDeserializationCallback(IDeserializationCallback&& other)
3640+
: IDeserializationCallback(Plugin::InternalUse::Only, other.Handle)
3641+
{
3642+
other.Handle = 0;
3643+
}
3644+
3645+
IDeserializationCallback::~IDeserializationCallback()
3646+
{
3647+
if (Handle)
3648+
{
3649+
Plugin::DereferenceManagedClass(Handle);
3650+
Handle = 0;
3651+
}
3652+
}
3653+
3654+
IDeserializationCallback& IDeserializationCallback::operator=(const IDeserializationCallback& other)
3655+
{
3656+
if (this->Handle)
3657+
{
3658+
Plugin::DereferenceManagedClass(this->Handle);
3659+
}
3660+
this->Handle = other.Handle;
3661+
if (this->Handle)
3662+
{
3663+
Plugin::ReferenceManagedClass(this->Handle);
3664+
}
3665+
return *this;
3666+
}
3667+
3668+
IDeserializationCallback& IDeserializationCallback::operator=(decltype(nullptr))
3669+
{
3670+
if (Handle)
3671+
{
3672+
Plugin::DereferenceManagedClass(Handle);
3673+
Handle = 0;
3674+
}
3675+
return *this;
3676+
}
3677+
3678+
IDeserializationCallback& IDeserializationCallback::operator=(IDeserializationCallback&& other)
3679+
{
3680+
if (Handle)
3681+
{
3682+
Plugin::DereferenceManagedClass(Handle);
3683+
}
3684+
Handle = other.Handle;
3685+
other.Handle = 0;
3686+
return *this;
3687+
}
3688+
3689+
bool IDeserializationCallback::operator==(const IDeserializationCallback& other) const
3690+
{
3691+
return Handle == other.Handle;
3692+
}
3693+
3694+
bool IDeserializationCallback::operator!=(const IDeserializationCallback& other) const
3695+
{
3696+
return Handle != other.Handle;
3697+
}
3698+
}
3699+
}
3700+
}
3701+
36273702
namespace System
36283703
{
36293704
Decimal::Decimal(decltype(nullptr))
@@ -3774,7 +3849,7 @@ namespace System
37743849
return nullptr;
37753850
}
37763851

3777-
System::Decimal::operator System::IFormattable()
3852+
System::Decimal::operator System::IComparable()
37783853
{
37793854
int32_t handle = Plugin::BoxDecimal(Handle);
37803855
if (Plugin::unhandledCsharpException)
@@ -3787,7 +3862,25 @@ namespace System
37873862
if (handle)
37883863
{
37893864
Plugin::ReferenceManagedClass(handle);
3790-
return System::IFormattable(Plugin::InternalUse::Only, handle);
3865+
return System::IComparable(Plugin::InternalUse::Only, handle);
3866+
}
3867+
return nullptr;
3868+
}
3869+
3870+
System::Decimal::operator System::IComparable_1<System::Decimal>()
3871+
{
3872+
int32_t handle = Plugin::BoxDecimal(Handle);
3873+
if (Plugin::unhandledCsharpException)
3874+
{
3875+
System::Exception* ex = Plugin::unhandledCsharpException;
3876+
Plugin::unhandledCsharpException = nullptr;
3877+
ex->ThrowReferenceToThis();
3878+
delete ex;
3879+
}
3880+
if (handle)
3881+
{
3882+
Plugin::ReferenceManagedClass(handle);
3883+
return System::IComparable_1<System::Decimal>(Plugin::InternalUse::Only, handle);
37913884
}
37923885
return nullptr;
37933886
}
@@ -3810,7 +3903,7 @@ namespace System
38103903
return nullptr;
38113904
}
38123905

3813-
System::Decimal::operator System::IComparable()
3906+
System::Decimal::operator System::IEquatable_1<System::Decimal>()
38143907
{
38153908
int32_t handle = Plugin::BoxDecimal(Handle);
38163909
if (Plugin::unhandledCsharpException)
@@ -3823,12 +3916,12 @@ namespace System
38233916
if (handle)
38243917
{
38253918
Plugin::ReferenceManagedClass(handle);
3826-
return System::IComparable(Plugin::InternalUse::Only, handle);
3919+
return System::IEquatable_1<System::Decimal>(Plugin::InternalUse::Only, handle);
38273920
}
38283921
return nullptr;
38293922
}
38303923

3831-
System::Decimal::operator System::IComparable_1<System::Decimal>()
3924+
System::Decimal::operator System::Runtime::Serialization::IDeserializationCallback()
38323925
{
38333926
int32_t handle = Plugin::BoxDecimal(Handle);
38343927
if (Plugin::unhandledCsharpException)
@@ -3841,12 +3934,12 @@ namespace System
38413934
if (handle)
38423935
{
38433936
Plugin::ReferenceManagedClass(handle);
3844-
return System::IComparable_1<System::Decimal>(Plugin::InternalUse::Only, handle);
3937+
return System::Runtime::Serialization::IDeserializationCallback(Plugin::InternalUse::Only, handle);
38453938
}
38463939
return nullptr;
38473940
}
38483941

3849-
System::Decimal::operator System::IEquatable_1<System::Decimal>()
3942+
System::Decimal::operator System::IFormattable()
38503943
{
38513944
int32_t handle = Plugin::BoxDecimal(Handle);
38523945
if (Plugin::unhandledCsharpException)
@@ -3859,7 +3952,7 @@ namespace System
38593952
if (handle)
38603953
{
38613954
Plugin::ReferenceManagedClass(handle);
3862-
return System::IEquatable_1<System::Decimal>(Plugin::InternalUse::Only, handle);
3955+
return System::IFormattable(Plugin::InternalUse::Only, handle);
38633956
}
38643957
return nullptr;
38653958
}
@@ -5325,7 +5418,7 @@ namespace UnityEngine
53255418
return nullptr;
53265419
}
53275420

5328-
UnityEngine::PrimitiveType::operator System::IFormattable()
5421+
UnityEngine::PrimitiveType::operator System::IComparable()
53295422
{
53305423
int32_t handle = Plugin::BoxPrimitiveType(*this);
53315424
if (Plugin::unhandledCsharpException)
@@ -5338,7 +5431,7 @@ namespace UnityEngine
53385431
if (handle)
53395432
{
53405433
Plugin::ReferenceManagedClass(handle);
5341-
return System::IFormattable(Plugin::InternalUse::Only, handle);
5434+
return System::IComparable(Plugin::InternalUse::Only, handle);
53425435
}
53435436
return nullptr;
53445437
}
@@ -5361,7 +5454,7 @@ namespace UnityEngine
53615454
return nullptr;
53625455
}
53635456

5364-
UnityEngine::PrimitiveType::operator System::IComparable()
5457+
UnityEngine::PrimitiveType::operator System::IFormattable()
53655458
{
53665459
int32_t handle = Plugin::BoxPrimitiveType(*this);
53675460
if (Plugin::unhandledCsharpException)
@@ -5374,7 +5467,7 @@ namespace UnityEngine
53745467
if (handle)
53755468
{
53765469
Plugin::ReferenceManagedClass(handle);
5377-
return System::IComparable(Plugin::InternalUse::Only, handle);
5470+
return System::IFormattable(Plugin::InternalUse::Only, handle);
53785471
}
53795472
return nullptr;
53805473
}

0 commit comments

Comments
 (0)