I have a data structure that I'm managing via some Inline::C code; this
structure keeps pointers into strings handed to it, and marks the strings
as readonly; furthermore, so as not to duplicate space I require that a
reference to the string is passed in (this get's used when the strings are
very, very large, so Perl's parameter copying get's in the way).

my $widget = new Widget \$string;

in so doing, $string is now readonly.

I have another function "add" to add new strings to the dataset:

$widget->add(\$newstring);

So far so good.  But in this loop:

while(<>) {
  my $str = $_;
  $widget->add(\$str);
}

I get "attempt to modify readonly value" at the end of the scope.  Here's
the relevant part of my "add" code:

static void _add_string(Widget *widget, SV *string) {

  char *sptr;
  int n;

  if (!SvROK(string)) {
    croak("Argument not a reference!");
  }

  string = SvRV(string);
  if (!SvPOK(string)) {
    croak("Argument not a reference to a string!");
  }

  sptr = SvPV(string, n);

  /* do stuff with sptr and widget */

  /* don't let anyone change it out from under us! */
  SvREADONLY_on(string);
}

So, what do I need to do special to handle the my variables within a loop?
I'm guessing I need to increment the refcount on the scalar, but I'm not
sure.

Thanks,

-Aaron

-- 
 Aaron J Mackey
 Pearson Laboratory
 University of Virginia
 (434) 924-2821
 [EMAIL PROTECTED]


Reply via email to