INIT_CLASS_ENTRY and char*

From: Date: Tue, 09 May 2006 04:58:43 +0000
Subject: INIT_CLASS_ENTRY and char*
Groups: php.internals 
Request: Send a blank email to internals+get-23207@lists.php.net to get a copy of this message
I think I found a bug in the INIT_OVERLOADED_CLASS_ENTRY_EX macro. At least, I think its a bug, somebody else might think its a feature. :) If you do something like INIT_CLASS_ENTRY(ce, "MyClass", ...) everything works fine. However, if you have something like void register_class(char* name, ...) { ... INIT_CLASS_ENTRY(ce, name, ...); ... } things don't work so well. When I run this through gdb and break right after the macro, ce.name = "MyClass" as expected. But ce.name_length = 3, which is not quite right. It looks to me like the problem is in the 3rd line of the INIT_OVERLOADED_CLASS_ENTRY_EX macro... --- #define INIT_OVERLOADED_CLASS_ENTRY_EX(class_container, class_name, functions, handle_fcall, handle_propget, handle_propset, handle_propunset, handle_propisset) \ { \ class_container.name = strdup(class_name); \ class_container.name_length = sizeof(class_name) - 1; \ --- ...where sizeof() is used instead of strlen(). When class_name is a variable, sizeof() dutifully returns the size of the variable instead of the string length. Obviously this works, and provides a bit of a speed boost, when using literal strings, but it doesn't work so well for char*'s. Is this desired behavior or a bug?

« previous php.internals (#23207) next »