[Libreoffice-commits] core.git: 2 commits - include/LibreOfficeKit libreofficekit/qa

Michael Meeks michael.meeks at collabora.com
Mon Jul 9 08:15:10 UTC 2018


 include/LibreOfficeKit/LibreOfficeKitInit.h |   40 ++++++++++++++++++++++--
 libreofficekit/qa/tilebench/tilebench.cxx   |   45 ++++++++++++++++++++++------
 2 files changed, 72 insertions(+), 13 deletions(-)

New commits:
commit 432a935d4e178b4e1e54c2ec864cb5e05bb03d9b
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Sat Jul 7 21:57:49 2018 +0100

    tilebench: add --preinit mode.
    
    Also cleanup DISPLAY to avoid various weird problems.
    
    Change-Id: Ib480c94fc50baab6185ecadaabda9a8063cedfee
    Reviewed-on: https://gerrit.libreoffice.org/57146
    Tested-by: Jenkins
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/libreofficekit/qa/tilebench/tilebench.cxx b/libreofficekit/qa/tilebench/tilebench.cxx
index 0984a3feee5c..16fc047ce655 100644
--- a/libreofficekit/qa/tilebench/tilebench.cxx
+++ b/libreofficekit/qa/tilebench/tilebench.cxx
@@ -31,8 +31,8 @@ static int help( const char *error = nullptr )
 {
     if (error)
         fprintf (stderr, "Error: %s\n\n", error);
-    fprintf( stderr, "Usage: tilebench <absolute-path-to-libreoffice-install> [path to document]\n");
-    fprintf( stderr, "\trenders a selection of small tiles from the document, checksums them and times the process\n" );
+    fprintf( stderr, "Usage: tilebench <absolute-path-to-libreoffice-install> [path to document] [--preinit] <options>\n");
+    fprintf( stderr, "\trenders a selection of small tiles from the document, checksums them and times the process based on options:\n" );
     fprintf( stderr, "\t--tile\t[max parts|-1] [max tiles|-1]\n" );
     fprintf( stderr, "\t--dialog\t<.uno:Command>\n" );
     return 1;
@@ -286,6 +286,11 @@ void testDialog( Document *pDocument, const char *uno_cmd )
 
 int main( int argc, char* argv[] )
 {
+    int arg;
+
+    // avoid X oddness etc.
+    unsetenv("DISPLAY");
+
     origin = getTimeNow();
     if( argc < 4 ||
         ( argc > 1 && ( !strcmp( argv[1], "--help" ) || !strcmp( argv[1], "-h" ) ) ) )
@@ -297,19 +302,41 @@ int main( int argc, char* argv[] )
         return 1;
     }
 
+    arg = 2;
+    const char *doc_url = argv[arg++];
+    const char *mode = argv[arg++];
+
+    bool pre_init = false;
+    if (!strcmp(mode, "--preinit"))
+    {
+        pre_init = true;
+        mode = argv[arg++];
+    }
+
+    char user_url[8046];;
+    strcpy(user_url, "file:///");
+    strcat(user_url, argv[1]);
+    strcat(user_url, "../user");
+
+    if (pre_init)
+    {
+        aTimes.emplace_back("pre-initialization");
+        setenv("LOK_WHITELIST_LANGUAGES", "en_US", 0);
+        // coverity[tainted_string] - build time test tool
+        lok_preinit(argv[1], user_url);
+        aTimes.emplace_back();
+    }
+
     aTimes.emplace_back("initialization");
     // coverity[tainted_string] - build time test tool
-    Office *pOffice = lok_cpp_init(argv[1]);
+    Office *pOffice = lok_cpp_init(argv[1], user_url);
     if (pOffice == nullptr)
     {
         fprintf(stderr, "Failed to initialize Office from %s\n", argv[1]);
         return 1;
     }
-
     aTimes.emplace_back();
 
-    const char *doc_url = argv[2];
-    const char *mode = argv[3];
     Document *pDocument = nullptr;
 
     aTimes.emplace_back("load document");
@@ -321,15 +348,15 @@ int main( int argc, char* argv[] )
     {
         if (!strcmp(mode, "--tile"))
         {
-            const int max_parts = (argc > 4 ? atoi(argv[4]) : -1);
-            int max_tiles = (argc > 5 ? atoi(argv[5]) : -1);
+            const int max_parts = (argc > arg ? atoi(argv[arg++]) : -1);
+            int max_tiles = (argc > arg ? atoi(argv[arg++]) : -1);
             const bool dump = true;
 
             testTile (pDocument, max_parts, max_tiles, dump);
         }
         else if (!strcmp (mode, "--dialog"))
         {
-            const char *uno_cmd = argc > 4 ? argv[4] : nullptr;
+            const char *uno_cmd = argc > arg ? argv[arg++] : nullptr;
             if (!uno_cmd)
             {
                 switch (pDocument->getDocumentType())
commit 2872653997b614cc788c8a632a4d5ccb63c4670d
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Fri Jul 6 17:41:58 2018 +0100

    lok: export preinit helper, and share code variously.
    
    Change-Id: I09f2992c4ba45ce91190a9f61dd0fedd0eb8a581
    Reviewed-on: https://gerrit.libreoffice.org/57145
    Tested-by: Jenkins
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/include/LibreOfficeKit/LibreOfficeKitInit.h b/include/LibreOfficeKit/LibreOfficeKitInit.h
index ce5054ac91c4..103c11be926c 100644
--- a/include/LibreOfficeKit/LibreOfficeKitInit.h
+++ b/include/LibreOfficeKit/LibreOfficeKitInit.h
@@ -17,6 +17,12 @@ extern "C"
 {
 #endif
 
+#if defined __GNUC__ || defined __clang__
+#  define LOK_TOLERATE_UNUSED __attribute__((used))
+#else
+#  define LOK_TOLERATE_UNUSED
+#endif
+
 #if defined(__linux__) || defined (__FreeBSD_kernel__) || defined(_AIX) ||\
     defined(_WIN32) || defined(__APPLE__) || defined (__NetBSD__) ||\
     defined (__sun) || defined(__OpenBSD__)
@@ -294,15 +300,41 @@ static LibreOfficeKit *lok_init_2( const char *install_path,  const char *user_p
 #endif
 }
 
-static
-#if defined __GNUC__ || defined __clang__
-__attribute__((used))
-#endif
+static LOK_TOLERATE_UNUSED
 LibreOfficeKit *lok_init( const char *install_path )
 {
     return lok_init_2( install_path, NULL );
 }
 
+#if !defined(IOS)
+static LOK_TOLERATE_UNUSED
+int lok_preinit( const char *install_path,  const char *user_profile_url )
+{
+    void *dlhandle;
+    char *imp_lib;
+    LokHookPreInit *pSym;
+
+    dlhandle = lok_dlopen(install_path, &imp_lib);
+    if (!dlhandle)
+        return -1;
+
+    pSym = (LokHookPreInit *) lok_dlsym(dlhandle, "lok_preinit");
+    if (!pSym)
+    {
+        fprintf( stderr, "failed to find pre-init hook in library '%s'\n", imp_lib );
+        lok_dlclose( dlhandle );
+        free( imp_lib );
+        return -1;
+    }
+
+    free( imp_lib );
+
+    // dlhandle is "leaked"
+    // coverity[leaked_storage]
+    return pSym( install_path, user_profile_url );
+}
+#endif
+
 #undef SEPARATOR // It is used at least in enum class MenuItemType
 
 #endif // defined(__linux__) || defined (__FreeBSD_kernel__) || defined(_AIX) || defined(_WIN32) || defined(__APPLE__)


More information about the Libreoffice-commits mailing list