diff --git a/.editorconfig b/.editorconfig
index d9c7ff3d7..f7658ff73 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -60,6 +60,9 @@ dotnet_diagnostic.CA1305.severity = none # CA1305: Specify IFormatProvide
dotnet_diagnostic.CA1307.severity = suggestion # CA1307: Specify StringComparison for clarity
dotnet_diagnostic.CA1309.severity = suggestion # CA1309: Use ordinal string comparison
dotnet_diagnostic.CA1310.severity = warning # CA1310: Specify StringComparison for correctness
+dotnet_diagnostic.CA1510.severity = none # CA1510: Use ArgumentNullException throw helper
+dotnet_diagnostic.CA1512.severity = none # CA1512: Use ArgumentOutOfRangeException throw helper
+dotnet_diagnostic.CA1513.severity = none # CA1513: Use ObjectDisposedException throw helper
dotnet_diagnostic.CA1707.severity = none # CA1707: Identifiers should not contain underscores
dotnet_diagnostic.CA1708.severity = none # CA1708: Identifiers should differ by more than case
dotnet_diagnostic.CA1710.severity = none # CA1710: Identifiers should have correct suffix
@@ -81,8 +84,10 @@ dotnet_diagnostic.CA1845.severity = none # CA1845: Use span-based 'string
dotnet_diagnostic.CA1846.severity = none # CA1846: Prefer 'AsSpan' over 'Substring'
dotnet_diagnostic.CA1847.severity = none # CA1847: Use char literal for a single character lookup
dotnet_diagnostic.CA1852.severity = suggestion # CA1852: Seal internal types
+dotnet_diagnostic.CA1854.severity = suggestion # CA1854: Prefer the 'IDictionary.TryGetValue(TKey, out TValue)' method
dotnet_diagnostic.CA1859.severity = suggestion # CA1859: Use concrete types when possible for improved performance
dotnet_diagnostic.CA1861.severity = suggestion # CA1861: Avoid constant arrays as arguments
+dotnet_diagnostic.CA1863.severity = none # CA1863: Use 'CompositeFormat'
dotnet_diagnostic.CA2101.severity = suggestion # CA2101: Specify marshaling for P/Invoke string arguments
dotnet_diagnostic.CA2201.severity = none # CA2201: Do not raise reserved exception types
dotnet_diagnostic.CA2208.severity = suggestion # CA2208: Instantiate argument exceptions correctly
@@ -95,3 +100,6 @@ dotnet_diagnostic.CA5350.severity = suggestion # CA5350: Do Not Use Weak Crypto
dotnet_diagnostic.CA5351.severity = suggestion # CA5351: Do Not Use Broken Cryptographic Algorithms
dotnet_diagnostic.CA5359.severity = suggestion # CA5359: Do Not Disable Certificate Validation
dotnet_diagnostic.CA5372.severity = suggestion # CA5372: Use XmlReader For XPathDocument
+
+dotnet_diagnostic.SYSLIB1045.severity = suggestion # SYSLIB1045: Use 'RegexGeneratorAttribute' to generate the regular expression implementation at compile-time
+dotnet_diagnostic.SYSLIB1054.severity = suggestion # SYSLIB1054: Use 'LibraryImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 0ddab2b28..8bd164487 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -10,23 +10,27 @@ jobs:
strategy:
fail-fast: false
matrix:
- os: [windows-latest, ubuntu-latest, macos-latest]
+ os: [windows-latest, ubuntu-latest, macos-latest-large]
steps:
- name: Install tools
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get -yq install mono-vbnc dos2unix
- - uses: actions/checkout@v2
+ - uses: actions/checkout@v4
with:
submodules: true
- name: Setup .NET Core 3.1
- uses: actions/setup-dotnet@v1
+ uses: actions/setup-dotnet@v4
with:
dotnet-version: '3.1.x'
- name: Setup .NET 6.0
- uses: actions/setup-dotnet@v1
+ uses: actions/setup-dotnet@v4
with:
dotnet-version: '6.0.x'
+ - name: Setup .NET 8.0
+ uses: actions/setup-dotnet@v4
+ with:
+ dotnet-version: '8.0.x'
- name: Version Information
run: |
dotnet --info
@@ -37,9 +41,9 @@ jobs:
run: pwsh make.ps1
- name: Package
run: pwsh make.ps1 package
- - uses: actions/upload-artifact@v2
+ - uses: actions/upload-artifact@v4
with:
- name: packages
+ name: packages-${{ matrix.os }}
path: Package/Release/Packages
- name: Test (net462)
run: ./make.ps1 -frameworks net462 test-all
@@ -50,3 +54,6 @@ jobs:
- name: Test (net6.0)
run: ./make.ps1 -frameworks net6.0 test-all
shell: pwsh
+ - name: Test (net8.0)
+ run: ./make.ps1 -frameworks net8.0 test-all
+ shell: pwsh
diff --git a/.gitmodules b/.gitmodules
index e58c860e5..5cd8e15d8 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,4 +1,4 @@
[submodule "Src/DLR"]
path = Src/DLR
url = https://github.com/IronLanguages/dlr
- branch = master
+ branch = main
diff --git a/Build/net8.0-windows.props b/Build/net8.0-windows.props
new file mode 100644
index 000000000..8e9067699
--- /dev/null
+++ b/Build/net8.0-windows.props
@@ -0,0 +1,9 @@
+
+
+ false
+ $(BaseIntermediateOutputPath)$(Configuration)\net8.0
+ $(BaseOutputPath)\net8.0
+
+
+
+
diff --git a/Build/net8.0.props b/Build/net8.0.props
new file mode 100644
index 000000000..926dadc14
--- /dev/null
+++ b/Build/net8.0.props
@@ -0,0 +1,38 @@
+
+
+
+ false
+
+
+
+ $(Features);FEATURE_APARTMENTSTATE
+ $(Features);FEATURE_ASSEMBLY_GETFORWARDEDTYPES
+ $(Features);FEATURE_ASSEMBLY_RESOLVE
+ $(Features);FEATURE_ASSEMBLYBUILDER_DEFINEDYNAMICASSEMBLY
+ $(Features);FEATURE_CODEDOM
+ $(Features);FEATURE_COM
+ $(Features);FEATURE_CONFIGURATION
+ $(Features);FEATURE_CTYPES
+ $(Features);FEATURE_CUSTOM_TYPE_DESCRIPTOR
+ $(Features);FEATURE_EXCEPTION_STATE
+ $(Features);FEATURE_FILESYSTEM
+ $(Features);FEATURE_FULL_CRYPTO
+ $(Features);FEATURE_FULL_NET
+ $(Features);FEATURE_LCG
+ $(Features);FEATURE_LOADWITHPARTIALNAME
+ $(Features);FEATURE_METADATA_READER
+ $(Features);FEATURE_MMAP
+ $(Features);FEATURE_NATIVE
+ $(Features);FEATURE_OSPLATFORMATTRIBUTE
+ $(Features);FEATURE_PIPES
+ $(Features);FEATURE_PROCESS
+ $(Features);FEATURE_REFEMIT
+ $(Features);FEATURE_REGISTRY
+ $(Features);FEATURE_RUNTIMEINFORMATION
+ $(Features);FEATURE_SECURITY_RULES
+ $(Features);FEATURE_STACK_TRACE
+ $(Features);FEATURE_SYNC_SOCKETS
+ $(Features);FEATURE_THREAD
+ $(Features);FEATURE_XMLDOC
+
+
diff --git a/Build/net9.0-windows.props b/Build/net9.0-windows.props
new file mode 100644
index 000000000..b64bb8ce9
--- /dev/null
+++ b/Build/net9.0-windows.props
@@ -0,0 +1,9 @@
+
+
+ false
+ $(BaseIntermediateOutputPath)$(Configuration)\net9.0
+ $(BaseOutputPath)\net9.0
+
+
+
+
diff --git a/Build/net9.0.props b/Build/net9.0.props
new file mode 100644
index 000000000..926dadc14
--- /dev/null
+++ b/Build/net9.0.props
@@ -0,0 +1,38 @@
+
+
+
+ false
+
+
+
+ $(Features);FEATURE_APARTMENTSTATE
+ $(Features);FEATURE_ASSEMBLY_GETFORWARDEDTYPES
+ $(Features);FEATURE_ASSEMBLY_RESOLVE
+ $(Features);FEATURE_ASSEMBLYBUILDER_DEFINEDYNAMICASSEMBLY
+ $(Features);FEATURE_CODEDOM
+ $(Features);FEATURE_COM
+ $(Features);FEATURE_CONFIGURATION
+ $(Features);FEATURE_CTYPES
+ $(Features);FEATURE_CUSTOM_TYPE_DESCRIPTOR
+ $(Features);FEATURE_EXCEPTION_STATE
+ $(Features);FEATURE_FILESYSTEM
+ $(Features);FEATURE_FULL_CRYPTO
+ $(Features);FEATURE_FULL_NET
+ $(Features);FEATURE_LCG
+ $(Features);FEATURE_LOADWITHPARTIALNAME
+ $(Features);FEATURE_METADATA_READER
+ $(Features);FEATURE_MMAP
+ $(Features);FEATURE_NATIVE
+ $(Features);FEATURE_OSPLATFORMATTRIBUTE
+ $(Features);FEATURE_PIPES
+ $(Features);FEATURE_PROCESS
+ $(Features);FEATURE_REFEMIT
+ $(Features);FEATURE_REGISTRY
+ $(Features);FEATURE_RUNTIMEINFORMATION
+ $(Features);FEATURE_SECURITY_RULES
+ $(Features);FEATURE_STACK_TRACE
+ $(Features);FEATURE_SYNC_SOCKETS
+ $(Features);FEATURE_THREAD
+ $(Features);FEATURE_XMLDOC
+
+
diff --git a/Build/steps.yml b/Build/steps.yml
index ab6945c4e..12a52759c 100644
--- a/Build/steps.yml
+++ b/Build/steps.yml
@@ -31,17 +31,23 @@ steps:
version: '3.1.x'
- task: UseDotNet@2
- displayName: Install .NET 6.0 SDK for build
+ displayName: Install .NET 6.0 runtime for testing
inputs:
- packageType: 'sdk'
+ packageType: 'runtime'
version: '6.0.x'
+ - task: UseDotNet@2
+ displayName: Install .NET 8.0 SDK for build
+ inputs:
+ packageType: 'sdk'
+ version: '8.0.x'
+
# Set Mono version on macOS
- ${{ if eq(parameters.os, 'macOS') }}:
- - task: ms-devlabs.utilitytasks.task-Shellpp.Shell++@0
+ - task: Bash@3
displayName: Set Mono Version
inputs:
- type: InlineScript
+ targetType: inline
script: |
# use Mono 6.4.0 version
SYMLINK=6.4.0
@@ -52,31 +58,22 @@ steps:
# Install mono when running on Linux
- ${{ if eq(parameters.os, 'Linux') }}:
- - task: ms-devlabs.utilitytasks.task-Shellpp.Shell++@0
- displayName: Version Information
+ - task: Bash@3
+ displayName: Install tools
inputs:
- type: InlineScript
+ targetType: inline
script: |
- # Testing and packaging tools
- sudo apt-get -yq install mono-vbnc dos2unix fakeroot
+ sudo apt-get -yq install mono-vbnc dos2unix
- # Dump some info about the tools
- mono --version
- msbuild /version
- dotnet --info
- df -Th
-
- # Dump version info on macOS
- - ${{ if eq(parameters.os, 'macOS') }}:
- - task: ms-devlabs.utilitytasks.task-Shellpp.Shell++@0
- displayName: Version Information
- inputs:
- type: InlineScript
- script: |
- # Dump some info about the tools
- mono --version
- msbuild /version
- dotnet --info
+ # Dump version info
+ - task: PowerShell@2
+ displayName: Version Information
+ inputs:
+ targetType: inline
+ script: |
+ dotnet --info
+ try { msbuild -version } catch { }
+ try { mono --version } catch { }
- powershell: ./make.ps1
displayName: Build
diff --git a/Directory.Build.props b/Directory.Build.props
index e7e2231de..709636925 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -21,8 +21,8 @@
1000
IronPython
- IronPython Team
- © IronPython Contributors
+ .NET Foundation
+ © .NET Foundation and Contributors
$(MajorVersion).$(MinorVersion).$(MicroVersion).$(AssemblyRevision)
$(MajorVersion).$(MinorVersion).$(MicroVersion).$(AssemblyFileRevision)
$(MSBuildProjectName) $(MajorVersion).$(MinorVersion).$(MicroVersion) $(ReleaseLevel) $(ReleaseSerial)
@@ -121,7 +121,7 @@
- false
+ true
portable
true
false
diff --git a/Documentation/getting-the-sources.md b/Documentation/getting-the-sources.md
index 1e2e41c4d..b5bd5e4a9 100644
--- a/Documentation/getting-the-sources.md
+++ b/Documentation/getting-the-sources.md
@@ -2,7 +2,7 @@ The main IronPython3 git repository is at [http://github.com/IronLanguages/ironp
## Downloading the sources
-You can [download a zipped copy](http://github.com/IronLanguages/ironpython3/zipball/master) of the latest IronPython3 sources as well.
+You can [download a zipped copy](http://github.com/IronLanguages/ironpython3/zipball/main) of the latest IronPython3 sources as well.
### Installing GIT
@@ -15,7 +15,7 @@ The following links include resources for installing and using GIT:
### Creating a local GIT repository
-You will first need to fork the IronPython3 project. [Creating a fork](https://help.github.com/fork-a-repo/) is recommended as it will allow you to contribute patches back easily. Click the "Fork" button on [https://github.com/IronLanguages/ironpython3/](https://github.com/IronLanguages/ironpython3/). This should create your personal fork, with a web URL like http://github.com/janedoe/ironpython3 (where janedoe is your github username).
+You will first need to fork the IronPython3 project. [Creating a fork](https://help.github.com/fork-a-repo/) is recommended as it will allow you to contribute patches back easily. Click the "Fork" button on [https://github.com/IronLanguages/ironpython3/](https://github.com/IronLanguages/ironpython3/). This should create your personal fork, with a web URL like http://github.com/janedoe/ironpython3 (where janedoe is your github username).
You can now use the git command-line client with many Linux distributions, Mac OS, Cygwin, and Windows (msysgit) to get the sources onto your local computer using the following commands:
@@ -27,13 +27,13 @@ git config --global user.email janedoe@example.com
git clone git@github.com:janedoe/ironpython3.git
cd ironpython3
git remote add ironpython3 git://github.com/IronLanguages/ironpython3.git
-git pull ironpython3 master
+git pull ironpython3 main
```
At a later date, to get the latest updates from the IronPython3 project, run the following command in the ironpython3 directory created above:
```
-git pull ironpython3 master
+git pull ironpython3 main
```
If there is a merge conflict, edit the unmerged files to remove the conflict markers, and then run the following command:
@@ -59,4 +59,4 @@ The DLR (Dynamic Language Runtime) is a submodule of the ironpython3 repository,
git submodule update --init
```
-For more information there is an excellent tutorial on [getting started with git](http://kylecordes.com/2008/04/30/git-windows-go/)
\ No newline at end of file
+For more information there is an excellent tutorial on [getting started with git](http://kylecordes.com/2008/04/30/git-windows-go/)
diff --git a/Documentation/installing.md b/Documentation/installing.md
index a4f85153f..7371f20c5 100644
--- a/Documentation/installing.md
+++ b/Documentation/installing.md
@@ -87,7 +87,7 @@ Use Powershell's `help` command on the script for information about available op
The script is also available online, so it can be downloaded and invoked without unzipping the archive first.
```
-PS> Invoke-WebRequest https://raw.githubusercontent.com/IronLanguages/ironpython3/master/Src/Scripts/Install-IronPython.ps1 -OutFile ./Install-IronPython.ps1
+PS> Invoke-WebRequest https://raw.githubusercontent.com/IronLanguages/ironpython3/main/Src/Scripts/Install-IronPython.ps1 -OutFile ./Install-IronPython.ps1
PS> ./Install-IronPython ~/ipyenv ~/Downloads/IronPython.3.X.Y.zip
PS> ~/ipyenv/Enter-IronPythonEnvironment
«ipyenv» PS> ipy
@@ -146,7 +146,7 @@ It is recommended to create one's own launcher script launching the newer IronPy
After a release, the development of IronPython continues so it is possible that a bug or a feature that is important to you was handled after the latest release. As each commit to the main project branch creates precompiled artifacts, it is still possible to install the relevant (or latest development) version of IronPython without the need to compile the whole project from scratch.
-Go to the project's [_Actions_ page](https://github.com/IronLanguages/ironpython3/actions) and find the commit you are interested in. Or simply find the topmost commit to `master` that has all tests passing. The _Status_ and _Branch_ filters in the top bar are helpful to narrow the list down. Then click on the commit hyperlink to access the CI run summary. At the bottom of that page there is artifact `packages`, which contains all binary artifacts the project produces. Download it and unzip. Choose the right package for your needs and follow instructions above for the officially released artifacts. For convenience, here is a table with usable packages:
+Go to the project's [_Actions_ page](https://github.com/IronLanguages/ironpython3/actions) and find the commit you are interested in. Or simply find the topmost commit to `main` that has all tests passing. The _Status_ and _Branch_ filters in the top bar are helpful to narrow the list down. Then click on the commit hyperlink to access the CI run summary. At the bottom of that page there is artifact `packages`, which contains all binary artifacts the project produces. Download it and unzip. Choose the right package for your needs and follow instructions above for the officially released artifacts. For convenience, here is a table with usable packages:
| Artifact | Framework | Operating System |
| -------------------- | ------------------------------ | ----------------------------------- |
@@ -158,7 +158,7 @@ Go to the project's [_Actions_ page](https://github.com/IronLanguages/ironpython
# Installing from Sources
-To build and install IronPython from sources, first follow instructions in [_Getting the Sources_](https://github.com/IronLanguages/ironpython3/blob/master/Documentation/getting-the-sources.md) and [_Building IronPython3_](https://github.com/IronLanguages/ironpython3/blob/master/Documentation/building.md).
+To build and install IronPython from sources, first follow instructions in [_Getting the Sources_](https://github.com/IronLanguages/ironpython3/blob/main/Documentation/getting-the-sources.md) and [_Building IronPython3_](https://github.com/IronLanguages/ironpython3/blob/main/Documentation/building.md).
When the command `./make.ps1 debug` completes successfully, runnable and usable `ipy` executables are available in subdirectories of `./bin/Debug`. To run executables from the release configuration (produced by a successful run of `./make.ps1`), first set environment variable `IRONPYTHONPATH`.
@@ -170,7 +170,7 @@ If those executables test out successfully, the binaries can be installed outsid
The artifacts are placed in directory `./Package/Release/Packages/IronPython-3.X.Y`. Pick a package suitable for your installation target and follow instructions above for the officially released packages.
-Note: as a convenience, if you run `Install-IronPython.ps1` directly from directory `./Src/Scripts` to install IronPython from the zip file, there is no need to pass the location to the zip file; the script finds it automatically using the relative path.
+Note: as a convenience, if you run `Install-IronPython.ps1` directly from directory `./Src/Scripts` to install IronPython from the zip file, there is no need to pass the location to the zip file; the script finds it automatically using the relative path.
Installation example:
diff --git a/Documentation/upgrading-from-ipy2.md b/Documentation/upgrading-from-ipy2.md
index 7c330cb07..4f59586da 100644
--- a/Documentation/upgrading-from-ipy2.md
+++ b/Documentation/upgrading-from-ipy2.md
@@ -57,7 +57,7 @@ Another way of achieving the redirection behavior similar to IronPython 2 is to
```c#
// IronPython 3
-var engine = Python.CreateEngine(new Dictionary {
+var engine = Python.CreateEngine(new Dictionary {
{ "ConsoleSupportLevel", Microsoft.Scripting.Runtime.SharedIO.SupportLevel.Basic },
});
var textWriter = new MyTextWriter();
@@ -70,14 +70,14 @@ This method is particularly useful when embedding the IronPython 3 engine in a h
```c#
// IronPython 3 in LINQPad
-var engine = Python.CreateEngine(new Dictionary {
+var engine = Python.CreateEngine(new Dictionary {
{ "ConsoleSupportLevel", Microsoft.Scripting.Runtime.SharedIO.SupportLevel.Basic },
});
engine.Execute("print('abc')"); // shows output in the "Results" pane
dynamic ans = engine.Execute("input()"); // pauses the script and asks for input at the bottom of the "Results" pane; terminate your input with Ctrl+Z, Enter
```
-[TextStream]: https://github.com/IronLanguages/dlr/blob/master/Src/Microsoft.Scripting/Utils/TextStream.cs
+[TextStream]: https://github.com/IronLanguages/dlr/blob/main/Src/Microsoft.Scripting/Utils/TextStream.cs
[LINQPad]: https://www.linqpad.net/
## `int` Type
diff --git a/IronPython.sln b/IronPython.sln
index d02363401..3de1c02d7 100644
--- a/IronPython.sln
+++ b/IronPython.sln
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Version 16
-VisualStudioVersion = 16.0.28917.181
+# Visual Studio Version 17
+VisualStudioVersion = 17.9.34714.143
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IronPython", "Src\IronPython\IronPython.csproj", "{95289EA9-5778-489D-AB48-F81F2CE2DA32}"
EndProject
@@ -37,6 +37,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{17737ACB
Build\net462.props = Build\net462.props
Build\net6.0-windows.props = Build\net6.0-windows.props
Build\net6.0.props = Build\net6.0.props
+ Build\net8.0-windows.props = Build\net8.0-windows.props
+ Build\net8.0.props = Build\net8.0.props
+ Build\net9.0-windows.props = Build\net9.0-windows.props
+ Build\net9.0.props = Build\net9.0.props
+ Build\netcoreapp3.1.props = Build\netcoreapp3.1.props
Build\netstandard2.0.props = Build\netstandard2.0.props
Build\steps.yml = Build\steps.yml
Build\Tasks.Targets = Build\Tasks.Targets
diff --git a/IronPythonAnalyzer/IronPythonAnalyzer/IronPythonAnalyzer.csproj b/IronPythonAnalyzer/IronPythonAnalyzer/IronPythonAnalyzer.csproj
index 14e1f56a7..38c0895fe 100644
--- a/IronPythonAnalyzer/IronPythonAnalyzer/IronPythonAnalyzer.csproj
+++ b/IronPythonAnalyzer/IronPythonAnalyzer/IronPythonAnalyzer.csproj
@@ -2,11 +2,12 @@
netstandard2.0
+ true
-
-
+
+
diff --git a/Package/choco/IronPython.nuspec b/Package/choco/IronPython.nuspec
index 5849bfc91..6a616379f 100644
--- a/Package/choco/IronPython.nuspec
+++ b/Package/choco/IronPython.nuspec
@@ -5,13 +5,13 @@
ironpython
3.4.0
- https://github.com/IronLanguages/ironpython3/tree/master/Package/choco
+ https://github.com/IronLanguages/ironpython3/tree/main/Package/choco
IronPython
IronPython Contributors, Microsoft
© IronPython Contributors
IronPython Community
https://ironpython.net
- https://github.com/IronLanguages/ironpython3/blob/master/LICENSE
+ https://github.com/IronLanguages/ironpython3/blob/main/LICENSE
false
IronPython is an open-source implementation of the Python programming language that is tightly integrated with the .NET Framework. IronPython can use the .NET Framework and Python libraries, and other .NET languages can use Python code just as easily.
IronPython is an open-source implementation of the Python programming language that is tightly integrated with the .NET Framework.
diff --git a/Package/choco/README.md b/Package/choco/README.md
index 7d16742a3..fbd5d23a1 100644
--- a/Package/choco/README.md
+++ b/Package/choco/README.md
@@ -9,7 +9,7 @@ The current target is Python 3.4, although features and behaviors from later ver
## Differences with CPython
-While compatibility with CPython is one of our main goals with IronPython 3, there are still some differences that may cause issues. See [Differences from CPython](https://github.com/IronLanguages/ironpython3/blob/master/Documentation/differences-from-c-python.md) for details.
+While compatibility with CPython is one of our main goals with IronPython 3, there are still some differences that may cause issues. See [Differences from CPython](https://github.com/IronLanguages/ironpython3/blob/main/Documentation/differences-from-c-python.md) for details.
## Package compatibility
-See the [Package compatibility](https://github.com/IronLanguages/ironpython3/blob/master/Documentation/package-compatibility.md) document for information on compatibility with popular Python packages.
+See the [Package compatibility](https://github.com/IronLanguages/ironpython3/blob/main/Documentation/package-compatibility.md) document for information on compatibility with popular Python packages.
diff --git a/Package/dotnettool/README.md b/Package/dotnettool/README.md
index d521932da..f6e7118d2 100644
--- a/Package/dotnettool/README.md
+++ b/Package/dotnettool/README.md
@@ -9,8 +9,8 @@ The current target is Python 3.4, although features and behaviors from later ver
## Differences with CPython
-While compatibility with CPython is one of our main goals with IronPython 3, there are still some differences that may cause issues. See [Differences from CPython](https://github.com/IronLanguages/ironpython3/blob/master/Documentation/differences-from-c-python.md) for details.
+While compatibility with CPython is one of our main goals with IronPython 3, there are still some differences that may cause issues. See [Differences from CPython](https://github.com/IronLanguages/ironpython3/blob/main/Documentation/differences-from-c-python.md) for details.
## Package compatibility
-See the [Package compatibility](https://github.com/IronLanguages/ironpython3/blob/master/Documentation/package-compatibility.md) document for information on compatibility with popular Python packages.
+See the [Package compatibility](https://github.com/IronLanguages/ironpython3/blob/main/Documentation/package-compatibility.md) document for information on compatibility with popular Python packages.
diff --git a/Package/msi/IronPython.Installer.wixproj b/Package/msi/IronPython.Installer.wixproj
index b8e471091..e122f51c8 100644
--- a/Package/msi/IronPython.Installer.wixproj
+++ b/Package/msi/IronPython.Installer.wixproj
@@ -1,4 +1,4 @@
-
+
x64
3.4
@@ -44,10 +44,10 @@
-
-
-
-
+
+
+
+
diff --git a/Package/msi/Version.wxi b/Package/msi/Version.wxi
index 8f7d4db54..4417c0e1a 100644
--- a/Package/msi/Version.wxi
+++ b/Package/msi/Version.wxi
@@ -1,4 +1,4 @@
-
+
diff --git a/Package/nuget/IronPython.nuspec b/Package/nuget/IronPython.nuspec
index 3cc2a5d76..8711f555a 100644
--- a/Package/nuget/IronPython.nuspec
+++ b/Package/nuget/IronPython.nuspec
@@ -33,12 +33,16 @@ This package contains the IronPython interpreter engine.
+
+
+
+
-
-
-
+
+
+
diff --git a/Package/nuget/README.md b/Package/nuget/README.md
index f125651b9..0365dcb75 100644
--- a/Package/nuget/README.md
+++ b/Package/nuget/README.md
@@ -22,8 +22,8 @@ System.Console.WriteLine(greetings("world"));
## Differences with CPython
-While compatibility with CPython is one of our main goals with IronPython 3, there are still some differences that may cause issues. See [Differences from CPython](https://github.com/IronLanguages/ironpython3/blob/master/Documentation/differences-from-c-python.md) for details.
+While compatibility with CPython is one of our main goals with IronPython 3, there are still some differences that may cause issues. See [Differences from CPython](https://github.com/IronLanguages/ironpython3/blob/main/Documentation/differences-from-c-python.md) for details.
## Package compatibility
-See the [Package compatibility](https://github.com/IronLanguages/ironpython3/blob/master/Documentation/package-compatibility.md) document for information on compatibility with popular Python packages. Note that to run most packages, IronPython Standard Library must be present.
+See the [Package compatibility](https://github.com/IronLanguages/ironpython3/blob/main/Documentation/package-compatibility.md) document for information on compatibility with popular Python packages. Note that to run most packages, IronPython Standard Library must be present.
diff --git a/Package/zip/README.md b/Package/zip/README.md
index 5714284e7..a39ca5ec6 100644
--- a/Package/zip/README.md
+++ b/Package/zip/README.md
@@ -50,8 +50,8 @@ System.Console.WriteLine(greetings("world"));
## Differences with CPython
-While compatibility with CPython is one of our main goals with IronPython 3, there are still some differences that may cause issues. See [Differences from CPython](https://github.com/IronLanguages/ironpython3/blob/master/Documentation/differences-from-c-python.md) for details.
+While compatibility with CPython is one of our main goals with IronPython 3, there are still some differences that may cause issues. See [Differences from CPython](https://github.com/IronLanguages/ironpython3/blob/main/Documentation/differences-from-c-python.md) for details.
## Package compatibility
-See the [Package compatibility](https://github.com/IronLanguages/ironpython3/blob/master/Documentation/package-compatibility.md) document for information on compatibility with popular packages. Note that to run most packages, IronPython Standard Library must be present.
+See the [Package compatibility](https://github.com/IronLanguages/ironpython3/blob/main/Documentation/package-compatibility.md) document for information on compatibility with popular packages. Note that to run most packages, IronPython Standard Library must be present.
diff --git a/Package/zip/Zip.Packaging.targets b/Package/zip/Zip.Packaging.targets
index cc1f64bb8..bec14c1fa 100644
--- a/Package/zip/Zip.Packaging.targets
+++ b/Package/zip/Zip.Packaging.targets
@@ -4,7 +4,7 @@
-
+
diff --git a/Src/DLR b/Src/DLR
index 872730ab3..fe26cf45d 160000
--- a/Src/DLR
+++ b/Src/DLR
@@ -1 +1 @@
-Subproject commit 872730ab305d37f67179db8ca778d1cd22984e67
+Subproject commit fe26cf45d383be65a56f0d4b964644eff89e01a8
diff --git a/Src/IronPython.Modules/IronPython.Modules.csproj b/Src/IronPython.Modules/IronPython.Modules.csproj
index 5a7b3cba0..4fc2771d2 100644
--- a/Src/IronPython.Modules/IronPython.Modules.csproj
+++ b/Src/IronPython.Modules/IronPython.Modules.csproj
@@ -1,7 +1,7 @@
- net462;netstandard2.0;net6.0
+ net462;netstandard2.0;net6.0;net8.0
885063680
true
true
diff --git a/Src/IronPython.Modules/_codecs.cs b/Src/IronPython.Modules/_codecs.cs
index 454b34e52..1bab21f30 100644
--- a/Src/IronPython.Modules/_codecs.cs
+++ b/Src/IronPython.Modules/_codecs.cs
@@ -620,7 +620,7 @@ private static Tuple DoEncode(CodeContext context, string encodingNa
///
/// Optimized encoding mapping that can be consumed by charmap_encode/EncodingMapEncoding.
///
- [PythonHidden]
+ [PythonType, PythonHidden]
public class EncodingMap {
private readonly string _smap;
[DisallowNull] private Dictionary? _dmap;
diff --git a/Src/IronPython.Modules/_csv.cs b/Src/IronPython.Modules/_csv.cs
index e4a2a6ec7..6d6c86ba6 100644
--- a/Src/IronPython.Modules/_csv.cs
+++ b/Src/IronPython.Modules/_csv.cs
@@ -652,7 +652,7 @@ public bool MoveNext() {
// If we ended on an escaped newline, then we want to continue onto
// the nextline without processing the end of this one, as the newline
// is in the middle of the field.
- if ((line.EndsWith("\n", StringComparison.Ordinal) || line.EndsWith("\r", StringComparison.Ordinal)) && _state == State.InField) {
+ if ((line.EndsWith('\n') || line.EndsWith('\r')) && _state == State.InField) {
continue;
}
}
diff --git a/Src/IronPython.Modules/_ctypes/_ctypes.cs b/Src/IronPython.Modules/_ctypes/_ctypes.cs
index fc5ed6665..47f4283ad 100644
--- a/Src/IronPython.Modules/_ctypes/_ctypes.cs
+++ b/Src/IronPython.Modules/_ctypes/_ctypes.cs
@@ -540,10 +540,12 @@ private static ModuleBuilder DynamicModule {
lock (_nativeTypes) {
if (!_nativeTypes.TryGetValue(size, out Type res)) {
int sizeRemaining = size;
+#pragma warning disable SYSLIB0050 // Type or member is obsolete
TypeBuilder tb = DynamicModule.DefineType("interop_type_size_" + size,
TypeAttributes.Public | TypeAttributes.SequentialLayout | TypeAttributes.Sealed | TypeAttributes.Serializable,
typeof(ValueType),
size);
+#pragma warning restore SYSLIB0050 // Type or member is obsolete
while (sizeRemaining > 8) {
tb.DefineField("field" + sizeRemaining, typeof(long), FieldAttributes.Private);
@@ -680,10 +682,6 @@ private static IntPtr GetHandleFromObject(object dll, string errorMsg) {
return intPtrHandle;
}
- private static void ValidateArraySizes(ArrayModule.array array, int offset, int size) {
- ValidateArraySizes(array.__len__() * array.itemsize, offset, size);
- }
-
private static void ValidateArraySizes(int arraySize, int offset, int size) {
if (offset < 0) {
throw PythonOps.ValueError("offset cannot be negative");
diff --git a/Src/IronPython.Modules/_operator.cs b/Src/IronPython.Modules/_operator.cs
index 92f262936..7dd04872a 100644
--- a/Src/IronPython.Modules/_operator.cs
+++ b/Src/IronPython.Modules/_operator.cs
@@ -59,7 +59,7 @@ private static object GetOneAttr(CodeContext context, object param, object val)
int dotPos = s.IndexOf('.');
if (dotPos >= 0) {
object nextParam = GetOneAttr(context, param, s.Substring(0, dotPos));
- return GetOneAttr(context, nextParam, s.Substring(dotPos + 1, s.Length - dotPos - 1));
+ return GetOneAttr(context, nextParam, s.Substring(dotPos + 1));
}
return PythonOps.GetBoundAttr(context, param, s);
}
diff --git a/Src/IronPython.Modules/_overlapped.cs b/Src/IronPython.Modules/_overlapped.cs
index 0a39d7072..b0f468af7 100644
--- a/Src/IronPython.Modules/_overlapped.cs
+++ b/Src/IronPython.Modules/_overlapped.cs
@@ -22,7 +22,7 @@ public static class PythonOverlapped {
private static extern IntPtr _CreateIoCompletionPort(IntPtr FileHandle, IntPtr ExistingCompletionPort, UIntPtr CompletionKey, uint NumberOfConcurrentThreads);
public static BigInteger CreateIoCompletionPort(BigInteger handle, BigInteger port, BigInteger key, int concurrency) {
- var res = _CreateIoCompletionPort((IntPtr)(long)handle, (IntPtr)(long)port, (UIntPtr)(ulong)key, (uint)concurrency);
+ var res = _CreateIoCompletionPort(checked((IntPtr)(long)handle), checked((IntPtr)(long)port), checked((UIntPtr)(ulong)key), (uint)concurrency);
if (res == IntPtr.Zero) {
throw PythonNT.GetLastWin32Error();
}
diff --git a/Src/IronPython.Modules/_socket.cs b/Src/IronPython.Modules/_socket.cs
index 9a59ee4bc..52bedab8c 100644
--- a/Src/IronPython.Modules/_socket.cs
+++ b/Src/IronPython.Modules/_socket.cs
@@ -863,7 +863,7 @@ public string __repr__(CodeContext context) {
///
internal static Socket? HandleToSocket(Int64 handle) {
lock (_handleToSocket) {
- if (_handleToSocket.TryGetValue((IntPtr)handle, out WeakReference? weakref)) {
+ if (_handleToSocket.TryGetValue(checked((IntPtr)handle), out WeakReference? weakref)) {
return weakref.Target as Socket;
}
}
@@ -2216,10 +2216,6 @@ internal struct WSAData {
[DllImport("ws2_32.dll", SetLastError = true)]
private static extern Int32 WSACleanup();
- private static T PtrToStructure(IntPtr result) {
- return (T)Marshal.PtrToStructure(result, typeof(T))!;
- }
-
public static string GetServiceByPort(ushort port, string? protocol) {
if (Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX)
return GetServiceByPortNonWindows(port, protocol);
@@ -2236,9 +2232,9 @@ static string GetServiceByPortWindows(ushort port, string? protocol) {
throw new SocketUtilException(string.Format("Could not resolve service for port {0}", port));
if (Environment.Is64BitProcess)
- return PtrToStructure(result).s_name;
+ return Marshal.PtrToStructure(result).s_name;
else
- return PtrToStructure(result).s_name;
+ return Marshal.PtrToStructure(result).s_name;
}
static string GetServiceByPortNonWindows(ushort port, string? protocol) {
@@ -2249,7 +2245,7 @@ static string GetServiceByPortNonWindows(ushort port, string? protocol) {
string.Format("Could not resolve service for port {0}", port));
}
- return PtrToStructure(result).s_name;
+ return Marshal.PtrToStructure(result).s_name;
}
}
@@ -2268,9 +2264,9 @@ static ushort GetServiceByNameWindows(string service, string? protocol) {
ushort port;
if (Environment.Is64BitProcess)
- port = PtrToStructure(result).s_port;
+ port = Marshal.PtrToStructure(result).s_port;
else
- port = PtrToStructure(result).s_port;
+ port = Marshal.PtrToStructure(result).s_port;
var hostport = IPAddress.NetworkToHostOrder(unchecked((short)port));
return unchecked((ushort)hostport);
@@ -2283,7 +2279,7 @@ static ushort GetServiceByNameNonWindows(string service, string? protocol) {
string.Format("Could not resolve port for service {0}", service));
}
- ushort port = PtrToStructure(result).s_port;
+ ushort port = Marshal.PtrToStructure(result).s_port;
var hostport = IPAddress.NetworkToHostOrder(unchecked((short)port));
return unchecked((ushort)hostport);
}
diff --git a/Src/IronPython.Modules/_ssl.cs b/Src/IronPython.Modules/_ssl.cs
index afd49f4ea..08ade85f6 100644
--- a/Src/IronPython.Modules/_ssl.cs
+++ b/Src/IronPython.Modules/_ssl.cs
@@ -5,6 +5,7 @@
#if FEATURE_FULL_NET
using System;
+using System.Buffers;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
@@ -590,30 +591,61 @@ public string issuer() {
[Documentation(@"read(size, [buffer])
Read up to size bytes from the SSL socket.")]
- public object read(CodeContext/*!*/ context, int size, ByteArray buffer = null) {
+ public Bytes read(CodeContext/*!*/ context, int size) {
EnsureSslStream(true);
+ if (size < 0) throw PythonOps.ValueError("size should not be negative");
+
+ var buf = ArrayPool.Rent(size);
try {
- byte[] buf = new byte[2048];
- MemoryStream result = new MemoryStream(size);
- while (true) {
- int readLength = (size < buf.Length) ? size : buf.Length;
- int bytes = _sslStream.Read(buf, 0, readLength);
- if (bytes > 0) {
- result.Write(buf, 0, bytes);
- size -= bytes;
- }
+ int numRead;
+ try {
+ numRead = _sslStream.Read(buf, 0, size);
+ } catch (Exception e) {
+ throw PythonSocket.MakeException(context, e);
+ }
+
+ var bytes = new byte[numRead];
+ Array.Copy(buf, bytes, bytes.Length);
+ return Bytes.Make(bytes);
+ } finally {
+ ArrayPool.Return(buf);
+ }
+ }
+
+ private static ArrayPool ArrayPool => ArrayPool.Shared;
+
+ [Documentation(@"read(size, [buffer])
+Read up to size bytes from the SSL socket.")]
+ public int read(CodeContext/*!*/ context, int size, [NotNone] IBufferProtocol buffer) {
+ EnsureSslStream(true);
+
+ using var pythonBuffer = buffer.GetBufferNoThrow(BufferFlags.Writable)
+ ?? throw PythonOps.TypeError("read() argument 2 must be read-write bytes-like object, not {0}", PythonOps.GetPythonTypeName(buffer));
- if (bytes == 0 || size == 0 || bytes < readLength) {
- var res = result.ToArray();
- if (buffer == null)
- return Bytes.Make(res);
+ var bufferLen = pythonBuffer.ItemCount;
+ if (size <= 0 || bufferLen < size) size = bufferLen;
- // TODO: get rid of the MemoryStream and write directly to the buffer
- buffer[new Slice(0, res.Length)] = res;
- return res.Length;
+ try {
+#if NETCOREAPP
+ return _sslStream.Read(pythonBuffer.AsSpan().Slice(0, size));
+#else
+ var buf = pythonBuffer.AsUnsafeWritableArray();
+ if (buf is null) {
+ buf = ArrayPool.Rent(size);
+ try {
+ var numRead = _sslStream.Read(buf, 0, size);
+ buf.AsSpan(0, numRead).CopyTo(pythonBuffer.AsSpan());
+ return numRead;
+ }
+ finally {
+ ArrayPool.Return(buf);
}
}
+ else {
+ return _sslStream.Read(buf, 0, size);
+ }
+#endif
} catch (Exception e) {
throw PythonSocket.MakeException(context, e);
}
diff --git a/Src/IronPython.Modules/_struct.cs b/Src/IronPython.Modules/_struct.cs
index 759dc2a53..d7b547704 100644
--- a/Src/IronPython.Modules/_struct.cs
+++ b/Src/IronPython.Modules/_struct.cs
@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
+using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Numerics;
@@ -220,10 +221,10 @@ public void __init__(CodeContext/*!*/ context, object fmt) {
}
[Documentation("Stores the deserialized data into the provided array")]
- public void pack_into(CodeContext/*!*/ context, [NotNone] ArrayModule.array/*!*/ buffer, int offset, params object[] args) {
- byte[] existing = buffer.ToByteArray();
+ public void pack_into(CodeContext/*!*/ context, [NotNone] ByteArray/*!*/ buffer, int offset, params object[] args) {
+ var existing = buffer.UnsafeByteList;
- if (offset + size > existing.Length) {
+ if (offset + size > existing.Count) {
throw Error(context, $"pack_into requires a buffer of at least {size} bytes");
}
@@ -232,23 +233,21 @@ public void pack_into(CodeContext/*!*/ context, [NotNone] ArrayModule.array/*!*/
for (int i = 0; i < data.Length; i++) {
existing[i + offset] = data[i];
}
-
- buffer.Clear();
- buffer.FromStream(new MemoryStream(existing));
}
- public void pack_into(CodeContext/*!*/ context, [NotNone] ByteArray/*!*/ buffer, int offset, params object[] args) {
- IList existing = buffer.UnsafeByteList;
+ public void pack_into(CodeContext/*!*/ context, [NotNone] IBufferProtocol/*!*/ buffer, int offset, params object[] args) {
+ using var existing = buffer.GetBufferNoThrow(BufferFlags.Writable)
+ ?? throw PythonOps.TypeError("argument must be read-write bytes-like object, not {0}", PythonOps.GetPythonTypeName(buffer));
- if (offset + size > existing.Count) {
+ var span = existing.AsSpan();
+
+ if (offset + size > span.Length) {
throw Error(context, $"pack_into requires a buffer of at least {size} bytes");
}
var data = pack(context, args).UnsafeByteArray;
- for (int i = 0; i < data.Length; i++) {
- existing[i + offset] = data[i];
- }
+ data.CopyTo(span.Slice(offset));
}
[Documentation("deserializes the string using the structs specified format")]
@@ -392,12 +391,8 @@ public void pack_into(CodeContext/*!*/ context, [NotNone] ByteArray/*!*/ buffer,
System.Diagnostics.Debug.Assert(res_idx == res.Length);
return PythonTuple.MakeTuple(res);
-
}
- public PythonTuple/*!*/ unpack(CodeContext/*!*/ context, [NotNone] ArrayModule.array/*!*/ buffer)
- => unpack(context, buffer.ToByteArray());
-
[Documentation("reads the current format from the specified array")]
public PythonTuple/*!*/ unpack_from(CodeContext/*!*/ context, [BytesLike][NotNone] IList/*!*/ buffer, int offset = 0) {
int bytesAvail = buffer.Count - offset;
@@ -408,19 +403,9 @@ public void pack_into(CodeContext/*!*/ context, [NotNone] ByteArray/*!*/ buffer,
return unpack(context, buffer.Substring(offset, size));
}
- [Documentation("reads the current format from the specified array")]
- public PythonTuple/*!*/ unpack_from(CodeContext/*!*/ context, [NotNone] ArrayModule.array/*!*/ buffer, int offset = 0) {
- return unpack_from(context, buffer.ToByteArray(), offset);
- }
-
[Documentation("iteratively unpack the current format from the specified array.")]
- public PythonUnpackIterator iter_unpack(CodeContext/*!*/ context, [BytesLike][NotNone] IList/*!*/ buffer, int offset = 0) {
- return new PythonUnpackIterator(this, context, buffer, offset);
- }
-
- [Documentation("iteratively unpack the current format from the specified array.")]
- public PythonUnpackIterator iter_unpack(CodeContext/*!*/ context, [NotNone] ArrayModule.array/*!*/ buffer, int offset = 0) {
- return new PythonUnpackIterator(this, context, buffer, offset);
+ public PythonUnpackIterator iter_unpack(CodeContext/*!*/ context, [BytesLike][NotNone] IList/*!*/ buffer) {
+ return new PythonUnpackIterator(this, context, buffer);
}
[Documentation("gets the number of bytes that the serialized string will occupy or are required to deserialize the data")]
@@ -586,14 +571,19 @@ private static Struct CompileAndCache(CodeContext/*!*/ context, string/*!*/ fmt)
fLittleEndian = false;
fStandardized = true;
break;
+ case '\x00':
+ throw Error(context, "embedded null character");
default:
if (char.IsDigit(fmt[i])) {
count = 0;
while (char.IsDigit(fmt[i])) {
count = count * 10 + (fmt[i] - '0');
i++;
+ if (i >= fmt.Length) {
+ throw Error(context, "repeat count given without format specifier");
+ }
}
- if (char.IsWhiteSpace(fmt[i])) Error(context, "white space not allowed between count and format");
+ if (char.IsWhiteSpace(fmt[i])) throw Error(context, "white space not allowed between count and format");
i--;
break;
}
@@ -654,51 +644,44 @@ internal static Struct Create(string/*!*/ format) {
}
[PythonType("unpack_iterator"), Documentation("Represents an iterator returned by _struct.iter_unpack()")]
- public class PythonUnpackIterator : System.Collections.IEnumerator, System.Collections.IEnumerable {
+ public sealed class PythonUnpackIterator : IEnumerator