Skip to content

Commit

Permalink
Fixed the code to read data from an IO instance: it was working befor…
Browse files Browse the repository at this point in the history
…e some recent DLR changes, but it was wrong and didn't look good anyway.
  • Loading branch information
nrk committed May 7, 2009
1 parent b2c0951 commit 68789c9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/Hpricot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ namespace IronRuby.Libraries.Hpricot {
[RubyModule("Hpricot")]
public static class Hpricot {
[RubyMethod("scan", RubyMethodAttributes.PublicSingleton)]
public static Object Scan(ConversionStorage<MutableString>/*!*/ toMutableStringStorage, RespondToStorage/*!*/ respondsTo,
RubyContext/*!*/ context, BlockParam/*!*/ block, RubyModule/*!*/ self, Object/*!*/ source) {
public static Object Scan(ConversionStorage<MutableString>/*!*/ toMutableStringStorage, RespondToStorage/*!*/ respondsTo,
BinaryOpStorage/*!*/ readIOStorage, BlockParam/*!*/ block, RubyModule/*!*/ self, Object/*!*/ source) {
if (block == null) {
throw RubyExceptions.NoBlockGiven();
}
HpricotScanner scanner = new HpricotScanner(respondsTo, toMutableStringStorage, context, block);
HpricotScanner scanner = new HpricotScanner(respondsTo, toMutableStringStorage, readIOStorage, block);
return scanner.Scan(source);
}

Expand Down
16 changes: 9 additions & 7 deletions src/HpricotScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Microsoft.Scripting.Runtime;

namespace IronRuby.Libraries.Hpricot {
using RubyIOReadCallSite = CallSite<Func<CallSite, RubyContext, Object, Int32, MutableString>>;
using RubyIOReadCallSite = CallSite<Func<CallSite, Object, Object, Object>>;

public class HpricotScanner {
#region fields
Expand All @@ -22,6 +22,7 @@ public class HpricotScanner {
private BlockParam/*!*/ _blockParam;
private RespondToStorage/*!*/ _respondToStorage;
private ConversionStorage<MutableString> _toMutableString;
private BinaryOpStorage _readIOStorage;

#endregion

Expand Down Expand Up @@ -60,11 +61,12 @@ public class HpricotScanner {

#region constructors

public HpricotScanner(RespondToStorage/*!*/ respondToStorage, ConversionStorage<MutableString>/*!*/ toMutableString,
RubyContext/*!*/ context, BlockParam/*!*/ block) {
public HpricotScanner(RespondToStorage/*!*/ respondToStorage, ConversionStorage<MutableString>/*!*/ toMutableString,
BinaryOpStorage/*!*/ readIOStorage, BlockParam block) {
_currentContext = respondToStorage.Context;
_respondToStorage = respondToStorage;
_toMutableString = toMutableString;
_currentContext = context;
_readIOStorage = readIOStorage;
_blockParam = block;
}

Expand Down Expand Up @@ -1150,9 +1152,9 @@ public Object Scan(Object/*!*/ source) {

bool sourceRespondsToRead = Protocols.RespondTo(_respondToStorage, source, "read");

RubyIOReadCallSite readCallSite = null;
RubyIOReadCallSite readIOCallSite = null;
if (sourceRespondsToRead) {
readCallSite = RubyIOReadCallSite.Create(RubyCallAction.Make(_currentContext, "read", 3));
readIOCallSite = _readIOStorage.GetCallSite("read", 1);
}
else if (Protocols.RespondTo(_respondToStorage, source, "to_str")) {
source = Protocols.CastToString(_toMutableString, source);
Expand Down Expand Up @@ -1184,7 +1186,7 @@ public Object Scan(Object/*!*/ source) {

char[] chars;
if (sourceRespondsToRead) {
chars = BinaryEncoding.Instance.GetChars(readCallSite.Target(readCallSite, _currentContext, source, space).ToByteArray());
chars = BinaryEncoding.Instance.GetChars((readIOCallSite.Target(readIOCallSite, source, space) as MutableString).ToByteArray());
}
else {
MutableString str = source as MutableString;
Expand Down
2 changes: 1 addition & 1 deletion src/Initializers.Generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private static void LoadHpricot_Class(IronRuby.Builtins.RubyModule/*!*/ module)
);

module.DefineLibraryMethod("scan", 0x21,
new System.Func<IronRuby.Runtime.ConversionStorage<IronRuby.Builtins.MutableString>, IronRuby.Runtime.RespondToStorage, IronRuby.Runtime.RubyContext, IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyModule, System.Object, System.Object>(IronRuby.Libraries.Hpricot.Hpricot.Scan)
new System.Func<IronRuby.Runtime.ConversionStorage<IronRuby.Builtins.MutableString>, IronRuby.Runtime.RespondToStorage, IronRuby.Runtime.BinaryOpStorage, IronRuby.Runtime.BlockParam, IronRuby.Builtins.RubyModule, System.Object, System.Object>(IronRuby.Libraries.Hpricot.Hpricot.Scan)
);

}
Expand Down

0 comments on commit 68789c9

Please sign in to comment.