[svn:parrot] r49148 - trunk/src/pmc
chromatic at svn.parrot.org
chromatic at svn.parrot.org
Sun Sep 19 04:14:44 UTC 2010
Author: chromatic
Date: Sun Sep 19 04:14:44 2010
New Revision: 49148
URL: https://trac.parrot.org/parrot/changeset/49148
Log:
[PMC] Fixed a segfault and optimized LexPad.
A VTABLE function documented to return a PMC * should always return PMCNULL
instead of NULL; get_pmc_keyed_str() is now safer. It's also slightly faster,
but you'll have trouble noticing in most benchmarks.
Modified:
trunk/src/pmc/lexpad.pmc
Modified: trunk/src/pmc/lexpad.pmc
==============================================================================
--- trunk/src/pmc/lexpad.pmc Sun Sep 19 03:57:38 2010 (r49147)
+++ trunk/src/pmc/lexpad.pmc Sun Sep 19 04:14:44 2010 (r49148)
@@ -1,5 +1,5 @@
/*
-Copyright (C) 2007-2009, Parrot Foundation.
+Copyright (C) 2007-2010, Parrot Foundation.
$Id$
=head1 NAME
@@ -97,10 +97,14 @@
}
VTABLE INTVAL exists_keyed_str(STRING *name) {
- PMC *info;
+ PMC *info;
+ Hash *hash;
GET_ATTR_lexinfo(INTERP, SELF, info);
- return parrot_hash_get_bucket(INTERP,
- (Hash *)VTABLE_get_pointer(INTERP, info), name) != 0;
+ hash = (Hash *)VTABLE_get_pointer(INTERP, info);
+
+ return hash->entries
+ ? (parrot_hash_get_bucket(INTERP, hash, name) != 0)
+ : 0;
}
VTABLE INTVAL exists_keyed(PMC *name) {
@@ -109,23 +113,24 @@
}
VTABLE PMC *get_pmc_keyed_str(STRING *name) {
- PMC * info;
- Hash * hash;
- PMC * ctx;
- HashBucket * b;
- INTVAL regno;
+ PMC *info;
+ Hash *hash;
+ PMC *ctx;
+ HashBucket *b;
GET_ATTR_lexinfo(INTERP, SELF, info);
- GET_ATTR_ctx(INTERP, SELF, ctx);
hash = (Hash *)VTABLE_get_pointer(INTERP, info);
- b = parrot_hash_get_bucket(INTERP, hash, name);
- if (!b)
- return NULL;
+ if (!hash->entries)
+ return PMCNULL;
- regno = (INTVAL) b->value;
+ b = parrot_hash_get_bucket(INTERP, hash, name);
+
+ if (!b)
+ return PMCNULL;
- return CTX_REG_PMC(ctx, regno);
+ GET_ATTR_ctx(INTERP, SELF, ctx);
+ return CTX_REG_PMC(ctx, (INTVAL)b->value);
}
VTABLE PMC *get_pmc_keyed(PMC *name) {
@@ -138,10 +143,8 @@
Hash * hash;
PMC * ctx;
HashBucket * b;
- INTVAL regno;
GET_ATTR_lexinfo(INTERP, SELF, info);
- GET_ATTR_ctx(INTERP, SELF, ctx);
hash = (Hash *)VTABLE_get_pointer(INTERP, info);
b = parrot_hash_get_bucket(INTERP, hash, name);
@@ -149,8 +152,8 @@
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_LEX_NOT_FOUND,
"Lexical '%Ss' not found", name);
- regno = (INTVAL) b->value;
- CTX_REG_PMC(ctx, regno) = value;
+ GET_ATTR_ctx(INTERP, SELF, ctx);
+ CTX_REG_PMC(ctx, (INTVAL)b->value) = value;
}
VTABLE void set_pmc_keyed(PMC *name, PMC *value) {
More information about the parrot-commits
mailing list