Skip to content

Commit

Permalink
huge refacto to avoid usless message passing, but stuck on a segfault
Browse files Browse the repository at this point in the history
  • Loading branch information
lisael committed Oct 18, 2016
1 parent 644f588 commit 972b7d4
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 107 deletions.
31 changes: 25 additions & 6 deletions example/main.pony
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,22 @@ class BlogEntryRecordNotify is FetchNotify
let view: BlogEntriesView tag
new iso create(v: BlogEntriesView tag) => view = v
fun ref descirption(desc: RowDescription) => None
fun size(): USize => 10000
fun size(): USize => 10
fun ref batch(r: Array[Record val] val, next: FetchNotifyNext val) =>
Debug.out("Batch")
if r.size() == size() then
next(None)
end
fun ref record(r: Record val) =>
Debug.out(".")
try
let e = recover val BlogEntry(
r(0) as I32,
2, 3
/*r(1) as I32,*/
/*r(2) as I32*/
) end
Debug.out(e.string())
// Debug.out(e.string())
/*(entries as Array[BlogEntry val] trn).push(e)*/

end
Expand All @@ -62,6 +68,17 @@ class UserRecordNotify is FetchNotify
let view: BlogEntriesView tag
new create(v: BlogEntriesView tag) => view = v
fun ref descirption(desc: RowDescription) => None

fun ref batch(b: Array[Record val] val, next: FetchNotifyNext val) =>
Debug(b.size())
for r in b.values() do
try
view.user(recover User(r("id") as I32) end)
else
Debug.out("Error")
end
end

fun ref record(r: Record val) =>
try
view.user(recover User(r("id") as I32) end)
Expand All @@ -76,9 +93,10 @@ actor BlogEntriesView

be fetch_entries() =>
try
Debug("fetch_entries")
(_conn as Connection).fetch(
/*"SELECT 1 as user_id, 2, 3 UNION ALL SELECT 4 as user_id, 5, 6 UNION ALL SELECT 7 as user_id, 8, 9",*/
"SELECT generate_series(0,1000000)",
"SELECT generate_series(0,100)",
recover BlogEntryRecordNotify(this) end)
end

Expand All @@ -91,6 +109,7 @@ actor BlogEntriesView

be user(u: User iso) =>
_user = recover val consume u end
Debug.out("###")
fetch_entries()

be render(entries': Array[BlogEntry val] val) =>
Expand Down Expand Up @@ -121,14 +140,14 @@ actor Main
password=EnvPasswordProvider(env),
database="macflytest")
let that = recover tag this end
session.execute("SELECT generate_series(0,10)",
"""
session.execute("SELECT generate_series(0,1)",
recover val
lambda(r: Rows val)(that) =>
that.raw_count(r)
None
end
end)
"""
session.execute("SELECT 42, 24 as foo;;",
recover val
Expand All @@ -145,12 +164,12 @@ actor Main
end
end,
recover val [as PGValue: I32(70000), I32(-100000)] end)
"""
let p = session.connect(recover val
lambda(c: Connection tag) =>
BlogEntriesView(c)
end
end)
"""

be raw_count(rows: Rows val) =>
_env.out.print(rows.size().string())
Expand Down
39 changes: 25 additions & 14 deletions pg/codec/registry.pony
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,37 @@ primitive TypeOids
end

primitive Decode
fun apply(type_oid: I32, value: Array[U8] val, 0): PGValue ? =>
DecodeText(type_oid, value)
fun apply(type_oid: I32, value: Array[U8] val, 1): PGValue ? =>
DecodeBinary(type_oid, value)
fun apply(type_oid: I32, value: Array[U8] val, format: I16): PGValue ? => error
fun apply(type_oid: I32, value: Array[U8] val, format: I16): PGValue ? =>
if format == 0 then
DecodeText(type_oid, value)
else if format == 1 then
DecodeBinary(type_oid, value)
else
Debug.out("Unknown fromat" + format.string())
error
end end

primitive DecodeText
fun apply(23, value: Array[U8] val): I32 ? =>
String.from_array(value).i32()
fun apply(type_oid: I32, value: Array[U8] val) ? => Debug.out("Unknown type OID: " + type_oid.string()); error
fun apply(type_oid: I32, value: Array[U8] val): PGValue ? =>
match type_oid
| 23 => String.from_array(value).i32()
else
Debug.out("Unknown type OID: " + type_oid.string()); error
end

primitive DecodeBinary
fun apply(23, value: Array[U8] val): I32 ? =>
var result = I32(0)
for i in value.values() do
result = (result << 8) + i.i32()
fun apply(type_oid: I32, value: Array[U8] val): PGValue ? =>
match type_oid
| 23 =>
var result = I32(0)
for i in value.values() do
result = (result << 8) + i.i32()
end
result
else
Debug.out("Unknown type OID: " + type_oid.string()); error
end
result

fun apply(type_oid: I32, value: Array[U8] val) ? => Debug.out("Unknown type OID: " + type_oid.string()); error

primitive EncodeBinary
fun apply(param: I32, writer: Writer) ? =>
Expand Down
4 changes: 4 additions & 0 deletions pg/connection.pony
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ use "debug"
use "pg/connection"
use "pg/introspect"


type FetchNotifyNext is {((FetchNotify iso | None))}

interface FetchNotify
fun ref descirption(desc: RowDescription) => None
fun ref record(r: Record val) => None
fun ref batch(r: Array[Record val] val, next: FetchNotifyNext val) => None
fun ref stop() => None
fun size(): USize => 30

Expand Down
Loading

0 comments on commit 972b7d4

Please sign in to comment.