Author: infinoid
Date: Sat Jul 19 14:29:17 2008
New Revision: 29613
Modified:
branches/pdd13pbc/src/pmc/packfile.pmc
branches/pdd13pbc/t/pmc/packfile.t
Log:
[PDD13]
* Fix get_string() to be more correct.
* Add a set_integer_keyed() wrapper around set_integer_keyed_str().
* Add a test for set_integer_keyed_str.
Modified: branches/pdd13pbc/src/pmc/packfile.pmc
==============================================================================
--- branches/pdd13pbc/src/pmc/packfile.pmc (original)
+++ branches/pdd13pbc/src/pmc/packfile.pmc Sat Jul 19 14:29:17 2008
@@ -64,11 +64,16 @@
*/
VTABLE STRING *get_string() {
PackFile *pf = PMC_data_typed(SELF, PackFile *);
- STRING *str = new_string_header(interp, 0);
opcode_t length = PackFile_pack_size(interp, pf) * sizeof(opcode_t);
- Parrot_allocate_string(interp, str, length);
- PackFile_pack(interp, pf, (opcode_t*)str->strstart);
- str->bufused = str->strlen = length;
+ char *ptr = mem_sys_allocate(length);
+ PackFile_pack(interp, pf, ptr);
+ /* FIXME: PARROT_BINARY_CHARSET seems like a better choice, but the
+ * comparison function for the binary charset plugin always returns
+ * "equal", which means tests fail.
+ */
+ STRING *str = string_make_direct(interp, ptr, length,
+ PARROT_FIXED_8_ENCODING, PARROT_DEFAULT_CHARSET, 0);
+ mem_sys_free(ptr);
return str;
}
@@ -256,6 +261,23 @@
Parrot_string_cstring(interp, key));
}
+
+/*
+
+=item C<void set_integer_keyed(PMC *key, INTVALval)>
+
+Set a keyed integer value in the packfile object. Dispatches to
+set_integer_keyed_str.
+
+=cut
+
+*/
+ VTABLE void set_integer_keyed(PMC *key, INTVAL val) {
+ STRING * const s = VTABLE_get_string(INTERP, key);
+ SELF.set_integer_keyed_str(s, val);
+ }
+
+
/*
=item C<PMC *get_directory()>
Modified: branches/pdd13pbc/t/pmc/packfile.t
==============================================================================
--- branches/pdd13pbc/t/pmc/packfile.t (original)
+++ branches/pdd13pbc/t/pmc/packfile.t Sat Jul 19 14:29:17 2008
@@ -6,7 +6,7 @@
use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More;
-use Parrot::Test tests => 4;
+use Parrot::Test tests => 5;
=head1 NAME
@@ -40,7 +40,7 @@
# get_integer_keyed_str
pir_output_is( <<'CODE', <<'OUT', 'get_integer_keyed_str' );
-.sub main :main
+.sub 'test' :main
$P0 = new 'Packfile'
$S0 = 'version_major'
$I0 = $P0[$S0]
@@ -66,7 +66,9 @@
# get_string gives us back what set_string_native got
-
+# FIXME: this doesn't actually return the same data. Same size, but the
+# strings differ. Figure out why... for now we're just comparing the
+# buffer sizes.
pir_output_is( <<'CODE', <<'OUT', 'set_string_native -> get_string' );
.sub 'test' :main
.include "stat.pasm"
@@ -85,10 +87,40 @@
eq $I0, $I1, OUT
print "not "
OUT:
- say "ok"
+ say "equal"
+.end
+CODE
+equal
+OUT
+
+
+# set_integer_keyed_str
+
+pir_output_is( <<'CODE', <<'OUT', 'set_integer_keyed_str' );
+.sub 'test' :main
+ .include "stat.pasm"
+ .include "interpinfo.pasm"
+ $S0 = interpinfo .INTERPINFO_RUNTIME_PREFIX
+ $S0 .= "/runtime/parrot/library/uuid.pbc"
+ $I0 = stat $S0, .STAT_FILESIZE
+ $P0 = open $S0, "<"
+ $S0 = read $P0, $I0
+ close $P0
+ $P0 = new 'Packfile'
+ $P0 = $S0
+ $S0 = $P0
+ $S1 = 'version_major'
+ $I0 = $P0[$S1]
+ inc $I0
+ $P0[$S1] = $I0
+ $S2 = $P0
+ eq $S0, $S2, OUT
+ print "not "
+ OUT:
+ say "equal"
.end
CODE
-ok
+not equal
OUT