Re: newbie question nr 2: compile error when using php_stream_get_line
| From: | Arnold Daniels | Date: | Sat, 11 Nov 2006 00:05:43 +0000 |
| Subject: | Re: newbie question nr 2: compile error when using php_stream_get_line | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-26505@lists.php.net to get a copy of this message | ||
Hi again,
I thought that this might not be interesting enough for the list. But I'll be sure CC it in the future.
Thanks for your help, the extension now builds. It doesn't run however. I crashes on PHP_STREAM_TO_ZVAL(stream, in). But I'm sure I'm able to fix that problem myself.
Thanks again and best regards,
Arnold
Johannes Schlüter schreef:
Hi Arnold, fist of all: Please use "Reply to all" and the lists in future. This way you might get a faster/better answer or additional input, but since I'm in a good mood currently I'll answer you this way, too. To your question: As you already found out your problem is the php_stream_get_line() thingy. So let's see where this comes from and what it looks like: php_streams.h:326 #define php_stream_get_line(stream, buf, maxlen, retlen) _php_stream_get_line((stream), IS_STRING, buf, (maxlen), 0, (retlen) TSRMLS_CC) So it's a macro which expands to a call of the _php_stream_get_line() function and that's where TSRMLS_CC comes into play. As you read in Sara's article this get's expanded to tsrm_ls as an additional parameter. Since that parameter is passed to the function we need to get it in declared inside the function. There are two possible ways to fix this: - Add TSRMLS_DC to your function's declaration and TSRMLS_CC to the calls. This is preferred but might not always work (thinking about callbacks used by other libraries) - Add TSRMLS_FETCH(); after the last local variable declaration. This macro does some magic to provide the tsrm_ls but costs some additional performance. Hope it helped and yes it's bad that there is no real online documentation, johannes On Fri, 2006-11-10 at 23:47 +0100, Arnold Daniels wrote:Hi, First of all thanks the link. It explains what tsrm is quite clearly. Unfortunately I don't seem to be able to understand it well enough to see the context this error. What I understand is (please correct me where I'm wrong) - option --enable-maintainer-zts is only for testing purposes to see if the extension is thread-safe - I need to include "TSRM.h" in thread-safe mode (#ifdef ZTS) - I need to include some other (unkown) file where tsrm_ls is defined and the macro's are defined when not in thread-safe mode. I don't understand what kind the php_stream_get_line function expects. Do I need to define a locale storage in PHP_MINIT_FUNCTION which is used by the function or perhaps I need to include ext/standard/file.h? I'm looking at it for several hours now and I'm starting to feel really stupid. I'm hoping you are willing to have a look at my source code and tell me what and why. I understand that you guys at PHP have better thing to do than answering newbie questions, though I hope you'll help me still. I've attached the source-code of the extension. I'm programming with MySQL and PHP for about 3 years (since the first beta of PHP5) and I'm trying to take it to another level. My first open source project ware MySQL UDF's to output XML directly from an SQL query (http://libmysqlbnxml.sourceforge.net). I indeed tent do write more PHP extensions and I'll be sure to buy to book you recommended. Thanks for all you help. Best regards, Arnold Johannes Schlüter schreef:errors complaining about something related to tsrm_ls mean that you're building a thread-safe PHP and forgot some TSRMLS[_...] macros. See for example http://blog.libssh2.org/index.php?/archives/22-What-the-heck-is-TSRMLS_CC-anyway.html for more about these macros. This should help you, but the book from Sara, mentioned in that article, is really worth buying (and being read) if you tend to do some more PHP extending stuff. johannes On Fri, 2006-11-10 at 21:03 +0100, Arnold Daniels wrote:Hi,I've got another newbie question. My .ini parser now works correctly when parsing a string (thanks to help of Matt Wilmas). With the same function I want to be able to parse content of a stream. I looked at fgets to see how to read a line from a stream. Unfortunately when I call php_stream_get_line. I get the following error: /root/php-5.1.6/ext/qconf/qconf_common.c: In function `qconf_readline_stream': /root/php-5.1.6/ext/qconf/qconf_common.c:42: error: `tsrm_ls' undeclared (first use in this function) /root/php-5.1.6/ext/qconf/qconf_common.c:42: error: (Each undeclared identifier is reported only once /root/php-5.1.6/ext/qconf/qconf_common.c:42: error: for each function it appears in.) make: *** [qconf_common.lo] Error 1 Googling the error returns lot's of websites, be I couldn't make out a real solution. This is the function: /** * Read a line out of a stream. */ char *qconf_readline_stream(zval *in, char **c) {Hi,char *line; php_stream *stream; size_t line_len = 0;PHP_STREAM_TO_ZVAL(stream, in); line = php_stream_get_line(stream, NULL, 0, &line_len); if (line != NULL) *(line + line_len) = (char)0; /* make the line into a null terminated string to use string functions link sscan */return line;} Thanks a lot, Arnold