Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
bingbingbingbing
mono
提交
b07a3824
M
mono
项目概览
bingbingbingbing
/
mono
与 Fork 源项目一致
从无法访问的项目Fork
通知
35
Star
0
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mono
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b07a3824
编写于
9月 24, 2010
作者:
Z
Zoltan Varga
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix the setting of pointer type fields using reflection. Fixes #641590.
上级
502b8e26
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
48 addition
and
1 deletion
+48
-1
mcs/class/corlib/Test/System.Reflection/FieldInfoTest.cs
mcs/class/corlib/Test/System.Reflection/FieldInfoTest.cs
+15
-1
mono/metadata/icall.c
mono/metadata/icall.c
+1
-0
mono/metadata/object.c
mono/metadata/object.c
+32
-0
未找到文件。
mcs/class/corlib/Test/System.Reflection/FieldInfoTest.cs
浏览文件 @
b07a3824
...
...
@@ -74,7 +74,7 @@ namespace MonoTests.System.Reflection
}
[
TestFixture
]
public
class
FieldInfoTest
public
unsafe
class
FieldInfoTest
{
[
NonSerialized
]
public
int
i
;
...
...
@@ -479,6 +479,20 @@ namespace MonoTests.System.Reflection
Assert
.
AreEqual
(
IntEnum
.
Third
,
typeof
(
Foo
<>).
GetField
(
"econstant"
).
GetValue
(
null
),
"#3"
);
}
public
static
unsafe
void
*
ip
;
[
Test
]
public
unsafe
void
GetSetValuePointers
()
{
int
i
=
5
;
void
*
p
=
&
i
;
typeof
(
FieldInfoTest
).
GetField
(
"ip"
).
SetValue
(
null
,
(
IntPtr
)
p
);
Pointer
p2
=
(
Pointer
)
typeof
(
FieldInfoTest
).
GetField
(
"ip"
).
GetValue
(
null
);
int
*
pi
=
(
int
*)
Pointer
.
Unbox
(
p2
);
Assert
.
AreEqual
(
5
,
*
pi
);
}
public
class
Foo
<
T
>
{
/*
...
...
mono/metadata/icall.c
浏览文件 @
b07a3824
...
...
@@ -1823,6 +1823,7 @@ ves_icall_MonoField_SetValueInternal (MonoReflectionField *field, MonoObject *ob
case
MONO_TYPE_I8
:
case
MONO_TYPE_R8
:
case
MONO_TYPE_VALUETYPE
:
case
MONO_TYPE_PTR
:
if
(
v
!=
NULL
)
v
+=
sizeof
(
MonoObject
);
break
;
...
...
mono/metadata/object.c
浏览文件 @
b07a3824
...
...
@@ -2994,6 +2994,7 @@ mono_field_get_value_object (MonoDomain *domain, MonoClassField *field, MonoObje
gboolean
is_static
=
FALSE
;
gboolean
is_ref
=
FALSE
;
gboolean
is_literal
=
FALSE
;
gboolean
is_ptr
=
FALSE
;
MonoError
error
;
MonoType
*
type
=
mono_field_get_type_checked
(
field
,
&
error
);
...
...
@@ -3028,6 +3029,9 @@ mono_field_get_value_object (MonoDomain *domain, MonoClassField *field, MonoObje
case
MONO_TYPE_GENERICINST
:
is_ref
=
!
mono_type_generic_inst_is_valuetype
(
type
);
break
;
case
MONO_TYPE_PTR
:
is_ptr
=
TRUE
;
break
;
default:
g_error
(
"type 0x%x not handled in "
"mono_field_get_value_object"
,
type
->
type
);
...
...
@@ -3067,6 +3071,34 @@ mono_field_get_value_object (MonoDomain *domain, MonoClassField *field, MonoObje
return
o
;
}
if
(
is_ptr
)
{
static
MonoMethod
*
m
;
gpointer
args
[
2
];
gpointer
*
ptr
;
gpointer
v
;
if
(
!
m
)
{
MonoClass
*
ptr_klass
=
mono_class_from_name_cached
(
mono_defaults
.
corlib
,
"System.Reflection"
,
"Pointer"
);
m
=
mono_class_get_method_from_name_flags
(
ptr_klass
,
"Box"
,
2
,
METHOD_ATTRIBUTE_STATIC
);
g_assert
(
m
);
}
v
=
&
ptr
;
if
(
is_literal
)
{
get_default_field_value
(
domain
,
field
,
v
);
}
else
if
(
is_static
)
{
mono_field_static_get_value
(
vtable
,
field
,
v
);
}
else
{
mono_field_get_value
(
obj
,
field
,
v
);
}
/* MONO_TYPE_PTR is passed by value to runtime_invoke () */
args
[
0
]
=
*
ptr
;
args
[
1
]
=
mono_type_get_object
(
mono_domain_get
(),
type
);
return
mono_runtime_invoke
(
m
,
NULL
,
args
,
NULL
);
}
/* boxed value type */
klass
=
mono_class_from_mono_type
(
type
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录