Stas Bekman <[EMAIL PROTECTED]> writes:

[...]

> > I still don't see how that's useful here.  There's nothing wrong with the
> > data inside apr_table.  It's the c2perl
> > translation (newSVpv) that's causing the lossage.
> 
> and I don't get where the lossage is :(

OK- I see we're having a disconnect.  Let me try to draw a picture
of an apr_table_entry_t that's coming from an apreq-2 parser:

               ATTRIBUTE            STORAGE (BYTES) 
table_entry:    key -------------------+
                                       |
                                       v  
                                     | f | o | o | \0

                val -------------------+
                                       |
                                       |
                                       v
             | 12345 |   0   |   8   | b | a | r | \0 | n | o | n | e | \0
               ^         ^       ^     ^
               |         |       |     |
             name     status   size  data


Notice that val points to the end of an apreq_value_t struct; what's
important here is that the location of the metadata (ie. the rest of
the apreq_value_t struct) is directly in front of *val.

So what happens when newSVpv copies *val?  It ignores the metadata,
so we wind up with unusable (segfaultable) garbage in front of SvPVX:

SvPVX(sv)  ----------------------------+
                                       |
                                       |
                                       v
      *** apreq_value_t is lost ***  | b | a | r | \0 
                                                      ^^^^^^^^^^^^^^^^^^
                                                   rest of string is missing


The original metadata isn't lost, it's just inaccessible through the
APR::Table API.  But by adding magic to the SV, so that mg->mg_ptr
points at the original C-string pointed at by the apr_table_entry_t's
val pointer, the full metadata can be recovered (via the conversion
macros in apreq.h, e.g. apreq_strtoval()), including the remainder
of the string that newSVpv lopped off.

[...]

> That's cool. But Joe, you don't seem to understand what I'm asking you
> about. I want to see an example of a conversion function where this
> meta data kicks in. 

I don't know if I've said enough to answer your question, but
I hope I've explained the problem with newSVpv well enough.
Short of coding up an entire APR::Table subclass, can you be
more specific about what you'd like to see?

> I don't seem to get into your head to see things the same way you do.

Dreadfully laconic, I know.  Sorry about that.  
My thesis advisor used to say the same thing :-/.

-- 
Joe Schaefer


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to