Browse Source

qlc with exact matching on pid fixed

Ulf Wiger 14 years ago
parent
commit
bdfb2e5704
3 changed files with 15 additions and 6 deletions
  1. 1 1
      src/gproc.app.src
  2. 5 3
      src/gproc.erl
  3. 9 2
      test/gproc_tests.erl

+ 1 - 1
src/gproc.app.src

@@ -5,7 +5,7 @@
 {application, gproc,
  [
   {description, "GPROC"},
-  {vsn, "0.2.3"},
+  {vsn, "0.2.4"},
   {id, "GPROC"},
   {registered, [ ] },
   %% NOTE: do not list applications which are load-only!

+ 5 - 3
src/gproc.erl

@@ -1224,7 +1224,9 @@ keypat(Context) ->
     {S,T} = get_s_t(Context),
     {{T,S,'_'},'_'}.
 
-
+rev_keypat(Context) ->
+    {S,T} = get_s_t(Context),
+    {T,S,'_'}.
 
 get_s_t({S,T}) -> {scope(S), type(T)};
 get_s_t(T) when is_atom(T) ->
@@ -1339,10 +1341,10 @@ qlc_lookup(_Scope, 1, Keys) ->
 qlc_lookup(Scope, 2, Pids) ->
     lists:flatmap(fun(Pid) ->
                           Found =
-                              ets:select(?TAB, [{ {{Pid,keypat(Scope)}},
+                              ets:select(?TAB, [{ {{Pid, rev_keypat(Scope)}, r},
                                                   [], ['$_']}]),
                           lists:flatmap(
-                            fun({{_,{T,_,_}=K}}) ->
+                            fun({{_,{T,_,_}=K}, r}) ->
                                     K2 = if T==n orelse T==a -> T;
                                             true -> Pid
                                          end,

+ 9 - 2
test/gproc_tests.erl

@@ -256,7 +256,7 @@ t_qlc() ->
     ?assertEqual(Exp3,
 		 qlc:e(qlc:q([N || {_,_,x} = N <- gproc:table(all)]))),
 
-    %% match all on pid
+    %% match all
     Exp4 = [{{a,l,{c,1}},self(),1},
 	    {{c,l,{c,1}},self(),1},
 	    {{n,l,{n,1}},self(),x},
@@ -265,7 +265,14 @@ t_qlc() ->
 	    {{p,l,{p,2}},self(),y}
 	   ],
     ?assertEqual(Exp4,
-		 qlc:e(qlc:q([X || X <- gproc:table(all)]))).
+		 qlc:e(qlc:q([X || X <- gproc:table(all)]))),
+    %% match on pid
+    ?assertEqual(Exp4,
+		 qlc:e(qlc:q([{K,P,V} || {K,P,V} <-
+					     gproc:table(all), P =:= self()]))),
+    ?assertEqual(Exp4,
+		 qlc:e(qlc:q([{K,P,V} || {K,P,V} <-
+					     gproc:table(all), P == self()]))).
 
 t_loop() ->
     receive