Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
NLua
Commits
08599a5b
Commit
08599a5b
authored
May 25, 2017
by
Hamish Milne
Browse files
Fixed object aliasing bug
parent
d0a17a61
Changes
1
Show whitespace changes
Inline
Side-by-side
Core/NLua/ObjectTranslator.cs
View file @
08599a5b
...
...
@@ -57,10 +57,26 @@ namespace NLua
*/
public
class
ObjectTranslator
{
// Compare cache entries by exact reference to avoid unwanted aliases
private
class
ReferenceComparer
:
IEqualityComparer
<
object
>
{
public
new
bool
Equals
(
object
x
,
object
y
)
{
if
(
x
!=
null
&&
y
!=
null
&&
x
.
GetType
()
==
y
.
GetType
()
&&
x
.
GetType
().
IsValueType
&&
y
.
GetType
().
IsValueType
)
return
x
.
Equals
(
y
);
// Special case for boxed value types
return
Object
.
ReferenceEquals
(
x
,
y
);
}
public
int
GetHashCode
(
object
obj
)
{
return
obj
.
GetHashCode
();
}
}
LuaNativeFunction
registerTableFunction
,
unregisterTableFunction
,
getMethodSigFunction
,
getConstructorSigFunction
,
importTypeFunction
,
loadAssemblyFunction
,
ctypeFunction
,
enumFromIntFunction
;
// object to object #
readonly
Dictionary
<
object
,
int
>
objectsBackMap
=
new
Dictionary
<
object
,
int
>
();
readonly
Dictionary
<
object
,
int
>
objectsBackMap
=
new
Dictionary
<
object
,
int
>
(
new
ReferenceComparer
()
);
// object # to object (FIXME - it should be possible to get object address as an object #)
readonly
Dictionary
<
int
,
object
>
objects
=
new
Dictionary
<
int
,
object
>
();
internal
EventHandlerContainer
pendingEvents
=
new
EventHandlerContainer
();
...
...
@@ -777,9 +793,9 @@ namespace NLua
int
index
=
nextObj
++;
objects
[
index
]
=
obj
;
#if NETFX_CORE
if
(!
obj
.
GetType
().
GetTypeInfo
().
IsValueType
||
obj
.
GetType
().
GetTypeInfo
().
Is
ValueType
)
if
(!
obj
.
GetType
().
GetTypeInfo
().
IsValueType
||
obj
.
GetType
().
GetTypeInfo
().
Is
Enum
)
#else
if
(!
obj
.
GetType
().
IsValueType
||
obj
.
GetType
().
Is
ValueType
)
if
(!
obj
.
GetType
().
IsValueType
||
obj
.
GetType
().
Is
Enum
)
#endif
objectsBackMap
[
obj
]
=
index
;
...
...
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