Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.

Type.Name instead of Type.CType #45

Merged
merged 13 commits into from
Mar 4, 2018
Merged

Type.Name instead of Type.CType #45

merged 13 commits into from
Mar 4, 2018

Conversation

sundermann
Copy link
Collaborator

No description provided.

sundermann and others added 9 commits March 3, 2018 23:35
It seems like Type.Name is more common in gir. For instance,
implements refers to the interface by name and not c:type. This is also
handy because we do not have to strip off any trailing const or leading
pointers.
Sometimes arrays do not have a name. In this case use Type.Name instead
Object is now resolved as Class
@@ -12,11 +12,12 @@ void RegisterBuiltIn (bool nativeWin64)
AddType (new StringMarshal ("gfilename", "string", "", "IntPtr"));//, "GLib.Marshaller.StringToFilenamePtr({0})", "GLib.Marshaller.FilenamePtrToStringGFree({0})"));
AddType (new StringMarshal ("gchar", "string", "", "IntPtr"));//, "GLib.Marshaller.StringToPtrGStrdup({0})", "GLib.Marshaller.PtrToStringGFree({0})"));
AddType (new StringMarshal ("char", "string", "", "IntPtr"));//, "GLib.Marshaller.StringToPtrGStrdup({0})", "GLib.Marshaller.PtrToStringGFree({0})"));
AddType (new StringMarshal ("utf8", "string", "", "IntPtr"));//, "GLib.Marshaller.StringToPtrGStrdup({0})", "GLib.Marshaller.PtrToStringGFree({0})"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just stubbed this out. I'm not sure what else we want here if anything?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decriptor
decriptor previously approved these changes Mar 4, 2018
@@ -48,12 +48,13 @@ public void NoAliasTypeAfterProcessing ()
}

[Test]
[Ignore("there is no void*")]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test can probably be removed as there are no pointers inside Type.Name

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets remove it. Ignored tests seem to cause problems with CI for right now.

