[gtk/wip/baedert/for-master: 1/2] Compile private sources in css/ as C++




commit 9d0de4155485a06e90e041e9cee2dffec40f0442
Author: Timm Bäder <mail baedert org>
Date:   Mon Oct 4 17:28:24 2021 +0200

    Compile private sources in css/ as C++

 gtk/css/{gtkcssdataurl.c => gtkcssdataurl.cpp}       |  6 +++---
 gtk/css/{gtkcssparser.c => gtkcssparser.cpp}         | 12 ++++++------
 gtk/css/{gtkcssserializer.c => gtkcssserializer.cpp} |  0
 gtk/css/{gtkcsstokenizer.c => gtkcsstokenizer.cpp}   | 12 ++++++------
 gtk/css/meson.build                                  | 12 ++++++++----
 meson.build                                          |  8 +++++---
 6 files changed, 28 insertions(+), 22 deletions(-)
---
diff --git a/gtk/css/gtkcssdataurl.c b/gtk/css/gtkcssdataurl.cpp
similarity index 96%
rename from gtk/css/gtkcssdataurl.c
rename to gtk/css/gtkcssdataurl.cpp
index 6645b4835d..218e51b04e 100644
--- a/gtk/css/gtkcssdataurl.c
+++ b/gtk/css/gtkcssdataurl.cpp
@@ -141,7 +141,7 @@ gtk_css_data_url_parse (const char  *url,
           g_free (mimetype);
           return NULL;
         }
-      bsize = strlen (bdata);
+      bsize = strlen (static_cast<const char *>(bdata));
     }
 
   /* Convert to UTF8 */
