Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base: master
...
compare: rurban/gh1017-proxy-get_id
  • 1 commit
  • 4 files changed
  • 0 commit comments
  • 1 contributor
Commits on Dec 18, 2014
Reini Urban rurban [ops] follow a proxy with get_id
Closes GH #1017
04b30a7
1  config/gen/makefiles/root.in
View
@@ -2154,6 +2154,7 @@ src/ops/core_ops$(O) : src/ops/core_ops.c \
$(INC_PMC_DIR)/pmc_exceptionhandler.h \
$(INC_PMC_DIR)/pmc_fixedintegerarray.h \
$(INC_PMC_DIR)/pmc_parrotlibrary.h \
+ $(INC_PMC_DIR)/pmc_proxy.h \
$(INC_PMC_DIR)/pmc_task.h \
$(INC_DIR)/events.h \
$(INC_DIR)/scheduler_private.h \
17 src/ops/core_ops.c
View
@@ -75,6 +75,7 @@ extern op_lib_t core_op_lib;
#include "parrot/scheduler_private.h"
+#include "pmc/pmc_proxy.h"
#include "pmc/pmc_task.h"
@@ -23639,13 +23640,25 @@ Parrot_get_label_i_p(opcode_t *cur_opcode, PARROT_INTERP) {
opcode_t *
Parrot_get_id_i_p(opcode_t *cur_opcode, PARROT_INTERP) {
- IREG(1) = Parrot_hash_pointer((void *)PREG(2), interp->hash_seed);
+ PMC * pmc = PREG(2);
+
+ if (pmc->vtable->base_type == enum_class_Proxy) {
+ pmc = PARROT_PROXY(pmc)->target;
+ }
+
+ IREG(1) = Parrot_hash_pointer((void *)pmc, interp->hash_seed);
return cur_opcode + 3;
}
opcode_t *
Parrot_get_id_i_pc(opcode_t *cur_opcode, PARROT_INTERP) {
- IREG(1) = Parrot_hash_pointer((void *)PCONST(2), interp->hash_seed);
+ PMC * pmc = PCONST(2);
+
+ if (pmc->vtable->base_type == enum_class_Proxy) {
+ pmc = PARROT_PROXY(pmc)->target;
+ }
+
+ IREG(1) = Parrot_hash_pointer((void *)pmc, interp->hash_seed);
return cur_opcode + 3;
}
15 src/ops/experimental.ops
View
@@ -5,6 +5,7 @@
BEGIN_OPS_PREAMBLE
#include "parrot/scheduler_private.h"
+#include "pmc/pmc_proxy.h"
#include "pmc/pmc_task.h"
END_OPS_PREAMBLE
@@ -86,14 +87,24 @@ Gets a unique(*) ID for a PMC.
This may or may not be based on the pointer of the PMC, but almost certainly is
not the raw pointer value.
-(*) Uniqueness of these IDs is only guarranteed within code to which this PMC is
+Across shared threads the writable object and the non-writable proxied
+object do return the same id.
+
+(*) Uniqueness of these IDs is only guaranteed within code to which this PMC is
currently visible (ie: not across processes, or share-nothing threads, and not
beyond the lifetime of the PMC).
+Currently it is not even persistant across garbage collections. To be
+persistant across garbage collections it needs to be changed to
+weakrefs.
+
=cut
inline op get_id(out INT, in PMC) {
- $1 = Parrot_hash_pointer((void *)$2, interp->hash_seed);
+ PMC * pmc = $2;
+ if (pmc->vtable->base_type == enum_class_Proxy)
+ pmc = PARROT_PROXY(pmc)->target;
+ $1 = Parrot_hash_pointer((void *)pmc, interp->hash_seed);
}
=item B<fetch>(out PMC, in PMC, in PMC, in PMC)
43 t/pmc/pmc.t
View
@@ -1,12 +1,12 @@
#!perl
-# Copyright (C) 2001-2009, Parrot Foundation.
+# Copyright (C) 2001-2014, Parrot Foundation.
use strict;
use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More;
-use Parrot::Test tests => 15;
+use Parrot::Test tests => 16;
use Parrot::PMC '%pmc_types';
=head1 NAME
@@ -265,6 +265,45 @@ String
42
OUTPUT
+pir_output_is( <<'CODE', <<'OUTPUT', "get_id", todo => 'GH#1017' );
+.sub foo
+ $P0 = get_global "wibble"
+ $I0 = get_id $P0
+ $P1 = $I0
+ set_global 'id', $P1
+ .return ()
+.end
+.sub main :main
+ $P0 = new ['ResizablePMCArray']
+ set_global "wibble", $P0
+ $P1 = new ['Integer']
+ set_global "id", $P1
+
+ .const "Sub" foo = "foo"
+ $P2 = new "Task", foo
+ schedule $P2
+ sleep 0.1
+ wait $P2
+
+ $P3 = get_global 'id'
+ $I0 = $P3
+ $I1 = get_id $P0
+ eq $I0, $I1, ok1
+ print "not "
+ok1:
+ say "ok 1"
+
+ $I2 = get_id $P3
+ ne $I1, $I2, ok2
+ print "not "
+ok2:
+ say "ok 2"
+.end
+CODE
+ok 1
+ok 2
+OUTPUT
+
# Local Variables:
# mode: cperl
# cperl-indent-level: 4

No commit comments for this range

Something went wrong with that request. Please try again.