Skip to content

Commit

Permalink
Fix compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin-Molinero committed Dec 20, 2024
1 parent d72be7f commit 8ae38e4
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 29 deletions.
1 change: 0 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<AssemblyCopyright>Copyright (c) 2006-2021 The Contributors of the Python.NET Project</AssemblyCopyright>
<AssemblyCompany>pythonnet</AssemblyCompany>
<AssemblyProduct>Python.NET</AssemblyProduct>
<LangVersion>10.0</LangVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>
</Project>
3 changes: 2 additions & 1 deletion src/embed_tests/StateSerialization/MethodSerialization.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.IO;
/*using System.IO;
using System.Reflection;
using NUnit.Framework;
Expand Down Expand Up @@ -44,3 +44,4 @@ public class MethodTestHost
public MethodTestHost(int _) { }
public void Generic<T>(T item, T[] array, ref T @ref) { }
}
*/
8 changes: 3 additions & 5 deletions src/runtime/MethodBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,6 @@ internal Binding Bind(BorrowedReference inst, BorrowedReference args, BorrowedRe

static BorrowedReference HandleParamsArray(BorrowedReference args, int arrayStart, int pyArgCount, out NewReference tempObject)
{
BorrowedReference op;
tempObject = default;
// for a params method, we may have a sequence or single/multiple items
// here we look to see if the item at the paramIndex is there or not
Expand All @@ -806,20 +805,19 @@ static BorrowedReference HandleParamsArray(BorrowedReference args, int arrayStar
if (!Runtime.PyString_Check(item) && (Runtime.PySequence_Check(item) || (ManagedType.GetManagedObject(item) as CLRObject)?.inst is IEnumerable))
{
// it's a sequence (and not a string), so we use it as the op
op = item;
return item;
}
else
{
tempObject = Runtime.PyTuple_GetSlice(args, arrayStart, pyArgCount);
op = tempObject.Borrow();
return tempObject.Borrow();
}
}
else
{
tempObject = Runtime.PyTuple_GetSlice(args, arrayStart, pyArgCount);
op = tempObject.Borrow();
return tempObject.Borrow();
}
return op;
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions src/runtime/Native/NewReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ref struct NewReference

/// <summary>Creates a <see cref="NewReference"/> pointing to the same object</summary>
[DebuggerHidden]
public NewReference(BorrowedReference reference, bool canBeNull = false)
public NewReference(scoped BorrowedReference reference, bool canBeNull = false)
{
var address = canBeNull
? reference.DangerousGetAddressOrNull()
Expand Down Expand Up @@ -157,15 +157,15 @@ public static bool IsNull(this in NewReference reference)

[Pure]
[DebuggerHidden]
public static BorrowedReference BorrowNullable(this in NewReference reference)
public static BorrowedReference BorrowNullable(this scoped in NewReference reference)
=> new(NewReference.DangerousGetAddressOrNull(reference));
[Pure]
[DebuggerHidden]
public static BorrowedReference Borrow(this in NewReference reference)
public static BorrowedReference Borrow(this scoped in NewReference reference)
=> reference.IsNull() ? throw new NullReferenceException() : reference.BorrowNullable();
[Pure]
[DebuggerHidden]
public static BorrowedReference BorrowOrThrow(this in NewReference reference)
public static BorrowedReference BorrowOrThrow(this scoped in NewReference reference)
=> reference.IsNull() ? throw PythonException.ThrowLastAsClrException() : reference.BorrowNullable();
}
}
2 changes: 1 addition & 1 deletion src/runtime/Native/StolenReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static StolenReference Take(ref IntPtr ptr)
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[DebuggerHidden]
public static StolenReference TakeNullable(ref IntPtr ptr)
public static StolenReference TakeNullable(scoped ref IntPtr ptr)
{
var stolenAddr = ptr;
ptr = IntPtr.Zero;
Expand Down
8 changes: 4 additions & 4 deletions src/runtime/Runtime.Delegates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ static Delegates()
Py_GetCompiler = (delegate* unmanaged[Cdecl]<IntPtr>)GetFunctionByName(nameof(Py_GetCompiler), GetUnmanagedDll(_PythonDll));
Py_GetBuildInfo = (delegate* unmanaged[Cdecl]<IntPtr>)GetFunctionByName(nameof(Py_GetBuildInfo), GetUnmanagedDll(_PythonDll));
PyRun_SimpleStringFlags = (delegate* unmanaged[Cdecl]<StrPtr, in PyCompilerFlags, int>)GetFunctionByName(nameof(PyRun_SimpleStringFlags), GetUnmanagedDll(_PythonDll));
PyRun_StringFlags = (delegate* unmanaged[Cdecl]<StrPtr, RunFlagType, BorrowedReference, BorrowedReference, in PyCompilerFlags, NewReference>)GetFunctionByName(nameof(PyRun_StringFlags), GetUnmanagedDll(_PythonDll));
PyRun_StringFlags = (delegate* unmanaged[Cdecl]<StrPtr, RunFlagType, BorrowedReference, BorrowedReference, PyCompilerFlags, NewReference>)GetFunctionByName(nameof(PyRun_StringFlags), GetUnmanagedDll(_PythonDll));
PyEval_EvalCode = (delegate* unmanaged[Cdecl]<BorrowedReference, BorrowedReference, BorrowedReference, NewReference>)GetFunctionByName(nameof(PyEval_EvalCode), GetUnmanagedDll(_PythonDll));
Py_CompileStringObject = (delegate* unmanaged[Cdecl]<StrPtr, BorrowedReference, int, in PyCompilerFlags, int, NewReference>)GetFunctionByName(nameof(Py_CompileStringObject), GetUnmanagedDll(_PythonDll));
Py_CompileStringObject = (delegate* unmanaged[Cdecl]<StrPtr, BorrowedReference, int, PyCompilerFlags, int, NewReference>)GetFunctionByName(nameof(Py_CompileStringObject), GetUnmanagedDll(_PythonDll));
PyImport_ExecCodeModule = (delegate* unmanaged[Cdecl]<StrPtr, BorrowedReference, NewReference>)GetFunctionByName(nameof(PyImport_ExecCodeModule), GetUnmanagedDll(_PythonDll));
PyObject_HasAttrString = (delegate* unmanaged[Cdecl]<BorrowedReference, StrPtr, int>)GetFunctionByName(nameof(PyObject_HasAttrString), GetUnmanagedDll(_PythonDll));
PyObject_GetAttrString = (delegate* unmanaged[Cdecl]<BorrowedReference, StrPtr, NewReference>)GetFunctionByName(nameof(PyObject_GetAttrString), GetUnmanagedDll(_PythonDll));
Expand Down Expand Up @@ -345,9 +345,9 @@ static Delegates()
internal static delegate* unmanaged[Cdecl]<IntPtr> Py_GetCompiler { get; }
internal static delegate* unmanaged[Cdecl]<IntPtr> Py_GetBuildInfo { get; }
internal static delegate* unmanaged[Cdecl]<StrPtr, in PyCompilerFlags, int> PyRun_SimpleStringFlags { get; }
internal static delegate* unmanaged[Cdecl]<StrPtr, RunFlagType, BorrowedReference, BorrowedReference, in PyCompilerFlags, NewReference> PyRun_StringFlags { get; }
internal static delegate* unmanaged[Cdecl]<StrPtr, RunFlagType, BorrowedReference, BorrowedReference, PyCompilerFlags, NewReference> PyRun_StringFlags { get; }
internal static delegate* unmanaged[Cdecl]<BorrowedReference, BorrowedReference, BorrowedReference, NewReference> PyEval_EvalCode { get; }
internal static delegate* unmanaged[Cdecl]<StrPtr, BorrowedReference, int, in PyCompilerFlags, int, NewReference> Py_CompileStringObject { get; }
internal static delegate* unmanaged[Cdecl]<StrPtr, BorrowedReference, int, PyCompilerFlags, int, NewReference> Py_CompileStringObject { get; }
internal static delegate* unmanaged[Cdecl]<StrPtr, BorrowedReference, NewReference> PyImport_ExecCodeModule { get; }
internal static delegate* unmanaged[Cdecl]<BorrowedReference, StrPtr, int> PyObject_HasAttrString { get; }
internal static delegate* unmanaged[Cdecl]<BorrowedReference, StrPtr, NewReference> PyObject_GetAttrString { get; }
Expand Down
15 changes: 3 additions & 12 deletions src/runtime/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,8 @@ internal static void Initialize(bool initSigs = false)
// Initialize modules that depend on the runtime class.
AssemblyManager.Initialize();
OperatorMethod.Initialize();
if (RuntimeData.HasStashData())
{
RuntimeData.RestoreRuntimeData();
}
else
{
PyCLRMetaType = MetaType.Initialize();
ImportHook.Initialize();
}
PyCLRMetaType = MetaType.Initialize();
ImportHook.Initialize();
Exceptions.Initialize();

// Need to add the runtime directory to sys.path so that we
Expand Down Expand Up @@ -269,8 +262,6 @@ internal static void Shutdown()
{
// avoid saving dead objects
TryCollectingGarbage(runs: 3);

RuntimeData.Stash();
}

AssemblyManager.Shutdown();
Expand Down Expand Up @@ -1715,7 +1706,7 @@ internal static bool PyType_IsSameAsOrSubtype(BorrowedReference type, BorrowedRe
internal static NewReference PyType_GenericAlloc(BorrowedReference type, nint n) => Delegates.PyType_GenericAlloc(type, n);

internal static IntPtr PyType_GetSlot(BorrowedReference type, TypeSlotID slot) => Delegates.PyType_GetSlot(type, slot);
internal static NewReference PyType_FromSpecWithBases(in NativeTypeSpec spec, BorrowedReference bases) => Delegates.PyType_FromSpecWithBases(in spec, bases);
internal static NewReference PyType_FromSpecWithBases(scoped in NativeTypeSpec spec, BorrowedReference bases) => Delegates.PyType_FromSpecWithBases(in spec, bases);

/// <summary>
/// Finalize a type object. This should be called on all type objects to finish their initialization. This function is responsible for adding inherited slots from a type�s base class. Return 0 on success, or return -1 and sets an exception on error.
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/StateSerialization/RuntimeData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
/*using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand Down Expand Up @@ -210,3 +210,4 @@ internal static IFormatter CreateFormatter()
}
}
}
*/

0 comments on commit 8ae38e4

Please sign in to comment.