Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
[ManagedTypeInfo] Only store the Type::Kind, not the string name (again)
Browse files Browse the repository at this point in the history
Implement the same fix as last time except this time round do not change the
value stored in Type::name. Instead just have an additional field which will
always store the full type name. This is the value that the parser should use
and fixes the regression where styles in the SL3 parser could not be found.
  • Loading branch information
alanmcgovern committed Mar 31, 2011
1 parent 4717f2a commit a4e14bf
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 51 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -48,3 +48,4 @@ xdb.*
/src/factory.h
/src/type-generated.cpp
/config.cache
*.pidb
7 changes: 6 additions & 1 deletion class/System.Windows/Mono/Types.cs
Expand Up @@ -147,7 +147,12 @@ private ManagedType RegisterType (Type type, ManagedType parent, ManagedType[] i
else {
string cp = GetContentPropertyName (type);

info.native_handle = NativeMethods.types_register_type (native, type.FullName, cp,
// We explicitly use type.FullName instead of type.Name for the second parameter there. This is
// because only built-in types can register type.Name as their 'name'. This allows builtins to be
// accessed in xaml by writing stuff like "Control.Width" whereas custom types must be explicitly
// namespaced and prefixed so you have to write: clrMyNs:MyControl.Foo in xaml instead of just
// MyControl.Foo.
info.native_handle = NativeMethods.types_register_type (native, type.FullName, type.FullName, cp,
GCHandle.ToIntPtr (info.gc_handle),
(parent != null ? parent.native_handle : Kind.INVALID),
type.IsEnum,
Expand Down
8 changes: 1 addition & 7 deletions class/System.Windows/Mono/Value.cs
Expand Up @@ -125,7 +125,6 @@ public VideoFormat ToVideoFormat ()

[StructLayout(LayoutKind.Sequential)]
internal struct ManagedTypeInfo {
public IntPtr full_name;
public Kind Kind;
}

Expand Down Expand Up @@ -711,13 +710,8 @@ public static Value FromObject (object v, bool box_value_types)
}
else if (v is Type) {
Type t = v as Type;
ManagedTypeInfo mti = new ManagedTypeInfo ();
mti.full_name = StringToIntPtr (t.FullName);
mti.Kind = Deployment.Current.Types.TypeToKind (t);

value.k = Kind.MANAGEDTYPEINFO;
value.u.p = Marshal.AllocHGlobal (sizeof (ManagedTypeInfo));
Marshal.StructureToPtr (mti, value.u.p, false);
value.u.p = NativeMethods.managed_type_info_new (Deployment.Current.Types.TypeToKind (t));
} else if (v is Value) {
throw new InvalidOperationException ("You can not create a Mono.Value from a Mono.Value.");
}
Expand Down
Expand Up @@ -637,6 +637,9 @@
# p/invoke declaration
+SC-M: System.IntPtr Mono.NativeMethods::log_ready_routed_event_args_get_log_(System.IntPtr)

# p/invoke declaration
+SC-M: System.IntPtr Mono.NativeMethods::managed_type_info_new(Mono.Kind)

# p/invoke declaration
+SC-M: System.IntPtr Mono.NativeMethods::matrix_get_matrix_values(System.IntPtr)

Expand Down
11 changes: 6 additions & 5 deletions generators/Generator.cs
Expand Up @@ -2849,9 +2849,9 @@ static void GenerateTypeStaticCpp (GlobalInfo all)
text.AppendLine ("Types::RegisterNativeTypes ()");
text.AppendLine ("{");
text.AppendLine ("\tDeployment *deployment = Deployment::GetCurrent ();");
text.AppendLine ("\ttypes [(int) Type::INVALID] = new Type (deployment, Type::INVALID, Type::INVALID, false, false, false, NULL, 0, 0, NULL, 0, NULL, false, NULL, NULL );");
text.AppendLine ("\ttypes [(int) Type::ENUM] = new Type (deployment, Type::ENUM, Type::OBJECT, false, false, false, \"Enum\", 0, 0, NULL, 0, NULL, false, NULL, NULL );");
text.AppendLine ("\ttypes [(int) Type::DATETIME] = new Type (deployment, Type::DATETIME, Type::OBJECT, false, false, false, \"DateTime\", 0, 0, NULL, 0, NULL, false, NULL, NULL );");
text.AppendLine ("\ttypes [(int) Type::INVALID] = new Type (deployment, Type::INVALID, Type::INVALID, false, false, false, NULL, NULL, 0, 0, NULL, 0, NULL, false, NULL, NULL );");
text.AppendLine ("\ttypes [(int) Type::ENUM] = new Type (deployment, Type::ENUM, Type::OBJECT, false, false, false, \"Enum\", \"System.Enum\", 0, 0, NULL, 0, NULL, false, NULL, NULL );");
text.AppendLine ("\ttypes [(int) Type::DATETIME] = new Type (deployment, Type::DATETIME, Type::OBJECT, false, false, false, \"DateTime\", \"System.DateTime\", 0, 0, NULL, 0, NULL, false, NULL, NULL );");

foreach (TypeInfo type in all.Children.SortedTypesByKind) {
MemberInfo member;
Expand Down Expand Up @@ -2883,13 +2883,14 @@ static void GenerateTypeStaticCpp (GlobalInfo all)
parentKind = "OBJECT";
}

text.AppendLine (string.Format (@" types [(int) {0}] = new Type (deployment, {0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13});",
text.AppendLine (string.Format (@" types [(int) {0}] = new Type (deployment, {0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {14});",
"Type::" + type.KindName,
"Type::" + parentKind,
type.IsEnum ? "true" : "false",
IsValueType (type) ? "true" : "false",
type.IsInterface ? "true" : "false",
"\"" + type.Name + "\"",
"\"" + type.ManagedFullName + "\"",
type.GetEventCount (),
type.GetTotalEventCount (),
events,
Expand All @@ -2906,7 +2907,7 @@ static void GenerateTypeStaticCpp (GlobalInfo all)
);
}

text.AppendLine ("\ttypes [(int) Type::LASTTYPE] = new Type (deployment, Type::LASTTYPE, Type::INVALID, false, false, false, NULL, 0, 0, NULL, 0, NULL, false, NULL, NULL);");
text.AppendLine ("\ttypes [(int) Type::LASTTYPE] = new Type (deployment, Type::LASTTYPE, Type::INVALID, false, false, false, NULL, NULL, 0, 0, NULL, 0, NULL, false, NULL, NULL);");

text.AppendLine ("}");

Expand Down
2 changes: 1 addition & 1 deletion generators/MemberInfo.cs
Expand Up @@ -155,7 +155,7 @@ class MemberInfo {
if (managed_fullname == null) {
if (Parent != null && !string.IsNullOrEmpty (Parent.ManagedFullName)) {
managed_fullname = Parent.ManagedFullName + "." + Name;
} else if (Namespace != null) {
} else if (Namespace != null && Namespace != "None") {
managed_fullname = Namespace + "." + FullName;
} else {
managed_fullname = FullName;
Expand Down
2 changes: 1 addition & 1 deletion src/contentcontrol.cpp
Expand Up @@ -24,7 +24,7 @@ ContentControl::ContentControl ()
SetContentSetsParent (true);
SetObjectType (Type::CONTENTCONTROL);

ManagedTypeInfo type_info (GetObjectType (), "System.Windows.Controls.ContentControl");
ManagedTypeInfo type_info (GetObjectType ());
SetDefaultStyleKey (&type_info);
}

Expand Down
22 changes: 4 additions & 18 deletions src/managedtypeinfo.cpp
Expand Up @@ -16,32 +16,20 @@

namespace Moonlight {

ManagedTypeInfo::ManagedTypeInfo (Type::Kind kind, const char *full_name)
ManagedTypeInfo::ManagedTypeInfo (Type::Kind kind)
{
Initialize (kind, full_name);
this->kind = kind;
}

ManagedTypeInfo::ManagedTypeInfo (const ManagedTypeInfo& v)
{
Initialize (v.kind, v.full_name);
}

ManagedTypeInfo::~ManagedTypeInfo ()
{
g_free (full_name);
}

void
ManagedTypeInfo::Initialize (Type::Kind kind, const char *full_name)
{
this->kind = kind;
this->full_name = g_strdup (full_name);
this->kind = v.kind;
}

bool
ManagedTypeInfo::operator == (const ManagedTypeInfo &v) const
{
return kind == v.kind && strcmp (full_name, v.full_name) == 0;
return kind == v.kind;
}

bool
Expand All @@ -54,9 +42,7 @@ ManagedTypeInfo&
ManagedTypeInfo::operator = (const ManagedTypeInfo &v)
{
if (this != &v) {
g_free (this->full_name);
this->kind = v.kind;
this->full_name = g_strdup (v.full_name);
}
return *this;
}
Expand Down
8 changes: 3 additions & 5 deletions src/managedtypeinfo.h
Expand Up @@ -18,14 +18,12 @@ namespace Moonlight {
/* @IncludeInKinds */
class ManagedTypeInfo {
public:
char *full_name;
Type::Kind kind;

ManagedTypeInfo (Type::Kind kind, const char *full_name);
/* @GeneratePInvoke */
ManagedTypeInfo (Type::Kind kind);
ManagedTypeInfo (const ManagedTypeInfo& v);
~ManagedTypeInfo ();

void Initialize (Type::Kind kind, const char *full_name);
~ManagedTypeInfo () { }

bool operator == (const ManagedTypeInfo &v) const;
bool operator != (const ManagedTypeInfo &v) const;
Expand Down
2 changes: 1 addition & 1 deletion src/provider.cpp
Expand Up @@ -1205,7 +1205,7 @@ AutoCreators::CreateBlackBrush (Type::Kind kind, DependencyProperty *property, D
Value *
AutoCreators::ControlTypeCreator (Type::Kind kind, DependencyProperty *property, DependencyObject *forObj)
{
ManagedTypeInfo info (Type::CONTROL, "System.Windows.Controls.Control");
ManagedTypeInfo info (Type::CONTROL);
return new Value (&info);
}

Expand Down
2 changes: 1 addition & 1 deletion src/richtextbox.cpp
Expand Up @@ -576,7 +576,7 @@ RichTextBox::RichTextBox ()
{
SetObjectType (Type::RICHTEXTBOX);

ManagedTypeInfo type_info (GetObjectType (), "System.Windows.Controls.RichTextBox");
ManagedTypeInfo type_info (GetObjectType ());
SetDefaultStyleKey (&type_info);

AddHandler (UIElement::MouseLeftButtonMultiClickEvent, RichTextBox::mouse_left_button_multi_click, this);
Expand Down
8 changes: 4 additions & 4 deletions src/textbox.cpp
Expand Up @@ -556,11 +556,11 @@ GetClipboard (TextBoxBase *textbox, MoonClipboardType clipboardType)
}

void
TextBoxBase::Initialize (Type::Kind type, const char *type_name)
TextBoxBase::Initialize (Type::Kind type)
{
SetObjectType (type);

ManagedTypeInfo type_info (GetObjectType (), type_name);
ManagedTypeInfo type_info (GetObjectType ());
SetDefaultStyleKey (&type_info);

AddHandler (UIElement::MouseLeftButtonMultiClickEvent, TextBoxBase::mouse_left_button_multi_click, this);
Expand Down Expand Up @@ -2529,7 +2529,7 @@ TextBox::TextBox ()
delete providers.dynamicvalue;
providers.dynamicvalue = new TextBoxDynamicPropertyValueProvider (this, PropertyPrecedence_DynamicValue);

Initialize (Type::TEXTBOX, "System.Windows.Controls.TextBox");
Initialize (Type::TEXTBOX);
events_mask = TEXT_CHANGED | SELECTION_CHANGED;
multiline = true;
}
Expand Down Expand Up @@ -2882,7 +2882,7 @@ PasswordBox::PasswordBox ()
delete providers.dynamicvalue;
providers.dynamicvalue = new PasswordBoxDynamicPropertyValueProvider (this, PropertyPrecedence_DynamicValue);

Initialize (Type::PASSWORDBOX, "System.Windows.Controls.PasswordBox");
Initialize (Type::PASSWORDBOX);
events_mask = TEXT_CHANGED;
secret = true;

Expand Down
2 changes: 1 addition & 1 deletion src/textbox.h
Expand Up @@ -242,7 +242,7 @@ class TextBoxBase : public Control, public ITextAttributes {
//
// Initialization/Destruction
//
void Initialize (Type::Kind type, const char *type_name);
void Initialize (Type::Kind type);
virtual ~TextBoxBase ();

public:
Expand Down
8 changes: 5 additions & 3 deletions src/type.cpp
Expand Up @@ -26,7 +26,7 @@ namespace Moonlight {
* Type implementation
*/
Type::Type (Deployment *deployment, Type::Kind type, Type::Kind parent, bool is_enum, bool is_value_type, bool is_interface,
const char *name,
const char *name, const char *full_name,
int event_count, int total_event_count, const char **events,
int interface_count, const Type::Kind *interfaces, bool ctor_visible,
create_inst_func *create_inst, const char *content_property)
Expand All @@ -37,6 +37,7 @@ Type::Type (Deployment *deployment, Type::Kind type, Type::Kind parent, bool is_
this->is_value_type = is_value_type;
this->is_interface = is_interface;
this->name = g_strdup (name);
this->full_name = g_strdup (full_name);
this->event_count = event_count;
this->total_event_count = total_event_count;
this->events = events;
Expand Down Expand Up @@ -73,6 +74,7 @@ Types::SetFastPaths ()
Type::~Type ()
{
g_free (name);
g_free (full_name);
g_free (content_property);

if (properties) {
Expand Down Expand Up @@ -521,9 +523,9 @@ Types::Find (const char *name, bool ignore_case)
}

Type::Kind
Types::RegisterType (const char *name, const char *content_property, void *gc_handle, Type::Kind parent, bool is_enum, bool is_value_type, bool is_interface, bool ctor_visible, Type::Kind* interfaces, int interface_count)
Types::RegisterType (const char *name, const char *full_name, const char *content_property, void *gc_handle, Type::Kind parent, bool is_enum, bool is_value_type, bool is_interface, bool ctor_visible, Type::Kind* interfaces, int interface_count)
{
Type *type = new Type (Deployment::GetCurrent (), Type::INVALID, parent, is_enum, is_value_type, is_interface, name, 0, Find (parent)->GetEventCount (), NULL, interface_count, interfaces, ctor_visible, NULL, content_property);
Type *type = new Type (Deployment::GetCurrent (), Type::INVALID, parent, is_enum, is_value_type, is_interface, name, full_name, 0, Find (parent)->GetEventCount (), NULL, interface_count, interfaces, ctor_visible, NULL, content_property);

// printf ("Types::RegisterType (%s, %p, %i (%s)). this: %p, size: %i, count: %i\n", name, gc_handle, parent, Type::Find (this, parent) ? Type::Find (this, parent)->name : NULL, this, size, count);

Expand Down
6 changes: 4 additions & 2 deletions src/type.h.in
Expand Up @@ -73,6 +73,7 @@ public:
bool IsInterface () { return is_interface; }
bool IsCustomType () { return type > LASTTYPE; }
const char *GetName () { return name; }
const char *GetFullName () { return full_name; }
int GetEventCount () { return total_event_count; }
int GetInterfaceCount () { return interface_count; }
Type::Kind GetInterface (int i) { return i >= 0 && i < interface_count ? interfaces[i] : Type::INVALID; }
Expand All @@ -81,7 +82,7 @@ public:

~Type ();
Type (Deployment *deployment, Type::Kind type, Type::Kind parent, bool is_enum, bool is_value_type, bool is_interface,
const char *name,
const char *name, const char *full_name,
int event_count, int total_event_count, const char **events,
int interface_count, const Type::Kind *interfaces, bool ctor_visible,
create_inst_func *create_inst, const char *content_property);
Expand Down Expand Up @@ -109,6 +110,7 @@ private:
bool is_dependencyobject; // if this type is a value type

char *name; // The name as it appears in code.
char *full_name; // The namespace prefixed typename.

int interface_count;
Type::Kind *interfaces;
Expand Down Expand Up @@ -145,7 +147,7 @@ public:
~Types ();

/* @GeneratePInvoke */
Type::Kind RegisterType (const char *name, const char *content_property, void *gc_handle, Type::Kind parent, bool is_enum, bool is_value_type, bool is_interface, bool ctor_visible, /* @MarshalAs=Kind[] */Type::Kind *interfaces, int interface_count);
Type::Kind RegisterType (const char *name, const char *full_name, const char *content_property, void *gc_handle, Type::Kind parent, bool is_enum, bool is_value_type, bool is_interface, bool ctor_visible, /* @MarshalAs=Kind[] */Type::Kind *interfaces, int interface_count);

/* @GeneratePInvoke */
void RegisterInterfaces (Type::Kind type, /* @MarshalAs=Kind[] */Type::Kind *interfaces, int interface_count);
Expand Down
2 changes: 1 addition & 1 deletion src/xaml.cpp
Expand Up @@ -4842,7 +4842,7 @@ get_key_from_child (XamlElementInstance *child)
if (Type::IsSubclassOf (c->GetDeployment (), Type::STYLE, child->info->GetKind ())) {
Value *v = c->GetValue (Style::TargetTypeProperty);
if (!Value::IsNull (v))
key = v->AsManagedTypeInfo ()->full_name;
key = c->GetDeployment ()->GetTypes ()->Find (v->AsManagedTypeInfo ()->kind)->GetFullName ();

if (key)
return key;
Expand Down

0 comments on commit a4e14bf

Please sign in to comment.