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

Commit782eff8

Browse files
authored
Merge pull request#1138 from pythonnet/python38
2 parentsd8f5ab0 +ed2b7e8 commit782eff8

File tree

6 files changed

+80
-35
lines changed

6 files changed

+80
-35
lines changed

‎.travis.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ dist: xenial
22
sudo:false
33
language:python
44
python:
5-
-2.7
6-
-3.5
7-
-3.6
5+
-3.8
86
-3.7
7+
-3.6
8+
-3.5
9+
-2.7
910

1011
env:
1112
matrix:

‎CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
1717
- Added PythonException.Format method to format exceptions the same as traceback.format_exception
1818
- Added Runtime.None to be able to pass None as parameter into Python from .NET
1919
- Added PyObject.IsNone() to check if a Python object is None in .NET.
20+
- Support for Python 3.8
2021

2122
###Changed
2223

@@ -29,6 +30,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
2930
- Added support for kwarg parameters when calling .NET methods from Python
3031
- Changed method for finding MSBuild using vswhere
3132
- Reworked`Finalizer`. Now objects drop into its queue upon finalization, which is periodically drained when new objects are created.
33+
- Marked`Runtime.OperatingSystemName` and`Runtime.MachineName` as`Obsolete`, should never have been`public` in the first place. They also don't necessarily return a result that matches the`platform` module's.
3234

3335
###Fixed
3436

@@ -37,6 +39,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
3739
- Fixes bug where delegates get casts (dotnetcore)
3840
- Determine size of interpreter longs at runtime
3941
- Handling exceptions ocurred in ModuleObject's getattribute
42+
- Fill`__classcell__` correctly for Python subclasses of .NET types
4043

4144
##[2.4.0][]
4245

‎appveyor.yml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,21 @@ environment:
1515
CODECOV_ENV:PYTHON_VERSION, PLATFORM
1616

1717
matrix:
18-
-PYTHON_VERSION:2.7
18+
-PYTHON_VERSION:3.8
1919
BUILD_OPTS:--xplat
20-
-PYTHON_VERSION:3.5
20+
-PYTHON_VERSION:3.7
2121
BUILD_OPTS:--xplat
2222
-PYTHON_VERSION:3.6
2323
BUILD_OPTS:--xplat
24-
-PYTHON_VERSION:3.7
25-
BUILD_OPTS:--xplat
26-
-PYTHON_VERSION:2.7
2724
-PYTHON_VERSION:3.5
28-
-PYTHON_VERSION:3.6
25+
BUILD_OPTS:--xplat
26+
-PYTHON_VERSION:2.7
27+
BUILD_OPTS:--xplat
28+
-PYTHON_VERSION:3.8
2929
-PYTHON_VERSION:3.7
30-
31-
matrix:
32-
allow_failures:
33-
-PYTHON_VERSION:3.4
34-
BUILD_OPTS:--xplat
35-
-PYTHON_VERSION:3.4
30+
-PYTHON_VERSION:3.6
31+
-PYTHON_VERSION:3.5
32+
-PYTHON_VERSION:2.7
3633

3734
init:
3835
# Update Environment Variables based on matrix/platform

‎src/embed_tests/TestRuntime.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ public static void PlatformCache()
2929
Runtime.Runtime.Initialize();
3030

3131
Assert.That(Runtime.Runtime.Machine,Is.Not.EqualTo(MachineType.Other));
32-
Assert.That(!string.IsNullOrEmpty(Runtime.Runtime.MachineName));
33-
3432
Assert.That(Runtime.Runtime.OperatingSystem,Is.Not.EqualTo(OperatingSystemType.Other));
35-
Assert.That(!string.IsNullOrEmpty(Runtime.Runtime.OperatingSystemName));
3633

3734
// Don't shut down the runtime: if the python engine was initialized
3835
// but not shut down by another test, we'd end up in a bad state.

‎src/runtime/runtime.cs

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
usingSystem.Reflection.Emit;
12
usingSystem;
23
usingSystem.Diagnostics.Contracts;
34
usingSystem.Runtime.InteropServices;
@@ -118,16 +119,16 @@ public class Runtime
118119
{"Linux",OperatingSystemType.Linux},
119120
};
120121

121-
/// <summary>
122-
/// Gets the operating system as reported by python's platform.system().
123-
/// </summary>
124-
publicstaticOperatingSystemTypeOperatingSystem{get;privateset;}
122+
[Obsolete]
123+
publicstaticstringOperatingSystemName=>OperatingSystem.ToString();
124+
125+
[Obsolete]
126+
publicstaticstringMachineName=>Machine.ToString();
125127

126128
/// <summary>
127129
/// Gets the operating system as reported by python's platform.system().
128130
/// </summary>
129-
publicstaticstringOperatingSystemName{get;privateset;}
130-
131+
publicstaticOperatingSystemTypeOperatingSystem{get;privateset;}
131132

132133
/// <summary>
133134
/// Map lower-case version of the python machine name to the processor
@@ -154,11 +155,6 @@ public class Runtime
154155
/// </summary>
155156
publicstaticMachineTypeMachine{get;privateset;}/* set in Initialize using python's platform.machine */
156157

157-
/// <summary>
158-
/// Gets the machine architecture as reported by python's platform.machine().
159-
/// </summary>
160-
publicstaticstringMachineName{get;privateset;}
161-
162158
internalstaticboolIsPython2=pyversionnumber<30;
163159
internalstaticboolIsPython3=pyversionnumber>=30;
164160