SymbolTable = new SymbolTable(Statistics, options.Win64Longs);
SymbolTable.AddTypes (repo.GetSymbols());
foreach (var repository in resolvedRepos) {
SymbolTable.AddTypes (repository.GetSymbols(), repository);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This includes the main repository so the mainrepository is in the symbol table twice: Once without and once with namespace prefix. This is because arrays seem to behave weird. There are array types inside GLib which have GLib.ByteArray as type where it should have been just ByteArray. That's why I added the repository twice.

@@ -5,7 +5,12 @@ public partial class Array
{
public ISymbol GetSymbol (GenerationOptions opts)
{
return opts.SymbolTable [CType];
if (Name != null) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes there is for some reason no Name on arrays. Bug in gi maybe?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

byte_array_new_take in GLib-2.0.gir

          <array length="1" zero-terminated="0" c:type="guint8*">
            <type name="guint8" c:type="guint8"/>
          </array>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure you haven't modified the gir locally? It does have it for me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    <function name="byte_array_new_take"
              c:identifier="g_byte_array_new_take"
              moved-to="ByteArray.new_take"
              version="2.32">
      <doc xml:space="preserve">Create byte array containing the data. The data will be owned by the array
and will be freed with g_free(), i.e. it could be allocated using g_strdup().</doc>
      <return-value transfer-ownership="full">
        <doc xml:space="preserve">a new #GByteArray</doc>
        <array name="GLib.ByteArray" c:type="GByteArray*">
          <type name="guint8" c:type="guint8"/>
        </array>
      </return-value>
      <parameters>
        <parameter name="data" transfer-ownership="full">
          <doc xml:space="preserve">byte data for the array</doc>
          <array length="1" zero-terminated="0" c:type="guint8*">
            <type name="guint8" c:type="guint8"/>
          </array>
        </parameter>
        <parameter name="len" transfer-ownership="none">
          <doc xml:space="preserve">length of @data</doc>
          <type name="gsize" c:type="gsize"/>
        </parameter>
      </parameters>
    </function>

It's not there in the data parameter

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, for that case, I looked at the code, and in that case, it's just a uint8 pointer:
https://github.com/GNOME/glib/blob/90d3337e1d9d8218f1f8509417b6ae65993aa029/glib/garray.c#L1661

I guess when name isn't there, we need to pass in an array of the element type, it's not a specific gtype

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, when we have a array with no name, it's just an Array ISymbol that has T[] as the managed type

@@ -12,11 +12,12 @@ void RegisterBuiltIn (bool nativeWin64)
AddType (new StringMarshal ("gfilename", "string", "", "IntPtr"));//, "GLib.Marshaller.StringToFilenamePtr({0})", "GLib.Marshaller.FilenamePtrToStringGFree({0})"));
AddType (new StringMarshal ("gchar", "string", "", "IntPtr"));//, "GLib.Marshaller.StringToPtrGStrdup({0})", "GLib.Marshaller.PtrToStringGFree({0})"));
AddType (new StringMarshal ("char", "string", "", "IntPtr"));//, "GLib.Marshaller.StringToPtrGStrdup({0})", "GLib.Marshaller.PtrToStringGFree({0})"));
AddType (new StringMarshal ("utf8", "string", "", "IntPtr"));//, "GLib.Marshaller.StringToPtrGStrdup({0})", "GLib.Marshaller.PtrToStringGFree({0})"));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we need the others. It seems like the string type name is utf8 for gchar and char in gir.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added char because I ran into it. The others I grabbed because of the old generator.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, if we go down this route, utf8 is the only one we need.

@@ -54,6 +55,20 @@ void RegisterPrimitives (bool nativeWin64)

AddType (new Primitive ("va_list", "...", ""));

var alias = new Alias {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of a hack. It seems like GType is kind of a primitive since in GObject GType is used without a prefix even though the definition is in GLib.

@@ -72,20 +86,20 @@ static string TrimConstAndPointer (string type)
return type.Substring (start, end - start);
}

public ISymbol this [string type] {
get {
var actualType = TrimConstAndPointer (type);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TrimConstAndPointer is not used anymore now but I kept the method for now. Do we want to remove it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a new project lets be proactive in removing stuff that isn't being used anymore.

Copy link
Contributor

@Therzok Therzok Mar 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove it.


if (!typeMap.TryGetValue(toType, out target)) {
// HACK?!: this might be in a included repository but these are prefixed in symbol table
toType = $"{repository}.{alias.Type.Name}";
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to correctly dealias symbols in included repositories.

@@ -5,7 +5,7 @@ public partial class Varargs : ISymbol
{
public string CSharpType => "...";

public string CType => "va_list";
public string Name => "va_list";
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this one

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole class will be rewritten to support overridden data, so it's fine for now.

@@ -23,7 +23,7 @@ public Object (UIntPtr object_type, string first_property_name, ... var_args) :
{
}

static extern IntPtr g_object_newv (UIntPtr object_type, uint n_parameters, Parameter parameters);
static extern Object g_object_newv (UIntPtr object_type, uint n_parameters, Parameter parameters);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right. We don't want the pinvoke signature to use the C# type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but Classes use RetVal.CSharpType right now which points to Object

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the test changed because Object was not resolved correctly?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aaaah, yes! I thought we used CType, but we don't 👍

@sundermann
Copy link
Collaborator Author

Not sure why jenkins is not building this PR

@Therzok
Copy link
Contributor

Therzok commented Mar 4, 2018

@directhex ^^

@Therzok
Copy link
Contributor

Therzok commented Mar 4, 2018

@monojenkins build

@Therzok
Copy link
Contributor

Therzok commented Mar 4, 2018

whitelist

@Therzok
Copy link
Contributor

Therzok commented Mar 4, 2018

@monojenkins whitelist

@sundermann sundermann changed the title Type name rebase Type.Name instead of Type.CType Mar 4, 2018
@Therzok
Copy link
Contributor

Therzok commented Mar 4, 2018

CLA was signed before, see #30

@Therzok Therzok merged commit a18b001 into master Mar 4, 2018
@Therzok Therzok deleted the type-name-rebase branch March 4, 2018 20:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants