Skip to content
This repository
Browse code

qlc with exact matching on pid fixed

  • Loading branch information...
commit df116355fbe4dd84b961d813624baeadf3965710 1 parent c16d339
authored April 20, 2011
2  src/gproc.app.src
@@ -5,7 +5,7 @@
5 5
 {application, gproc,
6 6
  [
7 7
   {description, "GPROC"},
8  
-  {vsn, "0.2.3"},
  8
+  {vsn, "0.2.4"},
9 9
   {id, "GPROC"},
10 10
   {registered, [ ] },
11 11
   %% NOTE: do not list applications which are load-only!
8  src/gproc.erl
@@ -1224,7 +1224,9 @@ keypat(Context) ->
1224 1224
     {S,T} = get_s_t(Context),
1225 1225
     {{T,S,'_'},'_'}.
1226 1226
 
1227  
-
  1227
+rev_keypat(Context) ->
  1228
+    {S,T} = get_s_t(Context),
  1229
+    {T,S,'_'}.
1228 1230
 
1229 1231
 get_s_t({S,T}) -> {scope(S), type(T)};
1230 1232
 get_s_t(T) when is_atom(T) ->
@@ -1339,10 +1341,10 @@ qlc_lookup(_Scope, 1, Keys) ->
1339 1341
 qlc_lookup(Scope, 2, Pids) ->
1340 1342
     lists:flatmap(fun(Pid) ->
1341 1343
                           Found =
1342  
-                              ets:select(?TAB, [{ {{Pid,keypat(Scope)}},
  1344
+                              ets:select(?TAB, [{ {{Pid, rev_keypat(Scope)}, r},
1343 1345
                                                   [], ['$_']}]),
1344 1346
                           lists:flatmap(
1345  
-                            fun({{_,{T,_,_}=K}}) ->
  1347
+                            fun({{_,{T,_,_}=K}, r}) ->
1346 1348
                                     K2 = if T==n orelse T==a -> T;
1347 1349
                                             true -> Pid
1348 1350
                                          end,
11  test/gproc_tests.erl
@@ -256,7 +256,7 @@ t_qlc() ->
256 256
     ?assertEqual(Exp3,
257 257
 		 qlc:e(qlc:q([N || {_,_,x} = N <- gproc:table(all)]))),
258 258
 
259  
-    %% match all on pid
  259
+    %% match all
260 260
     Exp4 = [{{a,l,{c,1}},self(),1},
261 261
 	    {{c,l,{c,1}},self(),1},
262 262
 	    {{n,l,{n,1}},self(),x},
@@ -265,7 +265,14 @@ t_qlc() ->
265 265
 	    {{p,l,{p,2}},self(),y}
266 266
 	   ],
267 267
     ?assertEqual(Exp4,
268  
-		 qlc:e(qlc:q([X || X <- gproc:table(all)]))).
  268
+		 qlc:e(qlc:q([X || X <- gproc:table(all)]))),
  269
+    %% match on pid
  270
+    ?assertEqual(Exp4,
  271
+		 qlc:e(qlc:q([{K,P,V} || {K,P,V} <-
  272
+					     gproc:table(all), P =:= self()]))),
  273
+    ?assertEqual(Exp4,
  274
+		 qlc:e(qlc:q([{K,P,V} || {K,P,V} <-
  275
+					     gproc:table(all), P == self()]))).
269 276
 
270 277
 t_loop() ->
271 278
     receive

0 notes on commit df11635

Please sign in to comment.
Something went wrong with that request. Please try again.