2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
gbx_object.c
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2018-02-12 02:53:46 +01:00
|
|
|
(c) 2000-2017 Benoît Minisini <g4mba5@gmail.com>
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#define __OBJECT_C
|
|
|
|
|
|
|
|
#include "gb_common.h"
|
|
|
|
#include "gb_alloc.h"
|
|
|
|
#include "gb_list.h"
|
|
|
|
#include "gbx_class.h"
|
|
|
|
#include "gbx_event.h"
|
|
|
|
#include "gbx_exec.h"
|
|
|
|
#include "gbx_compare.h"
|
2010-12-21 15:05:42 +01:00
|
|
|
#include "gbx_c_observer.h"
|
2010-05-27 00:01:28 +02:00
|
|
|
#include "gbx_c_array.h"
|
2010-05-25 13:19:00 +02:00
|
|
|
#include "gbx_struct.h"
|
2007-12-30 17:41:49 +01:00
|
|
|
#include "gbx_object.h"
|
|
|
|
|
2009-06-16 02:17:25 +02:00
|
|
|
#if DEBUG_REF
|
|
|
|
const char *OBJECT_ref_where = 0;
|
|
|
|
#endif
|
|
|
|
|
2010-12-24 13:20:11 +01:00
|
|
|
void **OBJECT_set_pointer = NULL;
|
|
|
|
|
2015-04-19 15:43:33 +02:00
|
|
|
static OBJECT *_event_object_list = NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-03-30 14:51:10 +01:00
|
|
|
#if DEBUG_REF
|
|
|
|
char *OBJECT_where_am_i(const char *file, int line, const char *func)
|
|
|
|
{
|
|
|
|
static char buffer[256];
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2013-03-30 14:51:10 +01:00
|
|
|
snprintf(buffer, sizeof(buffer), "[%s] %s:%d", file, func, line);
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
void *OBJECT_new(CLASS *class, const char *name, OBJECT *parent)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-06-09 01:08:04 +02:00
|
|
|
OBJECT *object;
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2013-03-30 00:33:01 +01:00
|
|
|
ALLOC_ZERO(&object, class->size);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
object->class = class;
|
2009-06-16 02:17:25 +02:00
|
|
|
#if DEBUG_REF
|
|
|
|
object->ref = 0;
|
2013-03-30 14:51:10 +01:00
|
|
|
OBJECT_REF(object);
|
2009-06-16 02:17:25 +02:00
|
|
|
#else
|
2010-12-21 15:05:42 +01:00
|
|
|
object->ref = 1;
|
2009-06-16 02:17:25 +02:00
|
|
|
#endif
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
class->count++;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
OBJECT_attach(object, parent, name);
|
2010-06-09 01:08:04 +02:00
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
return object;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2010-06-09 01:08:04 +02:00
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
#if 0
|
|
|
|
static void dump_attach(char *title)
|
|
|
|
{
|
|
|
|
void *ob;
|
|
|
|
|
|
|
|
fprintf(stderr, ">>>> %s: ", title);
|
2015-04-19 15:43:33 +02:00
|
|
|
for (ob = _event_object_list; ob; ob = OBJECT_event(ob)->next)
|
2007-12-30 17:41:49 +01:00
|
|
|
fprintf(stderr, "%p -> ", ob);
|
|
|
|
fprintf(stderr, "(nil)\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
static void call_attach_special_method(CLASS *class, void *ob, void *parent, const char *name)
|
|
|
|
{
|
|
|
|
STACK_check(2);
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
SP->_object.class = OBJECT_class(parent);
|
|
|
|
SP->_object.object = parent;
|
|
|
|
PUSH();
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
SP->type = T_CSTRING;
|
|
|
|
SP->_string.addr = (char *)name;
|
|
|
|
SP->_string.start = 0;
|
|
|
|
SP->_string.len = strlen(name);
|
|
|
|
}
|
|
|
|
else
|
2018-08-22 09:30:27 +02:00
|
|
|
VALUE_null(SP);
|
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
SP++;
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
EXEC_special(SPEC_ATTACH, class, ob, 2, TRUE);
|
|
|
|
}
|
|
|
|
|
2015-04-19 15:43:33 +02:00
|
|
|
static void insert_object(OBJECT *ob, OBJECT_EVENT *ev)
|
|
|
|
{
|
|
|
|
ev->next = _event_object_list;
|
|
|
|
ev->prev = NULL;
|
|
|
|
|
|
|
|
if (_event_object_list)
|
|
|
|
OBJECT_event(_event_object_list)->prev = ob;
|
|
|
|
|
|
|
|
_event_object_list = ob;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void remove_object(OBJECT *ob, OBJECT_EVENT *ev)
|
|
|
|
{
|
|
|
|
if (ev->prev)
|
|
|
|
OBJECT_event(ev->prev)->next = ev->next;
|
|
|
|
|
|
|
|
if (ev->next)
|
|
|
|
OBJECT_event(ev->next)->prev = ev->prev;
|
|
|
|
|
|
|
|
if (ob == _event_object_list)
|
|
|
|
_event_object_list = ev->next;
|
|
|
|
|
|
|
|
ev->prev = NULL;
|
|
|
|
ev->next = NULL;
|
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void OBJECT_detach(OBJECT *ob)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-21 15:05:42 +01:00
|
|
|
CLASS *class = OBJECT_class(ob);
|
|
|
|
OBJECT *parent;
|
|
|
|
OBJECT_EVENT *ev;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
if (!class->is_observer && class->n_event == 0)
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
ev = (OBJECT_EVENT *)((char *)ob + class->off_event);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
//if (!ev->parent)
|
|
|
|
// return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
// Do not free the observers there
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2015-04-19 15:43:33 +02:00
|
|
|
remove_object(ob, ev);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
//dump_attach("OBJECT_detach");
|
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
/* Avoids an infinite recursion, if freeing the parent implies freeing the object */
|
2015-05-15 15:17:18 +02:00
|
|
|
parent = ev->parent;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
if (parent)
|
|
|
|
{
|
2015-05-15 15:17:18 +02:00
|
|
|
ev->parent = NULL;
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2009-07-12 23:49:13 +02:00
|
|
|
if (class->special[SPEC_ATTACH] != NO_SYMBOL)
|
2010-12-21 15:05:42 +01:00
|
|
|
call_attach_special_method(class, ob, parent, NULL);
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
#if DEBUG_EVENT || DEBUG_REF
|
|
|
|
fprintf(stderr, "OBJECT_detach : Detach (%s %p) from (%s %p)\n",
|
|
|
|
ob->class->name, ob, parent->class->name, parent);
|
|
|
|
#endif
|
2013-03-30 14:51:10 +01:00
|
|
|
OBJECT_UNREF(parent);
|
2015-12-30 19:11:01 +01:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-02-14 12:59:36 +01:00
|
|
|
static void remove_observers(OBJECT *ob)
|
|
|
|
{
|
|
|
|
CLASS *class = OBJECT_class(ob);
|
2010-12-21 15:05:42 +01:00
|
|
|
OBJECT_EVENT *ev;
|
|
|
|
COBSERVER *obs, *next;
|
2008-02-14 12:59:36 +01:00
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
//fprintf(stderr, "Remove observers: %s %p\n", class->name, ob);
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
if (!class->is_observer && class->n_event == 0)
|
|
|
|
return;
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
ev = (OBJECT_EVENT *)((char *)ob + class->off_event);
|
|
|
|
obs = ev->observer;
|
|
|
|
ev->observer = NULL;
|
|
|
|
|
|
|
|
while (obs)
|
|
|
|
{
|
|
|
|
next = obs->list.next;
|
|
|
|
#if DEBUG_EVENT
|
2013-03-02 03:11:17 +01:00
|
|
|
fprintf(stderr, "Remove observer %p %d: %p: %p\n", obs, (int)obs->ob.ref, ob, obs->object);
|
2010-12-21 15:05:42 +01:00
|
|
|
#endif
|
2013-03-30 14:51:10 +01:00
|
|
|
OBJECT_UNREF(obs);
|
2015-12-30 19:11:01 +01:00
|
|
|
obs = next;
|
2008-02-14 12:59:36 +01:00
|
|
|
}
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
//ev->observer = NULL;
|
2008-02-14 12:59:36 +01:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void OBJECT_attach(OBJECT *ob, OBJECT *parent, const char *name)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-21 15:05:42 +01:00
|
|
|
CLASS *class = OBJECT_class(ob);
|
|
|
|
OBJECT_EVENT *ev;
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
if (!name)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!class->is_observer && class->n_event == 0)
|
2007-12-30 17:41:49 +01:00
|
|
|
return;
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
OBJECT_detach(ob);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
ev = (OBJECT_EVENT *)((char *)ob + class->off_event);
|
|
|
|
ev->parent = parent;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
#if DEBUG_EVENT || DEBUG_REF
|
|
|
|
fprintf(stderr, "OBJECT_attach : Attach (%s %p) to (%s %p) as %s\n",
|
|
|
|
ob->class->name, ob, parent->class->name, parent, name);
|
|
|
|
#endif
|
2015-04-19 15:43:33 +02:00
|
|
|
|
2013-03-30 14:51:10 +01:00
|
|
|
OBJECT_REF(parent);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
EVENT_search(class, ev->event, name, parent);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2015-04-19 15:43:33 +02:00
|
|
|
insert_object(ob, ev);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-07-12 23:49:13 +02:00
|
|
|
if (class->special[SPEC_ATTACH] != NO_SYMBOL)
|
2010-12-21 15:05:42 +01:00
|
|
|
call_attach_special_method(class, ob, parent, name);
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
//dump_attach("OBJECT_attach");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
bool OBJECT_comp_value(VALUE *ob1, VALUE *ob2)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-21 15:05:42 +01:00
|
|
|
if (ob1->type == T_NULL && ob2->type == T_NULL)
|
|
|
|
return FALSE;
|
|
|
|
else if (ob1->type == T_NULL)
|
|
|
|
return ob2->_object.object != NULL;
|
|
|
|
else if (ob2->type == T_NULL)
|
|
|
|
return ob1->_object.object != NULL;
|
|
|
|
else
|
|
|
|
return COMPARE_object(&ob1->_object.object, &ob2->_object.object);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2010-07-08 00:06:05 +02:00
|
|
|
void OBJECT_release_static(CLASS *class, CLASS_VAR *var, int nelt, char *data)
|
2010-05-27 00:01:28 +02:00
|
|
|
{
|
2010-06-09 01:08:04 +02:00
|
|
|
static void *jump[17] = {
|
|
|
|
&&__NEXT, &&__NEXT, &&__NEXT, &&__NEXT, &&__NEXT, &&__NEXT, &&__NEXT, &&__NEXT, &&__NEXT,
|
|
|
|
&&__STRING, &&__NEXT, &&__NEXT, &&__VARIANT, &&__ARRAY, &&__STRUCT, &&__NEXT, &&__OBJECT
|
|
|
|
};
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2010-06-09 01:08:04 +02:00
|
|
|
CTYPE type;
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2010-06-09 01:08:04 +02:00
|
|
|
while (nelt--)
|
|
|
|
{
|
2010-05-27 00:01:28 +02:00
|
|
|
#if TRACE_MEMORY
|
2010-06-09 01:08:04 +02:00
|
|
|
if (var->type.id == T_STRING || var->type.id == T_OBJECT)
|
|
|
|
fprintf(stderr, "release_static: %s [%d] trying %p\n", class->name, i, (*(void **)&data[var->pos]));
|
2010-05-27 00:01:28 +02:00
|
|
|
#endif
|
|
|
|
|
2010-06-09 01:08:04 +02:00
|
|
|
type = var->type;
|
|
|
|
goto *jump[type.id];
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2010-06-09 01:08:04 +02:00
|
|
|
__STRING:
|
|
|
|
STRING_unref((char **)&data[var->pos]);
|
|
|
|
goto __NEXT;
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2010-06-09 01:08:04 +02:00
|
|
|
__OBJECT:
|
2013-03-30 14:51:10 +01:00
|
|
|
OBJECT_UNREF(*((void **)&data[var->pos]));
|
2010-06-09 01:08:04 +02:00
|
|
|
goto __NEXT;
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2010-06-09 01:08:04 +02:00
|
|
|
__VARIANT:
|
|
|
|
VARIANT_free((VARIANT *)&data[var->pos]);
|
|
|
|
goto __NEXT;
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2010-06-09 01:08:04 +02:00
|
|
|
__ARRAY:
|
2010-07-08 00:06:05 +02:00
|
|
|
CARRAY_release_static(class, class->load->array[type.value], &data[var->pos]);
|
2010-06-09 01:08:04 +02:00
|
|
|
goto __NEXT;
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2010-06-09 01:08:04 +02:00
|
|
|
__STRUCT:
|
2010-05-27 00:01:28 +02:00
|
|
|
{
|
2010-06-09 01:08:04 +02:00
|
|
|
CLASS *sclass = class->load->class_ref[type.value];
|
2010-07-08 00:06:05 +02:00
|
|
|
OBJECT_release_static(sclass, sclass->load->dyn, sclass->load->n_dyn, &data[var->pos]);
|
2010-05-27 00:01:28 +02:00
|
|
|
}
|
|
|
|
|
2010-06-09 01:08:04 +02:00
|
|
|
__NEXT:
|
|
|
|
var++;
|
|
|
|
}
|
2010-05-27 00:01:28 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
static void release(CLASS *class, OBJECT *ob)
|
|
|
|
{
|
2010-12-21 15:05:42 +01:00
|
|
|
CLASS_VAR *var;
|
|
|
|
int nelt;
|
|
|
|
char *data;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
if (class->parent != NULL && ob)
|
|
|
|
release(class->parent, ob);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
if (CLASS_is_native(class))
|
|
|
|
return;
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
if (ob == NULL)
|
|
|
|
{
|
|
|
|
var = class->load->stat;
|
|
|
|
nelt = class->load->n_stat;
|
|
|
|
data = class->stat;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-26 21:30:58 +01:00
|
|
|
if (CLASS_is_struct(class))
|
2010-05-27 00:01:28 +02:00
|
|
|
{
|
2010-11-26 21:30:58 +01:00
|
|
|
if (((CSTRUCT *)ob)->ref)
|
|
|
|
{
|
|
|
|
CSTRUCT_release((CSTRUCT *)ob);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
data = (char *)ob + sizeof(CSTRUCT);
|
2010-05-27 00:01:28 +02:00
|
|
|
}
|
2010-11-26 21:30:58 +01:00
|
|
|
else
|
|
|
|
data = (char *)ob;
|
2010-05-25 13:19:00 +02:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
var = class->load->dyn;
|
|
|
|
nelt = class->load->n_dyn;
|
|
|
|
}
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
OBJECT_release_static(class, var, nelt, data);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void OBJECT_release(CLASS *class, OBJECT *ob)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
#if TRACE_MEMORY
|
2010-12-21 15:05:42 +01:00
|
|
|
printf("> OBJECT_release %s %p\n", class->name, ob);
|
2007-12-30 17:41:49 +01:00
|
|
|
#endif
|
|
|
|
|
2015-05-15 15:17:18 +02:00
|
|
|
if (ob)
|
|
|
|
{
|
|
|
|
ob->ref = 1; // Prevents anybody from freeing the object!
|
|
|
|
OBJECT_detach(ob);
|
|
|
|
remove_observers(ob);
|
|
|
|
ob->ref = 0;
|
|
|
|
}
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
release(class, ob);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
if (ob)
|
2015-05-15 15:17:18 +02:00
|
|
|
{
|
|
|
|
class->count--;
|
|
|
|
|
|
|
|
#if DEBUG_REF
|
|
|
|
ob->class = FREE_MARK;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
IFREE(ob);
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
#if TRACE_MEMORY
|
2010-12-21 15:05:42 +01:00
|
|
|
printf("< OBJECT_release %s %p\n", class->name, ob);
|
2007-12-30 17:41:49 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void OBJECT_exit(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
#if DEBUG_LOAD
|
|
|
|
fprintf(stderr, "------------ OBJECT_exit - BEGIN---------\n");
|
|
|
|
#endif
|
2015-04-19 15:43:33 +02:00
|
|
|
while (_event_object_list)
|
|
|
|
OBJECT_detach(_event_object_list);
|
2007-12-30 17:41:49 +01:00
|
|
|
#if DEBUG_LOAD
|
|
|
|
fprintf(stderr, "------------ OBJECT_exit - END ----------\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-09-28 01:20:35 +02:00
|
|
|
static void error_OBJECT_create(const char *name, void *object)
|
2010-06-18 02:14:53 +02:00
|
|
|
{
|
2017-09-28 01:20:35 +02:00
|
|
|
OBJECT_UNREF_KEEP(object);
|
|
|
|
EVENT_leave_name(name);
|
2010-06-18 02:14:53 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
void *OBJECT_create(CLASS *class, const char *name, void *parent, int nparam)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2015-12-30 19:11:01 +01:00
|
|
|
void *object;
|
2017-10-05 23:18:19 +02:00
|
|
|
const char *save;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
[CONFIGURATION]
* NEW: Qt 4.5.0 is now required to compile the gb.qt4 components.
[INTERPRETER]
* NEW: You can now define a non-creatable but auto-creatable class. It
means that you cannot instanciate the class, but you can use it
statically.
[GB.GTK]
* NEW: Screens is a new pseudo-array of all screens.
* NEW: Screen is a new class that represents the geometry of a screen. The
X, Y, Width and Height properties return the full geometry. The
AvailableX, AvailableY, AvailableWidth and AvailableHeight properties
return the geometry available to the windows. The screen class can be
used statically to get the geometry of the default screen.
BEWARE: The available geometry is not yet implemented on gb.gtk!
* NEW: Window.Screen is a new property that returns the screen where most
of the window is located.
* NEW: Desktop.{X,Y,Width,Height} are four new properties that return the
available geometry of the default screen. It is an equivalent of
Screen.{AvailableX,AvailableY,AvailableWidth,AvailableHeight}.
[GB.QT4]
* NEW: Screens is a new pseudo-array of all screens.
* NEW: Screen is a new class that represents the geometry of a screen. The
X, Y, Width and Height properties return the full geometry. The
AvailableX, AvailableY, AvailableWidth and AvailableHeight properties
return the geometry available to the windows. The screen class can be
used statically to get the geometry of the default screen.
* NEW: Window.Screen is a new property that returns the screen where most
of the window is located.
* NEW: Desktop.{X,Y,Width,Height} are four new properties that return the
available geometry of the default screen. It is an equivalent of
Screen.{AvailableX,AvailableY,AvailableWidth,AvailableHeight}.
git-svn-id: svn://localhost/gambas/trunk@3413 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2010-12-30 02:52:40 +01:00
|
|
|
// The "no create" flag only concerns users of NEW
|
|
|
|
//if (class->no_create)
|
2012-10-19 23:00:35 +02:00
|
|
|
// THROW(E_CSTATIC, CLASS_get_name(class));
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2017-10-05 23:18:19 +02:00
|
|
|
ON_ERROR_2(error_OBJECT_create, save = EVENT_enter_name(name), object = OBJECT_new(class, name, parent))
|
2010-12-21 15:05:42 +01:00
|
|
|
{
|
2010-12-24 13:20:11 +01:00
|
|
|
if (OBJECT_set_pointer)
|
|
|
|
{
|
2015-12-30 19:11:01 +01:00
|
|
|
*OBJECT_set_pointer = object;
|
|
|
|
OBJECT_ref(object);
|
2010-12-24 13:20:11 +01:00
|
|
|
OBJECT_set_pointer = NULL;
|
|
|
|
}
|
2015-12-30 19:11:01 +01:00
|
|
|
|
|
|
|
OBJECT_lock(object, TRUE);
|
|
|
|
EXEC_special_inheritance(SPEC_NEW, class, object, nparam, TRUE);
|
|
|
|
OBJECT_lock(object, FALSE);
|
|
|
|
|
|
|
|
EXEC_special(SPEC_READY, class, object, 0, TRUE);
|
|
|
|
|
2017-10-05 23:18:19 +02:00
|
|
|
error_OBJECT_create(save, object);
|
2010-12-21 15:05:42 +01:00
|
|
|
}
|
|
|
|
END_ERROR
|
2015-12-30 19:11:01 +01:00
|
|
|
|
|
|
|
return object;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-19 15:01:57 +02:00
|
|
|
/* FIXME: The _new methods are called differently from EXEC_special_inheritance */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
void *OBJECT_create_native(CLASS *class, VALUE *param)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-21 15:05:42 +01:00
|
|
|
CLASS_DESC *desc;
|
|
|
|
short index;
|
2010-06-18 02:14:53 +02:00
|
|
|
void *object;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
object = OBJECT_new(class, NULL, NULL);
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
index = class->special[SPEC_NEW];
|
|
|
|
if (index != NO_SYMBOL)
|
|
|
|
{
|
|
|
|
desc = CLASS_get_desc(class, index);
|
|
|
|
EXEC_call_native(desc->method.exec, object, desc->method.type, param);
|
|
|
|
}
|
|
|
|
class = class->parent;
|
|
|
|
if (!class)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-12-30 19:11:01 +01:00
|
|
|
EXEC_special(SPEC_READY, OBJECT_class(object), object, 0, TRUE);
|
2013-03-30 14:51:10 +01:00
|
|
|
OBJECT_UNREF_KEEP(object);
|
2010-06-18 02:14:53 +02:00
|
|
|
return object;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2015-04-19 15:43:33 +02:00
|
|
|
void OBJECT_lock(OBJECT *object, bool lock)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-21 15:05:42 +01:00
|
|
|
CLASS *class;
|
2015-04-19 15:43:33 +02:00
|
|
|
OBJECT_EVENT *ev;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
if (!object)
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
class = object->class;
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2009-02-17 02:51:25 +01:00
|
|
|
if (class->is_observer)
|
|
|
|
{
|
2015-04-19 15:43:33 +02:00
|
|
|
COBSERVER_lock((COBSERVER *)object, lock);
|
2009-02-17 02:51:25 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
if (class->n_event == 0)
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2015-04-19 15:43:33 +02:00
|
|
|
ev = (OBJECT_EVENT *)((char *)object + class->off_event);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2015-04-19 15:43:33 +02:00
|
|
|
if (lock)
|
|
|
|
ev->locked++;
|
2010-12-21 15:05:42 +01:00
|
|
|
else
|
2015-04-19 15:43:33 +02:00
|
|
|
ev->locked--;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
bool OBJECT_is_locked(OBJECT *object)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-12-21 15:05:42 +01:00
|
|
|
CLASS *class;
|
2009-02-17 02:51:25 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
if (!object)
|
|
|
|
return FALSE;
|
2009-02-17 02:51:25 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
class = object->class;
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2009-02-17 02:51:25 +01:00
|
|
|
if (class->is_observer)
|
|
|
|
return COBSERVER_is_locked((COBSERVER *)object);
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
if (class->n_event == 0)
|
|
|
|
return FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2015-04-19 15:43:33 +02:00
|
|
|
return OBJECT_event(object)->locked > 0;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
OBJECT *OBJECT_parent(void *object)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-05-27 00:01:28 +02:00
|
|
|
CLASS *class = OBJECT_class(object);
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2010-05-27 00:01:28 +02:00
|
|
|
if (!class->is_observer && class->n_event == 0)
|
|
|
|
return NULL;
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2015-04-19 15:43:33 +02:00
|
|
|
//return ((OBJECT *)((intptr_t)OBJECT_event(object)->parent & ~1));
|
|
|
|
return OBJECT_event(object)->parent;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
OBJECT *OBJECT_active_parent(void *object)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
OBJECT *parent = OBJECT_parent(object);
|
2015-12-30 19:11:01 +01:00
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
if (!parent || OBJECT_is_locked((OBJECT *)object) || OBJECT_is_locked(parent))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return parent;
|
|
|
|
}
|