Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
root = true

[*]
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4

Expand All @@ -15,10 +17,18 @@ csharp_new_line_before_catch = false
csharp_new_line_before_finally = false
csharp_space_after_keywords_in_control_flow_statements = true

# use language keywords instead of BCL types
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion

# disable default VS2017 naming rule
dotnet_naming_rule.methods_and_properties_must_be_pascal_case.severity = none
dotnet_naming_rule.methods_and_properties_must_be_pascal_case.symbols = method_and_property_symbols
dotnet_naming_rule.methods_and_properties_must_be_pascal_case.style = pascal_case_style
dotnet_naming_symbols.method_and_property_symbols.applicable_kinds = method;property
dotnet_naming_symbols.method_and_property_symbols.applicable_kinds = method, property
dotnet_naming_symbols.method_and_property_symbols.applicable_accessibilities = *
dotnet_naming_style.pascal_case_style.capitalization = pascal_case

# enforce some code styles
dotnet_style_require_accessibility_modifiers = for_non_interface_members:warning
csharp_preferred_modifier_order = public, private, protected, internal, static, extern, new, virtual, abstract, sealed, override, readonly, unsafe, volatile, async:warning
3 changes: 2 additions & 1 deletion Src/IronPython.Modules/_socket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2411,6 +2411,7 @@ public class ssl {
private readonly CodeContext _context;
private readonly RemoteCertificateValidationCallback _callback;
private Exception _validationFailure;
internal string _serverHostName;

public ssl(CodeContext context, PythonSocket.socket sock, string keyfile=null, string certfile=null, X509Certificate2Collection certs=null) {
_context = context;
Expand Down Expand Up @@ -2613,7 +2614,7 @@ public void do_handshake() {
if (_cert != null) {
collection.Add(_cert);
}
_sslStream.AuthenticateAsClient(_socket._hostName, collection, enabledSslProtocols, false);
_sslStream.AuthenticateAsClient(_serverHostName ?? _socket._hostName, collection, enabledSslProtocols, false);
}
} catch (AuthenticationException e) {
((IDisposable)_socket._socket).Dispose();
Expand Down
4 changes: 2 additions & 2 deletions Src/IronPython.Modules/_ssl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public void load_verify_locations(CodeContext context, [DefaultParameterValue(nu
}

public object _wrap_socket(CodeContext context, [DefaultParameterValue(null)] PythonSocket.socket sock, [DefaultParameterValue(false)] bool server_side, [DefaultParameterValue(null)] string server_hostname, [DefaultParameterValue(null)] object ssl_sock) {
return new PythonSocket.ssl(context, sock, server_side, null, _cafile, verify_mode, protocol | options, null, _cert_store);
return new PythonSocket.ssl(context, sock, server_side, null, _cafile, verify_mode, protocol | options, null, _cert_store) { _serverHostName = server_hostname };
}
}

Expand Down Expand Up @@ -703,7 +703,7 @@ private static Exception ErrorDecoding(CodeContext context, params object[] args
public const int VERIFY_X509_STRICT = 0x20; // from openssl/x509_vfy.h
public const int VERIFY_X509_TRUSTED_FIRST = 0x8000; // from openssl/x509_vfy.h

public const bool HAS_SNI = false;
public const bool HAS_SNI = true;
public const bool HAS_ECDH = true;
public const bool HAS_NPN = false;
public const bool HAS_ALPN = false;
Expand Down
16 changes: 9 additions & 7 deletions Src/IronPython.Modules/_weakref.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,15 @@ private weakproxy(CodeContext/*!*/ context, object target, object callback) {
/// <summary>
/// gets the object or throws a reference exception
/// </summary>
object GetObject() {
private object GetObject() {
object res;
if (!TryGetObject(out res)) {
throw PythonOps.ReferenceError("weakly referenced object no longer exists");
}
return res;
}

bool TryGetObject(out object result) {
private bool TryGetObject(out object result) {
result = _target.Target;
if (result == null) return false;
GC.KeepAlive(this);
Expand Down Expand Up @@ -764,7 +764,7 @@ public object __bool__() {
}
}

static class WeakRefHelpers {
private static class WeakRefHelpers {
public static WeakRefTracker InitializeWeakRef(PythonContext context, object self, object target, object callback) {
IWeakReferenceable iwr = ConvertToWeakReferenceable(context, target);

Expand All @@ -774,14 +774,16 @@ public static WeakRefTracker InitializeWeakRef(PythonContext context, object sel
throw PythonOps.TypeError("cannot create weak reference to '{0}' object", PythonOps.GetPythonTypeName(target));
}

wrt.ChainCallback(callback,self);
if (callback != null || !wrt.Contains(callback, self)) {
wrt.ChainCallback(callback, self);
}
return wrt;
}
}
}

[PythonType("wrapper_descriptor")]
class SlotWrapper : PythonTypeSlot, ICodeFormattable {
internal class SlotWrapper : PythonTypeSlot, ICodeFormattable {
private readonly string _name;
private readonly PythonType _type;

Expand Down Expand Up @@ -827,8 +829,8 @@ internal override bool TryGetValue(CodeContext context, object instance, PythonT

[PythonType("method-wrapper")]
public class GenericMethodWrapper {
string name;
IProxyObject target;
private readonly string name;
private readonly IProxyObject target;

public GenericMethodWrapper(string methodName, IProxyObject proxyTarget) {
name = methodName;
Expand Down
2 changes: 1 addition & 1 deletion Src/IronPython/Modules/Builtin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public static object compile(CodeContext/*!*/ context, object source, string fil
if (astOnly) {
return source;
} else {
PythonAst ast = _ast.ConvertToPythonAst(context, (_ast.AST) source);
PythonAst ast = _ast.ConvertToPythonAst(context, (_ast.AST)source, filename);
ast.Bind();
ScriptCode code = ast.ToScriptCode();
return ((RunnableScriptCode)code).GetFunctionCode(true);
Expand Down
4 changes: 2 additions & 2 deletions Src/IronPython/Modules/_ast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ public override void Add(SourceUnit sourceUnit, string message, SourceSpan span,
}
}

internal static PythonAst ConvertToPythonAst(CodeContext codeContext, AST source ) {
internal static PythonAst ConvertToPythonAst(CodeContext codeContext, AST source, string filename) {
Statement stmt;
PythonCompilerOptions options = new PythonCompilerOptions(ModuleOptions.ExecOrEvalCode);
SourceUnit unit = new SourceUnit(codeContext.LanguageContext, NullTextContentProvider.Null, "", SourceCodeKind.AutoDetect);
SourceUnit unit = new SourceUnit(codeContext.LanguageContext, NullTextContentProvider.Null, filename, SourceCodeKind.AutoDetect);
CompilerContext compilerContext = new CompilerContext(unit, options, ErrorSink.Default);
bool printExpression = false;

Expand Down
20 changes: 14 additions & 6 deletions Src/IronPython/Runtime/WeakRef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Dynamic;
using System.Linq;
using System.Threading;

using Microsoft.Scripting.Actions;
using Microsoft.Scripting.Runtime;
using Microsoft.Scripting.Utils;

using IronPython.Runtime.Binding;
using IronPython.Runtime.Operations;

namespace IronPython.Runtime {
Expand All @@ -35,10 +34,10 @@ namespace IronPython.Runtime {
/// is held in objects that implement IWeakReferenceable.
/// </summary>
public class WeakRefTracker {
struct CallbackInfo {
readonly object _callback;
readonly WeakHandle _longRef;
readonly WeakHandle _shortRef;
private readonly struct CallbackInfo {
private readonly object _callback;
private readonly WeakHandle _longRef;
private readonly WeakHandle _shortRef;

public CallbackInfo(object callback, object weakRef) {
_callback = callback;
Expand Down Expand Up @@ -137,6 +136,15 @@ public void RemoveHandler(object o) {

}

internal bool Contains(object callback, object weakref) {
_lock.EnterReadLock();
try {
return _callbacks.Any(o => o.Callback == callback && o.WeakRef == weakref);
} finally {
_lock.ExitReadLock();
}
}

public object GetHandlerCallback(int index) {
_lock.EnterReadLock();
try {
Expand Down