gambas-source-code/main/gbx/gbx_object.c

521 lines
10 KiB
C
Raw Normal View History

/***************************************************************************
gbx_object.c
(c) 2000-2012 Benoît Minisini <gambas@users.sourceforge.net>
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.
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.
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.
***************************************************************************/
#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"
#include "gbx_c_observer.h"
#include "gbx_c_array.h"
#include "gbx_struct.h"
#include "gbx_object.h"
#if DEBUG_REF
const char *OBJECT_ref_where = 0;
#endif
void **OBJECT_set_pointer = NULL;
static OBJECT *EventObject = NULL;
#if DEBUG_REF
char *OBJECT_where_am_i(const char *file, int line, const char *func)
{
static char buffer[256];
snprintf(buffer, sizeof(buffer), "[%s] %s:%d", file, func, line);
return buffer;
}
#endif
void *OBJECT_new(CLASS *class, const char *name, OBJECT *parent)
{
OBJECT *object;
ALLOC_ZERO(&object, class->size);
object->class = class;
#if DEBUG_REF
object->ref = 0;
OBJECT_REF(object);
#else
object->ref = 1;
#endif
class->count++;
OBJECT_attach(object, parent, name);
return object;
}
#if 0
static void dump_attach(char *title)
{
void *ob;
fprintf(stderr, ">>>> %s: ", title);
for (ob = EventObject; ob; ob = OBJECT_event(ob)->next)
fprintf(stderr, "%p -> ", ob);
fprintf(stderr, "(nil)\n");
}
#endif
static void call_attach_special_method(CLASS *class, void *ob, void *parent, const char *name)
{
STACK_check(2);
SP->_object.class = OBJECT_class(parent);
SP->_object.object = parent;
PUSH();
if (name)
{
SP->type = T_CSTRING;
SP->_string.addr = (char *)name;
SP->_string.start = 0;
SP->_string.len = strlen(name);
}
else
{
SP->type = T_NULL;
}
SP++;
EXEC_special(SPEC_ATTACH, class, ob, 2, TRUE);
}
******** Merged /branches/64bits r918:1003 into /trunk [CONFIGURATION] * NEW: 64 bits port. [EXAMPLES] * BUG: Fixed the AnalogWatch example. [WIKI CGI SCRIPT] * NEW: Some little cosmetic changes. [INTERPRETER] * NEW: The extern function implementation has been redesigned and is now based on libffi, so that it works on 64 bits system. Because of a flaw in the compiler design, projects that use the Pointer datatype must be recompiled to be used on a 64 bits system. This flaw will be fixed in Gambas 3. * OPT: Put some tables into read-only memory. About 1000 bytes are saved for each running interpreter, except the first one. * BUG: Does not crash anymore if a component cannot be loaded. * NEW: Spanish translation updated. * NEW: A new interpreter API for returning a pointer. [COMPILER] * BUG: Correctly compiles LONG constants inside code. [GB.DEBUG] * BUG: Compiles and links the gb.debug components with the thread libraries. [GB.DB.SQLITE3] * BUG: Getting the primary index of a table without primary index is safe now. [GB.GTK] * BUG: Modified the GLib priority of watched descriptors, as the main loop could enter in a loop in which user interface events were not managed. * BUG: Message boxes use application title without crashing now. [GB.OPENGL] * BUG: Disable dead code. [GB.QT.EXT] * BUG: TextEdit.TextWidth and TextEdit.TextHeight were not declared as read-only properties. [GB.XML.XSLT] * BUG: XSLT class is now declared as being not creatable. git-svn-id: svn://localhost/gambas/trunk@1006 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2008-01-17 22:39:26 +01:00
void OBJECT_detach(OBJECT *ob)
{
CLASS *class = OBJECT_class(ob);
OBJECT *parent;
OBJECT_EVENT *ev;
bool lock;
if (!class->is_observer && class->n_event == 0)
return;
ev = (OBJECT_EVENT *)((char *)ob + class->off_event);
//if (!ev->parent)
// return;
// Do not free the observers there
if (ev->prev)
OBJECT_event(ev->prev)->next = ev->next;
if (ev->next)
OBJECT_event(ev->next)->prev = ev->prev;
if (ob == EventObject)
EventObject = ev->next;
ev->prev = NULL;
ev->next = NULL;
//dump_attach("OBJECT_detach");
/* Avoids an infinite recursion, if freeing the parent implies freeing the object */
parent = OBJECT_parent(ob);
if (parent)
{
[DEVELOPMENT ENVIRONMENT] * NEW: Work continues on integrating the database manager. * NEW: Some cosmetic changes in the way controls are drawing on the form editor. * NEW: Panels with Border property set to None are now drawn with a light border. * BUG: Fix the "Show tab" button and menu. [INTERPRETER] * NEW: _attach is a new dynamic special method that is called when an object is attached to or detached from its event observer. The first argument of this method is the event observer, and the second argument the event handler prefix. [COMPILER] * NEW: An expression can be a NEW instruction now. Beware that it does not work inside braces. [GB.DB] * BUG: Fix an error message in the sqlite handler. [GB.DB.FORM] * NEW: DataSource.Table can now be any SQL query. The Filter property is ignored in that case. * BUG: Setting DataSource.Table to NULL correctly resets the DataSource and its children. * NEW: DataView automatically adjusts the height of its rows to the contents. * NEW: DataSource.CacheSize is a new property to set the number of rows stored in the internal DataSource cache. When this property is set to zero, the cache size takes its default value (64 rows). [GB.DB.SQLITE2] * BUG: Fix a crash in datatype mapping. [GB.DB.SQLITE3] * BUG: Fix a crash in datatype mapping. [GB.QT4] * BUG: Window.AutoResize property works as expected now. * OPT: Some optimizations in GridView. * NEW: GridView.Rows[].Visible returns if a specific row is visible. * NEW: GridView.Rows[].EnsureVisible ensures that a specific row is visible. * BUG: Draw.Style.Panel draws the same thing as a panel border now. * BUG: Window.Closed always returns the accurate value now. git-svn-id: svn://localhost/gambas/trunk@2108 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2009-07-12 23:49:13 +02:00
if (class->special[SPEC_ATTACH] != NO_SYMBOL)
call_attach_special_method(class, ob, parent, NULL);
[DEVELOPMENT ENVIRONMENT] * NEW: Work continues on integrating the database manager. * NEW: Some cosmetic changes in the way controls are drawing on the form editor. * NEW: Panels with Border property set to None are now drawn with a light border. * BUG: Fix the "Show tab" button and menu. [INTERPRETER] * NEW: _attach is a new dynamic special method that is called when an object is attached to or detached from its event observer. The first argument of this method is the event observer, and the second argument the event handler prefix. [COMPILER] * NEW: An expression can be a NEW instruction now. Beware that it does not work inside braces. [GB.DB] * BUG: Fix an error message in the sqlite handler. [GB.DB.FORM] * NEW: DataSource.Table can now be any SQL query. The Filter property is ignored in that case. * BUG: Setting DataSource.Table to NULL correctly resets the DataSource and its children. * NEW: DataView automatically adjusts the height of its rows to the contents. * NEW: DataSource.CacheSize is a new property to set the number of rows stored in the internal DataSource cache. When this property is set to zero, the cache size takes its default value (64 rows). [GB.DB.SQLITE2] * BUG: Fix a crash in datatype mapping. [GB.DB.SQLITE3] * BUG: Fix a crash in datatype mapping. [GB.QT4] * BUG: Window.AutoResize property works as expected now. * OPT: Some optimizations in GridView. * NEW: GridView.Rows[].Visible returns if a specific row is visible. * NEW: GridView.Rows[].EnsureVisible ensures that a specific row is visible. * BUG: Draw.Style.Panel draws the same thing as a panel border now. * BUG: Window.Closed always returns the accurate value now. git-svn-id: svn://localhost/gambas/trunk@2108 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2009-07-12 23:49:13 +02:00
lock = OBJECT_is_locked(ob);
ev->parent = NULL;
OBJECT_lock(ob, lock);
#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
OBJECT_UNREF(parent);
}
}
static void remove_observers(OBJECT *ob)
{
CLASS *class = OBJECT_class(ob);
OBJECT_EVENT *ev;
COBSERVER *obs, *next;
//fprintf(stderr, "Remove observers: %s %p\n", class->name, ob);
if (!class->is_observer && class->n_event == 0)
return;
ev = (OBJECT_EVENT *)((char *)ob + class->off_event);
obs = ev->observer;
ev->observer = NULL;
while (obs)
{
next = obs->list.next;
#if DEBUG_EVENT
fprintf(stderr, "Remove observer %p %d: %p: %p\n", obs, (int)obs->ob.ref, ob, obs->object);
#endif
OBJECT_UNREF(obs);
obs = next;
}
//ev->observer = NULL;
}
******** Merged /branches/64bits r918:1003 into /trunk [CONFIGURATION] * NEW: 64 bits port. [EXAMPLES] * BUG: Fixed the AnalogWatch example. [WIKI CGI SCRIPT] * NEW: Some little cosmetic changes. [INTERPRETER] * NEW: The extern function implementation has been redesigned and is now based on libffi, so that it works on 64 bits system. Because of a flaw in the compiler design, projects that use the Pointer datatype must be recompiled to be used on a 64 bits system. This flaw will be fixed in Gambas 3. * OPT: Put some tables into read-only memory. About 1000 bytes are saved for each running interpreter, except the first one. * BUG: Does not crash anymore if a component cannot be loaded. * NEW: Spanish translation updated. * NEW: A new interpreter API for returning a pointer. [COMPILER] * BUG: Correctly compiles LONG constants inside code. [GB.DEBUG] * BUG: Compiles and links the gb.debug components with the thread libraries. [GB.DB.SQLITE3] * BUG: Getting the primary index of a table without primary index is safe now. [GB.GTK] * BUG: Modified the GLib priority of watched descriptors, as the main loop could enter in a loop in which user interface events were not managed. * BUG: Message boxes use application title without crashing now. [GB.OPENGL] * BUG: Disable dead code. [GB.QT.EXT] * BUG: TextEdit.TextWidth and TextEdit.TextHeight were not declared as read-only properties. [GB.XML.XSLT] * BUG: XSLT class is now declared as being not creatable. git-svn-id: svn://localhost/gambas/trunk@1006 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2008-01-17 22:39:26 +01:00
void OBJECT_attach(OBJECT *ob, OBJECT *parent, const char *name)
{
CLASS *class = OBJECT_class(ob);
OBJECT_EVENT *ev;
bool lock;
if (!name)
return;
if (!class->is_observer && class->n_event == 0)
return;
lock = OBJECT_is_locked(ob);
OBJECT_detach(ob);
ev = (OBJECT_EVENT *)((char *)ob + class->off_event);
ev->parent = parent;
OBJECT_lock(ob, lock);
#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
OBJECT_REF(parent);
EVENT_search(class, ev->event, name, parent);
ev->next = EventObject;
ev->prev = NULL;
if (EventObject)
OBJECT_event(EventObject)->prev = ob;
EventObject = ob;
[DEVELOPMENT ENVIRONMENT] * NEW: Work continues on integrating the database manager. * NEW: Some cosmetic changes in the way controls are drawing on the form editor. * NEW: Panels with Border property set to None are now drawn with a light border. * BUG: Fix the "Show tab" button and menu. [INTERPRETER] * NEW: _attach is a new dynamic special method that is called when an object is attached to or detached from its event observer. The first argument of this method is the event observer, and the second argument the event handler prefix. [COMPILER] * NEW: An expression can be a NEW instruction now. Beware that it does not work inside braces. [GB.DB] * BUG: Fix an error message in the sqlite handler. [GB.DB.FORM] * NEW: DataSource.Table can now be any SQL query. The Filter property is ignored in that case. * BUG: Setting DataSource.Table to NULL correctly resets the DataSource and its children. * NEW: DataView automatically adjusts the height of its rows to the contents. * NEW: DataSource.CacheSize is a new property to set the number of rows stored in the internal DataSource cache. When this property is set to zero, the cache size takes its default value (64 rows). [GB.DB.SQLITE2] * BUG: Fix a crash in datatype mapping. [GB.DB.SQLITE3] * BUG: Fix a crash in datatype mapping. [GB.QT4] * BUG: Window.AutoResize property works as expected now. * OPT: Some optimizations in GridView. * NEW: GridView.Rows[].Visible returns if a specific row is visible. * NEW: GridView.Rows[].EnsureVisible ensures that a specific row is visible. * BUG: Draw.Style.Panel draws the same thing as a panel border now. * BUG: Window.Closed always returns the accurate value now. git-svn-id: svn://localhost/gambas/trunk@2108 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2009-07-12 23:49:13 +02:00
if (class->special[SPEC_ATTACH] != NO_SYMBOL)
call_attach_special_method(class, ob, parent, name);
[DEVELOPMENT ENVIRONMENT] * NEW: Work continues on integrating the database manager. * NEW: Some cosmetic changes in the way controls are drawing on the form editor. * NEW: Panels with Border property set to None are now drawn with a light border. * BUG: Fix the "Show tab" button and menu. [INTERPRETER] * NEW: _attach is a new dynamic special method that is called when an object is attached to or detached from its event observer. The first argument of this method is the event observer, and the second argument the event handler prefix. [COMPILER] * NEW: An expression can be a NEW instruction now. Beware that it does not work inside braces. [GB.DB] * BUG: Fix an error message in the sqlite handler. [GB.DB.FORM] * NEW: DataSource.Table can now be any SQL query. The Filter property is ignored in that case. * BUG: Setting DataSource.Table to NULL correctly resets the DataSource and its children. * NEW: DataView automatically adjusts the height of its rows to the contents. * NEW: DataSource.CacheSize is a new property to set the number of rows stored in the internal DataSource cache. When this property is set to zero, the cache size takes its default value (64 rows). [GB.DB.SQLITE2] * BUG: Fix a crash in datatype mapping. [GB.DB.SQLITE3] * BUG: Fix a crash in datatype mapping. [GB.QT4] * BUG: Window.AutoResize property works as expected now. * OPT: Some optimizations in GridView. * NEW: GridView.Rows[].Visible returns if a specific row is visible. * NEW: GridView.Rows[].EnsureVisible ensures that a specific row is visible. * BUG: Draw.Style.Panel draws the same thing as a panel border now. * BUG: Window.Closed always returns the accurate value now. git-svn-id: svn://localhost/gambas/trunk@2108 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2009-07-12 23:49:13 +02:00
//dump_attach("OBJECT_attach");
}
******** Merged /branches/64bits r918:1003 into /trunk [CONFIGURATION] * NEW: 64 bits port. [EXAMPLES] * BUG: Fixed the AnalogWatch example. [WIKI CGI SCRIPT] * NEW: Some little cosmetic changes. [INTERPRETER] * NEW: The extern function implementation has been redesigned and is now based on libffi, so that it works on 64 bits system. Because of a flaw in the compiler design, projects that use the Pointer datatype must be recompiled to be used on a 64 bits system. This flaw will be fixed in Gambas 3. * OPT: Put some tables into read-only memory. About 1000 bytes are saved for each running interpreter, except the first one. * BUG: Does not crash anymore if a component cannot be loaded. * NEW: Spanish translation updated. * NEW: A new interpreter API for returning a pointer. [COMPILER] * BUG: Correctly compiles LONG constants inside code. [GB.DEBUG] * BUG: Compiles and links the gb.debug components with the thread libraries. [GB.DB.SQLITE3] * BUG: Getting the primary index of a table without primary index is safe now. [GB.GTK] * BUG: Modified the GLib priority of watched descriptors, as the main loop could enter in a loop in which user interface events were not managed. * BUG: Message boxes use application title without crashing now. [GB.OPENGL] * BUG: Disable dead code. [GB.QT.EXT] * BUG: TextEdit.TextWidth and TextEdit.TextHeight were not declared as read-only properties. [GB.XML.XSLT] * BUG: XSLT class is now declared as being not creatable. git-svn-id: svn://localhost/gambas/trunk@1006 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2008-01-17 22:39:26 +01:00
void OBJECT_free(CLASS *class, OBJECT *ob)
{
OBJECT_detach(ob);
remove_observers(ob);
class->count--;
#if DEBUG_REF
ob->class = FREE_MARK;
#endif
FREE(&ob);
}
******** Merged /branches/64bits r918:1003 into /trunk [CONFIGURATION] * NEW: 64 bits port. [EXAMPLES] * BUG: Fixed the AnalogWatch example. [WIKI CGI SCRIPT] * NEW: Some little cosmetic changes. [INTERPRETER] * NEW: The extern function implementation has been redesigned and is now based on libffi, so that it works on 64 bits system. Because of a flaw in the compiler design, projects that use the Pointer datatype must be recompiled to be used on a 64 bits system. This flaw will be fixed in Gambas 3. * OPT: Put some tables into read-only memory. About 1000 bytes are saved for each running interpreter, except the first one. * BUG: Does not crash anymore if a component cannot be loaded. * NEW: Spanish translation updated. * NEW: A new interpreter API for returning a pointer. [COMPILER] * BUG: Correctly compiles LONG constants inside code. [GB.DEBUG] * BUG: Compiles and links the gb.debug components with the thread libraries. [GB.DB.SQLITE3] * BUG: Getting the primary index of a table without primary index is safe now. [GB.GTK] * BUG: Modified the GLib priority of watched descriptors, as the main loop could enter in a loop in which user interface events were not managed. * BUG: Message boxes use application title without crashing now. [GB.OPENGL] * BUG: Disable dead code. [GB.QT.EXT] * BUG: TextEdit.TextWidth and TextEdit.TextHeight were not declared as read-only properties. [GB.XML.XSLT] * BUG: XSLT class is now declared as being not creatable. git-svn-id: svn://localhost/gambas/trunk@1006 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2008-01-17 22:39:26 +01:00
bool OBJECT_comp_value(VALUE *ob1, VALUE *ob2)
{
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);
}
void OBJECT_release_static(CLASS *class, CLASS_VAR *var, int nelt, char *data)
{
static void *jump[17] = {
&&__NEXT, &&__NEXT, &&__NEXT, &&__NEXT, &&__NEXT, &&__NEXT, &&__NEXT, &&__NEXT, &&__NEXT,
&&__STRING, &&__NEXT, &&__NEXT, &&__VARIANT, &&__ARRAY, &&__STRUCT, &&__NEXT, &&__OBJECT
};
CTYPE type;
while (nelt--)
{
#if TRACE_MEMORY
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]));
#endif
type = var->type;
goto *jump[type.id];
__STRING:
STRING_unref((char **)&data[var->pos]);
goto __NEXT;
__OBJECT:
OBJECT_UNREF(*((void **)&data[var->pos]));
goto __NEXT;
__VARIANT:
VARIANT_free((VARIANT *)&data[var->pos]);
goto __NEXT;
__ARRAY:
CARRAY_release_static(class, class->load->array[type.value], &data[var->pos]);
goto __NEXT;
__STRUCT:
{
CLASS *sclass = class->load->class_ref[type.value];
OBJECT_release_static(sclass, sclass->load->dyn, sclass->load->n_dyn, &data[var->pos]);
}
__NEXT:
var++;
}
}
static void release(CLASS *class, OBJECT *ob)
{
CLASS_VAR *var;
int nelt;
char *data;
if (class->parent != NULL && ob)
release(class->parent, ob);
if (CLASS_is_native(class))
return;
if (ob == NULL)
{
var = class->load->stat;
nelt = class->load->n_stat;
data = class->stat;
}
else
{
if (CLASS_is_struct(class))
{
if (((CSTRUCT *)ob)->ref)
{
CSTRUCT_release((CSTRUCT *)ob);
return;
}
data = (char *)ob + sizeof(CSTRUCT);
}
else
data = (char *)ob;
var = class->load->dyn;
nelt = class->load->n_dyn;
}
OBJECT_release_static(class, var, nelt, data);
}
******** Merged /branches/64bits r918:1003 into /trunk [CONFIGURATION] * NEW: 64 bits port. [EXAMPLES] * BUG: Fixed the AnalogWatch example. [WIKI CGI SCRIPT] * NEW: Some little cosmetic changes. [INTERPRETER] * NEW: The extern function implementation has been redesigned and is now based on libffi, so that it works on 64 bits system. Because of a flaw in the compiler design, projects that use the Pointer datatype must be recompiled to be used on a 64 bits system. This flaw will be fixed in Gambas 3. * OPT: Put some tables into read-only memory. About 1000 bytes are saved for each running interpreter, except the first one. * BUG: Does not crash anymore if a component cannot be loaded. * NEW: Spanish translation updated. * NEW: A new interpreter API for returning a pointer. [COMPILER] * BUG: Correctly compiles LONG constants inside code. [GB.DEBUG] * BUG: Compiles and links the gb.debug components with the thread libraries. [GB.DB.SQLITE3] * BUG: Getting the primary index of a table without primary index is safe now. [GB.GTK] * BUG: Modified the GLib priority of watched descriptors, as the main loop could enter in a loop in which user interface events were not managed. * BUG: Message boxes use application title without crashing now. [GB.OPENGL] * BUG: Disable dead code. [GB.QT.EXT] * BUG: TextEdit.TextWidth and TextEdit.TextHeight were not declared as read-only properties. [GB.XML.XSLT] * BUG: XSLT class is now declared as being not creatable. git-svn-id: svn://localhost/gambas/trunk@1006 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2008-01-17 22:39:26 +01:00
void OBJECT_release(CLASS *class, OBJECT *ob)
{
#if TRACE_MEMORY
printf("> OBJECT_release %s %p\n", class->name, ob);
#endif
release(class, ob);
if (ob)
OBJECT_free(class, ob);
#if TRACE_MEMORY
printf("< OBJECT_release %s %p\n", class->name, ob);
#endif
}
******** Merged /branches/64bits r918:1003 into /trunk [CONFIGURATION] * NEW: 64 bits port. [EXAMPLES] * BUG: Fixed the AnalogWatch example. [WIKI CGI SCRIPT] * NEW: Some little cosmetic changes. [INTERPRETER] * NEW: The extern function implementation has been redesigned and is now based on libffi, so that it works on 64 bits system. Because of a flaw in the compiler design, projects that use the Pointer datatype must be recompiled to be used on a 64 bits system. This flaw will be fixed in Gambas 3. * OPT: Put some tables into read-only memory. About 1000 bytes are saved for each running interpreter, except the first one. * BUG: Does not crash anymore if a component cannot be loaded. * NEW: Spanish translation updated. * NEW: A new interpreter API for returning a pointer. [COMPILER] * BUG: Correctly compiles LONG constants inside code. [GB.DEBUG] * BUG: Compiles and links the gb.debug components with the thread libraries. [GB.DB.SQLITE3] * BUG: Getting the primary index of a table without primary index is safe now. [GB.GTK] * BUG: Modified the GLib priority of watched descriptors, as the main loop could enter in a loop in which user interface events were not managed. * BUG: Message boxes use application title without crashing now. [GB.OPENGL] * BUG: Disable dead code. [GB.QT.EXT] * BUG: TextEdit.TextWidth and TextEdit.TextHeight were not declared as read-only properties. [GB.XML.XSLT] * BUG: XSLT class is now declared as being not creatable. git-svn-id: svn://localhost/gambas/trunk@1006 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2008-01-17 22:39:26 +01:00
void OBJECT_exit(void)
{
#if DEBUG_LOAD
fprintf(stderr, "------------ OBJECT_exit - BEGIN---------\n");
#endif
while (EventObject)
OBJECT_detach(EventObject);
#if DEBUG_LOAD
fprintf(stderr, "------------ OBJECT_exit - END ----------\n");
#endif
}
static void *_object;
static char *_object_name;
static void error_OBJECT_create(void)
{
OBJECT_UNREF_KEEP(_object);
EVENT_leave_name(_object_name);
}
void *OBJECT_create(CLASS *class, const char *name, void *parent, int nparam)
{
void *ob;
void *save;
char *save_name;
[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)
// THROW(E_CSTATIC, CLASS_get_name(class));
save = _object;
save_name = _object_name;
ON_ERROR(error_OBJECT_create)
{
_object_name = EVENT_enter_name(name);
_object = ob = OBJECT_new(class, name, parent);
if (OBJECT_set_pointer)
{
*OBJECT_set_pointer = ob;
OBJECT_ref(ob);
OBJECT_set_pointer = NULL;
}
OBJECT_lock(ob, TRUE);
EXEC_special_inheritance(SPEC_NEW, class, ob, nparam, TRUE);
OBJECT_lock(ob, FALSE);
error_OBJECT_create();
}
END_ERROR
_object = save;
_object_name = save_name;
return ob;
}
/* FIXME: The _new methods are called differently from EXEC_special_inheritance */
void *OBJECT_create_native(CLASS *class, VALUE *param)
{
CLASS_DESC *desc;
short index;
void *object;
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;
}
OBJECT_UNREF_KEEP(object);
return object;
}
******** Merged /branches/64bits r918:1003 into /trunk [CONFIGURATION] * NEW: 64 bits port. [EXAMPLES] * BUG: Fixed the AnalogWatch example. [WIKI CGI SCRIPT] * NEW: Some little cosmetic changes. [INTERPRETER] * NEW: The extern function implementation has been redesigned and is now based on libffi, so that it works on 64 bits system. Because of a flaw in the compiler design, projects that use the Pointer datatype must be recompiled to be used on a 64 bits system. This flaw will be fixed in Gambas 3. * OPT: Put some tables into read-only memory. About 1000 bytes are saved for each running interpreter, except the first one. * BUG: Does not crash anymore if a component cannot be loaded. * NEW: Spanish translation updated. * NEW: A new interpreter API for returning a pointer. [COMPILER] * BUG: Correctly compiles LONG constants inside code. [GB.DEBUG] * BUG: Compiles and links the gb.debug components with the thread libraries. [GB.DB.SQLITE3] * BUG: Getting the primary index of a table without primary index is safe now. [GB.GTK] * BUG: Modified the GLib priority of watched descriptors, as the main loop could enter in a loop in which user interface events were not managed. * BUG: Message boxes use application title without crashing now. [GB.OPENGL] * BUG: Disable dead code. [GB.QT.EXT] * BUG: TextEdit.TextWidth and TextEdit.TextHeight were not declared as read-only properties. [GB.XML.XSLT] * BUG: XSLT class is now declared as being not creatable. git-svn-id: svn://localhost/gambas/trunk@1006 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2008-01-17 22:39:26 +01:00
void OBJECT_lock(OBJECT *object, bool block)
{
CLASS *class;
if (!object)
return;
class = object->class;
if (class->is_observer)
{
COBSERVER_lock((COBSERVER *)object, block);
return;
}
if (class->n_event == 0)
return;
// fprintf(stderr, "OBJECT_lock: (%s %p) %s\n", class->name, object, block ? "lock" : "unlock");
if (block)
OBJECT_event(object)->parent = (OBJECT *)((intptr_t)OBJECT_event(object)->parent | 1);
else
OBJECT_event(object)->parent = (OBJECT *)((intptr_t)OBJECT_event(object)->parent & ~1);
}
******** Merged /branches/64bits r918:1003 into /trunk [CONFIGURATION] * NEW: 64 bits port. [EXAMPLES] * BUG: Fixed the AnalogWatch example. [WIKI CGI SCRIPT] * NEW: Some little cosmetic changes. [INTERPRETER] * NEW: The extern function implementation has been redesigned and is now based on libffi, so that it works on 64 bits system. Because of a flaw in the compiler design, projects that use the Pointer datatype must be recompiled to be used on a 64 bits system. This flaw will be fixed in Gambas 3. * OPT: Put some tables into read-only memory. About 1000 bytes are saved for each running interpreter, except the first one. * BUG: Does not crash anymore if a component cannot be loaded. * NEW: Spanish translation updated. * NEW: A new interpreter API for returning a pointer. [COMPILER] * BUG: Correctly compiles LONG constants inside code. [GB.DEBUG] * BUG: Compiles and links the gb.debug components with the thread libraries. [GB.DB.SQLITE3] * BUG: Getting the primary index of a table without primary index is safe now. [GB.GTK] * BUG: Modified the GLib priority of watched descriptors, as the main loop could enter in a loop in which user interface events were not managed. * BUG: Message boxes use application title without crashing now. [GB.OPENGL] * BUG: Disable dead code. [GB.QT.EXT] * BUG: TextEdit.TextWidth and TextEdit.TextHeight were not declared as read-only properties. [GB.XML.XSLT] * BUG: XSLT class is now declared as being not creatable. git-svn-id: svn://localhost/gambas/trunk@1006 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2008-01-17 22:39:26 +01:00
bool OBJECT_is_locked(OBJECT *object)
{
CLASS *class;
if (!object)
return FALSE;
class = object->class;
if (class->is_observer)
return COBSERVER_is_locked((COBSERVER *)object);
if (class->n_event == 0)
return FALSE;
******** Merged /branches/64bits r918:1003 into /trunk [CONFIGURATION] * NEW: 64 bits port. [EXAMPLES] * BUG: Fixed the AnalogWatch example. [WIKI CGI SCRIPT] * NEW: Some little cosmetic changes. [INTERPRETER] * NEW: The extern function implementation has been redesigned and is now based on libffi, so that it works on 64 bits system. Because of a flaw in the compiler design, projects that use the Pointer datatype must be recompiled to be used on a 64 bits system. This flaw will be fixed in Gambas 3. * OPT: Put some tables into read-only memory. About 1000 bytes are saved for each running interpreter, except the first one. * BUG: Does not crash anymore if a component cannot be loaded. * NEW: Spanish translation updated. * NEW: A new interpreter API for returning a pointer. [COMPILER] * BUG: Correctly compiles LONG constants inside code. [GB.DEBUG] * BUG: Compiles and links the gb.debug components with the thread libraries. [GB.DB.SQLITE3] * BUG: Getting the primary index of a table without primary index is safe now. [GB.GTK] * BUG: Modified the GLib priority of watched descriptors, as the main loop could enter in a loop in which user interface events were not managed. * BUG: Message boxes use application title without crashing now. [GB.OPENGL] * BUG: Disable dead code. [GB.QT.EXT] * BUG: TextEdit.TextWidth and TextEdit.TextHeight were not declared as read-only properties. [GB.XML.XSLT] * BUG: XSLT class is now declared as being not creatable. git-svn-id: svn://localhost/gambas/trunk@1006 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2008-01-17 22:39:26 +01:00
return (((intptr_t)OBJECT_event(object)->parent & 1) != 0);
}
******** Merged /branches/64bits r918:1003 into /trunk [CONFIGURATION] * NEW: 64 bits port. [EXAMPLES] * BUG: Fixed the AnalogWatch example. [WIKI CGI SCRIPT] * NEW: Some little cosmetic changes. [INTERPRETER] * NEW: The extern function implementation has been redesigned and is now based on libffi, so that it works on 64 bits system. Because of a flaw in the compiler design, projects that use the Pointer datatype must be recompiled to be used on a 64 bits system. This flaw will be fixed in Gambas 3. * OPT: Put some tables into read-only memory. About 1000 bytes are saved for each running interpreter, except the first one. * BUG: Does not crash anymore if a component cannot be loaded. * NEW: Spanish translation updated. * NEW: A new interpreter API for returning a pointer. [COMPILER] * BUG: Correctly compiles LONG constants inside code. [GB.DEBUG] * BUG: Compiles and links the gb.debug components with the thread libraries. [GB.DB.SQLITE3] * BUG: Getting the primary index of a table without primary index is safe now. [GB.GTK] * BUG: Modified the GLib priority of watched descriptors, as the main loop could enter in a loop in which user interface events were not managed. * BUG: Message boxes use application title without crashing now. [GB.OPENGL] * BUG: Disable dead code. [GB.QT.EXT] * BUG: TextEdit.TextWidth and TextEdit.TextHeight were not declared as read-only properties. [GB.XML.XSLT] * BUG: XSLT class is now declared as being not creatable. git-svn-id: svn://localhost/gambas/trunk@1006 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2008-01-17 22:39:26 +01:00
OBJECT *OBJECT_parent(void *object)
{
CLASS *class = OBJECT_class(object);
if (!class->is_observer && class->n_event == 0)
return NULL;
return ((OBJECT *)((intptr_t)OBJECT_event(object)->parent & ~1));
}
******** Merged /branches/64bits r918:1003 into /trunk [CONFIGURATION] * NEW: 64 bits port. [EXAMPLES] * BUG: Fixed the AnalogWatch example. [WIKI CGI SCRIPT] * NEW: Some little cosmetic changes. [INTERPRETER] * NEW: The extern function implementation has been redesigned and is now based on libffi, so that it works on 64 bits system. Because of a flaw in the compiler design, projects that use the Pointer datatype must be recompiled to be used on a 64 bits system. This flaw will be fixed in Gambas 3. * OPT: Put some tables into read-only memory. About 1000 bytes are saved for each running interpreter, except the first one. * BUG: Does not crash anymore if a component cannot be loaded. * NEW: Spanish translation updated. * NEW: A new interpreter API for returning a pointer. [COMPILER] * BUG: Correctly compiles LONG constants inside code. [GB.DEBUG] * BUG: Compiles and links the gb.debug components with the thread libraries. [GB.DB.SQLITE3] * BUG: Getting the primary index of a table without primary index is safe now. [GB.GTK] * BUG: Modified the GLib priority of watched descriptors, as the main loop could enter in a loop in which user interface events were not managed. * BUG: Message boxes use application title without crashing now. [GB.OPENGL] * BUG: Disable dead code. [GB.QT.EXT] * BUG: TextEdit.TextWidth and TextEdit.TextHeight were not declared as read-only properties. [GB.XML.XSLT] * BUG: XSLT class is now declared as being not creatable. git-svn-id: svn://localhost/gambas/trunk@1006 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2008-01-17 22:39:26 +01:00
OBJECT *OBJECT_active_parent(void *object)
{
OBJECT *parent = OBJECT_parent(object);
if (!parent || OBJECT_is_locked((OBJECT *)object) || OBJECT_is_locked(parent))
return NULL;
return parent;
}