@@ -153,8 +153,8 @@ gtk_css_data_url_parse (const char  *url,
       gsize written;
       gpointer data;
 
-      data = g_convert_with_fallback (bdata, bsize,
-                                      "UTF-8", charset, 
+      data = g_convert_with_fallback (static_cast<const char *>(bdata), bsize,
+                                      "UTF-8", charset,
                                       (char *) "*",
                                       &read, &written, NULL);
       g_free (bdata);
diff --git a/gtk/css/gtkcssparser.c b/gtk/css/gtkcssparser.cpp
similarity index 99%
rename from gtk/css/gtkcssparser.c
rename to gtk/css/gtkcssparser.cpp
index aa2e171aa1..927897abdb 100644
--- a/gtk/css/gtkcssparser.c
+++ b/gtk/css/gtkcssparser.cpp
@@ -111,7 +111,7 @@ gtk_css_parser_new_for_bytes (GBytes                *bytes,
 {
   GtkCssTokenizer *tokenizer;
   GtkCssParser *result;
-  
+
   tokenizer = gtk_css_tokenizer_new (bytes);
   result = gtk_css_parser_new (tokenizer, file, base_directory, error_func, user_data, user_destroy);
   gtk_css_tokenizer_unref (tokenizer);
@@ -462,7 +462,7 @@ void
 gtk_css_parser_skip (GtkCssParser *self)
 {
   const GtkCssToken *token;
-  
+
   token = gtk_css_parser_get_token (self);
   if (gtk_css_token_is_preserved (token, NULL))
     {
@@ -495,7 +495,7 @@ gtk_css_parser_skip_until (GtkCssParser    *self,
                            GtkCssTokenType  token_type)
 {
   const GtkCssToken *token;
-  
+
   for (token = gtk_css_parser_get_token (self);
        !gtk_css_token_is (token, token_type) &&
        !gtk_css_token_is (token, GTK_CSS_TOKEN_EOF);
@@ -952,12 +952,12 @@ gtk_css_parser_parse_url_arg (GtkCssParser *parser,
                               guint         arg,
                               gpointer      data)
 {
-  char **out_url = data;
+  char **out_url = static_cast<char **>(data);
 
   *out_url = gtk_css_parser_consume_string (parser);
   if (*out_url == NULL)
     return 0;
-  
+
   return 1;
 }
 
@@ -995,7 +995,7 @@ gtk_css_parser_consume_url (GtkCssParser *self)
       gtk_css_parser_error_syntax (self, "Expected a URL");
       return NULL;
     }
-  
+
   return url;
 }
 
diff --git a/gtk/css/gtkcssserializer.c b/gtk/css/gtkcssserializer.cpp
similarity index 100%
rename from gtk/css/gtkcssserializer.c
rename to gtk/css/gtkcssserializer.cpp
diff --git a/gtk/css/gtkcsstokenizer.c b/gtk/css/gtkcsstokenizer.cpp
similarity index 99%
rename from gtk/css/gtkcsstokenizer.c
rename to gtk/css/gtkcsstokenizer.cpp
index 05fca8ed01..0360d963a9 100644
--- a/gtk/css/gtkcsstokenizer.c
+++ b/gtk/css/gtkcsstokenizer.cpp
@@ -568,7 +568,7 @@ gtk_css_tokenizer_new (GBytes *bytes)
   tokenizer->bytes = g_bytes_ref (bytes);
   tokenizer->name_buffer = g_string_new (NULL);
 
-  tokenizer->data = g_bytes_get_data (bytes, NULL);
+  tokenizer->data = static_cast<const char *>(g_bytes_get_data (bytes, NULL));
   tokenizer->end = tokenizer->data + g_bytes_get_size (bytes);
 
   gtk_css_location_init (&tokenizer->position);
@@ -580,7 +580,7 @@ GtkCssTokenizer *
 gtk_css_tokenizer_ref (GtkCssTokenizer *tokenizer)
 {
   tokenizer->ref_count++;
-  
+
   return tokenizer;
 }
 
@@ -772,7 +772,7 @@ gtk_css_tokenizer_consume_newline (GtkCssTokenizer *tokenizer)
     n = 2;
   else
     n = 1;
-  
+
   tokenizer->data += n;
   gtk_css_location_advance_newline (&tokenizer->position, n == 2 ? TRUE : FALSE);
 }
@@ -832,7 +832,7 @@ gtk_css_tokenizer_read_whitespace (GtkCssTokenizer *tokenizer,
   gtk_css_token_init (token, GTK_CSS_TOKEN_WHITESPACE);
 }
 
-static gunichar 
+static gunichar
 gtk_css_tokenizer_read_escape (GtkCssTokenizer *tokenizer)
 {
   gunichar value = 0;
@@ -921,7 +921,7 @@ gtk_css_tokenizer_read_bad_url (GtkCssTokenizer  *tokenizer,
       else
         gtk_css_tokenizer_consume_char (tokenizer, NULL);
     }
-  
+
   if (tokenizer->data < tokenizer->end)
     gtk_css_tokenizer_consume_ascii (tokenizer);
 
@@ -950,7 +950,7 @@ gtk_css_tokenizer_read_url (GtkCssTokenizer  *tokenizer,
           do
             gtk_css_tokenizer_consume_whitespace (tokenizer);
           while (tokenizer->data < tokenizer->end && is_whitespace (*tokenizer->data));
-          
+
           if (*tokenizer->data == ')')
             {
               gtk_css_tokenizer_consume_ascii (tokenizer);
diff --git a/gtk/css/meson.build b/gtk/css/meson.build
index 2785f41374..0192b32732 100644
--- a/gtk/css/meson.build
+++ b/gtk/css/meson.build
@@ -5,10 +5,10 @@ gtk_css_public_sources = files([
 ])
 
 gtk_css_private_sources = files([
-  'gtkcssdataurl.c',
-  'gtkcssparser.c',
-  'gtkcsstokenizer.c',
-  'gtkcssserializer.c',
+  'gtkcssdataurl.cpp',
+  'gtkcssparser.cpp',
+  'gtkcsstokenizer.cpp',
+  'gtkcssserializer.cpp',
 ])
 
 gtk_css_public_headers = files([
@@ -49,6 +49,10 @@ libgtk_css = static_library('gtk_css',
     '-DGTK_COMPILATION',
     '-DG_LOG_DOMAIN="Gtk"',
   ] + common_cflags,
+  cpp_args: [
+    '-DGTK_COMPILATION',
+    '-DG_LOG_DOMAIN="Gtk"',
+  ] + common_cxxflags,
 )
 
 # We don't have link_with: to internal static libs here on purpose, just
diff --git a/meson.build b/meson.build
index 897de13766..781ea2f7cc 100644
--- a/meson.build
+++ b/meson.build
@@ -1,4 +1,4 @@
-project('gtk', 'c',
+project('gtk', ['c', 'cpp'],
         version: '4.5.0',
         default_options: [
           'buildtype=debugoptimized',
@@ -142,6 +142,7 @@ gtk_schemasdir = join_paths(gtk_datadir, 'glib-2.0/schemas')
 gtk_appdatadir = join_paths(gtk_datadir, 'metainfo')
 
 cc = meson.get_compiler('c')
+cxx = meson.get_compiler('cpp')
 
 cdata = configuration_data()
 cdata.set_quoted('PACKAGE_VERSION', meson.project_version())
@@ -253,8 +254,8 @@ if cc.get_id() == 'msvc'
   # in GLib, based on _Win32_Programming_ by Rector and Newcomer
   test_cflags = [
     '-FImsvc_recommended_pragmas.h',
-       '-D_USE_MATH_DEFINES',
-       '-utf-8',
+    '-D_USE_MATH_DEFINES',
+    '-utf-8',
   ]
   add_project_arguments(cc.get_supported_arguments(test_cflags), language: 'c')
 
@@ -324,6 +325,7 @@ else
 endif
 
 common_cflags = cc.get_supported_arguments(test_cflags)
+common_cxxflags = cxx.get_supported_arguments(test_cflags)
 
 # Symbol visibility
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]