cvs: embed /php-irssi Makefile.am ext-irssi.c genobjdefs.php php-irssi-obj.c php-irssi.h typemap.php win-item.c
[email protected] ("Wez Furlong") Sun, 02 Feb 2003 01:33:46 -0000
| Newsgroups | php.embed.cvs |
|---|---|
| Message-ID | <cvswez1044149626@cvsserver> |
--wez1044149626
Content-Type: text/plain
wez Sat Feb 1 20:33:46 2003 EDT
Added files:
/embed/php-irssi win-item.c
Modified files:
/embed/php-irssi Makefile.am ext-irssi.c genobjdefs.php
php-irssi-obj.c php-irssi.h typemap.php
Log:
Implement primitve inheritance for WI_ITEM based "descendants".
--wez1044149626
Content-Type: text/plain
Content-Disposition: attachment; filename="wez-20030201203346.txt"
Index: embed/php-irssi/Makefile.am
diff -u embed/php-irssi/Makefile.am:1.3 embed/php-irssi/Makefile.am:1.4
--- embed/php-irssi/Makefile.am:1.3 Thu Jan 30 04:04:35 2003
+++ embed/php-irssi/Makefile.am Sat Feb 1 20:33:45 2003
@@ -18,10 +18,10 @@
$(LIBPHP_CFLAGS)
libphp_core_la_SOURCES = \
- php-core.c ext-irssi.c php-irssi-obj.c server.c channel.c nick.c
+ php-core.c ext-irssi.c php-irssi-obj.c server.c channel.c nick.c win-item.c
-php-core.c: php-signals-list.h
-php-irssi-obj.c: php-irssi-obj-defs.h
+
+$(libphp_core_la_SOURCES): php-signals-list.h php-irssi-obj-defs.h
php-irssi-obj-defs.h: $(srcdir)/genobjdefs.php $(srcdir)/typemap.php
$(LIBPHP_PREFIX)/bin/php $(srcdir)/genobjdefs.php "$(top_srcdir)" > php-irssi-obj-defs.h
Index: embed/php-irssi/ext-irssi.c
diff -u embed/php-irssi/ext-irssi.c:1.7 embed/php-irssi/ext-irssi.c:1.8
--- embed/php-irssi/ext-irssi.c:1.7 Sat Feb 1 08:51:34 2003
+++ embed/php-irssi/ext-irssi.c Sat Feb 1 20:33:45 2003
@@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
| Author: Wez Furlong <[email protected]> |
+----------------------------------------------------------------------+
- $Id: ext-irssi.c,v 1.7 2003/02/01 13:51:34 wez Exp $
+ $Id: ext-irssi.c,v 1.8 2003/02/02 01:33:45 wez Exp $
*/
#include "php-irssi.h"
#include "php-signals-list.h" /* generated by php during make */
@@ -165,8 +165,20 @@
func_name = rec->handler;
for (i = 0; i < sigargs->argc; i++) {
+ int type = sigargs->argtypes[i];
MAKE_STD_ZVAL(val);
+
+ /* runtime "inheritance" check */
+ if (type == PIAT_WI_ITEM) {
+ if (IS_SERVER((void*)args[i])) {
+ type = PIAT_SERVER;
+ } else if (IS_CHANNEL((void*)args[i])) {
+ type = PIAT_CHANNEL;
+ } else if (IS_NICK((void*)args[i])) {
+ type = PIAT_NICK;
+ }
+ }
switch(sigargs->argtypes[i]) {
case PIAT_STRING:
Index: embed/php-irssi/genobjdefs.php
diff -u embed/php-irssi/genobjdefs.php:1.4 embed/php-irssi/genobjdefs.php:1.5
--- embed/php-irssi/genobjdefs.php:1.4 Thu Jan 30 10:42:47 2003
+++ embed/php-irssi/genobjdefs.php Sat Feb 1 20:33:46 2003
@@ -15,7 +15,7 @@
+----------------------------------------------------------------------+
| Author: Wez Furlong <[email protected]> |
+----------------------------------------------------------------------+
- $Id: genobjdefs.php,v 1.4 2003/01/30 15:42:47 wez Exp $
+ $Id: genobjdefs.php,v 1.5 2003/02/02 01:33:46 wez Exp $
*/
/* We build three sets of tables:
@@ -33,6 +33,7 @@
foreach ($objects_to_scan as $filename => $data)
{
list($iclass, $pclass) = $data;
+ $obj_bind[] = $data;
$obj_props = array();
$obj_methods = array();
@@ -89,8 +90,7 @@
printf("{ NULL, 0, 0, 0 }\n};\n\n");
printf("#endif /* PHP_IRSSI_PROTOS_ONLY */\n");
- $obj_bind[] = array($iclass, $pclass);
- $label = preg_replace('/_.*/', '', $iclass);
+ $label = preg_replace('/_[^_]+$/U', '', $iclass);
printf("#define PHP_IRSSI_%s_PROP_READER_HEAD() \\\n" .
"\t%s *%s = (%s*)obj;\\\n" .
@@ -110,7 +110,7 @@
foreach ($obj_bind as $data) {
list($iclass, $pclass) = $data;
- $label = preg_replace('/_.*/', '', $iclass);
+ $label = preg_replace('/_[^_]+$/U', '', $iclass);
printf("void *php_irssi_resolve_to_%s(struct php_irssi_obj_ref *ref);\n", $iclass);
printf("extern function_entry php_irssi_%s_funcs[];\n", $label);
@@ -121,13 +121,19 @@
printf("#ifndef PHP_IRSSI_PROTOS_ONLY\n");
printf("\nstatic struct php_irssi_obj_bind php_irssi_object_bindings[] = {\n");
foreach ($obj_bind as $data) {
- list($iclass, $pclass) = $data;
- $label = preg_replace('/_.*/', '', $iclass);
- printf("{ \"%s\", 0, php_irssi_%s_props, php_irssi_resolve_to_%s, \"%s\", php_irssi_%s_funcs,\n" .
- "\tphp_irssi_%s_prop_reader, NULL, NULL },\n",
- $label, $iclass, $iclass, $pclass, $label, $iclass);
+ list($iclass, $pclass, $iflags) = $data;
+ $label = preg_replace('/_[^_]+$/U', '', $iclass);
+ if (is_array($iflags))
+ $iflags = implode("|", $iflags);
+ else
+ $iflags = "0";
+
+ printf("{ PIAT_%s, \"%s\", 0, php_irssi_%s_props, php_irssi_resolve_to_%s, \"%s\", php_irssi_%s_funcs,\n" .
+ "\t%s, php_irssi_%s_prop_reader, NULL, NULL },\n",
+ $label,
+ $label, $iclass, $iclass, $pclass, $label, $iflags, $iclass);
}
-printf("{ NULL, 0, NULL }\n};\n\n");
+printf("{ 0, NULL, 0, NULL }\n};\n\n");
printf("#endif /* PHP_IRSSI_PROTOS_ONLY */\n");
Index: embed/php-irssi/php-irssi-obj.c
diff -u embed/php-irssi/php-irssi-obj.c:1.3 embed/php-irssi/php-irssi-obj.c:1.4
--- embed/php-irssi/php-irssi-obj.c:1.3 Thu Jan 30 10:42:47 2003
+++ embed/php-irssi/php-irssi-obj.c Sat Feb 1 20:33:46 2003
@@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
| Author: Wez Furlong <[email protected]> |
+----------------------------------------------------------------------+
- $Id: php-irssi-obj.c,v 1.3 2003/01/30 15:42:47 wez Exp $
+ $Id: php-irssi-obj.c,v 1.4 2003/02/02 01:33:46 wez Exp $
*/
#include "php-irssi.h"
#include "php-irssi-obj-defs.h"
@@ -237,6 +237,7 @@
for (i = 0; php_irssi_object_bindings[i].bindname != NULL; i++) {
if (php_irssi_object_bindings[i].bindtype == objid) {
(*ref)->binding = &php_irssi_object_bindings[i];
+ (*ref)->actual_type = php_irssi_object_bindings[i].piat_type;
}
}
@@ -292,9 +293,14 @@
zend_hash_update(bind->hprops, (char*)props->propname, props->propnamelen + 1, (void**)&props, sizeof(props), NULL);
}
}
- if (bind->functable) {
+ if (bind->functable || bind->inheritance_flags) {
ALLOC_HASHTABLE(bind->hfuncs);
zend_hash_init(bind->hfuncs, 0, NULL, NULL, 0);
+
+ if (bind->inheritance_flags & PHP_IRSSI_INH_WI_ITEM) {
+ zend_register_functions(&php_irssi_ce, php_irssi_WI_ITEM_funcs, bind->hfuncs, MODULE_PERSISTENT TSRMLS_CC);
+
+ }
zend_register_functions(&php_irssi_ce, bind->functable, bind->hfuncs, MODULE_PERSISTENT TSRMLS_CC);
}
Index: embed/php-irssi/php-irssi.h
diff -u embed/php-irssi/php-irssi.h:1.4 embed/php-irssi/php-irssi.h:1.5
--- embed/php-irssi/php-irssi.h:1.4 Fri Jan 31 12:59:25 2003
+++ embed/php-irssi/php-irssi.h Sat Feb 1 20:33:46 2003
@@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
| Author: Wez Furlong <[email protected]> |
+----------------------------------------------------------------------+
- $Id: php-irssi.h,v 1.4 2003/01/31 17:59:25 tal Exp $
+ $Id: php-irssi.h,v 1.5 2003/02/02 01:33:46 wez Exp $
*/
#define MODULE_NAME "php/core"
@@ -48,6 +48,7 @@
PIAT_NICK,
PIAT_ARRAY_OF_STRING,
PIAT_BOOL,
+ PIAT_WI_ITEM,
};
struct php_irssi_signal_args {
@@ -70,13 +71,17 @@
struct php_irssi_obj_ref;
+#define PHP_IRSSI_INH_WI_ITEM 1
+
struct php_irssi_obj_bind {
+ int piat_type;
const char *bindname;
int bindtype; /* module_get_uniq_id(bindname, 0) -> resolved at runtime */
struct php_irssi_class_props *proptable;
void *(*resolve)(struct php_irssi_obj_ref *ref);
const char *classname; /* name of PHP class */
function_entry *functable;
+ int inheritance_flags;
int (*readprop)(char *member, int type, zval **retval, void *obj TSRMLS_DC);
@@ -97,6 +102,7 @@
struct php_irssi_obj_ref {
struct php_irssi_obj_bind *binding;
char *idents[PHP_IRSSI_MAX_IDENTS];
+ int actual_type; /* PIAT_XXX; used mostly for WI_ITEM */
};
#include "php-irssi-obj.h"
@@ -105,8 +111,12 @@
SERVER_REC *map_server(zval *object TSRMLS_DC);
CHANNEL_REC *map_channel(zval *object TSRMLS_DC);
+WI_ITEM_REC *map_wi_item(zval *object TSRMLS_DC);
NICK_REC *map_nick(zval *object, CHANNEL_REC **channel TSRMLS_DC);
#define SV_FETCH() SERVER_REC *server = map_server(getThis() TSRMLS_CC); if (server == NULL) RETURN_NULL();
#define CH_FETCH() CHANNEL_REC *channel = map_channel(getThis() TSRMLS_CC); if (channel == NULL) RETURN_NULL();
#define NK_FETCH() CHANNEL_REC *channel; NICK_REC *nick = map_nick(getThis(), &channel TSRMLS_CC); if (channel == NULL || nick == NULL) RETURN_NULL();
+
+#define WI_FETCH() WI_ITEM_REC *wi; map_wi_item(getThis() TSRMLS_CC); if (wi == NULL) RETURN_NULL();
+
Index: embed/php-irssi/typemap.php
diff -u embed/php-irssi/typemap.php:1.3 embed/php-irssi/typemap.php:1.4
--- embed/php-irssi/typemap.php:1.3 Thu Jan 30 10:42:47 2003
+++ embed/php-irssi/typemap.php Sat Feb 1 20:33:46 2003
@@ -15,16 +15,17 @@
+----------------------------------------------------------------------+
| Author: Wez Furlong <[email protected]> |
+----------------------------------------------------------------------+
- $Id: typemap.php,v 1.3 2003/01/30 15:42:47 wez Exp $
+ $Id: typemap.php,v 1.4 2003/02/02 01:33:46 wez Exp $
*/
/* This array describes the functions that can be used to convert between
* irssi and php/ze types */
$objects_to_scan = array(
- "src/core/server-rec.h" => array("SERVER_REC", "server"),
- "src/core/channel-rec.h" => array("CHANNEL_REC", "channel"),
- "src/core/nick-rec.h" => array("NICK_REC", "nick"),
+ "src/core/server-rec.h" => array("SERVER_REC", "server"),
+ "src/core/channel-rec.h" => array("CHANNEL_REC", "channel", array("PHP_IRSSI_INH_WI_ITEM")),
+ "src/core/nick-rec.h" => array("NICK_REC", "nick"),
+ "src/core/window-item-rec.h" => array("WI_ITEM_REC", "windowitem"),
);
$marshal = array(
@@ -42,7 +43,7 @@
/* fixup the marshal array to include supported objects */
foreach ($objects_to_scan as $data) {
list($rec, $name) = $data;
- $label = preg_replace('/_.*/', '', $rec);
+ $label = preg_replace('/_[^_]+$/U', '', $rec);
$marshal[$rec] = array("PIAT_$label", true);
}
Index: embed/php-irssi/win-item.c
+++ embed/php-irssi/win-item.c
/*
+----------------------------------------------------------------------+
| PHP for IRSSI |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2003 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 2.02 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available at through the world-wide-web at |
| http://www.php.net/license/2_02.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Wez Furlong <[email protected]> |
+----------------------------------------------------------------------+
$Id: win-item.c,v 1.1 2003/02/02 01:33:46 wez Exp $
*/
#include "php-irssi.h"
#define PHP_IRSSI_PROTOS_ONLY
#include "php-irssi-obj-defs.h"
/* ---------- Nick functions */
void *php_irssi_resolve_to_WI_ITEM_REC(struct php_irssi_obj_ref *ref)
{
/* somewhat tricky, since this is really an abstract base "class" */
switch(ref->actual_type) {
case PIAT_CHANNEL:
return php_irssi_resolve_to_CHANNEL_REC(ref TSRMLS_CC);
default:
return NULL;
}
return NULL;
}
void php_irssi_export_WI_ITEM(zval *obj, WI_ITEM_REC *wi TSRMLS_DC)
{
struct php_irssi_obj_ref *ref;
if (IS_SERVER(wi)) {
php_irssi_export_SERVER(obj, (SERVER_REC*)wi TSRMLS_CC);
return;
} else if (IS_CHANNEL(wi)) {
php_irssi_export_CHANNEL(obj, (CHANNEL_REC*)wi TSRMLS_CC);
return;
}
/* don't know really what it is, so export just the base wrapper */
php_irssi_create_wrapper(&ref, "WI_ITEM", obj TSRMLS_CC);
}
WI_ITEM_REC *map_wi_item(zval *object TSRMLS_DC)
{
struct php_irssi_obj_ref *ref = zend_object_store_get_object(object TSRMLS_CC);
if (ref == NULL) {
return NULL;
}
switch(ref->actual_type) {
case PIAT_CHANNEL:
return (WI_ITEM_REC*)map_channel(object TSRMLS_CC);
default:
return NULL;
}
}
/* Handle property reads */
int php_irssi_WI_ITEM_REC_prop_reader(char *member, int type, zval **retval, void *obj TSRMLS_DC)
{
PHP_IRSSI_WI_ITEM_REC_PROP_READER_HEAD();
PHP_IRSSI_WI_ITEM_REC_PROP_READER_FOOT();
}
/* Return TRUE if this item is the active window item in the window */
PHP_FUNCTION(window_item_is_active)
{
WI_FETCH();
if (ZEND_NUM_ARGS() != 0) {
WRONG_PARAM_COUNT;
}
RETURN_BOOL(window_item_is_active(wi));
}
function_entry php_irssi_WI_ITEM_funcs[] = {
PHP_NAMED_FE(is_active_item, PHP_FN(window_item_is_active), NULL)
NULL, NULL, NULL
};
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* indent-tabs-mode: t
* End:
*/
--wez1044149626--