Merge branch 'st-theme-use-css-instance-data' into 'main'

St theme: use css instance data

See merge request GNOME/gnome-shell!536
This commit is contained in:
Marco Trevisan 2024-06-29 19:46:28 +00:00
commit f91e172a1e
31 changed files with 430 additions and 604 deletions

View file

@ -47,15 +47,13 @@ cr_additional_sel_new (void)
{
CRAdditionalSel *result = NULL;
result = g_try_malloc (sizeof (CRAdditionalSel));
result = g_try_malloc0 (sizeof (CRAdditionalSel));
if (result == NULL) {
cr_utils_trace_debug ("Out of memory");
return NULL;
}
memset (result, 0, sizeof (CRAdditionalSel));
return result;
}

View file

@ -29,9 +29,11 @@
#include <string.h>
#include "cr-cascade.h"
#define PRIVATE(a_this) ((a_this)->priv)
#define PRIVATE(a_this) ((CRCascadeReal *) a_this)
typedef struct _CRCascadeReal {
CRCascade parent;
struct _CRCascadePriv {
/**
*the 3 style sheets of the cascade:
*author, user, and useragent sheet.
@ -40,8 +42,8 @@ struct _CRCascadePriv {
*of sheets[ORIGIN_UA] ;
*/
CRStyleSheet *sheets[3];
guint ref_count;
};
grefcount ref_count;
} CRCascadeReal;
/**
* cr_cascade_new:
@ -66,20 +68,13 @@ cr_cascade_new (CRStyleSheet * a_author_sheet,
{
CRCascade *result = NULL;
result = g_try_malloc (sizeof (CRCascade));
result = g_try_malloc0 (sizeof (CRCascadeReal));
if (!result) {
cr_utils_trace_info ("Out of memory");
return NULL;
}
memset (result, 0, sizeof (CRCascade));
PRIVATE (result) = g_try_malloc (sizeof (CRCascadePriv));
if (!PRIVATE (result)) {
cr_utils_trace_info ("Out of memory");
g_free (result);
return NULL;
}
memset (PRIVATE (result), 0, sizeof (CRCascadePriv));
g_ref_count_init (&PRIVATE (result)->ref_count);
if (a_author_sheet) {
cr_cascade_set_sheet (result, a_author_sheet, ORIGIN_AUTHOR);
@ -142,8 +137,7 @@ cr_cascade_set_sheet (CRCascade * a_this,
if (PRIVATE (a_this)->sheets[a_origin])
cr_stylesheet_unref (PRIVATE (a_this)->sheets[a_origin]);
PRIVATE (a_this)->sheets[a_origin] = a_sheet;
cr_stylesheet_ref (a_sheet);
PRIVATE (a_this)->sheets[a_origin] = cr_stylesheet_ref (a_sheet);
a_sheet->origin = a_origin;
return CR_OK;
}
@ -160,7 +154,7 @@ cr_cascade_ref (CRCascade * a_this)
{
g_return_if_fail (a_this && PRIVATE (a_this));
PRIVATE (a_this)->ref_count++;
g_ref_count_inc (&PRIVATE (a_this)->ref_count);
}
/**
@ -178,9 +172,7 @@ cr_cascade_unref (CRCascade * a_this)
{
g_return_if_fail (a_this && PRIVATE (a_this));
if (PRIVATE (a_this)->ref_count)
PRIVATE (a_this)->ref_count--;
if (!PRIVATE (a_this)->ref_count) {
if (g_ref_count_dec (&PRIVATE (a_this)->ref_count)) {
cr_cascade_destroy (a_this);
}
}
@ -196,20 +188,14 @@ cr_cascade_destroy (CRCascade * a_this)
{
g_return_if_fail (a_this);
if (PRIVATE (a_this)) {
gulong i = 0;
for (i = 0; i < NB_ORIGINS; i++) {
if (PRIVATE (a_this)->sheets[i]) {
if (cr_stylesheet_unref
(PRIVATE (a_this)->sheets[i])
== TRUE) {
PRIVATE (a_this)->sheets[i] = NULL;
}
for (int i = 0; i < NB_ORIGINS; i++) {
if (PRIVATE (a_this)->sheets[i]) {
if (cr_stylesheet_unref
(PRIVATE (a_this)->sheets[i])
== TRUE) {
PRIVATE (a_this)->sheets[i] = NULL;
}
}
g_free (PRIVATE (a_this));
PRIVATE (a_this) = NULL;
}
g_free (a_this);
}

View file

@ -38,8 +38,6 @@
G_BEGIN_DECLS
typedef struct _CRCascadePriv CRCascadePriv ;
/**
*An abstraction of the "Cascade" defined
*in the css2 spec, chapter 6.4.
@ -48,7 +46,7 @@ typedef struct _CRCascade CRCascade ;
struct _CRCascade
{
CRCascadePriv *priv ;
gpointer dummy;
};

View file

@ -86,14 +86,14 @@ cr_declaration_new (CRStatement * a_statement,
|| (a_statement->type
== AT_PAGE_RULE_STMT)), NULL);
result = g_try_malloc (sizeof (CRDeclaration));
result = g_try_malloc0 (sizeof (CRDeclaration));
if (!result) {
cr_utils_trace_info ("Out of memory");
return NULL;
}
memset (result, 0, sizeof (CRDeclaration));
result->property = a_property;
result->value = a_value;
g_ref_count_init (&result->ref_count);
if (a_value) {
cr_term_ref (a_value);
@ -145,7 +145,7 @@ cr_declaration_parse_from_buf (CRStatement * a_statement,
result = cr_declaration_new (a_statement, property, value);
if (result) {
property = NULL;
value = NULL;
g_clear_pointer (&value, cr_term_unref);
result->important = important;
}
@ -216,7 +216,7 @@ cr_declaration_parse_list_from_buf (const guchar * a_str,
result = cr_declaration_new (NULL, property, value);
if (result) {
property = NULL;
value = NULL;
g_clear_pointer (&value, cr_term_unref);
result->important = important;
}
/*now, go parse the other declarations */
@ -248,10 +248,9 @@ cr_declaration_parse_list_from_buf (const guchar * a_str,
cur_decl = cr_declaration_new (NULL, property, value);
if (cur_decl) {
cur_decl->important = important;
result = cr_declaration_append (result, cur_decl);
result = cr_declaration_append (result, g_steal_pointer (&cur_decl));
g_clear_pointer (&value, cr_term_unref);
property = NULL;
value = NULL;
cur_decl = NULL;
} else {
break;
}
@ -727,7 +726,7 @@ cr_declaration_ref (CRDeclaration * a_this)
{
g_return_if_fail (a_this);
a_this->ref_count++;
g_ref_count_inc (&a_this->ref_count);
}
/**
@ -745,11 +744,7 @@ cr_declaration_unref (CRDeclaration * a_this)
{
g_return_val_if_fail (a_this, FALSE);
if (a_this->ref_count) {
a_this->ref_count--;
}
if (a_this->ref_count == 0) {
if (g_ref_count_dec (&a_this->ref_count)) {
cr_declaration_destroy (a_this);
return TRUE;
}

View file

@ -64,7 +64,7 @@ struct _CRDeclaration
/*does the declaration have the important keyword ?*/
gboolean important ;
glong ref_count ;
grefcount ref_count ;
CRParsingLocation location ;
/*reserved for future usage*/

View file

@ -33,9 +33,13 @@
*to custom values.
*/
#define PRIVATE(obj) (obj)->priv
#define PRIVATE(obj) ((CRDocHandlerReal *) obj)
typedef struct _CRDocHandlerReal {
CRDocHandler parent;
grefcount ref_count;
struct _CRDocHandlerPriv {
/**
*This pointer is to hold an application parsing context.
*For example, it used by the Object Model parser to
@ -56,7 +60,7 @@ struct _CRDocHandlerPriv {
*the current document.
*/
CRParser *parser ;
};
} CRDocHandlerReal;
/**
* cr_doc_handler_new:
@ -71,22 +75,14 @@ cr_doc_handler_new (void)
{
CRDocHandler *result = NULL;
result = g_try_malloc (sizeof (CRDocHandler));
result = g_try_malloc0 (sizeof (CRDocHandlerReal));
g_return_val_if_fail (result, NULL);
memset (result, 0, sizeof (CRDocHandler));
result->ref_count++;
result->priv = g_try_malloc (sizeof (CRDocHandlerPriv));
if (!result->priv) {
cr_utils_trace_info ("Out of memory exception");
g_free (result);
return NULL;
}
cr_doc_handler_set_default_sac_handler (result);
g_ref_count_init (&PRIVATE (result)->ref_count);
return result;
}
@ -103,9 +99,9 @@ cr_doc_handler_new (void)
enum CRStatus
cr_doc_handler_get_ctxt (CRDocHandler const * a_this, gpointer * a_ctxt)
{
g_return_val_if_fail (a_this && a_this->priv, CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
*a_ctxt = a_this->priv->context;
*a_ctxt = PRIVATE (a_this)->context;
return CR_OK;
}
@ -122,8 +118,8 @@ cr_doc_handler_get_ctxt (CRDocHandler const * a_this, gpointer * a_ctxt)
enum CRStatus
cr_doc_handler_set_ctxt (CRDocHandler * a_this, gpointer a_ctxt)
{
g_return_val_if_fail (a_this && a_this->priv, CR_BAD_PARAM_ERROR);
a_this->priv->context = a_ctxt;
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
PRIVATE (a_this)->context = a_ctxt;
return CR_OK;
}
@ -140,9 +136,9 @@ cr_doc_handler_set_ctxt (CRDocHandler * a_this, gpointer a_ctxt)
enum CRStatus
cr_doc_handler_get_result (CRDocHandler const * a_this, gpointer * a_result)
{
g_return_val_if_fail (a_this && a_this->priv, CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
*a_result = a_this->priv->result;
*a_result = PRIVATE (a_this)->result;
return CR_OK;
}
@ -160,8 +156,8 @@ cr_doc_handler_get_result (CRDocHandler const * a_this, gpointer * a_result)
enum CRStatus
cr_doc_handler_set_result (CRDocHandler * a_this, gpointer a_result)
{
g_return_val_if_fail (a_this && a_this->priv, CR_BAD_PARAM_ERROR);
a_this->priv->result = a_result;
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
PRIVATE (a_this)->result = a_result;
return CR_OK;
}
@ -211,7 +207,7 @@ cr_doc_handler_ref (CRDocHandler * a_this)
{
g_return_if_fail (a_this);
a_this->ref_count++;
g_ref_count_inc (&PRIVATE (a_this)->ref_count);
}
/**
@ -228,11 +224,7 @@ cr_doc_handler_unref (CRDocHandler * a_this)
{
g_return_val_if_fail (a_this, FALSE);
if (a_this->ref_count > 0) {
a_this->ref_count--;
}
if (a_this->ref_count == 0) {
if (g_ref_count_dec (&PRIVATE (a_this)->ref_count)) {
cr_doc_handler_destroy (a_this);
return TRUE;
}
@ -251,10 +243,6 @@ cr_doc_handler_destroy (CRDocHandler * a_this)
{
g_return_if_fail (a_this);
if (a_this->priv) {
g_free (a_this->priv);
a_this->priv = NULL;
}
g_free (a_this);
}
@ -269,8 +257,7 @@ void
cr_doc_handler_associate_a_parser (CRDocHandler *a_this,
gpointer a_parser)
{
g_return_if_fail (a_this && PRIVATE (a_this)
&& a_parser) ;
g_return_if_fail (a_this && a_parser) ;
PRIVATE (a_this)->parser = a_parser ;
}

View file

@ -39,9 +39,6 @@ G_BEGIN_DECLS
typedef struct _CRDocHandler CRDocHandler ;
struct _CRDocHandlerPriv ;
typedef struct _CRDocHandlerPriv CRDocHandlerPriv ;
/**
*The SAC document handler.
@ -52,8 +49,6 @@ typedef struct _CRDocHandlerPriv CRDocHandlerPriv ;
*/
struct _CRDocHandler
{
CRDocHandlerPriv *priv ;
/**
*This pointer is to be used by the application for
*it custom needs. It is there to extend the doc handler.
@ -269,7 +264,6 @@ struct _CRDocHandler
void (*unrecoverable_error) (CRDocHandler *a_this) ;
gboolean resolve_import ;
gulong ref_count ;
} ;
CRDocHandler * cr_doc_handler_new (void) ;

View file

@ -155,14 +155,13 @@ cr_font_family_new (enum CRFontFamilyType a_type, guchar * a_name)
{
CRFontFamily *result = NULL;
result = g_try_malloc (sizeof (CRFontFamily));
result = g_try_malloc0 (sizeof (CRFontFamily));
if (!result) {
cr_utils_trace_info ("Out of memory");
return NULL;
}
memset (result, 0, sizeof (CRFontFamily));
result->type = a_type;
cr_font_family_set_name (result, a_name);
@ -335,12 +334,11 @@ cr_font_size_new (void)
{
CRFontSize *result = NULL;
result = g_try_malloc (sizeof (CRFontSize));
result = g_try_malloc0 (sizeof (CRFontSize));
if (!result) {
cr_utils_trace_info ("Out of memory");
return NULL;
}
memset (result, 0, sizeof (CRFontSize));
return result;
}
@ -921,12 +919,11 @@ cr_font_size_adjust_new (void)
{
CRFontSizeAdjust *result = NULL;
result = g_try_malloc (sizeof (CRFontSizeAdjust));
result = g_try_malloc0 (sizeof (CRFontSizeAdjust));
if (!result) {
cr_utils_trace_info ("Out of memory");
return NULL;
}
memset (result, 0, sizeof (CRFontSizeAdjust));
return result;
}

View file

@ -38,9 +38,11 @@
/**
*The private attributes of
*the #CRInputPriv class.
*the #RInputReal class.
*/
struct _CRInputPriv {
typedef struct _CRInputReal {
CRInput parent;
/*
*The input buffer
*/
@ -72,11 +74,11 @@ struct _CRInputPriv {
*the reference count of this
*instance.
*/
guint ref_count;
grefcount ref_count;
gboolean free_in_buf;
};
} CRInputReal;
#define PRIVATE(object) (object)->priv
#define PRIVATE(object) ((CRInputReal *) object)
/***************************
*private constants
@ -90,20 +92,13 @@ cr_input_new_real (void)
{
CRInput *result = NULL;
result = g_try_malloc (sizeof (CRInput));
result = g_try_malloc0 (sizeof (CRInputReal));
if (!result) {
cr_utils_trace_info ("Out of memory");
return NULL;
}
memset (result, 0, sizeof (CRInput));
PRIVATE (result) = g_try_malloc (sizeof (CRInputPriv));
if (!PRIVATE (result)) {
cr_utils_trace_info ("Out of memory");
g_free (result);
return NULL;
}
memset (PRIVATE (result), 0, sizeof (CRInputPriv));
g_ref_count_init (&PRIVATE (result)->ref_count);
PRIVATE (result)->free_in_buf = TRUE;
return result;
}
@ -285,15 +280,8 @@ cr_input_destroy (CRInput * a_this)
if (a_this == NULL)
return;
if (PRIVATE (a_this)) {
if (PRIVATE (a_this)->in_buf && PRIVATE (a_this)->free_in_buf) {
g_free (PRIVATE (a_this)->in_buf);
PRIVATE (a_this)->in_buf = NULL;
}
g_free (PRIVATE (a_this));
PRIVATE (a_this) = NULL;
}
if (PRIVATE (a_this)->free_in_buf)
g_clear_pointer (&PRIVATE (a_this)->in_buf, g_free);
g_free (a_this);
}
@ -308,9 +296,9 @@ cr_input_destroy (CRInput * a_this)
void
cr_input_ref (CRInput * a_this)
{
g_return_if_fail (a_this && PRIVATE (a_this));
g_return_if_fail (a_this);
PRIVATE (a_this)->ref_count++;
g_ref_count_inc (&PRIVATE (a_this)->ref_count);
}
/**
@ -326,13 +314,9 @@ cr_input_ref (CRInput * a_this)
gboolean
cr_input_unref (CRInput * a_this)
{
g_return_val_if_fail (a_this && PRIVATE (a_this), FALSE);
g_return_val_if_fail (a_this, FALSE);
if (PRIVATE (a_this)->ref_count) {
PRIVATE (a_this)->ref_count--;
}
if (PRIVATE (a_this)->ref_count == 0) {
if (g_ref_count_dec (&PRIVATE (a_this)->ref_count)) {
cr_input_destroy (a_this);
return TRUE;
}
@ -356,8 +340,7 @@ cr_input_unref (CRInput * a_this)
enum CRStatus
cr_input_end_of_input (CRInput const * a_this, gboolean * a_end_of_input)
{
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& a_end_of_input, CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this && a_end_of_input, CR_BAD_PARAM_ERROR);
*a_end_of_input = (PRIVATE (a_this)->next_byte_index
>= PRIVATE (a_this)->in_buf_size) ? TRUE : FALSE;
@ -375,7 +358,7 @@ cr_input_end_of_input (CRInput const * a_this, gboolean * a_end_of_input)
glong
cr_input_get_nb_bytes_left (CRInput const * a_this)
{
g_return_val_if_fail (a_this && PRIVATE (a_this), -1);
g_return_val_if_fail (a_this, -1);
g_return_val_if_fail (PRIVATE (a_this)->nb_bytes
<= PRIVATE (a_this)->in_buf_size, -1);
g_return_val_if_fail (PRIVATE (a_this)->next_byte_index
@ -406,8 +389,7 @@ cr_input_read_byte (CRInput * a_this, guchar * a_byte)
{
gulong nb_bytes_left = 0;
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& a_byte, CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this && a_byte, CR_BAD_PARAM_ERROR);
g_return_val_if_fail (PRIVATE (a_this)->next_byte_index <=
PRIVATE (a_this)->nb_bytes, CR_BAD_PARAM_ERROR);
@ -451,8 +433,7 @@ cr_input_read_char (CRInput * a_this, guint32 * a_char)
gulong consumed = 0,
nb_bytes_left = 0;
g_return_val_if_fail (a_this && PRIVATE (a_this) && a_char,
CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this && a_char, CR_BAD_PARAM_ERROR);
if (PRIVATE (a_this)->end_of_input == TRUE)
return CR_END_OF_INPUT_ERROR;
@ -502,7 +483,7 @@ cr_input_read_char (CRInput * a_this, guint32 * a_char)
enum CRStatus
cr_input_set_line_num (CRInput * a_this, glong a_line_num)
{
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
PRIVATE (a_this)->line = a_line_num;
@ -521,8 +502,7 @@ cr_input_set_line_num (CRInput * a_this, glong a_line_num)
enum CRStatus
cr_input_get_line_num (CRInput const * a_this, glong * a_line_num)
{
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& a_line_num, CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this && a_line_num, CR_BAD_PARAM_ERROR);
*a_line_num = PRIVATE (a_this)->line;
@ -541,7 +521,7 @@ cr_input_get_line_num (CRInput const * a_this, glong * a_line_num)
enum CRStatus
cr_input_set_column_num (CRInput * a_this, glong a_col)
{
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
PRIVATE (a_this)->col = a_col;
@ -560,8 +540,7 @@ cr_input_set_column_num (CRInput * a_this, glong a_col)
enum CRStatus
cr_input_get_column_num (CRInput const * a_this, glong * a_col)
{
g_return_val_if_fail (a_this && PRIVATE (a_this) && a_col,
CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this && a_col, CR_BAD_PARAM_ERROR);
*a_col = PRIVATE (a_this)->col;
@ -580,7 +559,7 @@ cr_input_get_column_num (CRInput const * a_this, glong * a_col)
enum CRStatus
cr_input_increment_line_num (CRInput * a_this, glong a_increment)
{
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
PRIVATE (a_this)->line += a_increment;
@ -599,7 +578,7 @@ cr_input_increment_line_num (CRInput * a_this, glong a_increment)
enum CRStatus
cr_input_increment_col_num (CRInput * a_this, glong a_increment)
{
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
PRIVATE (a_this)->col += a_increment;
@ -624,7 +603,7 @@ cr_input_consume_char (CRInput * a_this, guint32 a_char)
guint32 c;
enum CRStatus status;
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
if ((status = cr_input_peek_char (a_this, &c)) != CR_OK) {
return status;
@ -665,11 +644,9 @@ cr_input_consume_chars (CRInput * a_this, guint32 a_char, gulong * a_nb_char)
enum CRStatus status = CR_OK;
gulong nb_consumed = 0;
g_return_val_if_fail (a_this && PRIVATE (a_this) && a_nb_char,
CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this && a_nb_char, CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_char != 0 || a_nb_char != NULL,
CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_char != 0 || a_nb_char != NULL, CR_BAD_PARAM_ERROR);
for (nb_consumed = 0; ((status == CR_OK)
&& (*a_nb_char > 0
@ -707,8 +684,7 @@ cr_input_consume_white_spaces (CRInput * a_this, gulong * a_nb_chars)
guint32 cur_char = 0,
nb_consumed = 0;
g_return_val_if_fail (a_this && PRIVATE (a_this) && a_nb_chars,
CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this && a_nb_chars, CR_BAD_PARAM_ERROR);
for (nb_consumed = 0;
((*a_nb_chars > 0) && (nb_consumed < *a_nb_chars));
@ -758,7 +734,7 @@ cr_input_peek_char (CRInput const * a_this, guint32 * a_char)
gulong consumed = 0,
nb_bytes_left = 0;
g_return_val_if_fail (a_this && PRIVATE (a_this)
g_return_val_if_fail (a_this
&& a_char, CR_BAD_PARAM_ERROR);
if (PRIVATE (a_this)->next_byte_index >=
@ -806,7 +782,7 @@ cr_input_peek_byte (CRInput const * a_this, enum CRSeekPos a_origin,
{
gulong abs_offset = 0;
g_return_val_if_fail (a_this && PRIVATE (a_this)
g_return_val_if_fail (a_this
&& a_byte, CR_BAD_PARAM_ERROR);
switch (a_origin) {
@ -858,7 +834,7 @@ cr_input_peek_byte2 (CRInput const * a_this, gulong a_offset, gboolean * a_eof)
guchar result = 0;
enum CRStatus status = CR_ERROR;
g_return_val_if_fail (a_this && PRIVATE (a_this), 0);
g_return_val_if_fail (a_this, 0);
if (a_eof)
*a_eof = FALSE;
@ -886,7 +862,7 @@ cr_input_peek_byte2 (CRInput const * a_this, gulong a_offset, gboolean * a_eof)
guchar *
cr_input_get_byte_addr (CRInput * a_this, gulong a_offset)
{
g_return_val_if_fail (a_this && PRIVATE (a_this), NULL);
g_return_val_if_fail (a_this, NULL);
if (a_offset >= PRIVATE (a_this)->nb_bytes) {
return NULL;
@ -907,8 +883,7 @@ cr_input_get_byte_addr (CRInput * a_this, gulong a_offset)
enum CRStatus
cr_input_get_cur_byte_addr (CRInput * a_this, guchar ** a_offset)
{
g_return_val_if_fail (a_this && PRIVATE (a_this) && a_offset,
CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this && a_offset, CR_BAD_PARAM_ERROR);
if (!PRIVATE (a_this)->next_byte_index) {
return CR_START_OF_INPUT_ERROR;
@ -942,7 +917,7 @@ cr_input_seek_index (CRInput * a_this, enum CRSeekPos a_origin, gint a_pos)
glong abs_offset = 0;
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
switch (a_origin) {
@ -994,8 +969,7 @@ cr_input_seek_index (CRInput * a_this, enum CRSeekPos a_origin, gint a_pos)
enum CRStatus
cr_input_get_cur_pos (CRInput const * a_this, CRInputPos * a_pos)
{
g_return_val_if_fail (a_this && PRIVATE (a_this) && a_pos,
CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this && a_pos, CR_BAD_PARAM_ERROR);
a_pos->next_byte_index = PRIVATE (a_this)->next_byte_index;
a_pos->line = PRIVATE (a_this)->line;
@ -1023,10 +997,7 @@ enum CRStatus
cr_input_get_parsing_location (CRInput const *a_this,
CRParsingLocation *a_loc)
{
g_return_val_if_fail (a_this
&& PRIVATE (a_this)
&& a_loc,
CR_BAD_PARAM_ERROR) ;
g_return_val_if_fail (a_this && a_loc, CR_BAD_PARAM_ERROR) ;
a_loc->line = PRIVATE (a_this)->line ;
a_loc->column = PRIVATE (a_this)->col ;
@ -1054,8 +1025,7 @@ cr_input_get_parsing_location (CRInput const *a_this,
enum CRStatus
cr_input_get_cur_index (CRInput const * a_this, glong * a_index)
{
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& a_index, CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this && a_index, CR_BAD_PARAM_ERROR);
*a_index = PRIVATE (a_this)->next_byte_index;
@ -1076,7 +1046,7 @@ cr_input_get_cur_index (CRInput const * a_this, glong * a_index)
enum CRStatus
cr_input_set_cur_index (CRInput * a_this, glong a_index)
{
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
PRIVATE (a_this)->next_byte_index = a_index;
@ -1095,7 +1065,7 @@ cr_input_set_cur_index (CRInput * a_this, glong a_index)
enum CRStatus
cr_input_set_end_of_file (CRInput * a_this, gboolean a_eof)
{
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
PRIVATE (a_this)->end_of_input = a_eof;
@ -1115,8 +1085,7 @@ cr_input_set_end_of_file (CRInput * a_this, gboolean a_eof)
enum CRStatus
cr_input_get_end_of_file (CRInput const * a_this, gboolean * a_eof)
{
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& a_eof, CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this && a_eof, CR_BAD_PARAM_ERROR);
*a_eof = PRIVATE (a_this)->end_of_input;
@ -1136,7 +1105,7 @@ cr_input_get_end_of_file (CRInput const * a_this, gboolean * a_eof)
enum CRStatus
cr_input_set_end_of_line (CRInput * a_this, gboolean a_eol)
{
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
PRIVATE (a_this)->end_of_line = a_eol;
@ -1157,8 +1126,7 @@ cr_input_set_end_of_line (CRInput * a_this, gboolean a_eol)
enum CRStatus
cr_input_get_end_of_line (CRInput const * a_this, gboolean * a_eol)
{
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& a_eol, CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this && a_eol, CR_BAD_PARAM_ERROR);
*a_eol = PRIVATE (a_this)->end_of_line;
@ -1178,8 +1146,7 @@ cr_input_get_end_of_line (CRInput const * a_this, gboolean * a_eol)
enum CRStatus
cr_input_set_cur_pos (CRInput * a_this, CRInputPos const * a_pos)
{
g_return_val_if_fail (a_this && PRIVATE (a_this) && a_pos,
CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this && a_pos, CR_BAD_PARAM_ERROR);
cr_input_set_column_num (a_this, a_pos->col);
cr_input_set_line_num (a_this, a_pos->line);

View file

@ -38,7 +38,6 @@ G_BEGIN_DECLS
*/
typedef struct _CRInput CRInput ;
typedef struct _CRInputPriv CRInputPriv ;
/**
*The #CRInput class provides the abstraction of
@ -46,7 +45,7 @@ typedef struct _CRInputPriv CRInputPriv ;
*/
struct _CRInput
{
CRInputPriv *priv ;
gpointer dummy;
} ;
typedef struct _CRInputPos CRInputPos ;

View file

@ -45,15 +45,13 @@ cr_num_new (void)
{
CRNum *result = NULL;
result = g_try_malloc (sizeof (CRNum));
result = g_try_malloc0 (sizeof (CRNum));
if (result == NULL) {
cr_utils_trace_info ("Out of memory");
return NULL;
}
memset (result, 0, sizeof (CRNum));
return result;
}

View file

@ -33,11 +33,13 @@
*in cr-parser.h and cr-doc-handler.h
*/
struct _CROMParserPriv {
CRParser *parser;
};
typedef struct _CROMParserReal {
CROMParser parent;
#define PRIVATE(a_this) ((a_this)->priv)
CRParser *parser;
} CROMParserReal;
#define PRIVATE(a_this) ((CROMParserReal *) a_this)
/*
*Forward declaration of a type defined later
@ -145,8 +147,7 @@ cr_om_parser_init_default_sac_handler (CROMParser * a_this)
gboolean created_handler = FALSE;
enum CRStatus status = CR_OK;
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& PRIVATE (a_this)->parser,
g_return_val_if_fail (a_this && PRIVATE (a_this)->parser,
CR_BAD_PARAM_ERROR);
status = cr_parser_get_sac_handler (PRIVATE (a_this)->parser,
@ -795,23 +796,12 @@ cr_om_parser_new (CRInput * a_input)
CROMParser *result = NULL;
enum CRStatus status = CR_OK;
result = g_try_malloc (sizeof (CROMParser));
result = g_try_malloc0 (sizeof (CROMParserReal));
if (!result) {
cr_utils_trace_info ("Out of memory");
return NULL;
}
memset (result, 0, sizeof (CROMParser));
PRIVATE (result) = g_try_malloc (sizeof (CROMParserPriv));
if (!PRIVATE (result)) {
cr_utils_trace_info ("Out of memory");
goto error;
}
memset (PRIVATE (result), 0, sizeof (CROMParserPriv));
PRIVATE (result)->parser = cr_parser_new_from_input (a_input);
if (!PRIVATE (result)->parser) {
@ -1062,13 +1052,12 @@ cr_om_parser_parse_paths_to_cascade (CROMParser * a_this,
}
}
result = cr_cascade_new (sheets[0], sheets[1], sheets[2]);
if (!result) {
for (i = 0; i < 3; i++) {
cr_stylesheet_unref (sheets[i]);
sheets[i] = 0;
}
for (i = 0; i < 3; i++)
g_clear_pointer (&sheets[i], cr_stylesheet_unref);
if (!result)
return CR_ERROR;
}
*a_result = result;
return CR_OK;
}
@ -1123,20 +1112,8 @@ cr_om_parser_simply_parse_paths_to_cascade (const guchar * a_author_path,
void
cr_om_parser_destroy (CROMParser * a_this)
{
g_return_if_fail (a_this && PRIVATE (a_this));
g_return_if_fail (a_this);
if (PRIVATE (a_this)->parser) {
cr_parser_destroy (PRIVATE (a_this)->parser);
PRIVATE (a_this)->parser = NULL;
}
if (PRIVATE (a_this)) {
g_free (PRIVATE (a_this));
PRIVATE (a_this) = NULL;
}
if (a_this) {
g_free (a_this);
a_this = NULL;
}
g_clear_pointer (&PRIVATE (a_this)->parser, cr_parser_destroy);
g_free (a_this);
}

View file

@ -42,7 +42,6 @@
G_BEGIN_DECLS
typedef struct _CROMParser CROMParser ;
typedef struct _CROMParserPriv CROMParserPriv ;
/**
*The Object model parser.
@ -52,7 +51,7 @@ typedef struct _CROMParserPriv CROMParserPriv ;
*/
struct _CROMParser
{
CROMParserPriv *priv ;
gpointer dummy;
} ;
CROMParser * cr_om_parser_new (CRInput *a_input) ;

View file

@ -105,7 +105,7 @@ enum CRParserState {
*The private attributes of
*#CRParser.
*/
struct _CRParserPriv {
typedef struct _CRParserReal {
/**
*The tokenizer
*/
@ -130,9 +130,9 @@ struct _CRParserPriv {
gboolean resolve_import;
gboolean is_case_sensitive;
gboolean use_core_grammar;
};
} CRParserReal;
#define PRIVATE(obj) ((obj)->priv)
#define PRIVATE(obj) ((CRParserReal *) obj)
#define CHARS_TAB_SIZE 12
@ -418,15 +418,13 @@ cr_parser_error_new (const guchar * a_msg, enum CRStatus a_status)
{
CRParserError *result = NULL;
result = g_try_malloc (sizeof (CRParserError));
result = g_try_malloc0 (sizeof (CRParserError));
if (result == NULL) {
cr_utils_trace_info ("Out of memory");
return NULL;
}
memset (result, 0, sizeof (CRParserError));
cr_parser_error_set_msg (result, a_msg);
cr_parser_error_set_status (result, a_status);
@ -525,8 +523,7 @@ cr_parser_push_error (CRParser * a_this,
CRParserError *error = NULL;
CRInputPos pos;
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& a_msg, CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this && a_msg, CR_BAD_PARAM_ERROR);
error = cr_parser_error_new (a_msg, a_status);
@ -568,7 +565,7 @@ cr_parser_dump_err_stack (CRParser * a_this, gboolean a_clear_errs)
{
GList *cur = NULL;
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
if (PRIVATE (a_this)->err_stack == NULL)
return CR_OK;
@ -594,7 +591,7 @@ cr_parser_clear_errors (CRParser * a_this)
{
GList *cur = NULL;
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
for (cur = PRIVATE (a_this)->err_stack; cur; cur = cur->next) {
if (cur->data) {
@ -626,7 +623,7 @@ cr_parser_try_to_skip_spaces_and_comments (CRParser * a_this)
enum CRStatus status = CR_ERROR;
CRToken *token = NULL;
g_return_val_if_fail (a_this && PRIVATE (a_this)
g_return_val_if_fail (a_this
&& PRIVATE (a_this)->tknzr, CR_BAD_PARAM_ERROR);
do {
if (token) {
@ -683,7 +680,7 @@ cr_parser_parse_stylesheet_core (CRParser * a_this)
CRInputPos init_pos;
enum CRStatus status = CR_ERROR;
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
RECORD_INITIAL_POS (a_this, &init_pos);
@ -765,7 +762,7 @@ cr_parser_parse_atrule_core (CRParser * a_this)
CRInputPos init_pos;
enum CRStatus status = CR_ERROR;
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
RECORD_INITIAL_POS (a_this, &init_pos);
@ -840,7 +837,7 @@ cr_parser_parse_ruleset_core (CRParser * a_this)
CRInputPos init_pos;
enum CRStatus status = CR_ERROR;
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
RECORD_INITIAL_POS (a_this, &init_pos);
status = cr_parser_parse_selector_core (a_this);
@ -929,7 +926,7 @@ cr_parser_parse_selector_core (CRParser * a_this)
CRInputPos init_pos;
enum CRStatus status = CR_ERROR;
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
RECORD_INITIAL_POS (a_this, &init_pos);
@ -970,7 +967,7 @@ cr_parser_parse_block_core (CRParser * a_this,
CRInputPos init_pos;
enum CRStatus status = CR_ERROR;
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
if (n_calls > RECURSIVE_CALLERS_LIMIT)
return CR_ERROR;
@ -1043,7 +1040,7 @@ cr_parser_parse_declaration_core (CRParser * a_this)
enum CRStatus status = CR_ERROR;
CRString *prop = NULL;
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
RECORD_INITIAL_POS (a_this, &init_pos);
@ -1099,7 +1096,7 @@ cr_parser_parse_value_core (CRParser * a_this)
enum CRStatus status = CR_ERROR;
glong ref = 0;
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
RECORD_INITIAL_POS (a_this, &init_pos);
continue_parsing:
@ -1481,8 +1478,7 @@ cr_parser_parse_property (CRParser * a_this,
enum CRStatus status = CR_OK;
CRInputPos init_pos;
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& PRIVATE (a_this)->tknzr
g_return_val_if_fail (a_this && PRIVATE (a_this)->tknzr
&& a_property,
CR_BAD_PARAM_ERROR);
@ -1617,9 +1613,7 @@ cr_parser_parse_term (CRParser * a_this, CRTerm ** a_term)
}
cr_parsing_location_copy (&result->location,
&location) ;
*a_term = cr_term_append_term (*a_term, result);
result = NULL;
*a_term = cr_term_append_term (*a_term, g_steal_pointer (&result));
cr_parser_try_to_skip_spaces_and_comments (a_this);
@ -1947,10 +1941,7 @@ cr_parser_parse_simple_sels (CRParser * a_this,
CRSimpleSel *sel = NULL;
guint32 cur_char = 0;
g_return_val_if_fail (a_this
&& PRIVATE (a_this)
&& a_sel,
CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this && a_sel, CR_BAD_PARAM_ERROR);
RECORD_INITIAL_POS (a_this, &init_pos);
@ -2146,7 +2137,7 @@ cr_parser_parse_function (CRParser * a_this,
CRToken *token = NULL;
CRTerm *expr = NULL;
g_return_val_if_fail (a_this && PRIVATE (a_this)
g_return_val_if_fail (a_this
&& a_func_name,
CR_BAD_PARAM_ERROR);
@ -2228,7 +2219,7 @@ cr_parser_parse_uri (CRParser * a_this, CRString ** a_str)
enum CRStatus status = CR_PARSING_ERROR;
g_return_val_if_fail (a_this && PRIVATE (a_this)
g_return_val_if_fail (a_this
&& PRIVATE (a_this)->tknzr, CR_BAD_PARAM_ERROR);
status = cr_tknzr_parse_token (PRIVATE (a_this)->tknzr,
@ -2258,7 +2249,7 @@ cr_parser_parse_string (CRParser * a_this, CRString ** a_str)
{
enum CRStatus status = CR_OK;
g_return_val_if_fail (a_this && PRIVATE (a_this)
g_return_val_if_fail (a_this
&& PRIVATE (a_this)->tknzr
&& a_str, CR_BAD_PARAM_ERROR);
@ -2286,7 +2277,7 @@ cr_parser_parse_ident (CRParser * a_this, CRString ** a_str)
{
enum CRStatus status = CR_OK;
g_return_val_if_fail (a_this && PRIVATE (a_this)
g_return_val_if_fail (a_this
&& PRIVATE (a_this)->tknzr
&& a_str, CR_BAD_PARAM_ERROR);
@ -2321,7 +2312,7 @@ cr_parser_parse_stylesheet (CRParser * a_this)
CRToken *token = NULL;
CRString *charset = NULL;
g_return_val_if_fail (a_this && PRIVATE (a_this)
g_return_val_if_fail (a_this
&& PRIVATE (a_this)->tknzr, CR_BAD_PARAM_ERROR);
RECORD_INITIAL_POS (a_this, &init_pos);
@ -2766,9 +2757,7 @@ cr_parser_new (CRTknzr * a_tknzr)
CRParser *result = NULL;
enum CRStatus status = CR_OK;
result = g_malloc0 (sizeof (CRParser));
PRIVATE (result) = g_malloc0 (sizeof (CRParserPriv));
result = g_malloc0 (sizeof (CRParserReal));
if (a_tknzr) {
status = cr_parser_set_tknzr (result, a_tknzr);
@ -2808,11 +2797,11 @@ cr_parser_new_from_buf (guchar * a_buf,
g_return_val_if_fail (input, NULL);
result = cr_parser_new_from_input (input);
if (!result) {
cr_input_destroy (input);
input = NULL;
cr_input_unref (input);
if (!result)
return NULL;
}
return result;
}
@ -2834,6 +2823,7 @@ cr_parser_new_from_input (CRInput * a_input)
}
result = cr_parser_new (tokenizer);
g_clear_pointer (&tokenizer, cr_tknzr_unref);
g_return_val_if_fail (result, NULL);
return result;
@ -2859,6 +2849,7 @@ cr_parser_new_from_file (const guchar * a_file_uri, enum CREncoding a_enc)
}
result = cr_parser_new (tokenizer);
cr_tknzr_unref (tokenizer);
g_return_val_if_fail (result, NULL);
return result;
}
@ -2923,7 +2914,7 @@ cr_parser_set_default_sac_handler (CRParser * a_this)
CRDocHandler *default_sac_handler = NULL;
enum CRStatus status = CR_ERROR;
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
default_sac_handler = cr_doc_handler_new ();
@ -2950,7 +2941,7 @@ enum CRStatus
cr_parser_set_use_core_grammar (CRParser * a_this,
gboolean a_use_core_grammar)
{
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
PRIVATE (a_this)->use_core_grammar = a_use_core_grammar;
@ -2968,7 +2959,7 @@ enum CRStatus
cr_parser_get_use_core_grammar (CRParser const * a_this,
gboolean * a_use_core_grammar)
{
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
*a_use_core_grammar = PRIVATE (a_this)->use_core_grammar;
@ -2993,7 +2984,7 @@ cr_parser_parse_file (CRParser * a_this,
enum CRStatus status = CR_ERROR;
CRTknzr *tknzr = NULL;
g_return_val_if_fail (a_this && PRIVATE (a_this)
g_return_val_if_fail (a_this
&& a_file_uri, CR_BAD_PARAM_ERROR);
tknzr = cr_tknzr_new_from_uri (a_file_uri, a_enc);
@ -3001,6 +2992,7 @@ cr_parser_parse_file (CRParser * a_this,
g_return_val_if_fail (tknzr != NULL, CR_ERROR);
status = cr_parser_set_tknzr (a_this, tknzr);
cr_tknzr_unref (tknzr);
g_return_val_if_fail (status == CR_OK, CR_ERROR);
status = cr_parser_parse (a_this);
@ -3030,8 +3022,7 @@ cr_parser_parse_expr (CRParser * a_this, CRTerm ** a_expr)
guchar next_byte = 0;
gulong nb_terms = 0;
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& a_expr, CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this && a_expr, CR_BAD_PARAM_ERROR);
RECORD_INITIAL_POS (a_this, &init_pos);
@ -3134,7 +3125,7 @@ cr_parser_parse_prio (CRParser * a_this, CRString ** a_prio)
CRInputPos init_pos;
CRToken *token = NULL;
g_return_val_if_fail (a_this && PRIVATE (a_this)
g_return_val_if_fail (a_this
&& a_prio
&& *a_prio == NULL, CR_BAD_PARAM_ERROR);
@ -3189,7 +3180,7 @@ cr_parser_parse_declaration (CRParser * a_this,
CRTerm *expr = NULL;
CRString *prio = NULL;
g_return_val_if_fail (a_this && PRIVATE (a_this)
g_return_val_if_fail (a_this
&& a_property && a_expr
&& a_important, CR_BAD_PARAM_ERROR);
@ -3279,7 +3270,7 @@ cr_parser_parse_statement_core (CRParser * a_this)
CRInputPos init_pos;
enum CRStatus status = CR_ERROR;
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
RECORD_INITIAL_POS (a_this, &init_pos);
@ -3367,14 +3358,6 @@ cr_parser_parse_ruleset (CRParser * a_this)
if (PRIVATE (a_this)->sac_handler
&& PRIVATE (a_this)->sac_handler->start_selector) {
/*
*the selector is ref counted so that the parser's user
*can choose to keep it.
*/
if (selector) {
cr_selector_ref (selector);
}
PRIVATE (a_this)->sac_handler->start_selector
(PRIVATE (a_this)->sac_handler, selector);
start_selector = TRUE;
@ -3387,9 +3370,6 @@ cr_parser_parse_ruleset (CRParser * a_this)
status = cr_parser_parse_declaration (a_this, &property,
&expr,
&is_important);
if (expr) {
cr_term_ref (expr);
}
if (status == CR_OK
&& PRIVATE (a_this)->sac_handler
&& PRIVATE (a_this)->sac_handler->property) {
@ -3442,9 +3422,6 @@ cr_parser_parse_ruleset (CRParser * a_this)
status = cr_parser_parse_declaration (a_this, &property,
&expr, &is_important);
if (expr) {
cr_term_ref (expr);
}
if (status == CR_OK
&& PRIVATE (a_this)->sac_handler
&& PRIVATE (a_this)->sac_handler->property) {
@ -3725,9 +3702,7 @@ cr_parser_parse_media (CRParser * a_this)
GList *media_list = NULL;
CRParsingLocation location = {0} ;
g_return_val_if_fail (a_this
&& PRIVATE (a_this),
CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
RECORD_INITIAL_POS (a_this, &init_pos);
@ -3980,9 +3955,6 @@ cr_parser_parse_page (CRParser * a_this)
*/
if (PRIVATE (a_this)->sac_handler
&& PRIVATE (a_this)->sac_handler->property) {
if (css_expression)
cr_term_ref (css_expression);
PRIVATE (a_this)->sac_handler->property
(PRIVATE (a_this)->sac_handler,
property, css_expression, important);
@ -4034,7 +4006,6 @@ cr_parser_parse_page (CRParser * a_this)
*/
if (PRIVATE (a_this)->sac_handler
&& PRIVATE (a_this)->sac_handler->property) {
cr_term_ref (css_expression);
PRIVATE (a_this)->sac_handler->property
(PRIVATE (a_this)->sac_handler,
property, css_expression, important);
@ -4281,7 +4252,6 @@ cr_parser_parse_font_face (CRParser * a_this)
/*
*here, call the relevant SAC handler.
*/
cr_term_ref (css_expression);
if (PRIVATE (a_this)->sac_handler &&
PRIVATE (a_this)->sac_handler->property) {
PRIVATE (a_this)->sac_handler->property
@ -4316,7 +4286,6 @@ cr_parser_parse_font_face (CRParser * a_this)
/*
*here, call the relevant SAC handler.
*/
cr_term_ref (css_expression);
if (PRIVATE (a_this)->sac_handler->property) {
PRIVATE (a_this)->sac_handler->property
(PRIVATE (a_this)->sac_handler,
@ -4387,7 +4356,7 @@ cr_parser_parse (CRParser * a_this)
{
enum CRStatus status = CR_ERROR;
g_return_val_if_fail (a_this && PRIVATE (a_this)
g_return_val_if_fail (a_this
&& PRIVATE (a_this)->tknzr, CR_BAD_PARAM_ERROR);
if (PRIVATE (a_this)->use_core_grammar == FALSE) {
@ -4409,7 +4378,7 @@ cr_parser_parse (CRParser * a_this)
enum CRStatus
cr_parser_set_tknzr (CRParser * a_this, CRTknzr * a_tknzr)
{
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
if (PRIVATE (a_this)->tknzr) {
cr_tknzr_unref (PRIVATE (a_this)->tknzr);
@ -4436,8 +4405,7 @@ cr_parser_set_tknzr (CRParser * a_this, CRTknzr * a_tknzr)
enum CRStatus
cr_parser_get_tknzr (CRParser * a_this, CRTknzr ** a_tknzr)
{
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& a_tknzr, CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this && a_tknzr, CR_BAD_PARAM_ERROR);
*a_tknzr = PRIVATE (a_this)->tknzr;
return CR_OK;
@ -4457,9 +4425,7 @@ enum CRStatus
cr_parser_get_parsing_location (CRParser const *a_this,
CRParsingLocation *a_loc)
{
g_return_val_if_fail (a_this
&& PRIVATE (a_this)
&& a_loc, CR_BAD_PARAM_ERROR) ;
g_return_val_if_fail (a_this && a_loc, CR_BAD_PARAM_ERROR);
return cr_tknzr_get_parsing_location
(PRIVATE (a_this)->tknzr, a_loc) ;
@ -4484,14 +4450,14 @@ cr_parser_parse_buf (CRParser * a_this,
enum CRStatus status = CR_ERROR;
CRTknzr *tknzr = NULL;
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& a_buf, CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this && a_buf, CR_BAD_PARAM_ERROR);
tknzr = cr_tknzr_new_from_buf ((guchar*)a_buf, a_len, a_enc, FALSE);
g_return_val_if_fail (tknzr != NULL, CR_ERROR);
status = cr_parser_set_tknzr (a_this, tknzr);
cr_tknzr_unref (tknzr);
g_return_val_if_fail (status == CR_OK, CR_ERROR);
status = cr_parser_parse (a_this);
@ -4510,7 +4476,7 @@ cr_parser_parse_buf (CRParser * a_this,
void
cr_parser_destroy (CRParser * a_this)
{
g_return_if_fail (a_this && PRIVATE (a_this));
g_return_if_fail (a_this);
if (PRIVATE (a_this)->tknzr) {
if (cr_tknzr_unref (PRIVATE (a_this)->tknzr) == TRUE)
@ -4527,13 +4493,5 @@ cr_parser_destroy (CRParser * a_this)
PRIVATE (a_this)->err_stack = NULL;
}
if (PRIVATE (a_this)) {
g_free (PRIVATE (a_this));
PRIVATE (a_this) = NULL;
}
if (a_this) {
g_free (a_this);
a_this = NULL; /*useless. Just for the sake of coherence */
}
g_free (a_this);
}

View file

@ -38,7 +38,6 @@ G_BEGIN_DECLS
*of the #CRParser class.
*/
typedef struct _CRParser CRParser ;
typedef struct _CRParserPriv CRParserPriv ;
/**
@ -49,7 +48,7 @@ typedef struct _CRParserPriv CRParserPriv ;
*the provided methods.
*/
struct _CRParser {
CRParserPriv *priv ;
gpointer dummy;
} ;

View file

@ -22,14 +22,16 @@
#include <string.h>
#include "cr-prop-list.h"
#define PRIVATE(a_obj) (a_obj)->priv
#define PRIVATE(a_obj) ((CRPropListReal *) a_obj)
typedef struct _CRPropListReal {
CRPropList parent;
struct _CRPropListPriv {
CRString *prop;
CRDeclaration *decl;
CRPropList *next;
CRPropList *prev;
};
} CRPropListReal;
static CRPropList *cr_prop_list_allocate (void);
@ -43,19 +45,11 @@ cr_prop_list_allocate (void)
{
CRPropList *result = NULL;
result = g_try_malloc (sizeof (CRPropList));
result = g_try_malloc0 (sizeof (CRPropListReal));
if (!result) {
cr_utils_trace_info ("could not allocate CRPropList");
return NULL;
}
memset (result, 0, sizeof (CRPropList));
PRIVATE (result) = g_try_malloc (sizeof (CRPropListPriv));
if (!result) {
cr_utils_trace_info ("could not allocate CRPropListPriv");
g_free (result);
return NULL;
}
memset (PRIVATE (result), 0, sizeof (CRPropListPriv));
return result;
}
@ -167,8 +161,7 @@ cr_prop_list_prepend2 (CRPropList * a_this,
CRPropList *list = NULL,
*result = NULL;
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& a_prop_name && a_decl, NULL);
g_return_val_if_fail (a_this && a_prop_name && a_decl, NULL);
list = cr_prop_list_allocate ();
g_return_val_if_fail (list, NULL);
@ -188,8 +181,7 @@ cr_prop_list_prepend2 (CRPropList * a_this,
enum CRStatus
cr_prop_list_set_prop (CRPropList * a_this, CRString * a_prop)
{
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& a_prop, CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this && a_prop, CR_BAD_PARAM_ERROR);
PRIVATE (a_this)->prop = a_prop;
return CR_OK;
@ -209,8 +201,7 @@ cr_prop_list_set_prop (CRPropList * a_this, CRString * a_prop)
enum CRStatus
cr_prop_list_get_prop (CRPropList const * a_this, CRString ** a_prop)
{
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& a_prop, CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this && a_prop, CR_BAD_PARAM_ERROR);
*a_prop = PRIVATE (a_this)->prop;
return CR_OK;
@ -226,8 +217,7 @@ cr_prop_list_get_prop (CRPropList const * a_this, CRString ** a_prop)
enum CRStatus
cr_prop_list_set_decl (CRPropList * a_this, CRDeclaration * a_decl)
{
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& a_decl, CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this && a_decl, CR_BAD_PARAM_ERROR);
PRIVATE (a_this)->decl = a_decl;
return CR_OK;
@ -243,8 +233,7 @@ cr_prop_list_set_decl (CRPropList * a_this, CRDeclaration * a_decl)
enum CRStatus
cr_prop_list_get_decl (CRPropList const * a_this, CRDeclaration ** a_decl)
{
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& a_decl, CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this && a_decl, CR_BAD_PARAM_ERROR);
*a_decl = PRIVATE (a_this)->decl;
return CR_OK;
@ -307,7 +296,7 @@ cr_prop_list_lookup_prop (CRPropList * a_this,
CRPropList *
cr_prop_list_get_next (CRPropList * a_this)
{
g_return_val_if_fail (a_this && PRIVATE (a_this), NULL);
g_return_val_if_fail (a_this, NULL);
return PRIVATE (a_this)->next;
}
@ -324,7 +313,7 @@ cr_prop_list_get_next (CRPropList * a_this)
CRPropList *
cr_prop_list_get_prev (CRPropList * a_this)
{
g_return_val_if_fail (a_this && PRIVATE (a_this), NULL);
g_return_val_if_fail (a_this, NULL);
return PRIVATE (a_this)->prev;
}
@ -344,7 +333,7 @@ cr_prop_list_unlink (CRPropList * a_this, CRPropList * a_pair)
CRPropList *prev = NULL,
*next = NULL;
g_return_val_if_fail (a_this && PRIVATE (a_this) && a_pair, NULL);
g_return_val_if_fail (a_this && a_pair, NULL);
/*some sanity checks */
if (PRIVATE (a_pair)->next) {
@ -382,10 +371,10 @@ cr_prop_list_destroy (CRPropList * a_this)
CRPropList *tail = NULL,
*cur = NULL;
g_return_if_fail (a_this && PRIVATE (a_this));
g_return_if_fail (a_this);
for (tail = a_this;
tail && PRIVATE (tail) && PRIVATE (tail)->next;
tail && PRIVATE (tail)->next;
tail = cr_prop_list_get_next (tail)) ;
g_return_if_fail (tail);
@ -393,11 +382,9 @@ cr_prop_list_destroy (CRPropList * a_this)
while (cur) {
tail = PRIVATE (cur)->prev;
if (tail && PRIVATE (tail))
if (tail)
PRIVATE (tail)->next = NULL;
PRIVATE (cur)->prev = NULL;
g_free (PRIVATE (cur));
PRIVATE (cur) = NULL;
g_free (cur);
cur = tail;
}

View file

@ -29,11 +29,10 @@
G_BEGIN_DECLS
typedef struct _CRPropList CRPropList ;
typedef struct _CRPropListPriv CRPropListPriv ;
struct _CRPropList
{
CRPropListPriv * priv;
gpointer dummy;
} ;
CRPropList * cr_prop_list_append (CRPropList *a_this,

View file

@ -192,15 +192,13 @@ cr_rgb_new (void)
{
CRRgb *result = NULL;
result = g_try_malloc (sizeof (CRRgb));
result = g_try_malloc0 (sizeof (CRRgb));
if (result == NULL) {
cr_utils_trace_info ("No more memory");
return NULL;
}
memset (result, 0, sizeof (CRRgb));
return result;
}

View file

@ -40,13 +40,13 @@ cr_selector_new (CRSimpleSel * a_simple_sel)
{
CRSelector *result = NULL;
result = g_try_malloc (sizeof (CRSelector));
result = g_try_malloc0 (sizeof (CRSelector));
if (!result) {
cr_utils_trace_info ("Out of memory");
return NULL;
}
memset (result, 0, sizeof (CRSelector));
result->simple_sel = a_simple_sel;
g_ref_count_init (&result->ref_count);
return result;
}
@ -120,7 +120,7 @@ cr_selector_append_simple_sel (CRSelector * a_this,
selector = cr_selector_new (a_simple_sel);
g_return_val_if_fail (selector, NULL);
return cr_selector_append (a_this, selector);
return cr_selector_append (a_this, g_steal_pointer (&selector));
}
guchar *
@ -200,7 +200,7 @@ cr_selector_ref (CRSelector * a_this)
{
g_return_if_fail (a_this);
a_this->ref_count++;
g_ref_count_inc (&a_this->ref_count);
}
/**
@ -221,11 +221,7 @@ cr_selector_unref (CRSelector * a_this)
{
g_return_val_if_fail (a_this, FALSE);
if (a_this->ref_count) {
a_this->ref_count--;
}
if (a_this->ref_count == 0) {
if (g_ref_count_dec (&a_this->ref_count)) {
cr_selector_destroy (a_this);
return TRUE;
}

View file

@ -65,7 +65,7 @@ struct _CRSelector
CRSelector *next ;
CRSelector *prev ;
CRParsingLocation location ;
glong ref_count ;
grefcount ref_count;
};
CRSelector* cr_selector_new (CRSimpleSel *a_sel_expr) ;

View file

@ -37,12 +37,11 @@ cr_simple_sel_new (void)
{
CRSimpleSel *result = NULL;
result = g_try_malloc (sizeof (CRSimpleSel));
result = g_try_malloc0 (sizeof (CRSimpleSel));
if (!result) {
cr_utils_trace_info ("Out of memory");
return NULL;
}
memset (result, 0, sizeof (CRSimpleSel));
return result;
}

View file

@ -204,7 +204,8 @@ parse_page_property_cb (CRDocHandler * a_this,
g_return_if_fail (decl);
decl->important = a_important;
stmt->kind.page_rule->decl_list =
cr_declaration_append (stmt->kind.page_rule->decl_list, decl);
cr_declaration_append (stmt->kind.page_rule->decl_list,
g_steal_pointer (&decl));
g_return_if_fail (stmt->kind.page_rule->decl_list);
}
@ -235,7 +236,7 @@ parse_at_media_start_media_cb (CRDocHandler * a_this,
CRStatement *at_media = NULL;
GList *media_list = NULL;
g_return_if_fail (a_this && a_this->priv);
g_return_if_fail (a_this);
if (a_media_list) {
/*duplicate media list */
@ -287,7 +288,7 @@ parse_at_media_start_selector_cb (CRDocHandler * a_this,
CRStatement **at_media_ptr = NULL;
CRStatement *ruleset = NULL;
g_return_if_fail (a_this && a_this->priv && a_sellist);
g_return_if_fail (a_this && a_sellist);
at_media_ptr = &at_media;
status = cr_doc_handler_get_ctxt (a_this, (gpointer *) at_media_ptr);
@ -367,7 +368,7 @@ parse_at_media_end_media_cb (CRDocHandler * a_this,
CRStatement *at_media = NULL;
CRStatement **at_media_ptr = NULL;
g_return_if_fail (a_this && a_this->priv);
g_return_if_fail (a_this);
at_media_ptr = &at_media;
status = cr_doc_handler_get_ctxt (a_this,
@ -382,7 +383,7 @@ parse_ruleset_start_selector_cb (CRDocHandler * a_this,
{
CRStatement *ruleset = NULL;
g_return_if_fail (a_this && a_this->priv && a_sellist);
g_return_if_fail (a_this && a_sellist);
ruleset = cr_statement_new_ruleset (NULL, a_sellist, NULL, NULL);
g_return_if_fail (ruleset);
@ -422,7 +423,7 @@ parse_ruleset_property_cb (CRDocHandler * a_this,
CRDeclaration *decl = NULL;
CRString *stringue = NULL;
g_return_if_fail (a_this && a_this->priv && a_name);
g_return_if_fail (a_this && a_name);
stringue = cr_string_dup (a_name);
g_return_if_fail (stringue);
@ -1124,7 +1125,7 @@ cr_statement_new_ruleset (CRStyleSheet * a_sheet,
NULL);
}
result = g_try_malloc (sizeof (CRStatement));
result = g_try_malloc0 (sizeof (CRStatement));
if (!result) {
cr_utils_trace_info ("Out of memory");
@ -1133,7 +1134,7 @@ cr_statement_new_ruleset (CRStyleSheet * a_sheet,
memset (result, 0, sizeof (CRStatement));
result->type = RULESET_STMT;
result->kind.ruleset = g_try_malloc (sizeof (CRRuleSet));
result->kind.ruleset = g_try_malloc0 (sizeof (CRRuleSet));
if (!result->kind.ruleset) {
cr_utils_trace_info ("Out of memory");
@ -1142,7 +1143,6 @@ cr_statement_new_ruleset (CRStyleSheet * a_sheet,
return NULL;
}
memset (result->kind.ruleset, 0, sizeof (CRRuleSet));
result->kind.ruleset->sel_list = a_sel_list;
if (a_sel_list)
cr_selector_ref (a_sel_list);
@ -1259,23 +1259,21 @@ cr_statement_new_at_media_rule (CRStyleSheet * a_sheet,
if (a_rulesets)
g_return_val_if_fail (a_rulesets->type == RULESET_STMT, NULL);
result = g_try_malloc (sizeof (CRStatement));
result = g_try_malloc0 (sizeof (CRStatement));
if (!result) {
cr_utils_trace_info ("Out of memory");
return NULL;
}
memset (result, 0, sizeof (CRStatement));
result->type = AT_MEDIA_RULE_STMT;
result->kind.media_rule = g_try_malloc (sizeof (CRAtMediaRule));
result->kind.media_rule = g_try_malloc0 (sizeof (CRAtMediaRule));
if (!result->kind.media_rule) {
cr_utils_trace_info ("Out of memory");
g_free (result);
return NULL;
}
memset (result->kind.media_rule, 0, sizeof (CRAtMediaRule));
result->kind.media_rule->rulesets = a_rulesets;
for (cur = a_rulesets; cur; cur = cur->next) {
if (cur->type != RULESET_STMT || !cur->kind.ruleset) {
@ -1318,17 +1316,16 @@ cr_statement_new_at_import_rule (CRStyleSheet * a_container_sheet,
{
CRStatement *result = NULL;
result = g_try_malloc (sizeof (CRStatement));
result = g_try_malloc0 (sizeof (CRStatement));
if (!result) {
cr_utils_trace_info ("Out of memory");
return NULL;
}
memset (result, 0, sizeof (CRStatement));
result->type = AT_IMPORT_RULE_STMT;
result->kind.import_rule = g_try_malloc (sizeof (CRAtImportRule));
result->kind.import_rule = g_try_malloc0 (sizeof (CRAtImportRule));
if (!result->kind.import_rule) {
cr_utils_trace_info ("Out of memory");
@ -1336,7 +1333,6 @@ cr_statement_new_at_import_rule (CRStyleSheet * a_container_sheet,
return NULL;
}
memset (result->kind.import_rule, 0, sizeof (CRAtImportRule));
result->kind.import_rule->url = a_url;
result->kind.import_rule->media_list = a_media_list;
result->kind.import_rule->sheet = a_imported_sheet;
@ -1441,17 +1437,16 @@ cr_statement_new_at_page_rule (CRStyleSheet * a_sheet,
{
CRStatement *result = NULL;
result = g_try_malloc (sizeof (CRStatement));
result = g_try_malloc0 (sizeof (CRStatement));
if (!result) {
cr_utils_trace_info ("Out of memory");
return NULL;
}
memset (result, 0, sizeof (CRStatement));
result->type = AT_PAGE_RULE_STMT;
result->kind.page_rule = g_try_malloc (sizeof (CRAtPageRule));
result->kind.page_rule = g_try_malloc0 (sizeof (CRAtPageRule));
if (!result->kind.page_rule) {
cr_utils_trace_info ("Out of memory");
@ -1459,7 +1454,6 @@ cr_statement_new_at_page_rule (CRStyleSheet * a_sheet,
return NULL;
}
memset (result->kind.page_rule, 0, sizeof (CRAtPageRule));
if (a_decl_list) {
result->kind.page_rule->decl_list = a_decl_list;
cr_declaration_ref (a_decl_list);
@ -1566,24 +1560,22 @@ cr_statement_new_at_charset_rule (CRStyleSheet * a_sheet,
g_return_val_if_fail (a_charset, NULL);
result = g_try_malloc (sizeof (CRStatement));
result = g_try_malloc0 (sizeof (CRStatement));
if (!result) {
cr_utils_trace_info ("Out of memory");
return NULL;
}
memset (result, 0, sizeof (CRStatement));
result->type = AT_CHARSET_RULE_STMT;
result->kind.charset_rule = g_try_malloc (sizeof (CRAtCharsetRule));
result->kind.charset_rule = g_try_malloc0 (sizeof (CRAtCharsetRule));
if (!result->kind.charset_rule) {
cr_utils_trace_info ("Out of memory");
g_free (result);
return NULL;
}
memset (result->kind.charset_rule, 0, sizeof (CRAtCharsetRule));
result->kind.charset_rule->charset = a_charset;
cr_statement_set_parent_sheet (result, a_sheet);
@ -1660,13 +1652,12 @@ cr_statement_new_at_font_face_rule (CRStyleSheet * a_sheet,
{
CRStatement *result = NULL;
result = g_try_malloc (sizeof (CRStatement));
result = g_try_malloc0 (sizeof (CRStatement));
if (!result) {
cr_utils_trace_info ("Out of memory");
return NULL;
}
memset (result, 0, sizeof (CRStatement));
result->type = AT_FONT_FACE_RULE_STMT;
result->kind.font_face_rule = g_try_malloc

View file

@ -34,12 +34,11 @@ cr_string_new (void)
{
CRString *result = NULL ;
result = g_try_malloc (sizeof (CRString)) ;
result = g_try_malloc0 (sizeof (CRString)) ;
if (!result) {
cr_utils_trace_info ("Out of memory") ;
return NULL ;
}
memset (result, 0, sizeof (CRString)) ;
result->stryng = g_string_new (NULL) ;
return result ;
}

View file

@ -28,6 +28,27 @@
*The definition of the #CRStyleSheet class
*/
typedef struct {
CRStyleSheet stylesheet;
/**
*the reference count of this instance of #CRStyleSheet.
*It can be manipulated with cr_stylesheet_ref() and
*cr_stylesheet_unref()
*/
grefcount ref_count;
/**
*custom application data pointer
*Can be used by applications.
*libcroco itself will handle its destruction
*if app_data_destroy_func is set via
*cr_stylesheet_set_app_data().
*/
gpointer app_data;
GDestroyNotify app_data_destroy_func;
} CRStyleSheetReal;
/**
*Constructor of the #CRStyleSheet class.
*@param the initial list of css statements.
@ -37,14 +58,16 @@ CRStyleSheet *
cr_stylesheet_new (CRStatement * a_stmts)
{
CRStyleSheet *result;
CRStyleSheetReal *real;
result = g_try_malloc (sizeof (CRStyleSheet));
result = g_try_malloc0 (sizeof (CRStyleSheetReal));
if (!result) {
cr_utils_trace_info ("Out of memory");
return NULL;
}
memset (result, 0, sizeof (CRStyleSheet));
real = (CRStyleSheetReal *) result;
g_ref_count_init (&real->ref_count);
if (a_stmts)
result->statements = a_stmts;
@ -136,23 +159,24 @@ cr_stylesheet_statement_get_from_list (CRStyleSheet * a_this, int itemnr)
return cr_statement_get_from_list (a_this->statements, itemnr);
}
void
CRStyleSheet *
cr_stylesheet_ref (CRStyleSheet * a_this)
{
g_return_if_fail (a_this);
CRStyleSheetReal *real = (CRStyleSheetReal *) a_this;
a_this->ref_count++;
g_return_val_if_fail (a_this, NULL);
g_ref_count_inc (&real->ref_count);
return a_this;
}
gboolean
cr_stylesheet_unref (CRStyleSheet * a_this)
{
g_return_val_if_fail (a_this, FALSE);
CRStyleSheetReal *real = (CRStyleSheetReal *) a_this;
if (a_this->ref_count)
a_this->ref_count--;
if (!a_this->ref_count) {
if (g_ref_count_dec (&real->ref_count)) {
cr_stylesheet_destroy (a_this);
return TRUE;
}
@ -160,6 +184,15 @@ cr_stylesheet_unref (CRStyleSheet * a_this)
return FALSE;
}
static void
cleanup_app_data (CRStyleSheetReal * real)
{
if (real->app_data_destroy_func) {
g_clear_pointer (&real->app_data, real->app_data_destroy_func);
real->app_data_destroy_func = NULL;
}
}
/**
*Destructor of the #CRStyleSheet class.
*@param a_this the current instance of the #CRStyleSheet class.
@ -167,11 +200,40 @@ cr_stylesheet_unref (CRStyleSheet * a_this)
void
cr_stylesheet_destroy (CRStyleSheet * a_this)
{
CRStyleSheetReal *real = (CRStyleSheetReal *) a_this;
g_return_if_fail (a_this);
if (a_this->statements) {
cr_statement_destroy (a_this->statements);
a_this->statements = NULL;
}
cleanup_app_data (real);
g_free (a_this);
}
void
cr_stylesheet_set_app_data (CRStyleSheet * a_this,
gpointer app_data,
GDestroyNotify app_data_destroy_func)
{
CRStyleSheetReal *real = (CRStyleSheetReal *) a_this;
g_return_if_fail (a_this);
cleanup_app_data (real);
real->app_data = app_data;
real->app_data_destroy_func = app_data_destroy_func;
}
gpointer
cr_stylesheet_get_app_data (CRStyleSheet *a_this)
{
CRStyleSheetReal *real = (CRStyleSheetReal *) a_this;
g_return_val_if_fail (a_this, NULL);
return real->app_data;
}

View file

@ -34,7 +34,6 @@ G_BEGIN_DECLS
*The declaration of the #CRStyleSheet class.
*/
enum CRStyleOrigin
{
/*Please don't change the order of
@ -66,20 +65,6 @@ struct _CRStyleSheet
/**custom data used by libcroco*/
gpointer croco_data ;
/**
*custom application data pointer
*Can be used by applications.
*/
gpointer app_data ;
/**
*the reference count of this instance
*Please, don't never ever modify it
*directly. Use cr_stylesheet_ref()
*and cr_stylesheet_unref() instead.
*/
gulong ref_count ;
} ;
CRStyleSheet * cr_stylesheet_new (CRStatement *a_stmts) ;
@ -91,12 +76,17 @@ gint cr_stylesheet_nr_rules (CRStyleSheet const *a_this) ;
CRStatement * cr_stylesheet_statement_get_from_list (CRStyleSheet *a_this, int itemnr) ;
void cr_stylesheet_ref (CRStyleSheet *a_this) ;
CRStyleSheet * cr_stylesheet_ref (CRStyleSheet *a_this) ;
gboolean cr_stylesheet_unref (CRStyleSheet *a_this) ;
void cr_stylesheet_destroy (CRStyleSheet *a_this) ;
void cr_stylesheet_set_app_data (CRStyleSheet *a_this, gpointer app_data, GDestroyNotify app_data_destroy_func);
gpointer cr_stylesheet_get_app_data (CRStyleSheet *a_this);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (CRStyleSheet, cr_stylesheet_unref);
G_END_DECLS
#endif /*__CR_STYLESHEET_H__*/

View file

@ -86,12 +86,12 @@ cr_term_new (void)
{
CRTerm *result = NULL;
result = g_try_malloc (sizeof (CRTerm));
result = g_try_malloc0 (sizeof (CRTerm));
if (!result) {
cr_utils_trace_info ("Out of memory");
return NULL;
}
memset (result, 0, sizeof (CRTerm));
g_ref_count_init (&result->ref_count);
return result;
}
@ -735,7 +735,7 @@ cr_term_ref (CRTerm * a_this)
{
g_return_if_fail (a_this);
a_this->ref_count++;
g_ref_count_inc (&a_this->ref_count);
}
/**
@ -750,11 +750,7 @@ cr_term_unref (CRTerm * a_this)
{
g_return_val_if_fail (a_this, FALSE);
if (a_this->ref_count) {
a_this->ref_count--;
}
if (a_this->ref_count == 0) {
if (g_ref_count_dec (&a_this->ref_count)) {
cr_term_destroy (a_this);
return TRUE;
}

View file

@ -128,7 +128,7 @@ struct _CRTerm
*/
gpointer app_data ;
glong ref_count ;
grefcount ref_count ;
/**
*A pointer to the next term,

View file

@ -31,7 +31,9 @@
#include "cr-tknzr.h"
#include "cr-doc-handler.h"
struct _CRTknzrPriv {
typedef struct _CRTknzrReal {
CRTknzr parent;
/**The parser input stream of bytes*/
CRInput *input;
@ -57,10 +59,10 @@ struct _CRTknzrPriv {
*of #CRTknzr. Is manipulated by cr_tknzr_ref()
*and cr_tknzr_unref().
*/
glong ref_count;
};
grefcount ref_count;
} CRTknzrReal;
#define PRIVATE(obj) ((obj)->priv)
#define PRIVATE(obj) ((CRTknzrReal *) obj)
/**
*return TRUE if the character is a number ([0-9]), FALSE otherwise
@ -267,8 +269,7 @@ cr_tknzr_parse_w (CRTknzr * a_this,
CRInputPos init_pos;
enum CRStatus status = CR_OK;
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& PRIVATE (a_this)->input
g_return_val_if_fail (a_this && PRIVATE (a_this)->input
&& a_start && a_end,
CR_BAD_PARAM_ERROR);
@ -341,7 +342,7 @@ cr_tknzr_parse_nl (CRTknzr * a_this,
guchar next_chars[2] = { 0 };
enum CRStatus status = CR_PARSING_ERROR;
g_return_val_if_fail (a_this && PRIVATE (a_this)
g_return_val_if_fail (a_this
&& a_start && a_end, CR_BAD_PARAM_ERROR);
RECORD_INITIAL_POS (a_this, &init_pos);
@ -395,8 +396,7 @@ cr_tknzr_try_to_skip_spaces (CRTknzr * a_this)
enum CRStatus status = CR_ERROR;
guint32 cur_char = 0;
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& PRIVATE (a_this)->input, CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this && PRIVATE (a_this)->input, CR_BAD_PARAM_ERROR);
status = cr_input_peek_char (PRIVATE (a_this)->input, &cur_char);
@ -435,8 +435,7 @@ cr_tknzr_parse_comment (CRTknzr * a_this,
CRString *comment = NULL;
CRParsingLocation loc = {0} ;
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& PRIVATE (a_this)->input,
g_return_val_if_fail (a_this && PRIVATE (a_this)->input,
CR_BAD_PARAM_ERROR);
RECORD_INITIAL_POS (a_this, &init_pos);
@ -538,8 +537,7 @@ cr_tknzr_parse_unicode_escape (CRTknzr * a_this,
*tmp_char_ptr2 = NULL;
enum CRStatus status = CR_OK;
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& a_unicode, CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this && a_unicode, CR_BAD_PARAM_ERROR);
/*first, let's backup the current position pointer */
RECORD_INITIAL_POS (a_this, &init_pos);
@ -607,8 +605,7 @@ cr_tknzr_parse_escape (CRTknzr * a_this, guint32 * a_esc_code,
CRInputPos init_pos;
guchar next_chars[2];
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& a_esc_code, CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this && a_esc_code, CR_BAD_PARAM_ERROR);
RECORD_INITIAL_POS (a_this, &init_pos);
@ -674,8 +671,7 @@ cr_tknzr_parse_string (CRTknzr * a_this, CRString ** a_str)
enum CRStatus status = CR_OK;
CRString *str = NULL;
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& PRIVATE (a_this)->input
g_return_val_if_fail (a_this && PRIVATE (a_this)->input
&& a_str, CR_BAD_PARAM_ERROR);
RECORD_INITIAL_POS (a_this, &init_pos);
@ -801,8 +797,7 @@ cr_tknzr_parse_nmstart (CRTknzr * a_this,
guint32 cur_char = 0,
next_char = 0;
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& PRIVATE (a_this)->input
g_return_val_if_fail (a_this && PRIVATE (a_this)->input
&& a_char, CR_BAD_PARAM_ERROR);
RECORD_INITIAL_POS (a_this, &init_pos);
@ -867,7 +862,7 @@ cr_tknzr_parse_nmchar (CRTknzr * a_this, guint32 * a_char,
enum CRStatus status = CR_OK;
CRInputPos init_pos;
g_return_val_if_fail (a_this && PRIVATE (a_this) && a_char,
g_return_val_if_fail (a_this && a_char,
CR_BAD_PARAM_ERROR);
RECORD_INITIAL_POS (a_this, &init_pos);
@ -934,8 +929,7 @@ cr_tknzr_parse_ident (CRTknzr * a_this, CRString ** a_str)
enum CRStatus status = CR_OK;
gboolean location_is_set = FALSE ;
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& PRIVATE (a_this)->input
g_return_val_if_fail (a_this && PRIVATE (a_this)->input
&& a_str, CR_BAD_PARAM_ERROR);
RECORD_INITIAL_POS (a_this, &init_pos);
@ -1024,9 +1018,7 @@ cr_tknzr_parse_name (CRTknzr * a_this,
glong i = 0;
CRParsingLocation loc = {0} ;
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& PRIVATE (a_this)->input
&& a_str,
g_return_val_if_fail (a_this && PRIVATE (a_this)->input && a_str,
CR_BAD_PARAM_ERROR) ;
RECORD_INITIAL_POS (a_this, &init_pos);
@ -1076,8 +1068,7 @@ cr_tknzr_parse_hash (CRTknzr * a_this, CRString ** a_str)
gboolean str_needs_free = FALSE;
CRParsingLocation loc = {0} ;
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& PRIVATE (a_this)->input,
g_return_val_if_fail (a_this && PRIVATE (a_this)->input,
CR_BAD_PARAM_ERROR);
RECORD_INITIAL_POS (a_this, &init_pos);
@ -1130,8 +1121,7 @@ cr_tknzr_parse_uri (CRTknzr * a_this,
CRParsingLocation location = {0} ;
g_return_val_if_fail (a_this
&& PRIVATE (a_this)
&& PRIVATE (a_this)->input
&& PRIVATE (a_this)->input
&& a_str,
CR_BAD_PARAM_ERROR);
@ -1254,7 +1244,7 @@ cr_tknzr_parse_rgb (CRTknzr * a_this, CRRgb ** a_rgb)
gboolean is_percentage = FALSE;
CRParsingLocation location = {0} ;
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
RECORD_INITIAL_POS (a_this, &init_pos);
@ -1389,8 +1379,7 @@ cr_tknzr_parse_atkeyword (CRTknzr * a_this,
gboolean str_needs_free = FALSE;
enum CRStatus status = CR_OK;
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& PRIVATE (a_this)->input
g_return_val_if_fail (a_this && PRIVATE (a_this)->input
&& a_str, CR_BAD_PARAM_ERROR);
RECORD_INITIAL_POS (a_this, &init_pos);
@ -1429,8 +1418,7 @@ cr_tknzr_parse_important (CRTknzr * a_this,
CRInputPos init_pos;
enum CRStatus status = CR_OK;
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& PRIVATE (a_this)->input,
g_return_val_if_fail (a_this && PRIVATE (a_this)->input,
CR_BAD_PARAM_ERROR);
RECORD_INITIAL_POS (a_this, &init_pos);
@ -1497,8 +1485,7 @@ cr_tknzr_parse_num (CRTknzr * a_this,
CRParsingLocation location = {0} ;
int sign = 1;
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& PRIVATE (a_this)->input,
g_return_val_if_fail (a_this && PRIVATE (a_this)->input,
CR_BAD_PARAM_ERROR);
RECORD_INITIAL_POS (a_this, &init_pos);
@ -1596,28 +1583,15 @@ cr_tknzr_new (CRInput * a_input)
{
CRTknzr *result = NULL;
result = g_try_malloc (sizeof (CRTknzr));
result = g_try_malloc0 (sizeof (CRTknzrReal));
if (result == NULL) {
cr_utils_trace_info ("Out of memory");
return NULL;
}
memset (result, 0, sizeof (CRTknzr));
g_ref_count_init (&PRIVATE (result)->ref_count);
result->priv = g_try_malloc (sizeof (CRTknzrPriv));
if (result->priv == NULL) {
cr_utils_trace_info ("Out of memory");
if (result) {
g_free (result);
result = NULL;
}
return NULL;
}
memset (result->priv, 0, sizeof (CRTknzrPriv));
if (a_input)
cr_tknzr_set_input (result, a_input);
return result;
@ -1637,6 +1611,7 @@ cr_tknzr_new_from_buf (guchar * a_buf, gulong a_len,
g_return_val_if_fail (input != NULL, NULL);
result = cr_tknzr_new (input);
g_clear_pointer (&input, cr_input_unref);
return result;
}
@ -1652,6 +1627,7 @@ cr_tknzr_new_from_uri (const guchar * a_file_uri,
g_return_val_if_fail (input != NULL, NULL);
result = cr_tknzr_new (input);
g_clear_pointer (&input, cr_input_unref);
return result;
}
@ -1659,21 +1635,17 @@ cr_tknzr_new_from_uri (const guchar * a_file_uri,
void
cr_tknzr_ref (CRTknzr * a_this)
{
g_return_if_fail (a_this && PRIVATE (a_this));
g_return_if_fail (a_this);
PRIVATE (a_this)->ref_count++;
g_ref_count_inc (&PRIVATE (a_this)->ref_count);
}
gboolean
cr_tknzr_unref (CRTknzr * a_this)
{
g_return_val_if_fail (a_this && PRIVATE (a_this), FALSE);
g_return_val_if_fail (a_this, FALSE);
if (PRIVATE (a_this)->ref_count > 0) {
PRIVATE (a_this)->ref_count--;
}
if (PRIVATE (a_this)->ref_count == 0) {
if (g_ref_count_dec (&PRIVATE (a_this)->ref_count)) {
cr_tknzr_destroy (a_this);
return TRUE;
}
@ -1684,7 +1656,7 @@ cr_tknzr_unref (CRTknzr * a_this)
enum CRStatus
cr_tknzr_set_input (CRTknzr * a_this, CRInput * a_input)
{
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
if (PRIVATE (a_this)->input) {
cr_input_unref (PRIVATE (a_this)->input);
@ -1700,7 +1672,7 @@ cr_tknzr_set_input (CRTknzr * a_this, CRInput * a_input)
enum CRStatus
cr_tknzr_get_input (CRTknzr * a_this, CRInput ** a_input)
{
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
*a_input = PRIVATE (a_this)->input;
@ -1723,7 +1695,7 @@ cr_tknzr_get_input (CRTknzr * a_this, CRInput ** a_input)
enum CRStatus
cr_tknzr_read_byte (CRTknzr * a_this, guchar * a_byte)
{
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
return cr_input_read_byte (PRIVATE (a_this)->input, a_byte);
@ -1739,8 +1711,7 @@ cr_tknzr_read_byte (CRTknzr * a_this, guchar * a_byte)
enum CRStatus
cr_tknzr_read_char (CRTknzr * a_this, guint32 * a_char)
{
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& PRIVATE (a_this)->input
g_return_val_if_fail (a_this && PRIVATE (a_this)->input
&& a_char, CR_BAD_PARAM_ERROR);
if (PRIVATE (a_this)->token_cache) {
@ -1764,8 +1735,7 @@ cr_tknzr_read_char (CRTknzr * a_this, guint32 * a_char)
enum CRStatus
cr_tknzr_peek_char (CRTknzr * a_this, guint32 * a_char)
{
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& PRIVATE (a_this)->input
g_return_val_if_fail (a_this && PRIVATE (a_this)->input
&& a_char, CR_BAD_PARAM_ERROR);
if (PRIVATE (a_this)->token_cache) {
@ -1790,8 +1760,7 @@ cr_tknzr_peek_char (CRTknzr * a_this, guint32 * a_char)
enum CRStatus
cr_tknzr_peek_byte (CRTknzr * a_this, gulong a_offset, guchar * a_byte)
{
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& PRIVATE (a_this)->input && a_byte,
g_return_val_if_fail (a_this && PRIVATE (a_this)->input && a_byte,
CR_BAD_PARAM_ERROR);
if (PRIVATE (a_this)->token_cache) {
@ -1818,8 +1787,7 @@ cr_tknzr_peek_byte (CRTknzr * a_this, gulong a_offset, guchar * a_byte)
guchar
cr_tknzr_peek_byte2 (CRTknzr * a_this, gulong a_offset, gboolean * a_eof)
{
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& PRIVATE (a_this)->input, 0);
g_return_val_if_fail (a_this && PRIVATE (a_this)->input, 0);
return cr_input_peek_byte2 (PRIVATE (a_this)->input, a_offset, a_eof);
}
@ -1833,8 +1801,7 @@ cr_tknzr_peek_byte2 (CRTknzr * a_this, gulong a_offset, gboolean * a_eof)
glong
cr_tknzr_get_nb_bytes_left (CRTknzr * a_this)
{
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& PRIVATE (a_this)->input, CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this && PRIVATE (a_this)->input, CR_BAD_PARAM_ERROR);
if (PRIVATE (a_this)->token_cache) {
cr_input_set_cur_pos (PRIVATE (a_this)->input,
@ -1849,8 +1816,7 @@ cr_tknzr_get_nb_bytes_left (CRTknzr * a_this)
enum CRStatus
cr_tknzr_get_cur_pos (CRTknzr * a_this, CRInputPos * a_pos)
{
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& PRIVATE (a_this)->input
g_return_val_if_fail (a_this && PRIVATE (a_this)->input
&& a_pos, CR_BAD_PARAM_ERROR);
if (PRIVATE (a_this)->token_cache) {
@ -1867,10 +1833,7 @@ enum CRStatus
cr_tknzr_get_parsing_location (CRTknzr *a_this,
CRParsingLocation *a_loc)
{
g_return_val_if_fail (a_this
&& PRIVATE (a_this)
&& a_loc,
CR_BAD_PARAM_ERROR) ;
g_return_val_if_fail (a_this && a_loc, CR_BAD_PARAM_ERROR) ;
return cr_input_get_parsing_location
(PRIVATE (a_this)->input, a_loc) ;
@ -1879,8 +1842,7 @@ cr_tknzr_get_parsing_location (CRTknzr *a_this,
enum CRStatus
cr_tknzr_get_cur_byte_addr (CRTknzr * a_this, guchar ** a_addr)
{
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& PRIVATE (a_this)->input, CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this && PRIVATE (a_this)->input, CR_BAD_PARAM_ERROR);
if (PRIVATE (a_this)->token_cache) {
cr_input_set_cur_pos (PRIVATE (a_this)->input,
&PRIVATE (a_this)->prev_pos);
@ -1894,8 +1856,7 @@ cr_tknzr_get_cur_byte_addr (CRTknzr * a_this, guchar ** a_addr)
enum CRStatus
cr_tknzr_seek_index (CRTknzr * a_this, enum CRSeekPos a_origin, gint a_pos)
{
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& PRIVATE (a_this)->input, CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this && PRIVATE (a_this)->input, CR_BAD_PARAM_ERROR);
if (PRIVATE (a_this)->token_cache) {
cr_input_set_cur_pos (PRIVATE (a_this)->input,
@ -1912,8 +1873,7 @@ cr_tknzr_consume_chars (CRTknzr * a_this, guint32 a_char, glong * a_nb_char)
{
gulong consumed = *(gulong *) a_nb_char;
enum CRStatus status;
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& PRIVATE (a_this)->input, CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this && PRIVATE (a_this)->input, CR_BAD_PARAM_ERROR);
if (PRIVATE (a_this)->token_cache) {
cr_input_set_cur_pos (PRIVATE (a_this)->input,
@ -1931,8 +1891,7 @@ cr_tknzr_consume_chars (CRTknzr * a_this, guint32 a_char, glong * a_nb_char)
enum CRStatus
cr_tknzr_set_cur_pos (CRTknzr * a_this, CRInputPos * a_pos)
{
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& PRIVATE (a_this)->input, CR_BAD_PARAM_ERROR);
g_return_val_if_fail (a_this && PRIVATE (a_this)->input, CR_BAD_PARAM_ERROR);
if (PRIVATE (a_this)->token_cache) {
cr_token_destroy (PRIVATE (a_this)->token_cache);
@ -1945,8 +1904,7 @@ cr_tknzr_set_cur_pos (CRTknzr * a_this, CRInputPos * a_pos)
enum CRStatus
cr_tknzr_unget_token (CRTknzr * a_this, CRToken * a_token)
{
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& PRIVATE (a_this)->token_cache == NULL,
g_return_val_if_fail (a_this && PRIVATE (a_this)->token_cache == NULL,
CR_BAD_PARAM_ERROR);
PRIVATE (a_this)->token_cache = a_token;
@ -1979,9 +1937,9 @@ cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk)
CRRgb *rgb = NULL;
CRParsingLocation location = {0} ;
g_return_val_if_fail (a_this && PRIVATE (a_this)
g_return_val_if_fail (a_this
&& a_tk && *a_tk == NULL
&& PRIVATE (a_this)->input,
&& PRIVATE (a_this)->input,
CR_BAD_PARAM_ERROR);
if (PRIVATE (a_this)->token_cache) {
@ -2633,8 +2591,7 @@ cr_tknzr_parse_token (CRTknzr * a_this, enum CRTokenType a_type,
enum CRStatus status = CR_OK;
CRToken *token = NULL;
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& PRIVATE (a_this)->input
g_return_val_if_fail (a_this && PRIVATE (a_this)->input
&& a_res, CR_BAD_PARAM_ERROR);
status = cr_tknzr_get_next_token (a_this, &token);
@ -2741,7 +2698,7 @@ cr_tknzr_destroy (CRTknzr * a_this)
{
g_return_if_fail (a_this);
if (PRIVATE (a_this) && PRIVATE (a_this)->input) {
if (PRIVATE (a_this)->input) {
if (cr_input_unref (PRIVATE (a_this)->input)
== TRUE) {
PRIVATE (a_this)->input = NULL;
@ -2753,10 +2710,5 @@ cr_tknzr_destroy (CRTknzr * a_this)
PRIVATE (a_this)->token_cache = NULL;
}
if (PRIVATE (a_this)) {
g_free (PRIVATE (a_this));
PRIVATE (a_this) = NULL;
}
g_free (a_this);
}

View file

@ -38,7 +38,6 @@ G_BEGIN_DECLS
typedef struct _CRTknzr CRTknzr ;
typedef struct _CRTknzrPriv CRTknzrPriv ;
/**
*The tokenizer is the class that knows
@ -48,8 +47,7 @@ typedef struct _CRTknzrPriv CRTknzrPriv ;
*/
struct _CRTknzr
{
/*the private data of the tokenizer.*/
CRTknzrPriv *priv ;
gpointer dummy;
} ;
CRTknzr * cr_tknzr_new (CRInput *a_input) ;

View file

@ -135,15 +135,13 @@ cr_token_new (void)
{
CRToken *result = NULL;
result = g_try_malloc (sizeof (CRToken));
result = g_try_malloc0 (sizeof (CRToken));
if (result == NULL) {
cr_utils_trace_info ("Out of memory");
return NULL;
}
memset (result, 0, sizeof (CRToken));
return result;
}

View file

@ -64,14 +64,25 @@ struct _StTheme
GFile *application_stylesheet;
GFile *default_stylesheet;
GFile *theme_stylesheet;
GSList *custom_stylesheets;
GHashTable *stylesheets_by_file;
GHashTable *files_by_stylesheet;
CRCascade *cascade;
};
typedef struct _StyleSheetData
{
GFile *file;
gboolean extension_stylesheet;
} StyleSheetData;
static void
stylesheet_data_free (StyleSheetData *stylesheet_data)
{
g_clear_object (&stylesheet_data->file);
g_free (stylesheet_data);
}
enum
{
PROP_0,
@ -110,9 +121,10 @@ file_equal0 (GFile *file1,
static void
st_theme_init (StTheme *theme)
{
theme->stylesheets_by_file = g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal,
(GDestroyNotify)g_object_unref, (GDestroyNotify)cr_stylesheet_unref);
theme->files_by_stylesheet = g_hash_table_new (g_direct_hash, g_direct_equal);
theme->stylesheets_by_file =
g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal,
(GDestroyNotify) g_object_unref,
(GDestroyNotify) cr_stylesheet_unref);
}
static void
@ -182,7 +194,7 @@ parse_stylesheet (GFile *file,
{
enum CRStatus status;
CRStyleSheet *stylesheet;
char *contents;
g_autofree char *contents = NULL;
gsize length;
if (file == NULL)
@ -195,20 +207,14 @@ parse_stylesheet (GFile *file,
length,
CR_UTF_8,
&stylesheet);
g_free (contents);
if (status != CR_OK)
{
char *uri = g_file_get_uri (file);
g_autofree char *uri = g_file_get_uri (file);
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Error parsing stylesheet '%s'; errcode:%d", uri, status);
g_free (uri);
return NULL;
}
/* Extension stylesheet */
stylesheet->app_data = GUINT_TO_POINTER (FALSE);
return stylesheet;
}
@ -235,19 +241,28 @@ parse_stylesheet_nofail (GFile *file)
return result;
}
static void
static gboolean
insert_stylesheet (StTheme *theme,
GFile *file,
CRStyleSheet *stylesheet)
{
StyleSheetData *stylesheet_data;
if (stylesheet == NULL)
return;
return FALSE;
g_object_ref (file);
cr_stylesheet_ref (stylesheet);
if (g_hash_table_contains (theme->stylesheets_by_file, file))
return FALSE;
g_hash_table_insert (theme->stylesheets_by_file, file, stylesheet);
g_hash_table_insert (theme->files_by_stylesheet, stylesheet, file);
stylesheet_data = g_new0 (StyleSheetData, 1);
stylesheet_data->file = g_object_ref (file);
cr_stylesheet_set_app_data (stylesheet, stylesheet_data,
(GDestroyNotify) stylesheet_data_free);
g_hash_table_insert (theme->stylesheets_by_file,
g_object_ref (file), cr_stylesheet_ref (stylesheet));
return TRUE;
}
/**
@ -265,17 +280,16 @@ st_theme_load_stylesheet (StTheme *theme,
GFile *file,
GError **error)
{
CRStyleSheet *stylesheet;
g_autoptr(CRStyleSheet) stylesheet = NULL;
StyleSheetData *stylesheet_data;
stylesheet = parse_stylesheet (file, error);
if (!stylesheet)
if (!insert_stylesheet (theme, file, stylesheet))
return FALSE;
stylesheet->app_data = GUINT_TO_POINTER (TRUE);
stylesheet_data = cr_stylesheet_get_app_data (stylesheet);
stylesheet_data->extension_stylesheet = TRUE;
insert_stylesheet (theme, file, stylesheet);
cr_stylesheet_ref (stylesheet);
theme->custom_stylesheets = g_slist_prepend (theme->custom_stylesheets, stylesheet);
g_signal_emit (theme, signals[STYLESHEETS_CHANGED], 0);
return TRUE;
@ -294,24 +308,23 @@ st_theme_unload_stylesheet (StTheme *theme,
GFile *file)
{
CRStyleSheet *stylesheet;
StyleSheetData *stylesheet_data;
stylesheet = g_hash_table_lookup (theme->stylesheets_by_file, file);
if (!stylesheet)
return;
if (!g_slist_find (theme->custom_stylesheets, stylesheet))
stylesheet_data = cr_stylesheet_get_app_data (stylesheet);
if (!stylesheet_data || !stylesheet_data->extension_stylesheet)
return;
theme->custom_stylesheets = g_slist_remove (theme->custom_stylesheets, stylesheet);
g_signal_emit (theme, signals[STYLESHEETS_CHANGED], 0);
/* We need to remove the entry from the hashtable after emitting the signal
* since we might still access the files_by_stylesheet hashtable in
* _st_theme_resolve_url() during the signal emission.
/* We need to keep a reference while emitting the signal since we might
* still access the stylesheet in _st_theme_resolve_url() during the signal
* emission.
*/
cr_stylesheet_ref (stylesheet);
g_hash_table_remove (theme->stylesheets_by_file, file);
g_hash_table_remove (theme->files_by_stylesheet, stylesheet);
g_signal_emit (theme, signals[STYLESHEETS_CHANGED], 0);
cr_stylesheet_unref (stylesheet);
}
@ -328,14 +341,18 @@ GSList*
st_theme_get_custom_stylesheets (StTheme *theme)
{
GSList *result = NULL;
GSList *iter;
GHashTableIter iter;
gpointer value;
for (iter = theme->custom_stylesheets; iter; iter = iter->next)
g_hash_table_iter_init (&iter, theme->stylesheets_by_file);
while (g_hash_table_iter_next (&iter, NULL, &value))
{
CRStyleSheet *stylesheet = iter->data;
GFile *file = g_hash_table_lookup (theme->files_by_stylesheet, stylesheet);
CRStyleSheet *stylesheet = value;
StyleSheetData *stylesheet_data = cr_stylesheet_get_app_data (stylesheet);
result = g_slist_prepend (result, g_object_ref (file));
if (stylesheet_data && stylesheet_data->extension_stylesheet && stylesheet_data->file)
result = g_slist_prepend (result, g_object_ref (stylesheet_data->file));
}
return result;
@ -345,9 +362,9 @@ static void
st_theme_constructed (GObject *object)
{
StTheme *theme = ST_THEME (object);
CRStyleSheet *application_stylesheet;
CRStyleSheet *theme_stylesheet;
CRStyleSheet *default_stylesheet;
g_autoptr(CRStyleSheet) application_stylesheet = NULL;
g_autoptr(CRStyleSheet) theme_stylesheet = NULL;
g_autoptr(CRStyleSheet) default_stylesheet = NULL;
G_OBJECT_CLASS (st_theme_parent_class)->constructed (object);
@ -372,22 +389,13 @@ st_theme_finalize (GObject * object)
{
StTheme *theme = ST_THEME (object);
g_slist_foreach (theme->custom_stylesheets, (GFunc) cr_stylesheet_unref, NULL);
g_slist_free (theme->custom_stylesheets);
theme->custom_stylesheets = NULL;
g_hash_table_destroy (theme->stylesheets_by_file);
g_hash_table_destroy (theme->files_by_stylesheet);
g_clear_pointer (&theme->stylesheets_by_file, g_hash_table_destroy);
g_clear_object (&theme->application_stylesheet);
g_clear_object (&theme->theme_stylesheet);
g_clear_object (&theme->default_stylesheet);
if (theme->cascade)
{
cr_cascade_unref (theme->cascade);
theme->cascade = NULL;
}
g_clear_pointer (&theme->cascade, cr_cascade_unref);
G_OBJECT_CLASS (st_theme_parent_class)->finalize (object);
}
@ -890,31 +898,28 @@ add_matched_properties (StTheme *a_this,
if (import_rule->sheet == NULL)
{
GFile *file = NULL;
g_autoptr (GFile) file = NULL;
if (import_rule->url->stryng && import_rule->url->stryng->str)
{
g_autoptr(CRStyleSheet) sheet = NULL;
file = _st_theme_resolve_url (a_this,
a_nodesheet,
import_rule->url->stryng->str);
import_rule->sheet = parse_stylesheet (file, NULL);
sheet = parse_stylesheet (file, NULL);
if (insert_stylesheet (a_this, file, sheet))
import_rule->sheet = sheet;
}
if (import_rule->sheet)
{
insert_stylesheet (a_this, file, import_rule->sheet);
/* refcount of stylesheets starts off at zero, so we don't need to unref! */
}
else
if (!import_rule->sheet)
{
/* Set a marker to avoid repeatedly trying to parse a non-existent or
* broken stylesheet
*/
import_rule->sheet = (CRStyleSheet *) - 1;
}
if (file)
g_object_unref (file);
}
if (import_rule->sheet != (CRStyleSheet *) - 1)
@ -979,13 +984,14 @@ add_matched_properties (StTheme *a_this,
static inline int
get_origin (const CRDeclaration * decl)
{
enum CRStyleOrigin origin = decl->parent_statement->parent_sheet->origin;
gboolean is_extension_sheet = GPOINTER_TO_UINT (decl->parent_statement->parent_sheet->app_data);
CRStyleSheet *stylesheet = decl->parent_statement->parent_sheet;
enum CRStyleOrigin origin = stylesheet->origin;
StyleSheetData *sheet_data = cr_stylesheet_get_app_data (stylesheet);
if (decl->important)
origin += ORIGIN_OFFSET_IMPORTANT;
if (is_extension_sheet)
if (sheet_data && sheet_data->extension_stylesheet)
origin += ORIGIN_OFFSET_EXTENSION;
return origin;
@ -1020,7 +1026,7 @@ _st_theme_get_matched_properties (StTheme *theme,
enum CRStyleOrigin origin = 0;
CRStyleSheet *sheet = NULL;
GPtrArray *props = g_ptr_array_new ();
GSList *iter;
GHashTableIter iter;
g_return_val_if_fail (ST_IS_THEME (theme), NULL);
g_return_val_if_fail (ST_IS_THEME_NODE (node), NULL);
@ -1034,8 +1040,14 @@ _st_theme_get_matched_properties (StTheme *theme,
add_matched_properties (theme, sheet, node, props);
}
for (iter = theme->custom_stylesheets; iter; iter = iter->next)
add_matched_properties (theme, iter->data, node, props);
g_hash_table_iter_init (&iter, theme->stylesheets_by_file);
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &sheet))
{
StyleSheetData *sheet_data = cr_stylesheet_get_app_data (sheet);
if (sheet_data && sheet_data->extension_stylesheet)
add_matched_properties (theme, sheet, node, props);
}
/* We count on a stable sort here so that later declarations come
* after earlier declarations */
@ -1053,19 +1065,18 @@ _st_theme_resolve_url (StTheme *theme,
CRStyleSheet *base_stylesheet,
const char *url)
{
char *scheme;
g_autofree char *scheme = NULL;
GFile *resource;
if ((scheme = g_uri_parse_scheme (url)))
{
g_free (scheme);
resource = g_file_new_for_uri (url);
}
else if (base_stylesheet != NULL)
{
GFile *base_file = NULL, *parent;
base_file = g_hash_table_lookup (theme->files_by_stylesheet, base_stylesheet);
StyleSheetData *stylesheet_data = cr_stylesheet_get_app_data (base_stylesheet);
GFile *base_file = stylesheet_data->file;
g_autoptr (GFile) parent = NULL;
/* This is an internal function, if we get here with
a bad @base_stylesheet we have a problem. */
@ -1073,8 +1084,6 @@ _st_theme_resolve_url (StTheme *theme,
parent = g_file_get_parent (base_file);
resource = g_file_resolve_relative_path (parent, url);
g_object_unref (parent);
}
else
{