Re: Help with PHP Extension

[email protected] (Ciaran Moore)
Newsgroups php.general
Message-ID <CAGdnuQTCCLMN2bxCmVdtmB3umn1mzruKSTg4dW9eEbFdD8CpRw@mail.gmail.com>
Hello Christoph,

You were absolutely correct! Thank you so much!

It looks like I misinterpreted the `static zval*` return type on
current data to actually require a return of a zval from the function.
After checking how it was done in `com_dotnet/com_iterator.c` and
initialising in the `php_sparsehashmap_iterator` with a zval for data,
and assigning the data to that rather than an in-scope variable, it
worked like a dream :)

Again, thank you for your help with this. Happy to finally see this
working after months of trying :)

Regards,

Ciaran Moore

On Sat, Sep 10, 2022 at 6:12 PM Christoph M. Becker <[email protected]> wrote:
>
> On 10.09.2022 at 18:04, Ciaran Moore wrote:
>
> > I'm not sure where else to turn with this. It says something about a
> > problem when you post a question on StackOverflow and it gets zero
> > responses in over a week.
> >
> > I have been learning extension development, and have managed to build
> > the extension to do what I want and how I want it, until I try to
> > implement the Iterator. I don't know what it is about the data being
> > returned but I keep getting segmentation faults on the return *zval
> > for current data.
> >
> > This is a link to the StackOverflow question I posted which goes into
> > more detail about what is happening when the SIGSEGV is thrown.
> >
> > https://stackoverflow.com/questions/73542769/segmentation-fault-zval-str-when-accessing-current-data-in-iterator
> >
> > This also includes a link to a Github Repo I created to give a full
> > view of the extension and not rely on just posting snippets here and
> > there on the post.
> >
> > Any help or guidance with this would be greatly appreciated.
>
> The problem is that `data` points to uninitialized memory.  You need to
> actually have a `zval` somewhere, which is usually in the
> `php_sparsehashmap_iterator_t` structure.  See, for instance, how that
> is done in ext/com_dotnet/com_iterator.c.  The `zdata` member is set on
> initialization and whenever the iterator is moved, and then simply
> returned on `get_current_data()`.
>
> --
> Christoph M. Becker
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.