Permalink
Browse files

clone - the patch

As discussed on p6i the clone vtables signature is now back again to
  PMC* clone()
returning a newly created PMC of type SELF.
Patch is a bit lengthy - there are a lot of clones out in the wild.

Please make realclean ; perl Configure.pl ...


git-svn-id: https://svn.parrot.org/parrot/trunk@4979 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information...
1 parent c39c79e commit d7d307c663b5b6a16dae796ed856b4c8be2cf85c Leopold Toetsch committed Dec 19, 2003
View
@@ -105,9 +105,11 @@ pmclass Array need_ext does array {
list_mark(INTERP, (List *) PMC_data(SELF));
}
- void clone (PMC *dest) {
+ PMC* clone () {
+ PMC* dest = pmc_new_noinit(INTERP, SELF->vtable->base_type);
PObj_custom_mark_SET(dest);
PMC_data(dest) = list_clone(INTERP, (List *) PMC_data(SELF));
+ return dest;
}
INTVAL get_integer () {
View
@@ -39,11 +39,12 @@ pmclass Closure extends Sub {
return SUPER(next);
}
- void clone (PMC *ret) {
+ PMC* clone () {
struct Parrot_Sub * sub;
- SUPER(ret);
+ PMC* ret = SUPER();
sub = PMC_sub(ret);
stack_mark_cow(sub->ctx.pad_stack);
+ return ret;
}
void set_same (PMC* value) {
View
@@ -31,12 +31,13 @@ pmclass Continuation extends Closure {
SUPER(); /* mark pad_stack, warns in closure */
}
- void clone(PMC *ret) {
+ PMC* clone() {
struct Parrot_Sub * sub;
- SUPER(ret);
+ PMC* ret = SUPER();
sub = PMC_sub(ret);
stack_mark_cow(sub->ctx.user_stack);
stack_mark_cow(sub->ctx.control_stack);
+ return ret;
}
void* invoke (void* next) {
View
@@ -16,8 +16,10 @@
pmclass CSub {
- void clone (PMC *dest) {
+ PMC* clone () {
+ PMC* dest = pmc_new_noinit(INTERP, SELF->vtable->base_type);
dest->cache.struct_val = SELF->cache.struct_val;
+ return dest;
}
PMC* get_pmc () {
View
@@ -16,9 +16,11 @@
pmclass IntList need_ext {
- void clone (PMC *dest) {
+ PMC* clone () {
+ PMC* dest = pmc_new_noinit(INTERP, SELF->vtable->base_type);
PObj_custom_mark_SET(dest);
PMC_data(dest) = intlist_clone(INTERP, (IntList *) PMC_data(SELF));
+ return dest;
}
void init () {
View
@@ -31,7 +31,8 @@ pmclass Iterator {
pobject_lives(INTERP, (PObj *) PMC_ptr2p(SELF));
}
- void clone (PMC* dest) {
+ PMC* clone () {
+ return SUPER();
/* XXX TODO */
}
View
@@ -17,10 +17,11 @@ pmclass Key need_ext {
PObj_custom_mark_SET(SELF);
}
- void clone(PMC *dest) {
+ PMC* clone() {
+ PMC *dest = pmc_new_noinit(INTERP, SELF->vtable->base_type);
PMC *dkey = dest;
PMC *key = SELF;
- PMC *p, *c;
+ PMC *p;
PObj_custom_mark_SET(dest);
for (; key ; ) {
@@ -42,9 +43,7 @@ pmclass Key need_ext {
case KEY_pmc_FLAG:
case KEY_pmc_FLAG|KEY_register_FLAG:
p = key_pmc(INTERP, key);
- c = pmc_new_noinit(INTERP, VTABLE_type(INTERP, p));
- key_set_pmc(INTERP, dkey, c);
- VTABLE_clone(INTERP, p, c);
+ key_set_pmc(INTERP, dkey, VTABLE_clone(INTERP, p));
break;
}
key = key_next(INTERP, key);
@@ -54,6 +53,7 @@ pmclass Key need_ext {
dkey = p;
}
}
+ return dest;
}
void mark () {
View
@@ -34,13 +34,15 @@ pmclass NCI need_ext {
mem_sys_free(PMC_data(SELF));
}
- void clone (PMC *ret) {
+ PMC* clone () {
+ PMC* ret = pmc_new_noinit(INTERP, SELF->vtable->base_type);
ret->cache.struct_val = SELF->cache.struct_val;
/* FIXME if data is malloced (JIT/i386!) then we need
* the length of data here, to memcpy it
* ManagedStruct or Buffer?
*/
PMC_data(ret) = PMC_data(SELF);
+ return ret;
}
INTVAL defined () {
View
@@ -39,9 +39,10 @@ pmclass OrderedHash extends PerlArray need_ext does array does hash {
PerlHash.SUPER();
}
- void clone (PMC *dest) {
- SUPER(dest);
- PerlHash.SUPER(dest);
+ PMC* clone () {
+ PMC* dest = SUPER();
+ hash_clone(INTERP, (Hash *)PMC_ptr1v(SELF), (Hash**)&PMC_ptr1v(dest));
+ return dest;
}
PMC* get_pmc_keyed (PMC* key) {
@@ -20,6 +20,7 @@
#include "parrot/embed.h"
#include <assert.h>
+void clone_interpreter(PMC* dest, PMC* self);
/*
* copy / clone interpreter registers
* all resources are created in the destination interpreter
@@ -46,14 +47,41 @@ clone_regs(Parrot_Interp d, Parrot_Interp s, PMC *dest)
sp->vtable->base_type == enum_class_ParrotThread))
d->pmc_reg.registers[i] = dest;
else {
- PMC *dp = pmc_new_noinit(d, sp->vtable->base_type);
- VTABLE_clone(d, sp, dp);
+ PMC* dp = VTABLE_clone(d, sp);
d->pmc_reg.registers[i] = dp;
}
}
}
}
+void
+clone_interpreter(PMC* dest, PMC* self)
+{
+
+ Parrot_Interp s = PMC_data(self);
+ Parrot_Interp d;
+
+ d = PMC_data(dest);
+
+ /*
+ * copy register files
+ */
+ clone_regs(d, s, dest);
+ /*
+ * copy over packfile - done currently in the runinterp opcode
+ * for multi-threading we have to generate separate
+ * profile, prederef, and JIT data
+ */
+#if 0
+ pt_clone_code(d, s);
+#endif
+ /*
+ * set flags and run core
+ */
+ d->run_core = s->run_core;
+ d->flags = s->flags;
+}
+
/*
* copied from parrotio.pmc - this ought to be a global
* helper function
@@ -201,36 +229,10 @@ pmclass ParrotInterpreter need_ext {
*
* XXX this should of course call Parrot_clone() and use freeze/thaw
*/
- void clone(PMC* dest) {
- Parrot_Interp s = PMC_data(SELF);
- Parrot_Interp d;
-
- /*
- * clone may be called internally (from thread creation in
- * ParrotThread::init_pmc() or stand-alone
- * so we check, if the interpreter is already setup
- */
- if (!PMC_data(dest))
- VTABLE_init_pmc(s, dest, SELF);
- d = PMC_data(dest);
-
- /*
- * copy register files
- */
- clone_regs(d, s, dest);
- /*
- * copy over packfile - done currently in the runinterp opcode
- * for multi-threading we have to generate separate
- * profile, prederef, and JIT data
- */
-#if 0
- pt_clone_code(d, s);
-#endif
- /*
- * set flags and run core
- */
- d->run_core = s->run_core;
- d->flags = s->flags;
+ PMC* clone() {
+ PMC* dest = pmc_new(INTERP, SELF->vtable->base_type);
+ clone_interpreter(dest, SELF);
+ return dest;
}
}
View
@@ -88,13 +88,14 @@ pmclass ParrotIO need_ext {
}
}
- void clone (PMC *dest) {
- VTABLE_init(INTERP, dest);
+ PMC* clone () {
+ PMC* dest = pmc_new(INTERP, SELF->vtable->base_type);
/* For now both PMCs refer to the same ParrotIO object.
* If we have different IO layers, we might copy these structures
*/
PMC_data(dest) = PMC_data(SELF);
dest->cache.struct_val = SELF->cache.struct_val;
+ return dest;
}
INTVAL get_bool() {
View
@@ -39,13 +39,13 @@ pmclass ParrotLibrary need_ext does library const_too {
SUPER(type);
}
- void clone(PMC* dest) {
- dest->cache.struct_val = SELF->cache.struct_val;
- PMC_data(dest) = PMC_data(SELF);
- if (SELF->metadata) {
- dest->metadata = pmc_new_noinit(INTERP,
- SELF->metadata->vtable->base_type);
- VTABLE_clone(INTERP, SELF->metadata, dest->metadata);
- }
+ PMC* clone() {
+ PMC* dest = pmc_new_noinit(INTERP, SELF->vtable->base_type);
+ dest->cache.struct_val = SELF->cache.struct_val;
+ PMC_data(dest) = PMC_data(SELF);
+ if (SELF->metadata) {
+ dest->metadata = VTABLE_clone(INTERP, SELF->metadata);
+ }
+ return dest;
}
}
View
@@ -28,6 +28,7 @@
#include "parrot/embed.h"
#include <assert.h>
+void clone_interpreter(PMC* dest, PMC* self);
pmclass ParrotThread extends ParrotInterpreter need_ext {
@@ -51,7 +52,7 @@ pmclass ParrotThread extends ParrotInterpreter need_ext {
UNLOCK(interpreter_array_mutex);
parent = VTABLE_get_pmc_keyed_int(interpreter, interpreter->iglobals,
IGLOBALS_INTERPRETER);
- VTABLE_clone(INTERP, parent, SELF);
+ clone_interpreter(SELF, parent);
}
/*
@@ -62,7 +63,7 @@ pmclass ParrotThread extends ParrotInterpreter need_ext {
SUPER(parent);
pt_add_to_interpreters(PMC_data(parent), PMC_data(SELF));
UNLOCK(interpreter_array_mutex);
- VTABLE_clone(INTERP, parent, SELF);
+ clone_interpreter(SELF, parent);
}
}
View
@@ -74,9 +74,11 @@ pmclass PerlHash need_ext does hash {
return VTABLE_type_keyed(INTERP, valpmc, nextkey);
}
- void clone (PMC *ret) {
- PObj_custom_mark_SET(ret);
- hash_clone(INTERP, (Hash *)PMC_ptr1v(SELF), (Hash**)&PMC_ptr1v(ret));
+ PMC* clone () {
+ PMC* dest = pmc_new_noinit(INTERP, SELF->vtable->base_type);
+ PObj_custom_mark_SET(dest);
+ hash_clone(INTERP, (Hash *)PMC_ptr1v(SELF), (Hash**)&PMC_ptr1v(dest));
+ return dest;
}
INTVAL get_integer () {
View
@@ -26,9 +26,11 @@ pmclass PerlString extends perlscalar {
pobject_lives(INTERP, (PObj *)SELF->cache.string_val);
}
- void clone (PMC *dest) {
+ PMC* clone () {
+ PMC* dest = pmc_new_noinit(INTERP, SELF->vtable->base_type);
PObj_custom_mark_SET(dest);
dest->cache.string_val = string_copy(INTERP,SELF->cache.string_val);
+ return dest;
}
INTVAL get_integer () {
View
@@ -32,9 +32,11 @@ pmclass Pointer need_ext {
(*mark_function)(INTERP, PMC_data(SELF));
}
- void clone (PMC *dest) {
+ PMC* clone () {
+ PMC* dest = pmc_new_noinit(INTERP, SELF->vtable->base_type);
PObj_custom_mark_SET(dest);
PMC_data(dest) = PMC_data(SELF);
+ return dest;
}
INTVAL get_integer () {
@@ -24,12 +24,14 @@ pmclass RetContinuation extends Continuation {
PObj_custom_mark_destroy_SETALL(SELF);
}
- void clone(PMC *ret) {
+ PMC* clone() {
struct Parrot_Sub * sub;
+ PMC* ret = pmc_new_noinit(INTERP, SELF->vtable->base_type);
sub = PMC_sub(ret) = mem_sys_allocate(sizeof(struct Parrot_Sub));
memcpy(sub, PMC_sub(SELF), sizeof(struct Parrot_Sub));
ret->cache.struct_val = SELF->cache.struct_val;
PObj_custom_mark_destroy_SETALL(ret);
+ return ret;
}
}
View
@@ -170,14 +170,14 @@ pmclass SArray const_too need_ext does array {
PMC_data(SELF) = NULL;
}
- void clone (PMC *dest) {
+ PMC* clone () {
HashEntry *e, *d;
int i, start, end;
INTVAL size;
- PMC * np;
+ PMC * dest = pmc_new(INTERP, SELF->vtable->base_type);
if (!PMC_data(SELF))
- return;
+ return dest;
size = SELF->cache.int_val;
dest->cache.int_val = size;
PMC_data(dest) = mem_sys_allocate_zeroed((2 + size) *
@@ -203,16 +203,14 @@ pmclass SArray const_too need_ext does array {
d->val.string_val = string_copy(INTERP, e->val.string_val);
break;
case enum_hash_pmc:
- np = pmc_new_noinit(interpreter,
- e->val.pmc_val->vtable->base_type);
- d->val.pmc_val = np;
- VTABLE_clone(INTERP, e->val.pmc_val, np);
+ d->val.pmc_val = VTABLE_clone(INTERP, e->val.pmc_val);
break;
default:
break;
}
}
PObj_custom_mark_destroy_SETALL(dest);
+ return dest;
}
INTVAL get_bool () {
Oops, something went wrong.

0 comments on commit d7d307c

Please sign in to comment.