a lot of bugfixes #19

Open
wants to merge 5 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+1,033 −347
Diff settings

Always

Just for now

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -116,7 +116,7 @@ public struct Relative
#region Parse
- public static int Parse(string/*!*/ str, DateTime utcStart, out string error)
+ public static long Parse(string/*!*/ str, DateTime utcStart, out string error)
{
Debug.Assert(str != null);
@@ -141,7 +141,7 @@ public static int Parse(string/*!*/ str, DateTime utcStart, out string error)
#region GetUnixTimeStamp
- private int GetUnixTimeStamp(DateTime utcStart, out string error)
+ private long GetUnixTimeStamp(DateTime utcStart, out string error)
{
var zone = PhpTimeZone.CurrentTimeZone;
DateTime start = TimeZoneInfo.ConvertTimeFromUtc(utcStart, zone);// zone.ToLocalTime(utcStart);
@@ -55,6 +55,8 @@ private static void Clear()
statCacheUrl = null;
}
+ private static char[] invalidPathChars = Path.GetInvalidPathChars();
+
#endregion
#region Stat Basics (BuildStatArray, StatInternal, lstat, stat, fstat, clearstatcache; exists, touch)
@@ -510,11 +512,11 @@ public static string GetType(string path)
/// <returns>The file access time or -1 in case of failure.</returns>
[ImplementsFunction("fileatime")]
[return: CastToFalse]
- public static int GetAccessTime(string path)
+ public static long GetAccessTime(string path)
{
bool ok = StatInternal(path, false);
if (!ok) return -1;
- return unchecked((int)statCache.st_atime);
+ return statCache.st_atime;
}
/// <summary>
@@ -666,7 +668,7 @@ public static bool IsDirectory(string path)
{
StreamWrapper wrapper;
- if (!string.IsNullOrEmpty(path) && StatInternalCheck(ref path, false, out wrapper)) // do not throw warning if path is null or empty
+ if (!string.IsNullOrEmpty(path) && path.IndexOfAny(invalidPathChars) < 0 && StatInternalCheck(ref path, false, out wrapper)) // do not throw warning if path is null or empty
{
string url;
if (StatInternalTryCache(path, out url))
@@ -693,7 +695,7 @@ public static bool IsDirectory(string path)
[ImplementsFunction("is_executable")]
public static bool IsExecutable(string path)
{
- bool ok = StatInternal(path, false);
+ bool ok = !string.IsNullOrEmpty(path) && path.IndexOfAny(invalidPathChars) < 0 && StatInternal(path, false);
if (!ok) return false;
return ((FileModeFlags)statCache.st_mode & FileModeFlags.Execute) > 0;
}
@@ -708,7 +710,7 @@ public static bool IsFile(string path)
{
StreamWrapper wrapper;
- if (StatInternalCheck(ref path, false, out wrapper))
+ if (!string.IsNullOrEmpty(path) && path.IndexOfAny(invalidPathChars) < 0 && StatInternalCheck(ref path, false, out wrapper))
{
string url;
if (StatInternalTryCache(path, out url))
@@ -744,7 +746,7 @@ public static bool IsLink(string path)
[ImplementsFunction("is_readable")]
public static bool IsReadable(string path)
{
- bool ok = StatInternal(path, false);
+ bool ok = !string.IsNullOrEmpty(path) && path.IndexOfAny(invalidPathChars) < 0 && StatInternal(path, false);
if (!ok) return false;
return ((FileModeFlags)statCache.st_mode & FileModeFlags.Read) > 0;
}
@@ -769,7 +771,7 @@ public static bool IsWriteable(string path)
[ImplementsFunction("is_writable")]
public static bool IsWritable(string path)
{
- bool ok = StatInternal(path, false);
+ bool ok = !string.IsNullOrEmpty(path) && path.IndexOfAny(invalidPathChars) < 0 && StatInternal(path, false);
if (!ok) return false;
return ((FileModeFlags)statCache.st_mode & FileModeFlags.Write) > 0;
}
@@ -378,7 +378,7 @@ public static int GetCurrentProcessId()
/// </summary>
/// <returns>The UNIX timestamp or -1 on error.</returns>
[ImplementsFunction("getlastmod")]
- public static int GetLastModification()
+ public static long GetLastModification()
{
try
{
@@ -332,7 +332,22 @@ public static PhpArray GetStatus(bool full)
public static void FlushHttpBuffers()
{
HttpContext http_context = HttpContext.Current;
- if (http_context != null) http_context.Response.Flush();
+ if (http_context != null)
+ {
+ try
+ {
+ http_context.Response.Flush();
+ }
+ catch (HttpException)
+ {
+ var context = RequestContext.CurrentContext;
+ if (context != null && !context.TrackClientDisconnection)
+ {
+ return;
+ }
+ throw;
+ }
+ }
}
/// <summary>
@@ -213,15 +213,15 @@ protected override void Collect(string savePath, string sid, int lifetime)
{
if (dir == null) return;
- int threshold = DateTimeUtils.UtcToUnixTimeStamp(DateTime.Now.ToUniversalTime().AddSeconds(-lifetime));
+ long threshold = DateTimeUtils.UtcToUnixTimeStamp(DateTime.Now.ToUniversalTime().AddSeconds(-lifetime));
string file_name;
while ((file_name = PhpDirectory.Read(dir)) != null)
{
if (file_name.Length >= FilePrefix.Length && file_name.Substring(0, FilePrefix.Length) == FilePrefix)
{
string full_path = Path.Combine(savePath, file_name);
- int time = PhpFile.GetAccessTime(full_path);
+ long time = PhpFile.GetAccessTime(full_path);
if (time < threshold)
{
@@ -378,7 +378,7 @@ public static string RawUrlEncode(string str)
[ImplementsFunction("urldecode")]
public static string UrlDecode(string str)
{
- return HttpUtility.UrlDecode(str);
+ return HttpUtility.UrlDecode(str, Configuration.Application.Globalization.PageEncoding);
}
/// <summary>
@@ -387,7 +387,7 @@ public static string UrlDecode(string str)
[ImplementsFunction("urlencode")]
public static string UrlEncode(string str)
{
- return UpperCaseEncodedChars(HttpUtility.UrlEncode(str));
+ return UpperCaseEncodedChars(HttpUtility.UrlEncode(str, Configuration.Application.Globalization.PageEncoding));
}
private static string UpperCaseEncodedChars(string encoded)
@@ -1324,7 +1324,7 @@ public static bool IsPureUnit(string/*!*/ value)
}
PhpAssemblyBuilder assembly_builder = PhpAssemblyBuilder.Create(applicationContext, kind, ps.Pure, ps.OutPath,
- ps.DocPath, entry_point_file, ps.Version, ps.Key, ps.Icon, resource_files, config.Compiler.Debug, ps.Force32Bit);
+ ps.DocPath, entry_point_file, ps.Version, ps.Key, ps.Icon, resource_files, config.Compiler.DebugMode, ps.Force32Bit);
assembly_builder.IsMTA = ps.IsMTA;
@@ -2950,7 +2950,7 @@ internal void EmitPhpException(ILEmitter/*!*/ il, MethodInfo/*!*/ method)
/// <param name="endColumn">Real last column of the point.</param>
internal void MarkSequencePoint(int startLine, int startColumn, int endLine, int endColumn)
{
- if (context.Config.Compiler.Debug)
+ if (context.Config.Compiler.DebugMode != DebugMode.None)
{
// ignores #pragma inside the code span:
ISymbolDocumentWriter symbol_writer = sourceUnit.GetMappedSymbolDocumentWriter(startLine);
@@ -2971,7 +2971,7 @@ internal void MarkSequencePoint(int startLine, int startColumn, int endLine, int
}
}
- /// <summary>
+ /// <summary>
/// Marks a sequence point (see <see cref="MarkSequencePoint"/>) using position of given <paramref name="expression"/>.
/// </summary>
/// <param name="expression">Expression which position is used to mark sequence point.</param>
@@ -381,7 +381,7 @@ public IPhpModuleBuilder DefineModuleBuilder(CompilationUnitBase/*!*/ compiledUn
// creates a script assembly builder:
SingleScriptAssemblyBuilder builder = new SingleScriptAssemblyBuilder(applicationContext,
- name, outDir, name.Name + AssemblyExt, AssemblyKinds.WebPage, context.Config.Compiler.Debug, false, context.SaveOnlyAssembly, null);
+ name, outDir, name.Name + AssemblyExt, AssemblyKinds.WebPage, context.Config.Compiler.DebugMode, false, context.SaveOnlyAssembly, null);
return builder.DefineScript(unit);
}
@@ -851,7 +851,15 @@ internal int HashCode
hashcode += mapping.Pattern.ToString().GetHashCode();
hashcode += mapping.Replacement.GetHashCode();
}
- hashcode += debug ? 897987897 : 12;
+ if (debug)
+ {
+ hashcode += 897987897;
+ }
+ else
+ {
+ hashcode += 12;
+ hashcode += genegatePdbInRelease ? 564456654 : 35;
+ }
}
dirty = false;
@@ -873,6 +881,7 @@ internal CompilerSection()
dirty = true;
hashcode = 0;
debug = true;
+ genegatePdbInRelease = true;
disabledWarnings = WarningGroups.DeferredToRuntime | WarningGroups.CompilerStrict;
disabledWarningNumbers = ArrayUtils.EmptyIntegers;
@@ -979,6 +988,10 @@ public bool Parse(string name, string value, XmlNode node)
debug = (value == "true");
return true;
+ case "GeneratePdbInRelease":
+ genegatePdbInRelease = (value == "true");
+ return true;
+
case "WatchSourceChanges":
{
// applicable only in run-time:
@@ -16,6 +16,12 @@
namespace PHP.Core
{
+ public enum DebugMode
+ {
+ None,
+ Pdb,
+ Full
+ }
#region Language Features Enum
/// <summary>
@@ -222,7 +228,14 @@ public sealed partial class OutputControlSection : IPhpConfigurationSection
internal OutputControlSection DeepCopy()
{
- return (OutputControlSection)MemberwiseClone();
+ return new OutputControlSection()
+ {
+ charSet = charSet,
+ contentType = contentType,
+ implicitFlush = implicitFlush,
+ outputBuffering = outputBuffering,
+ outputHandler = outputHandler == null ? null : outputHandler.DeepCopy()
+ };
}
}
@@ -337,7 +350,12 @@ private static string AbsolutizeLogFile(string value, System.Xml.XmlNode/*!*/nod
/// </summary>
internal ErrorControlSection DeepCopy()
{
- return (ErrorControlSection)this.MemberwiseClone();

This comment has been minimized.

@jakubmisek

jakubmisek Sep 12, 2013

Member

please keep MemberwiseClone() and copy UserExceptionHandler and UserHandler additionally. Copying properties one-by-one is unmaintainable.

@jakubmisek

jakubmisek Sep 12, 2013

Member

please keep MemberwiseClone() and copy UserExceptionHandler and UserHandler additionally. Copying properties one-by-one is unmaintainable.

This comment has been minimized.

@proff

proff Oct 31, 2013

Contributor

done

@proff

proff Oct 31, 2013

Contributor

done

+ var copy = (ErrorControlSection)MemberwiseClone();
+ if (UserExceptionHandler != null)
+ copy.UserExceptionHandler = UserExceptionHandler.DeepCopy();
+ if (UserHandler != null)
+ copy.UserHandler = UserHandler.DeepCopy();
+ return copy;
}
}
@@ -422,7 +440,10 @@ public sealed partial class AssertionSection : IPhpConfigurationSection
/// </summary>
internal AssertionSection DeepCopy()
{
- return (AssertionSection)this.MemberwiseClone();

This comment has been minimized.

@jakubmisek

jakubmisek Sep 12, 2013

Member

please keep MemberwiseClone() and handle Callback additionally. Copying properties one-by-one is unmaintainable.

@jakubmisek

jakubmisek Sep 12, 2013

Member

please keep MemberwiseClone() and handle Callback additionally. Copying properties one-by-one is unmaintainable.

This comment has been minimized.

@proff

proff Oct 31, 2013

Contributor

done

@proff

proff Oct 31, 2013

Contributor

done

+ var copy = (AssertionSection) MemberwiseClone();
+ if (Callback != null)
+ copy.Callback = Callback.DeepCopy();
+ return copy;
}
}
@@ -503,7 +524,12 @@ public static bool ValidateRegisteringOrder(string value)
/// </summary>
internal VariablesSection DeepCopy()
{
- return (VariablesSection)this.MemberwiseClone();

This comment has been minimized.

@jakubmisek

jakubmisek Sep 12, 2013

Member

please keep MemberwiseClone() and handle DeserializationCallback additionally. Copying properties one-by-one is unmaintainable.

@jakubmisek

jakubmisek Sep 12, 2013

Member

please keep MemberwiseClone() and handle DeserializationCallback additionally. Copying properties one-by-one is unmaintainable.

This comment has been minimized.

@proff

proff Sep 12, 2013

Contributor

ok, but handlers also can be added in config :)

@proff

proff Sep 12, 2013

Contributor

ok, but handlers also can be added in config :)

This comment has been minimized.

@jakubmisek

jakubmisek Sep 12, 2013

Member

DeepCopy is ok, but do not copy all the properties one-by-one. Keep MemberwiseClone() and call DeepCopy additionally on cloned object. If sb. would add a property, this is number one source of bug.

@jakubmisek

jakubmisek Sep 12, 2013

Member

DeepCopy is ok, but do not copy all the properties one-by-one. Keep MemberwiseClone() and call DeepCopy additionally on cloned object. If sb. would add a property, this is number one source of bug.

This comment has been minimized.

@proff

proff Oct 31, 2013

Contributor

done

@proff

proff Oct 31, 2013

Contributor

done

+ var copy = (VariablesSection) MemberwiseClone();
+ if (DeserializationCallback != null)
+ {
+ copy.DeserializationCallback = DeserializationCallback.DeepCopy();
+ }
+ return copy;
}
}
@@ -787,7 +813,34 @@ public bool Debug
}
internal bool debug;
- #endregion
+ public bool GenegatePdbInRelease {
+ get { return genegatePdbInRelease; }
+ set
+ {
+ genegatePdbInRelease = value;
+#if !SILVERLIGHT
+ dirty = true;
+#endif
+ }
+ }
+ internal bool genegatePdbInRelease;
+
+ public DebugMode DebugMode
+ {
+ get
+ {
+ DebugMode result;
+ if (debug)
+ result = DebugMode.Full;
+ else if (genegatePdbInRelease)
+ result = DebugMode.Pdb;
+ else
+ result = DebugMode.None;
+ return result;
+ }
+ }
+
+ #endregion
#region Inclusions
Oops, something went wrong.