From 59276e355f0ed9a5a3b607d76affd3566047e893 Mon Sep 17 00:00:00 2001 From: Pedram Nimreezi Date: Thu, 8 Sep 2016 00:42:31 -0400 Subject: [PATCH] Support pids in storage --- src/glc.erl | 9 ++++++++- src/glc_code.erl | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/glc.erl b/src/glc.erl index ed7dbc2..4baf1b2 100644 --- a/src/glc.erl +++ b/src/glc.erl @@ -322,6 +322,12 @@ reset_counters(Module) -> reset_counters(Module, Counter) -> Module:reset_counters(Counter). +prepare_store(Store) -> + lists:map(fun({K, V}) when is_pid(V) + -> {K, {pid, binary_to_list(term_to_binary(V))}} ; + ({K, V}) -> {K, V} + end, Store). + %% @private Map a query to a module data term. -spec module_data(atom(), term(), term()) -> {ok, #module{}}. module_data(Module, Query, Store) -> @@ -337,7 +343,8 @@ module_data(Module, Query, Store) -> %% function maps names to registered processes response for those tables. Tables = module_tables(Module), Query2 = glc_lib:reduce(Query), - {ok, #module{'query'=Query, tables=Tables, qtree=Query2, store=Store}}. + Store2 = prepare_store(Store), + {ok, #module{'query'=Query, tables=Tables, qtree=Query2, store=Store2}}. %% @private Create a data managed supervised process for params, counter tables module_tables(Module) -> diff --git a/src/glc_code.erl b/src/glc_code.erl index 5fefe0b..9686fd3 100644 --- a/src/glc_code.erl +++ b/src/glc_code.erl @@ -203,6 +203,9 @@ abstract_query({any, [{with, _Q, _A}|_] = I}) -> abstract_query({all, [{with, _Q, _A}|_] = I}) -> Queries = glc_lib:reduce(glc:all([Q || {with, Q, _} <- I])), [?erl:abstract(Queries)]; +abstract_query({ok, {pid, Pid}}) -> + PidBin = abstract_apply(erlang, 'list_to_binary', [?erl:abstract(Pid)]), + [?erl:tuple([?erl:atom(ok), abstract_apply(erlang, 'binary_to_term', [(PidBin)])])]; abstract_query(Query) -> [?erl:abstract(Query)].