@@ -356,20 +352,21 @@ internal static void Initialize(bool initSigs = false)
356352
/// </summary>
357353
privatestaticvoidInitializePlatformData()
358354
{
355+
#if!NETSTANDARD
359356
IntPtrop;
360357
IntPtrfn;
361358
IntPtrplatformModule=PyImport_ImportModule("platform");
362359
IntPtremptyTuple=PyTuple_New(0);
363360

364361
fn=PyObject_GetAttrString(platformModule,"system");
365362
op=PyObject_Call(fn,emptyTuple,IntPtr.Zero);
366-
OperatingSystemName=GetManagedString(op);
363+
stringoperatingSystemName=GetManagedString(op);
367364
XDecref(op);
368365
XDecref(fn);
369366

370367
fn=PyObject_GetAttrString(platformModule,"machine");
371368
op=PyObject_Call(fn,emptyTuple,IntPtr.Zero);
372-
MachineName=GetManagedString(op);
369+
stringmachineName=GetManagedString(op);
373370
XDecref(op);
374371
XDecref(fn);
375372

@@ -379,18 +376,47 @@ private static void InitializePlatformData()
379376
// Now convert the strings into enum values so we can do switch
380377
// statements rather than constant parsing.
381378
OperatingSystemTypeOSType;
382-
if(!OperatingSystemTypeMapping.TryGetValue(OperatingSystemName,outOSType))
379+
if(!OperatingSystemTypeMapping.TryGetValue(operatingSystemName,outOSType))
383380
{
384381
OSType=OperatingSystemType.Other;
385382
}
386383
OperatingSystem=OSType;
387384

388385
MachineTypeMType;
389-
if(!MachineTypeMapping.TryGetValue(MachineName.ToLower(),outMType))
386+
if(!MachineTypeMapping.TryGetValue(machineName.ToLower(),outMType))
390387
{
391388
MType=MachineType.Other;
392389
}
393390
Machine=MType;
391+
#else
392+
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
393+
OperatingSystem=OperatingSystemType.Linux;
394+
elseif(RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
395+
OperatingSystem=OperatingSystemType.Darwin;
396+
elseif(RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
397+
OperatingSystem=OperatingSystemType.Windows;
398+
else
399+
OperatingSystem=OperatingSystemType.Other;
400+
401+
switch(RuntimeInformation.ProcessArchitecture)
402+
{
403+
caseArchitecture.X86:
404+
Machine=MachineType.i386;
405+
break;
406+
caseArchitecture.X64:
407+
Machine=MachineType.x86_64;
408+
break;
409+
caseArchitecture.Arm:
410+
Machine=MachineType.armv7l;
411+
break;
412+
caseArchitecture.Arm64:
413+
Machine=MachineType.aarch64;
414+
break;
415+
default:
416+
Machine=MachineType.Other;
417+
break;
418+
}
419+
#endif
394420
}
395421

396422
internalstaticvoidShutdown()
@@ -1966,6 +1992,15 @@ internal static IntPtr PyMem_Realloc(IntPtr ptr, long size)
19661992
[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl)]
19671993
internalstaticexternvoid PyErr_Print();
19681994

1995+
//====================================================================
1996+
// Cell API
1997+
//====================================================================
1998+
1999+
[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl)]
2000+
internalstaticextern NewReference PyCell_Get(BorrowedReference cell);
2001+
2002+
[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl)]
2003+
internalstaticexternint PyCell_Set(BorrowedReference cell, IntPtr value);
19692004

19702005
//====================================================================
19712006
// Miscellaneous

‎src/runtime/typemanager.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,14 @@ internal static IntPtr CreateSubType(IntPtr py_name, IntPtr py_base_type, IntPtr
280280
IntPtrcls_dict=Marshal.ReadIntPtr(py_type,TypeOffset.tp_dict);
281281
Runtime.PyDict_Update(cls_dict,py_dict);
282282

283+
// Update the __classcell__ if it exists
284+
varcell=newBorrowedReference(Runtime.PyDict_GetItemString(cls_dict,"__classcell__"));
285+
if(!cell.IsNull)
286+
{
287+
Runtime.PyCell_Set(cell,py_type);
288+
Runtime.PyDict_DelItemString(cls_dict,"__classcell__");
289+
}
290+
283291
returnpy_type;
284292
}
285293
catch(Exceptione)
@@ -617,7 +625,9 @@ int MAP_ANONYMOUS
617625
caseOperatingSystemType.Linux:
618626
return0x20;
619627
default:
620-
thrownewNotImplementedException($"mmap is not supported on{Runtime.OperatingSystemName}");
628+
thrownewNotImplementedException(
629+
$"mmap is not supported on{Runtime.OperatingSystem}"
630+
);
621631
}
622632
}
623633
}
@@ -651,7 +661,9 @@ internal static IMemoryMapper CreateMemoryMapper()
651661
caseOperatingSystemType.Windows:
652662
returnnewWindowsMemoryMapper();
653663
default:
654-
thrownewNotImplementedException($"No support for{Runtime.OperatingSystemName}");
664+
thrownewNotImplementedException(
665+
$"No support for{Runtime.OperatingSystem}"
666+
);
655667
}
656668
}
657669

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp