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
d87a3e5a
Commit
d87a3e5a
authored
Sep 24, 2017
by
Vinicius Jarina
Committed by
GitHub
Sep 24, 2017
Browse files
Merge pull request #230 from hamish-milne/master
Fixed object aliasing bug
parents
d0a17a61
08599a5b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Core/NLua/ObjectTranslator.cs
View file @
d87a3e5a
...
@@ -57,10 +57,26 @@ namespace NLua
...
@@ -57,10 +57,26 @@ namespace NLua
*/
*/
public
class
ObjectTranslator
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
,
LuaNativeFunction
registerTableFunction
,
unregisterTableFunction
,
getMethodSigFunction
,
getConstructorSigFunction
,
importTypeFunction
,
loadAssemblyFunction
,
ctypeFunction
,
enumFromIntFunction
;
getConstructorSigFunction
,
importTypeFunction
,
loadAssemblyFunction
,
ctypeFunction
,
enumFromIntFunction
;
// object to object #
// 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 #)
// object # to object (FIXME - it should be possible to get object address as an object #)
readonly
Dictionary
<
int
,
object
>
objects
=
new
Dictionary
<
int
,
object
>
();
readonly
Dictionary
<
int
,
object
>
objects
=
new
Dictionary
<
int
,
object
>
();
internal
EventHandlerContainer
pendingEvents
=
new
EventHandlerContainer
();
internal
EventHandlerContainer
pendingEvents
=
new
EventHandlerContainer
();
...
@@ -777,9 +793,9 @@ namespace NLua
...
@@ -777,9 +793,9 @@ namespace NLua
int
index
=
nextObj
++;
int
index
=
nextObj
++;
objects
[
index
]
=
obj
;
objects
[
index
]
=
obj
;
#if NETFX_CORE
#if NETFX_CORE
if
(!
obj
.
GetType
().
GetTypeInfo
().
IsValueType
||
obj
.
GetType
().
GetTypeInfo
().
Is
ValueType
)
if
(!
obj
.
GetType
().
GetTypeInfo
().
IsValueType
||
obj
.
GetType
().
GetTypeInfo
().
Is
Enum
)
#else
#else
if
(!
obj
.
GetType
().
IsValueType
||
obj
.
GetType
().
Is
ValueType
)
if
(!
obj
.
GetType
().
IsValueType
||
obj
.
GetType
().
Is
Enum
)
#endif
#endif
objectsBackMap
[
obj
]
=
index
;
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