Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

PyType class, wrapper for Python types#1395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
lostmsu merged 3 commits intopythonnet:masterfromlosttech:features/PyType
Mar 30, 2021

Conversation

lostmsu
Copy link
Member

What does this implement/fix? Explain your changes.

This introduces a newPyType class (similar toPyInt, but for types). It can:

  • wrap existingPyObject, that points to a type
  • create a new heap type from spec (TypeSpec class)

Does this close any currently open issues?

It is WIP on#1033
It is related to#1196

Checklist

Check all those that are applicable and complete.

  • Make sure to include one or more tests for your change
  • Updated theCHANGELOG

@lostmsu
Copy link
MemberAuthor

lostmsu commentedFeb 22, 2021
edited
Loading

Hm, on non-Windows, utf8 decoding fails inside Python with a funky nÁmæ. This might be an existing problem with UTF-8 string marshaling.

@@ -14,7 +14,7 @@ internal CLRObject(object ob, IntPtr tp)
System.Diagnostics.Debug.Assert(tp != IntPtr.Zero);
IntPtr py = Runtime.PyType_GenericAlloc(tp, 0);

long flags =Util.ReadCLong(tp, TypeOffset.tp_flags);
var flags =(TypeFlags)Marshal.ReadInt32(tp, TypeOffset.tp_flags);
Copy link
Member

Choose a reason for hiding this comment

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

tp_flags is along, not anint32.

Copy link
MemberAuthor

@lostmsulostmsuFeb 23, 2021
edited
Loading

Choose a reason for hiding this comment

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

Reverted back to usingUtil.ReadCLong.
Surprisingly inPyType_Spec flags are of typeunsigned int, which implies they should never exceed2^32.

typedefstruct{constchar*name;intbasicsize;intitemsize;unsignedintflags;PyType_Slot*slots;/* terminated by slot==0. */}PyType_Spec;

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Hm. Actually, because of the above we can probably useReadInt32.
tp_flags is the only field, that is assumed to be declared aslong. So we could removeReadCLong andWriteCLong helpers then.

@lostmsulostmsuforce-pushed thefeatures/PyType branch 4 times, most recently from982a4de to73661fdCompareFebruary 23, 2021 02:18
@lostmsu
Copy link
MemberAuthor

lostmsu commentedFeb 23, 2021
edited
Loading

Damn Mono incorrectly marshaled

[StructLayout(Sequential)]classByReference{SomeFields;}

No idea why. Wasted whole day trying to figure it out. .NET Core and .NET Framework worked correctly on all platforms. According toMono docs it should have worked.

After switching to

[StructLayout(Sequential)]structByValue{SomeFields;}

and passing it asin ByValue, tests are passing.

@lostmsu
Copy link
MemberAuthor

P.S. I tried to isolate commits, so best to rebase or merge.

@lostmsulostmsu requested a review fromfilmorFebruary 23, 2021 02:26
@lostmsu
Copy link
MemberAuthor

@filmor can you re-review this one? I am continuing to do cleanup, and in-progress work onTypeManager would greatly benefit from this class.

@lostmsulostmsu merged commit95d5e35 intopythonnet:masterMar 30, 2021
@lostmsulostmsu deleted the features/PyType branchMarch 30, 2021 23:39
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@filmorfilmorAwaiting requested review from filmor

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@lostmsu@filmor

[8]ページ先頭

©2009-2025 Movatter.jp