diff options
Diffstat (limited to 'include/sal')
-rw-r--r-- | include/sal/alloca.h | 57 | ||||
-rw-r--r-- | include/sal/backtrace.hxx | 49 | ||||
-rw-r--r-- | include/sal/config.h | 122 | ||||
-rw-r--r-- | include/sal/detail/log.h | 108 | ||||
-rw-r--r-- | include/sal/log-areas.dox | 671 | ||||
-rw-r--r-- | include/sal/log.hxx | 436 | ||||
-rw-r--r-- | include/sal/macros.h | 62 | ||||
-rw-r--r-- | include/sal/main.h | 153 | ||||
-rw-r--r-- | include/sal/mathconf.h | 172 | ||||
-rw-r--r-- | include/sal/saldllapi.h | 39 | ||||
-rw-r--r-- | include/sal/types.h | 699 | ||||
-rw-r--r-- | include/sal/typesizes.h | 20 |
12 files changed, 2588 insertions, 0 deletions
diff --git a/include/sal/alloca.h b/include/sal/alloca.h new file mode 100644 index 0000000000..3e0c949425 --- /dev/null +++ b/include/sal/alloca.h @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ + +#ifndef INCLUDED_SAL_ALLOCA_H +#define INCLUDED_SAL_ALLOCA_H + +#if defined(__sun) || defined(LINUX) || defined(ANDROID) || defined(HAIKU) || defined(MACOSX) \ + || defined(IOS) || defined(EMSCRIPTEN) + +#ifndef INCLUDED_ALLOCA_H +#include <alloca.h> +#define INCLUDED_ALLOCA_H +#endif + +#elif defined(FREEBSD) || defined(NETBSD) || defined(OPENBSD) || defined(DRAGONFLY) + +#ifndef INCLUDED_STDLIB_H +#include <stdlib.h> +#define INCLUDED_STDLIB_H +#endif + +#elif defined(_WIN32) + +#ifndef INCLUDED_MALLOC_H +#include <malloc.h> +#define INCLUDED_MALLOC_H +#endif + +#else + +#error "unknown platform: please check for alloca" + +#endif + +#endif /* INCLUDED_SAL_ALLOCA_H */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/sal/backtrace.hxx b/include/sal/backtrace.hxx new file mode 100644 index 0000000000..5f44e5e01d --- /dev/null +++ b/include/sal/backtrace.hxx @@ -0,0 +1,49 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_SAL_BACKTRACE_HXX +#define INCLUDED_SAL_BACKTRACE_HXX + +#include "sal/config.h" +#include "sal/saldllapi.h" +#include "sal/types.h" +#include "rtl/ustring.hxx" +#include <memory> + +/// @cond INTERNAL +/** + Two stage API for recording and then later decoding stack backtraces. + Useful for debugging facilities where we are only interested in decoding + a small handful of recorded stack traces. + + @param backtraceDepth value indicating the maximum backtrace depth; must be > 0 + + @since LibreOffice 6.0 +*/ +#if defined LIBO_INTERNAL_ONLY + +namespace sal +{ +struct BacktraceState +{ + void** buffer; + int nDepth; + ~BacktraceState() { delete[] buffer; } +}; + +SAL_DLLPUBLIC std::unique_ptr<BacktraceState> backtrace_get(sal_uInt32 backtraceDepth); + +SAL_DLLPUBLIC OUString backtrace_to_string(BacktraceState* backtraceState); +} + +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/sal/config.h b/include/sal/config.h new file mode 100644 index 0000000000..5d6bd34592 --- /dev/null +++ b/include/sal/config.h @@ -0,0 +1,122 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ + +#ifndef INCLUDED_SAL_CONFIG_H +#define INCLUDED_SAL_CONFIG_H + +#if defined LIBO_INTERNAL_ONLY && defined ANDROID && defined __cplusplus +#include <android/compatibility.hxx> +#endif + +#ifdef _WIN32 +#define SAL_W32 +#define SAL_DLLEXTENSION ".dll" +#define SAL_EXEEXTENSION ".exe" +#define SAL_PATHSEPARATOR ';' +#define SAL_PATHDELIMITER '\\' +#define SAL_NEWLINE_STRING "\r\n" +#define SAL_CONFIGFILE(name) name ".ini" + +#ifdef _MSC_VER + +#ifndef _USE_MATH_DEFINES +#define _USE_MATH_DEFINES // needed by Visual C++ for math constants +#endif + +#endif /* defined _MSC_VER */ + +#endif /* defined _WIN32 */ + +#if defined(__sun) || defined(LINUX) || defined(NETBSD) || defined(FREEBSD) || defined(OPENBSD) \ + || defined(DRAGONFLY) || defined(ANDROID) || defined(HAIKU) +#define SAL_UNX +#define SAL_DLLEXTENSION ".so" +#define SAL_EXEEXTENSION "" +#define SAL_DLLPREFIX "lib" +#define SAL_PATHSEPARATOR ':' +#define SAL_PATHDELIMITER '/' +#define SAL_NEWLINE_STRING "\n" +#define SAL_CONFIGFILE(name) name "rc" +#endif + +#ifdef MACOSX +#define SAL_UNX +#define SAL_DLLEXTENSION ".dylib" +#define SAL_EXEEXTENSION "" +#define SAL_DLLPREFIX "lib" +#define SAL_PATHSEPARATOR ':' +#define SAL_PATHDELIMITER '/' +#define SAL_NEWLINE_STRING "\n" +#define SAL_CONFIGFILE(name) name "rc" +#endif + +#ifdef IOS +#define SAL_UNX +/* SAL_DLLEXTENSION should not really be used on iOS, as iOS apps are + * not allowed to load own dynamic libraries. + */ +#define SAL_DLLEXTENSION ".dylib" +#define SAL_DLLPREFIX "lib" +#define SAL_PATHSEPARATOR ':' +#define SAL_PATHDELIMITER '/' +#define SAL_NEWLINE_STRING "\n" +#define SAL_CONFIGFILE(name) name "rc" +#endif + +#ifdef EMSCRIPTEN +#define SAL_UNX +#define SAL_DLLEXTENSION ".bc" +#define SAL_EXEEXTENSION "" +#define SAL_DLLPREFIX "lib" +#define SAL_PATHSEPARATOR ':' +#define SAL_PATHDELIMITER '/' +#define SAL_NEWLINE_STRING "\n" +#define SAL_CONFIGFILE(name) name "rc" +#endif + +/* The following spell is for Solaris and its descendants. + * See the "Solaris" section of + * <http://sourceforge.net/p/predef/wiki/OperatingSystems/>, and + * <http://stackoverflow.com/questions/16618604/solaris-and-preprocessor-macros>. + */ +#ifdef sun +#undef sun +#define sun sun +#endif + +#if defined __clang__ +#if __has_warning("-Wpotentially-evaluated-expression") +#pragma GCC diagnostic ignored "-Wpotentially-evaluated-expression" +#endif +// Before fixing occurrences of this warning, lets see whether C++20 will still change to obsolete +// the warning (see +// <https://github.com/llvm/llvm-project/commit/974c8b7e2fde550fd87850d50695341101c38c2d> "[c++20] +// Add rewriting from comparison operators to <=> / =="): +#if __has_warning("-Wambiguous-reversed-operator") +#pragma GCC diagnostic ignored "-Wambiguous-reversed-operator" +#endif +#endif + +#endif // INCLUDED_SAL_CONFIG_H + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/sal/detail/log.h b/include/sal/detail/log.h new file mode 100644 index 0000000000..f68512d166 --- /dev/null +++ b/include/sal/detail/log.h @@ -0,0 +1,108 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +/* + * This file is part of LibreOffice published API. + */ + +#ifndef INCLUDED_SAL_DETAIL_LOG_H +#define INCLUDED_SAL_DETAIL_LOG_H + +#include "sal/config.h" + +#include "sal/saldllapi.h" +#include "sal/types.h" + +/** @cond INTERNAL */ + +/* This header makes available replacements working in both C and C++ for the + obsolete osl/diagnose.h functionality that in turn is used from both C and + C++ code and the obsolete tools/debug.hxx functionality that uses printf-style + formatting. Once that obsolete functionality is removed, this header can be + removed, too. + + This header uses variadic macros in both C (where they are officially only + supported since C99) and C++ (where they are officially only supported since + C++11). It appears that all relevant compilers (esp. GCC 4.0 and MS VS 2008 + Express) already support them in their C and C++ dialects. See also + <http://wiki.apache.org/stdcxx/C++0xCompilerSupport>. + + Avoid the use of other sal code in this header as much as possible, so that + this code can be called from other sal code without causing endless + recursion. +*/ + +#if defined __cplusplus +extern "C" { +#endif + +/* + Clang warns about 'sal_True && sal_True' (those being integers and not booleans) + when it sees preprocessed source (-save-temps or using icecream) +*/ +#if defined __cplusplus +#define SAL_LOG_TRUE true +#define SAL_LOG_FALSE false +#else +#define SAL_LOG_TRUE sal_True +#define SAL_LOG_FALSE sal_False +#endif + +enum sal_detail_LogLevel { + SAL_DETAIL_LOG_LEVEL_INFO, SAL_DETAIL_LOG_LEVEL_WARN, + SAL_DETAIL_LOG_LEVEL_DEBUG = SAL_MAX_ENUM +}; + +SAL_DLLPUBLIC void SAL_CALL sal_detail_logFormat( + enum sal_detail_LogLevel level, char const * area, char const * where, + char const * format, ...) +#if defined __GNUC__ + __attribute__((format(printf, 4, 5))) +#endif + ; + +#if defined __cplusplus +} +#endif + +#define SAL_DETAIL_LOG_FORMAT(condition, level, area, where, ...) \ + do { \ + if (condition) { \ + sal_detail_logFormat((level), (area), (where), __VA_ARGS__); \ + } \ + } while (SAL_LOG_FALSE) + +#if defined SAL_LOG_INFO +#define SAL_DETAIL_ENABLE_LOG_INFO SAL_LOG_TRUE +#else +#define SAL_DETAIL_ENABLE_LOG_INFO SAL_LOG_FALSE +#endif +#if defined SAL_LOG_WARN +#define SAL_DETAIL_ENABLE_LOG_WARN SAL_LOG_TRUE +#else +#define SAL_DETAIL_ENABLE_LOG_WARN SAL_LOG_FALSE +#endif + +#define SAL_DETAIL_WHERE __FILE__ ":" SAL_STRINGIFY(__LINE__) ": " + +#define SAL_DETAIL_INFO_IF_FORMAT(condition, area, ...) \ + SAL_DETAIL_LOG_FORMAT( \ + SAL_DETAIL_ENABLE_LOG_INFO && (condition), SAL_DETAIL_LOG_LEVEL_INFO, \ + area, SAL_DETAIL_WHERE, __VA_ARGS__) + +#define SAL_DETAIL_WARN_IF_FORMAT(condition, area, ...) \ + SAL_DETAIL_LOG_FORMAT( \ + SAL_DETAIL_ENABLE_LOG_WARN && (condition), SAL_DETAIL_LOG_LEVEL_WARN, \ + area, SAL_DETAIL_WHERE, __VA_ARGS__) + +/** @endcond */ + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/sal/log-areas.dox b/include/sal/log-areas.dox new file mode 100644 index 0000000000..a2240a89a8 --- /dev/null +++ b/include/sal/log-areas.dox @@ -0,0 +1,671 @@ +// NOTE: This file is also parsed by a compiler plugin. Make sure all +// areas are marked with '@li @c'. + +/** +@page sal_log_areas SAL debug areas + +@short List and description of areas for the SAL debug macros + +This is a list of areas that are used by the SAL_INFO family of macros. See +@ref sal_log "basic log functionality" for details about this functionality. + +If you need a debug area in some code, first check this list and use the +appropriate area if it exists. This list is not definite, if you need a new +area, use it and add it to an appropriate section with an explanation. +Generally, use the name of the relevant code module as the first area segment. +Please keep all entries sorted. + +This list should give you an overview of which areas to enable when debugging +certain functionality. + +@section SAL + +@li @c sal.bootstrap - SAL bootstrap +@li @c sal.cppunittester +@li @c sal.debug - SAL debugging functionality +@li @c sal.file - file system operations +@li @c sal.fileio - file I/O +@li @c sal.osl - SAL OSL library +@li @c sal.osl.condition +@li @c sal.osl.mutex +@li @c sal.osl.pipe +@li @c sal.rtl - SAL RTL library +@li @c sal.textenc - the textencoding SAL library + +@section basctl + +@li @c basctl +@li @c basctl.basicide + +@section basic + +@li @c basic +@li @c basic.sbx + +@section bridges + +@li @c bridges +@li @c bridges.ios +@li @c bridges.osx + +@section canvas + +@li @c canvas +@li @c canvas.cairo +@li @c canvas.directx +@li @c canvas.null +@li @c canvas.ogl +@li @c canvas.vcl + +@section chart2 + +@li @c chart2 +@li @c chart2.accessibility +@li @c chart2.areachart +@li @c chart2.main +@li @c chart2.pie.label.bestfit +@li @c chart2.pie.label.bestfit.inside +@li @c chart2.template +@li @c chart2.tools + +@section connectivity + +@li @c connectivity.ado +@li @c connectivity.commontools +@li @c connectivity.cpool +@li @c connectivity.dbase +@li @c connectivity.drivers - a bit overly general, maybe it should be removed? +@li @c connectivity.evoab2 +@li @c connectivity.firebird +@li @c connectivity.flat +@li @c connectivity.hsqldb +@li @c connectivity.jdbc +@li @c connectivity.kab +@li @c connectivity.macab +@li @c connectivity.manager +@li @c connectivity.mozab +@li @c connectivity.mysqlc +@li @c connectivity.odbc +@li @c connectivity.parse +@li @c connectivity.postgresql +@li @c connectivity.resource +@li @c connectivity.writer + +@section comphelper + +@li @c comphelper +@li @c comphelper.backupfilehelper +@li @c comphelper.container - EmbeddedObjectContainer +@li @c comphelper.crypto +@li @c comphelper.lok +@li @c comphelper.traceevent + +@section cppu + +@li @c cppu +@li @c cppu.affinebridge +@li @c cppu.log +@li @c cppu.purpenv +@li @c cppu.threadpool +@li @c cppu.typelib +@li @c cppu.unsafebridge + +@section cppuhelper + +@li @c cppuhelper +@li @c cppuhelper.shlib + +@section cpputools + +@li @c cpputools +@li @c cpputools.unoexe + +@section cui + +@li @c cui.customize +@li @c cui.customnotebookbar +@li @c cui.dialogs +@li @c cui.factory +@li @c cui.options +@li @c cui.tabpages + +@section drawinglayer + +@li @c drawinglayer +@li @c drawinglayer.emf + +@section emfio + +@li @c emfio - EMF and VMF image file formats import module + +@section Calc + +@li @c sc +@li @c sc.core +@li @c sc.core.formulacell - ScFormulaCell and group +@li @c sc.core.formulagroup +@li @c sc.core.grouparealistener - sc::FormulaGroupAreaListener +@li @c sc.filter - Calc filter +@li @c sc.lok.docsize +@li @c sc.lok.header +@li @c sc.lok.poshelper +@li @c sc.opencl - OpenCL-related stuff in general +@li @c sc.opencl.source - Generated OpenCL source code +@li @c sc.orcus +@li @c sc.orcus.autofilter +@li @c sc.orcus.condformat +@li @c sc.orcus.style +@li @c sc.orcus.table +@li @c sc.qa +@li @c sc.threaded +@li @c sc.timing +@li @c sc.ui - Calc UI +@li @c sc.uitest - Calc UI Test part +@li @c sc.viewdata + +@section desktop + +@li @c desktop +@li @c desktop.app +@li @c desktop.deployment +@li @c desktop.lib +@li @c desktop.migration +@li @c desktop.offacc +@li @c desktop.splash +@li @c desktop.test +@li @c desktop.updater + +@section Draw + +@li @c sd +@li @c sd.core +@li @c sd.eppt +@li @c sd.filter +@li @c sd.fwk +@li @c sd.slideshow +@li @c sd.sls - slidesorter +@li @c sd.tools +@li @c sd.transitions +@li @c sd.ui +@li @c sd.view +@li @c sdremote +@li @c sdremote.bluetooth +@li @c sdremote.wifi + +@section editeng + +@li @c editeng +@li @c editeng.chaining +@li @c editeng.items +@li @c editeng.quicktextsize + +@section embeddedobj + +@li @c embeddedobj - embedded objects +@li @c embeddedobj.common +@li @c embeddedobj.general +@li @c embeddedobj.ole - OLE embedded objects + +@section embedserv +@li @c embedserv - embedding server +@li @c embedserv.ole - OLE server + +@section extensions + +@li @c extensions.abpilot +@li @c extensions.biblio +@li @c extensions.config +@li @c extensions.dbpilots +@li @c extensions.evoab +@li @c extensions.logging +@li @c extensions.olebridge - OLE automation bridge +@li @c extensions.plugin +@li @c extensions.propctrlr +@li @c extensions.scanner +@li @c extensions.update + +@section Filter + +@li @c filter.config +@li @c filter.eps +@li @c filter.hwp - Hangul word processor import +@li @c filter.icgm +@li @c filter.ms - escher import/export +@li @c filter.odfflatxml +@li @c filter.os2met +@li @c filter.pdf +@li @c filter.pict +@li @c filter.psd +@li @c filter.ras +@li @c filter.svg +@li @c filter.tga +@li @c filter.tiff +@li @c filter.xmlfa +@li @c filter.xmlfd +@li @c filter.xslt - xslt import/export + +@section oox + +@li @c oox +@li @c oox.chart +@li @c oox.cscode - see oox/source/drawingml/customshapes/README +@li @c oox.csdata - see oox/source/drawingml/customshapes/README +@li @c oox.drawingml - DrawingML +@li @c oox.drawingml.gradient +@li @c oox.ppt - pptx filter +@li @c oox.shape +@li @c oox.storage - ZipStorage class +@li @c oox.vml - VML +@li @c oox.xmlstream - XmlStream class + +@section forms + +@li @c forms.component +@li @c forms.helper +@li @c forms.misc +@li @c forms.richtext +@li @c forms.runtime +@li @c forms.xforms + +@section formula + +@li @c formula.core +@li @c formula.ui + +@section fpicker + +@li @c fpicker +@li @c fpicker.aqua +@li @c fpicker.office + +@section framework + +@li @c fwk - framework (abbreviation) +@li @c fwk.accelerators +@li @c fwk.autorecovery +@li @c fwk.desktop +@li @c fwk.dispatch +@li @c fwk.frame +@li @c fwk.joburl +@li @c fwk.loadenv +@li @c fwk.session +@li @c fwk.session.debug +@li @c fwk.uiconfiguration +@li @c fwk.uielement + +@section i18nlangtag + +@li @c i18nlangtag - language tags + +@section i18npool + +@li @c i18npool - general i18npool + +@section i18n + +@li @c i18n - module independent i18n related, e.g. language tag usage + +@section io + +@li @c io.connector +@li @c io.streams + +@section jvmfwk + +@li @c jfw +@li @c jfw.level1 +@li @c jfw.level2 + +@section LanguageTool + +@li @c languagetool + +@section LibreOfficeKit + +@li @c lok +@li @c lok.fontsubst +@li @c lok.tiledrendering +@li @c lok.dialog +@li @c lok.a11y - LOK accessibility +@li @c lok.urp - Uno Remote Protocol + +@section l10ntools + +@li @c l10ntools + +@section Math + +@li @c starmath +@li @c starmath.ooxml - OOXML import/export +@li @c starmath.rtf +@li @c starmath.wordbase + +@section package + +@li @c package +@li @c package.manifest +@li @c package.xstor +@li @c package.threadeddeflate + +@section pyuno + +@li @c pyuno.runtime + +@section sdext + +@li @c sdext +@li @c sdext.minimizer +@li @c sdext.pdfimport +@li @c sdext.pdfimport.pdfparse +@li @c sdext.presenter + +@section sfx + +@li @c sfx +@li @c sfx.appl +@li @c sfx.bastyp +@li @c sfx.config +@li @c sfx.control +@li @c sfx.dialog +@li @c sfx.doc +@li @c sfx.notify +@li @c sfx.sidebar +@li @c sfx.view + +@section slideshow + +@li @c slideshow +@li @c slideshow.eventqueue +@li @c slideshow.opengl +@li @c slideshow.verbose + +@section sot + +@li @c sot - COM structured storage + +@section svl + +@li @c svl +@li @c svl.crypto +@li @c svl.items +@li @c svl.misc +@li @c svl.numbers + +@section svtools + +@li @c svtools +@li @c svtools.config +@li @c svtools.contnr +@li @c svtools.control +@li @c svtools.dialogs +@li @c svtools.misc +@li @c svtools.table +@li @c svtools.uno + +@section svx + +@li @c svx +@li @c svx.chaining +@li @c svx.diagram - Diagram ModelData +@li @c svx.dialog +@li @c svx.fmcomp +@li @c svx.form +@li @c svx.sdr +@li @c svx.sidebar +@li @c svx.stbcrtls - StatusBarControl +@li @c svx.svdraw +@li @c svx.table +@li @c svx.tbxcrtls - ToolboxControl +@li @c svx.uno + +@section toolkit + +@li @c toolkit +@li @c toolkit.controls +@li @c toolkit.helper + +@section tools + +@li @c tools +@li @c tools.datetime +@li @c tools.debug +@li @c tools.fraction +@li @c tools.generic +@li @c tools.memtools +@li @c tools.rc - resource manager +@li @c tools.stream - SvStream class +@li @c tools.urlobj - INetURLObject class + +@section ucb + +@li @c ucb +@li @c ucb.core +@li @c ucb.ucp +@li @c ucb.ucp.cmis +@li @c ucb.ucp.ext +@li @c ucb.ucp.file +@li @c ucb.ucp.gio +@li @c ucb.ucp.tdoc +@li @c ucb.ucp.webdav +@li @c ucb.ucp.webdav.curl + +@section unotools + +@li @c unotools +@li @c unotools.config +@li @c unotools.i18n +@li @c unotools.misc +@li @c unotools.ucbhelper + +@section URE + +@li @c rtl.string - ::rtl::OString, ::rtl::OUString, and related functionality +@li @c salhelper.thread - ::salhelper::Thread class + +@section sax + +@li @c sax.cppunit +@li @c sax.fastparser + +@section stoc + +@li @c stoc.corerefl - CoreReflection +@li @c stoc.java - javaloader and javavm + +@section VCL + +@li @c vcl +@li @c vcl.a11y +@li @c vcl.app +@li @c vcl.builder +@li @c vcl.control +@li @c vcl.ct - CoreText-using code for macOS and iOS +@li @c vcl.debugevent +@li @c vcl.driver Graphics driver handling +@li @c vcl.emf - EMF/EMF+ processing +@li @c vcl.eventtesting +@li @c vcl.filter +@li @c vcl.filter.webp +@li @c vcl.fonts - font-specific code +@li @c vcl.fonts.detail +@li @c vcl.gdi - the GDI part of VCL, devices, bitmaps, etc. +@li @c vcl.gdi.wndproc - Windows Procedure part of VCL +@li @c vcl.gdi.fontmetric +@li @c vcl.gtk - Gtk+ 2/3 plugin +@li @c vcl.gtk3 +@li @c vcl.gtkkde5 +@li @c vcl.harfbuzz - HarfBuzz text layout +@li @c vcl.headless - bitmap-based backend +@li @c vcl.helper +@li @c vcl.icontest +@li @c vcl.ios.clipboard +@li @c vcl.items +@li @c vcl.kf5 - KF5 +@li @c vcl.layout - Widget layout +@li @c vcl.lazydelete +@li @c vcl.opengl +@li @c vcl.opengl.qt - Qt OpenGL +@li @c vcl.osx +@li @c vcl.osx.clipboard +@li @c vcl.osx.print +@li @c vcl.pdfwriter +@li @c vcl.print +@li @c vcl.plugadapt - the Unix/X11 backend plugin mechanism +@li @c vcl.qt - Qt +@li @c vcl.quartz +@li @c vcl.schedule - scheduler / main-loop information +@li @c vcl.schedule.deinit +@li @c vcl.sessioninhibitor +@li @c vcl.scrollbar - Scroll Bars +@li @c vcl.se - VCL Session Manager +@li @c vcl.se.debug +@li @c vcl.skia - VCL Skia-based code +@li @c vcl.skia.trace - tracing drawing in VCL Skia-based code +@li @c vcl.sm - Session Manager Client +@li @c vcl.sm.debug +@li @c vcl.uitest - The UI testing framework code +@li @c vcl.unity +@li @c vcl.unx.dtrans +@li @c vcl.unx.freetype +@li @c vcl.unx.print +@li @c vcl.virdev +@li @c vcl.watchdog +@li @c vcl.window +@li @c vcl.win.dtrans + +@section winaccessibility + +@li @c iacc2 - IAccessible2 bridge debug + +@section Writer + +@li @c sw +@li @c sw.a11y - accessibility +@li @c sw.calc - formula calculation +@li @c sw.core - Writer core +@li @c sw.createcopy +@li @c sw.doc +@li @c sw.docappend +@li @c sw.docx +@li @c sw.envelp +@li @c sw.filter +@li @c sw.html - Writer HTML import/export +@li @c sw.idle +@li @c sw.layout - Writer core view: document layout +@li @c sw.layout.debug - Writer layout dbg_lay output +@li @c sw.mailmerge - Writer mail merge +@li @c sw.pageframe - debug lifecycle of SwPageFrame +@li @c sw.qa +@li @c sw.rtf - .rtf export filter +@li @c sw.tiled +@li @c sw.ui +@li @c sw.uno - Writer UNO interfaces +@li @c sw.vba - Writer VBA +@li @c sw.ww8 - .doc/.docx export filter, .doc import filter (not writerfilter) +@li @c sw.ww8.level2 - further info for sw.ww8 +@li @c sw.xml - Writer .odt import/export + +@section writerfilter + +@li @c writerfilter +@li @c writerfilter.dmapper +@li @c writerfilter.ooxml +@li @c writerfilter.profile - load times of filters +@li @c writerfilter.rtf + +@section writerperfect + +@li @c writerperfect + +@section xmloff + +@li @c xmloff +@li @c xmloff.chart +@li @c xmloff.core +@li @c xmloff.draw +@li @c xmloff.forms +@li @c xmloff.style +@li @c xmloff.table +@li @c xmloff.text +@li @c xmloff.transform + +@section xmlsecurity + +@li @c xmlsecurity.comp - xml security component +@li @c xmlsecurity.dialogs - xml security dialogs +@li @c xmlsecurity.helper +@li @c xmlsecurity.nss +@li @c xmlsecurity.ooxml - OOXML signature support +@li @c xmlsecurity.qa +@li @c xmlsecurity.workben +@li @c xmlsecurity.xmlsec - xmlsec wrapper +@li @c xmlsecurity.xmlsec.gpg - gpg xmlsec component + +@section xmlscript + +@li @c xmlscript.xmldlg +@li @c xmlscript.xmlflat +@li @c xmlscript.xmlhelper +@li @c xmlscript.xmllib +@li @c xmlscript.xmlmod + +@section dbaccess + +@li @c dbaccess +@li @c dbaccess.core +@li @c dbaccess.ui +@li @c dbaccess.ui.generalpage + +@section avmedia + +@li @c avmedia +@li @c avmedia.gstreamer +@li @c avmedia.gtk +@li @c avmedia.quicktime + +@section other + +@li @c accessibility +@li @c animations +@li @c basegfx +@li @c binaryurp +@li @c cli +@li @c configmgr +@li @c configmgr.dconf +@li @c cppcanvas +@li @c cppcanvas.emf +@li @c helpcompiler +@li @c idl +@li @c javaunohelper +@li @c jvmaccess +@li @c lingucomponent +@li @c linguistic +@li @c lwp - lotuswordpro +@li @c opencl +@li @c opencl.device +@li @c opencl.file +@li @c registry +@li @c reportdesign +@li @c rsc +@li @c sax +@li @c scripting +@li @c scripting.provider +@li @c shell +@li @c shell.jumplist +@li @c stoc +@li @c store +@li @c svg +@li @c svgio +@li @c test +@li @c ucbhelper +@li @c unodevtools +@li @c unoidl +@li @c unoxml +@li @c uui +@li @c vbahelper +@li @c wasm +@li @c xmlhelp +@li @c xmlreader + +*/ +/* vim:set ft=cpp shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/sal/log.hxx b/include/sal/log.hxx new file mode 100644 index 0000000000..a60d8dc248 --- /dev/null +++ b/include/sal/log.hxx @@ -0,0 +1,436 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +/* + * This file is part of LibreOffice published API. + */ + +#ifndef INCLUDED_SAL_LOG_HXX +#define INCLUDED_SAL_LOG_HXX + +#include "sal/config.h" + +#include <cstdlib> +#include <sstream> +#include <string> + +#include "sal/detail/log.h" +#include "sal/saldllapi.h" +#include "sal/types.h" + +// Avoid the use of other sal code in this header as much as possible, so that +// this code can be called from other sal code without causing endless +// recursion. + +/// @cond INTERNAL + +enum sal_detail_LogAction +{ + SAL_DETAIL_LOG_ACTION_IGNORE, + SAL_DETAIL_LOG_ACTION_LOG, + SAL_DETAIL_LOG_ACTION_FATAL +}; + +extern "C" SAL_DLLPUBLIC void SAL_CALL sal_detail_log( + sal_detail_LogLevel level, char const * area, char const * where, + char const * message, sal_uInt32 backtraceDepth); + +extern "C" SAL_DLLPUBLIC void SAL_CALL sal_detail_set_log_selector(char const *logSelector); + +// the return value is actually "enum sal_detail_LogAction", but due to ABI +// compatibility, it's left as the original "sal_Bool" / "unsigned char". +extern "C" SAL_DLLPUBLIC unsigned char SAL_CALL sal_detail_log_report( + sal_detail_LogLevel level, char const * area); + +namespace sal { namespace detail { + +inline void log( + sal_detail_LogLevel level, char const * area, char const * where, + std::ostringstream const & stream, sal_uInt32 backtraceDepth) +{ + // An alternative would be to have sal_detail_log take a std::ostringstream + // pointer (via a C void pointer); the advantage would be smaller client + // code (the ".str().c_str()" part would move into the implementation of + // sal_detail_log) and potential for proper support of embedded null + // characters within the message, but the disadvantage would be dependence + // on the C++ ABI; as a compromise, the ".str().c_str()" part has been moved + // to this inline function so that it is potentially only emitted once per + // dynamic library: + sal_detail_log(level, area, where, stream.str().c_str(), backtraceDepth); +} + +// Special handling of the common case where the message consists of just a +// string literal, to produce smaller call-site code: + +struct StreamStart {}; + +struct StreamString { + StreamString(char const * s): string(s) {} + + char const * string; + + typedef char Result; +}; + +struct StreamIgnore { + typedef struct { char a[2]; } Result; +}; + +inline StreamString operator <<( + SAL_UNUSED_PARAMETER StreamStart const &, char const * s) +{ + return StreamString(s); +} + +template< typename T > inline StreamIgnore operator <<( + SAL_UNUSED_PARAMETER StreamStart const &, SAL_UNUSED_PARAMETER T const &) +{ + std::abort(); +#if defined _MSC_VER && _MSC_VER < 1700 + return StreamIgnore(); +#endif +} + +template< typename T > inline StreamIgnore operator <<( + SAL_UNUSED_PARAMETER StreamString const &, SAL_UNUSED_PARAMETER T const &) +{ + std::abort(); +#if defined _MSC_VER && _MSC_VER < 1700 + return StreamIgnore(); +#endif +} + +template< typename T > inline StreamIgnore operator <<( + SAL_UNUSED_PARAMETER StreamIgnore const &, SAL_UNUSED_PARAMETER T const &) +{ + std::abort(); +#if defined _MSC_VER && _MSC_VER < 1700 + return StreamIgnore(); +#endif +} + +template< typename T > typename T::Result getResult(T const &); + +inline char const * unwrapStream(StreamString const & s) { return s.string; } + +inline char const * unwrapStream(SAL_UNUSED_PARAMETER StreamIgnore const &) { + std::abort(); +#if defined _MSC_VER && _MSC_VER < 1700 + return 0; +#endif +} + +} } + +// to prevent using a local variable, which can eventually shadow, +// resulting in compiler warnings (or even errors with -Werror) +#define SAL_DETAIL_LOG_STREAM_PRIVATE_(level, area, where, stream) \ + if (sizeof ::sal::detail::getResult( \ + ::sal::detail::StreamStart() << stream) == 1) \ + { \ + ::sal_detail_log( \ + (level), (area), (where), \ + ::sal::detail::unwrapStream( \ + ::sal::detail::StreamStart() << stream), \ + 0); \ + } else { \ + ::std::ostringstream sal_detail_stream; \ + sal_detail_stream << stream; \ + ::sal::detail::log( \ + (level), (area), (where), sal_detail_stream, 0); \ + } + +#define SAL_DETAIL_LOG_STREAM(condition, level, area, where, stream) \ + do { \ + if (SAL_UNLIKELY(condition)) \ + { \ + switch (sal_detail_log_report(level, area)) \ + { \ + case SAL_DETAIL_LOG_ACTION_IGNORE: break; \ + case SAL_DETAIL_LOG_ACTION_LOG: \ + SAL_DETAIL_LOG_STREAM_PRIVATE_(level, area, where, stream); \ + break; \ + case SAL_DETAIL_LOG_ACTION_FATAL: \ + SAL_DETAIL_LOG_STREAM_PRIVATE_(level, area, where, stream); \ + std::abort(); \ + break; \ + } \ + } \ + } while (false) + +/// @endcond + +/** A simple macro to create a "file and line number" string. + + Potentially not only useful within the log framework (where it is used + automatically), but also when creating exception messages. + + @attention For now, this functionality should only be used internally within + LibreOffice. It may change again in a future version. + + @since LibreOffice 3.5 +*/ +#define SAL_WHERE SAL_DETAIL_WHERE + +/** A facility for generating temporary string messages by piping items into a + C++ std::ostringstream. + + This can be useful for example in a call to SAL_INFO when depending on some + boolean condition data of incompatible types shall be streamed into the + message, as in: + + SAL_INFO("foo", "object: " << (hasName ? obj->name : SAL_STREAM(obj))); + + @attention For now, this functionality should only be used internally within + LibreOffice. It may change again in a future version. + + @since LibreOffice 3.5 +*/ +#if defined _LIBCPP_VERSION \ + || (defined _GLIBCXX_RELEASE \ + && (_GLIBCXX_RELEASE >= 12 || (_GLIBCXX_RELEASE == 11 && __GLIBCXX__ > 20210428))) \ + || (defined _MSC_VER && _MSC_VER >= 1915) +#define SAL_STREAM(stream) \ + (::std::ostringstream() << stream).str() +#else +#define SAL_STREAM(stream) \ + (dynamic_cast< ::std::ostringstream & >(::std::ostringstream() << stream).str()) +#endif + +/** + @page sal_log Basic logging functionality. + + @short Macros for logging. + + SAL_INFO(char const * area, expr), + SAL_INFO_IF(bool condition, char const * area, expr), + SAL_WARN(char const * area, expr), + SAL_WARN_IF(bool condition, char const * area, expr), and SAL_DEBUG(expr) + produce an info, warning, or debug log entry with a message produced by + piping items into a C++ std::ostringstream. The given expr must be so that + the full expression "stream << expr" is valid, where stream is a variable of + type std::ostringstream. + + SAL_INFO("foo", "string " << s << " of length " << n) + + would be an example of such a call. + + The composed message should be in UTF-8 and it should contain no vertical + formatting characters and no null characters + + For the _IF variants, log output is only generated if the given condition is + true (in addition to the other conditions that have to be met). + + The SAL_DEBUG macro is for temporary debug statements that are used while + working on code. It is never meant to remain in the code. It will always + simply output the given expression in debug builds. + + For all the other macros, the given area argument must be non-null and must + match the regular expression + + @verbatim + <area> ::= <segment>("."<segment>)* + @endverbatim + + with + + @verbatim + <segment> ::= [0-9a-z]+ + @endverbatim + + For a list of areas used see @ref sal_log_areas "SAL debug areas". Whenever + you use a new log area, add it to the file include/sal/log-areas.dox . + + Whether these macros generate any log output is controlled in a two-stage + process. + + First, at compile time the macros SAL_LOG_INFO and SAL_LOG_WARN, + respectively, control whether the INFO and WARN macros, respectively, + expand to actual code (in case the macro is defined, to any value) or to + no-ops (in case the macro is not defined). + + Second, at runtime the environment variable SAL_LOG further limits which + macro calls actually generate log output. The environment variable SAL_LOG + must either be unset or must match the regular expression + + @verbatim + <env> ::= <switch>* + @endverbatim + + with + + @verbatim + <switch> ::= <sense><item> + <sense> ::= "+"|"-" + <item> ::= <flag>|<level>("."<area>)? + <flag> ::= "TIMESTAMP"|"RELATIVETIMER"|"FATAL" + <level> ::= "INFO"|"WARN" + @endverbatim + + If the environment variable is unset, the setting "+WARN" is + assumed instead (which results in all warnings being output but no + infos). If the given value does not match the regular expression, + "+INFO+WARN" is used instead (which in turn results in everything + being output). + + The "+TIMESTAMP" flag causes each output line (as selected by the level + switch(es)) to be prefixed by a timestamp like 2016-08-18:14:04:43. + + The "+RELATIVETIMER" flag causes each output line (as selected by + the level switch(es)) to be prefixed by a relative timestamp in + seconds since the first output line like 1.312. + + The "+FATAL" flag will cause later matching rules to log and call + std::abort. This can be disabled at some later point by using the + "-FATAL" flag before specifying additional rules. The flag will just + abort on positive rules, as it doesn't seem to make sense to abort + on ignored output. + + If both +TIMESTAMP and +RELATIVETIMER are specified, they are + output in that order. + + Specifying a flag with a negative sense has no effect. Specifying + the same flag multiple times has no extra effect. + + A given macro call's level (INFO or WARN) and area is matched against the + given switches as follows: Only those switches for which the level matches + the given level and for which the area is a prefix (including both empty and + full prefixes) of the given area are considered. Log output is generated if + and only if among the longest such switches (if any), there is at least one + that has a sense of "+". (That is, if both +INFO.foo and -INFO.foo are + present, +INFO.foo wins.) + + If no WARN selection is specified, but an INFO selection is, the + INFO selection is used for WARN messages, too. + + For example, if SAL_LOG is "+INFO-INFO.foo+INFO.foo.bar", then calls like + SAL_INFO("foo.bar", ...), SAL_INFO("foo.bar.baz", ...), or + SAL_INFO("other", ...) generate output, while calls like + SAL_INFO("foo", ...) or SAL_INFO("foo.barzzz", ...) do not. + + The generated log output consists of the optional timestamp, the given level + ("info" or "warn"), the given area, the process ID, the thread ID, the + source file, and the source line number, each followed by a colon, followed + by a space, the given message, and a newline. The precise format of the log + output is subject to change. The log output is printed to stderr without + further text encoding conversion. + + On some systems, log output can be redirected to other log sinks, + notably a file provided as a system path and filename via + environment variable SAL_LOG_FILE; or to a syslog facility if + LibreOffice is suitably built, by setting environment variable + SAL_LOG_SYSLOG. + + @see @ref sal_log_areas + + @attention For now, this functionality should only be used internally within + LibreOffice. It may change again in a future version. + + @since LibreOffice 3.5 +*/ + +/** + Produce log entry from stream in the given log area. + + See @ref sal_log "basic logging functionality" for details. +*/ +#define SAL_INFO(area, stream) \ + SAL_DETAIL_LOG_STREAM( \ + SAL_DETAIL_ENABLE_LOG_INFO, ::SAL_DETAIL_LOG_LEVEL_INFO, area, \ + SAL_WHERE, stream) + +/** + Produce log entry from stream in the given log area if condition is true. + + See @ref sal_log "basic logging functionality" for details. +*/ +#define SAL_INFO_IF(condition, area, stream) \ + SAL_DETAIL_LOG_STREAM( \ + SAL_DETAIL_ENABLE_LOG_INFO && (condition), \ + ::SAL_DETAIL_LOG_LEVEL_INFO, area, SAL_WHERE, stream) + +/** + Produce warning entry from stream in the given log area. + + See @ref sal_log "basic logging functionality" for details. +*/ +#define SAL_WARN(area, stream) \ + SAL_DETAIL_LOG_STREAM( \ + SAL_DETAIL_ENABLE_LOG_WARN, ::SAL_DETAIL_LOG_LEVEL_WARN, area, \ + SAL_WHERE, stream) + +/** + Produce warning entry from stream in the given log area if condition is true. + + See @ref sal_log "basic logging functionality" for details. +*/ +#define SAL_WARN_IF(condition, area, stream) \ + SAL_DETAIL_LOG_STREAM( \ + SAL_DETAIL_ENABLE_LOG_WARN && (condition), \ + ::SAL_DETAIL_LOG_LEVEL_WARN, area, SAL_WHERE, stream) + +/** + Produce temporary debugging output from stream. This macro is meant to be + used only while working on code and should never exist in production code. + + See @ref sal_log "basic logging functionality" for details. +*/ +#define SAL_DEBUG(stream) \ + SAL_DETAIL_LOG_STREAM( \ + SAL_LOG_TRUE, ::SAL_DETAIL_LOG_LEVEL_DEBUG, NULL, NULL, stream) + +/** + Produce temporary debugging output from stream, if condition is true. This + macro is meant to be used only while working on code and should never exist + in production code. + + See @ref sal_log "basic logging functionality" for details. +*/ +#define SAL_DEBUG_IF(condition, stream) \ + SAL_DETAIL_LOG_STREAM( \ + (condition), ::SAL_DETAIL_LOG_LEVEL_DEBUG, NULL, NULL, stream) + +/** + Produce temporary debugging output from stream along with a backtrace of the + calling location. + + This macro is meant to be used only while working on code and should never + exist in production code. + + @param stream input stream + + @param backtraceDepth a sal_uInt32 value indicating the maximum backtrace + depth; zero means no backtrace + + See @ref sal_log "basic logging functionality" for details. +*/ +#define SAL_DEBUG_BACKTRACE(stream, backtraceDepth) \ + do { \ + if (sizeof ::sal::detail::getResult( \ + ::sal::detail::StreamStart() << stream) == 1) \ + { \ + ::sal_detail_log( \ + ::SAL_DETAIL_LOG_LEVEL_DEBUG, NULL, NULL, \ + ::sal::detail::unwrapStream( \ + ::sal::detail::StreamStart() << stream), \ + backtraceDepth); \ + } else { \ + ::std::ostringstream sal_detail_stream; \ + sal_detail_stream << stream; \ + ::sal::detail::log( \ + ::SAL_DETAIL_LOG_LEVEL_DEBUG, NULL, NULL, sal_detail_stream, \ + backtraceDepth); \ + } \ + } while (false) + + + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/sal/macros.h b/include/sal/macros.h new file mode 100644 index 0000000000..2705fa63f4 --- /dev/null +++ b/include/sal/macros.h @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ + +#ifndef INCLUDED_SAL_MACROS_H +#define INCLUDED_SAL_MACROS_H + +#include <stddef.h> + +#ifndef SAL_N_ELEMENTS +# if defined(__cplusplus) && ( defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L ) + /* + * Magic template to calculate at compile time the number of elements + * in an array. Enforcing that the argument must be an array and not + * a pointer, e.g. + * char *pFoo="foo"; + * SAL_N_ELEMENTS(pFoo); + * fails while + * SAL_N_ELEMENTS("foo"); + * or + * char aFoo[]="foo"; + * SAL_N_ELEMENTS(aFoo); + * pass + * + * Unfortunately if arr is an array of an anonymous class then we need + * C++0x, i.e. see + * http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#757 + */ + template <typename T, size_t S> char (&sal_n_array_size( T(&)[S] ))[S]; +# define SAL_N_ELEMENTS(arr) (sizeof(sal_n_array_size(arr))) +# else +# define SAL_N_ELEMENTS(arr) (sizeof (arr) / sizeof ((arr)[0])) +# endif +#endif + +#ifndef SAL_STRINGIFY +# define SAL_STRINGIFY_ARG(x) #x +# define SAL_STRINGIFY(x) SAL_STRINGIFY_ARG(x) +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/sal/main.h b/include/sal/main.h new file mode 100644 index 0000000000..42ffdb7618 --- /dev/null +++ b/include/sal/main.h @@ -0,0 +1,153 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ + +#ifndef INCLUDED_SAL_MAIN_H +#define INCLUDED_SAL_MAIN_H + +#include "sal/config.h" + +#include "sal/saldllapi.h" +#include "sal/types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined LIBO_INTERNAL_ONLY && defined __cplusplus +// Special token for sal_detail_initialize argc parameter, used by the soffice.bin process to tell +// SAL that it is running as part of that process (see sal/osl/unx/soffice.hxx); argv should be null +// in such a sal_detail_initialize call: +namespace sal::detail { constexpr int InitializeSoffice = -1; } +#endif + +SAL_DLLPUBLIC void SAL_CALL sal_detail_initialize(int argc, char ** argv); +SAL_DLLPUBLIC void SAL_CALL sal_detail_deinitialize(void); + +#if !(defined IOS || defined ANDROID) + /* No code that uses this should be built for iOS or Android */ + +#define SAL_MAIN_WITH_ARGS_IMPL \ +int SAL_DLLPUBLIC_EXPORT SAL_CALL main(int argc, char ** argv) \ +{ \ + int ret; \ + sal_detail_initialize(argc, argv); \ + ret = sal_main_with_args(argc, argv); \ + sal_detail_deinitialize(); \ + return ret; \ +} + +#define SAL_MAIN_IMPL \ +int SAL_DLLPUBLIC_EXPORT SAL_CALL main(int argc, char ** argv) \ +{ \ + int ret; \ + sal_detail_initialize(argc, argv); \ + ret = sal_main(); \ + sal_detail_deinitialize(); \ + return ret; \ +} + +#endif + + +/* Definition macros for CRT entries */ + +#ifdef _WIN32 + +#include <stdlib.h> + +/* Sorry but this is necessary cause HINSTANCE is a typedef that differs (C++ causes an error) */ + +#ifndef WINAPI +# define WINAPI __stdcall +#endif + +#if !defined(DECLARE_HANDLE) +# ifdef STRICT + typedef void *HANDLE; +# define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name +# else + typedef void *PVOID; + typedef PVOID HANDLE; +# define DECLARE_HANDLE(name) typedef HANDLE name +# endif +DECLARE_HANDLE(HINSTANCE); +#endif + + + +#define SAL_WIN_WinMain \ +int WINAPI WinMain( HINSTANCE _hinst, HINSTANCE _dummy, char* _cmdline, int _nshow ) \ +{ \ + int argc = __argc; char ** argv = __argv; \ + (void) _hinst; (void) _dummy; (void) _cmdline; (void) _nshow; /* unused */ \ + return main(argc, argv); \ +} + +#else /* ! _WIN32 */ + +# define SAL_WIN_WinMain + +#endif /* ! _WIN32 */ + +/* Implementation macro */ + +#define SAL_IMPLEMENT_MAIN_WITH_ARGS(_argc_, _argv_) \ + static int SAL_CALL sal_main_with_args (int _argc_, char ** _argv_); \ + SAL_MAIN_WITH_ARGS_IMPL \ + SAL_WIN_WinMain \ + static int SAL_CALL sal_main_with_args(int _argc_, char ** _argv_) + +#define SAL_IMPLEMENT_MAIN() \ + static int SAL_CALL sal_main(void); \ + SAL_MAIN_IMPL \ + SAL_WIN_WinMain \ + static int SAL_CALL sal_main(void) + +/* + "How to use" Examples: + + #include <sal/main.h> + + SAL_IMPLEMENT_MAIN() + { + DoSomething(); + + return 0; + } + + SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) + { + DoSomethingWithArgs(argc, argv); + + return 0; + } + +*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif // INCLUDED_SAL_MAIN_H + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/sal/mathconf.h b/include/sal/mathconf.h new file mode 100644 index 0000000000..ac824f1e48 --- /dev/null +++ b/include/sal/mathconf.h @@ -0,0 +1,172 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ + +#ifndef INCLUDED_SAL_MATHCONF_H +#define INCLUDED_SAL_MATHCONF_H + +#include "osl/endian.h" + +#if defined __sun +#include <ieeefp.h> +#endif /* __sun */ + +#if defined(__cplusplus) && ( defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L ) +#include <cmath> +#endif + +#if defined(IOS) +#if defined(__cplusplus) +#include <cmath> +#else +#include <math.h> +#endif +#endif + +#if defined __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +/* Generally, the C standard guarantees that at program startup, "trapping or + stopping (if supported) is disabled on all [floating-point] exceptions" + (F.7.3/1 of the August 3, 1998 draft of C99), and that during program + execution, "a programmer can safely assume default modes (or be unaware of + them)" (7.6/2, footnote 161 of the August 3, 1998 draft of C99). Reportedly, + on Windows there are printer drivers that switch on exceptions. To avoid + problems, the SAL_MATH_FPEXCEPTIONS_OFF macro can be used to explicitly + switch off exceptions (on Windows). + */ +#if defined(_WIN32) +#define SAL_MATH_FPEXCEPTIONS_OFF() _control87( _MCW_EM, _MCW_EM ) +#else /* WNT */ +#define SAL_MATH_FPEXCEPTIONS_OFF() +#endif /* WNT */ + + +/* SAL_MATH_FINITE(d): test double d on INFINITY, NaN et al. */ +#if !defined __sun && !defined ANDROID \ + && defined(__cplusplus) \ + && ( defined(__GXX_EXPERIMENTAL_CXX0X__) \ + || __cplusplus >= 201103L \ + || defined(IOS) ) +#define SAL_MATH_FINITE(d) std::isfinite(d) +#elif defined __APPLE__ && !(defined __i386__ || defined __x86_64__) +#define SAL_MATH_FINITE(d) isfinite(d) +#elif defined(_WIN32) +#define SAL_MATH_FINITE(d) _finite(d) +#elif defined(ANDROID) || defined LINUX || defined UNX +#define SAL_MATH_FINITE(d) finite(d) +#else /* WNT, LINUX, UNX */ +#error "SAL_MATH_FINITE not defined" +#endif /* WNT, LINUX, UNX */ + + +/* This needs to be fixed for non--IEEE-754 platforms: */ +#if 1 /* IEEE 754 supported */ +#if defined OSL_BIGENDIAN + +/* IEEE 754 double structures for BigEndian */ +union sal_math_Double +{ + struct + { + unsigned sign : 1; + unsigned exponent :11; + unsigned fraction_hi :20; + unsigned fraction_lo :32; + } inf_parts; + struct + { + unsigned sign : 1; + unsigned exponent :11; + unsigned qnan_bit : 1; + unsigned bits :19; + unsigned fraction_lo :32; + } nan_parts; + struct + { + unsigned msw :32; + unsigned lsw :32; + } w32_parts; + struct + { + sal_uInt64 sign : 1; + sal_uInt64 exponent :11; + sal_uInt64 fraction :52; + } parts; + sal_uInt64 intrep; + double value; +}; + +#elif defined OSL_LITENDIAN + +/* IEEE 754 double structures for LittleEndian */ +union sal_math_Double +{ + struct { + unsigned fraction_lo :32; + unsigned fraction_hi :20; + unsigned exponent :11; + unsigned sign : 1; + } inf_parts; + struct { + unsigned fraction_lo :32; + unsigned bits :19; + unsigned qnan_bit : 1; + unsigned exponent :11; + unsigned sign : 1; + } nan_parts; + struct + { + unsigned lsw :32; + unsigned msw :32; + } w32_parts; + struct + { + sal_uInt64 fraction :52; + sal_uInt64 exponent :11; + sal_uInt64 sign : 1; + } parts; + sal_uInt64 intrep; + double value; +}; + +#else /* OSL_BIGENDIAN, OSL_LITENDIAN */ + +#error "neither OSL_BIGENDIAN nor OSL_LITENDIAN" + +#endif /* OSL_BIGENDIAN, OSL_LITENDIAN */ +#else /* IEEE 754 supported */ + +#error "don't know how to handle IEEE 754" + +#endif /* IEEE 754 supported */ + + +#if defined __cplusplus +} +#endif /* __cplusplus */ + +#endif /* INCLUDED_SAL_MATHCONF_H */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/sal/saldllapi.h b/include/sal/saldllapi.h new file mode 100644 index 0000000000..d5ec89e677 --- /dev/null +++ b/include/sal/saldllapi.h @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ + +#ifndef INCLUDED_SAL_SALDLLAPI_H +#define INCLUDED_SAL_SALDLLAPI_H + +#include "sal/config.h" + +#include "sal/types.h" + +#if defined(SAL_DLLIMPLEMENTATION) +#define SAL_DLLPUBLIC SAL_DLLPUBLIC_EXPORT +#else +#define SAL_DLLPUBLIC SAL_DLLPUBLIC_IMPORT +#endif + +#endif // INCLUDED_SAL_SALDLLAPI_H + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/sal/types.h b/include/sal/types.h new file mode 100644 index 0000000000..df160d2eef --- /dev/null +++ b/include/sal/types.h @@ -0,0 +1,699 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/* + * This file is part of LibreOffice published API. + */ + +#ifndef INCLUDED_SAL_TYPES_H +#define INCLUDED_SAL_TYPES_H + +#include "sal/config.h" + +#include <stddef.h> + +#include "sal/macros.h" +#include "sal/typesizes.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef unsigned char sal_Bool; +# define sal_False ((sal_Bool)0) +# define sal_True ((sal_Bool)1) + +/* char is assumed to always be 1 byte long */ +typedef signed char sal_Int8; +typedef unsigned char sal_uInt8; + +#if SAL_TYPES_SIZEOFSHORT == 2 + typedef signed short sal_Int16; + typedef unsigned short sal_uInt16; +#else + #error "Could not find 16-bit type, add support for your architecture" +#endif + +#if SAL_TYPES_SIZEOFLONG == 4 + typedef signed long sal_Int32; + typedef unsigned long sal_uInt32; + #define SAL_PRIdINT32 "ld" + #define SAL_PRIuUINT32 "lu" + #define SAL_PRIxUINT32 "lx" + #define SAL_PRIXUINT32 "lX" +#elif SAL_TYPES_SIZEOFINT == 4 + typedef signed int sal_Int32; + typedef unsigned int sal_uInt32; + #define SAL_PRIdINT32 "d" + #define SAL_PRIuUINT32 "u" + #define SAL_PRIxUINT32 "x" + #define SAL_PRIXUINT32 "X" +#else + #error "Could not find 32-bit type, add support for your architecture" +#endif + +#ifdef _MSC_VER + typedef __int64 sal_Int64; + typedef unsigned __int64 sal_uInt64; + + /* The following are macros that will add the 64 bit constant suffix. */ + #define SAL_CONST_INT64(x) x##i64 + #define SAL_CONST_UINT64(x) x##ui64 + + #define SAL_PRIdINT64 "I64d" + #define SAL_PRIuUINT64 "I64u" + #define SAL_PRIxUINT64 "I64x" + #define SAL_PRIXUINT64 "I64X" +#elif defined (__GNUC__) + #if SAL_TYPES_SIZEOFLONG == 8 + typedef signed long int sal_Int64; + typedef unsigned long int sal_uInt64; + + + /* The following are macros that will add the 64 bit constant suffix. */ + #define SAL_CONST_INT64(x) x##l + #define SAL_CONST_UINT64(x) x##ul + + #define SAL_PRIdINT64 "ld" + #define SAL_PRIuUINT64 "lu" + #define SAL_PRIxUINT64 "lx" + #define SAL_PRIXUINT64 "lX" + #elif SAL_TYPES_SIZEOFLONGLONG == 8 + typedef signed long long sal_Int64; + typedef unsigned long long sal_uInt64; + + /* The following are macros that will add the 64 bit constant suffix. */ + #define SAL_CONST_INT64(x) x##ll + #define SAL_CONST_UINT64(x) x##ull + + #define SAL_PRIdINT64 "lld" + #define SAL_PRIuUINT64 "llu" + #define SAL_PRIxUINT64 "llx" + #define SAL_PRIXUINT64 "llX" + #else + #error "Could not find 64-bit type, add support for your architecture" + #endif +#else + #error "Please define the 64-bit types for your architecture/compiler in include/sal/types.h" +#endif + +#if defined LIBO_INTERNAL_ONLY && defined __cplusplus + #define SAL_UNICODE_NOTEQUAL_WCHAR_T + typedef char16_t sal_Unicode; +#elif defined(_WIN32) + typedef wchar_t sal_Unicode; +#else + #define SAL_UNICODE_NOTEQUAL_WCHAR_T + typedef sal_uInt16 sal_Unicode; +#endif + +typedef void * sal_Handle; + +/* sal_Size should currently be the native width of the platform */ +#if SAL_TYPES_SIZEOFPOINTER == 4 + typedef sal_uInt32 sal_Size; + typedef sal_Int32 sal_sSize; +#elif SAL_TYPES_SIZEOFPOINTER == 8 + typedef sal_uInt64 sal_Size; + typedef sal_Int64 sal_sSize; +#else + #error "Please make sure SAL_TYPES_SIZEOFPOINTER is defined for your architecture/compiler" +#endif + +/* sal_PtrDiff holds the result of a pointer subtraction */ +#if SAL_TYPES_SIZEOFPOINTER == 4 + typedef sal_Int32 sal_PtrDiff; +#elif SAL_TYPES_SIZEOFPOINTER == 8 + typedef sal_Int64 sal_PtrDiff; +#else + #error "Please make sure SAL_TYPES_SIZEOFPOINTER is defined for your architecture/compiler" +#endif + +/* printf-style conversion specification length modifiers for size_t and + ptrdiff_t (most platforms support C99, MSC has its own extension) */ +#if defined(_MSC_VER) + #define SAL_PRI_SIZET "I" + #define SAL_PRI_PTRDIFFT "I" +#else + #define SAL_PRI_SIZET "z" + #define SAL_PRI_PTRDIFFT "t" +#endif + +/* sal_IntPtr, sal_uIntPtr are integer types designed to hold pointers so that any valid + * pointer to void can be converted to this type and back to a pointer to void and the + * result will compare to the original pointer */ +#if SAL_TYPES_SIZEOFPOINTER == 4 + typedef sal_Int32 sal_IntPtr; + typedef sal_uInt32 sal_uIntPtr; + #define SAL_PRIdINTPTR SAL_PRIdINT32 + #define SAL_PRIuUINTPTR SAL_PRIuUINT32 + #define SAL_PRIxUINTPTR SAL_PRIxUINT32 + #define SAL_PRIXUINTPTR SAL_PRIXUINT32 +#elif SAL_TYPES_SIZEOFPOINTER == 8 + typedef sal_Int64 sal_IntPtr; + typedef sal_uInt64 sal_uIntPtr; + #define SAL_PRIdINTPTR SAL_PRIdINT64 + #define SAL_PRIuUINTPTR SAL_PRIuUINT64 + #define SAL_PRIxUINTPTR SAL_PRIxUINT64 + #define SAL_PRIXUINTPTR SAL_PRIXUINT64 +#else + #error "Please make sure SAL_TYPES_SIZEOFPOINTER is defined for your architecture/compiler" +#endif + +/* The following SAL_MIN_INTn defines codify the assumption that the signed + * sal_Int types use two's complement representation. Defining them as + * "-0x7F... - 1" instead of as "-0x80..." prevents warnings about applying the + * unary minus operator to unsigned quantities. + */ +#define SAL_MIN_INT8 ((sal_Int8) (-0x7F - 1)) +#define SAL_MAX_INT8 ((sal_Int8) 0x7F) +#define SAL_MAX_UINT8 ((sal_uInt8) 0xFF) +#define SAL_MIN_INT16 ((sal_Int16) (-0x7FFF - 1)) +#define SAL_MAX_INT16 ((sal_Int16) 0x7FFF) +#define SAL_MAX_UINT16 ((sal_uInt16) 0xFFFF) +#define SAL_MIN_INT32 ((sal_Int32) (-0x7FFFFFFF - 1)) +#define SAL_MAX_INT32 ((sal_Int32) 0x7FFFFFFF) +#define SAL_MAX_UINT32 ((sal_uInt32) 0xFFFFFFFF) +#define SAL_MIN_INT64 ((sal_Int64) (SAL_CONST_INT64(-0x7FFFFFFFFFFFFFFF) - 1)) +#define SAL_MAX_INT64 ((sal_Int64) SAL_CONST_INT64(0x7FFFFFFFFFFFFFFF)) +#define SAL_MAX_UINT64 ((sal_uInt64) SAL_CONST_UINT64(0xFFFFFFFFFFFFFFFF)) + +#if SAL_TYPES_SIZEOFPOINTER == 4 +#define SAL_MAX_SSIZE SAL_MAX_INT32 +#define SAL_MAX_SIZE SAL_MAX_UINT32 +#elif SAL_TYPES_SIZEOFPOINTER == 8 +#define SAL_MAX_SSIZE SAL_MAX_INT64 +#define SAL_MAX_SIZE SAL_MAX_UINT64 +#endif + +#define SAL_MAX_ENUM 0x7fffffff + +#if defined(_MSC_VER) +# define SAL_DLLPUBLIC_EXPORT __declspec(dllexport) +# define SAL_JNI_EXPORT __declspec(dllexport) +# define SAL_DLLPUBLIC_IMPORT __declspec(dllimport) +# define SAL_DLLPRIVATE +# define SAL_DLLPUBLIC_TEMPLATE +# define SAL_DLLPUBLIC_RTTI +# define SAL_CALL __cdecl +#elif defined SAL_UNX +# if defined(__GNUC__) +# if defined(DISABLE_DYNLOADING) +# define SAL_DLLPUBLIC_EXPORT __attribute__ ((visibility("hidden"))) +# define SAL_JNI_EXPORT __attribute__ ((visibility("default"))) +# define SAL_DLLPUBLIC_IMPORT __attribute__ ((visibility("hidden"))) +# define SAL_DLLPRIVATE __attribute__ ((visibility("hidden"))) +# define SAL_DLLPUBLIC_TEMPLATE __attribute__ ((visibility("hidden"))) +# define SAL_DLLPUBLIC_RTTI +# else +# define SAL_DLLPUBLIC_EXPORT __attribute__ ((visibility("default"))) +# define SAL_JNI_EXPORT __attribute__ ((visibility("default"))) +# define SAL_DLLPUBLIC_IMPORT __attribute__ ((visibility("default"))) +# define SAL_DLLPRIVATE __attribute__ ((visibility("hidden"))) +# define SAL_DLLPUBLIC_TEMPLATE __attribute__ ((visibility("default"))) +# if defined __clang__ +# if __has_attribute(type_visibility) +# define SAL_DLLPUBLIC_RTTI __attribute__ ((type_visibility("default"))) +# else +# define SAL_DLLPUBLIC_RTTI __attribute__ ((visibility("default"))) +# endif +# else +# define SAL_DLLPUBLIC_RTTI +# endif +# endif +# else +# define SAL_DLLPUBLIC_EXPORT +# define SAL_JNI_EXPORT +# define SAL_DLLPUBLIC_IMPORT +# define SAL_DLLPRIVATE +# define SAL_DLLPUBLIC_TEMPLATE +# define SAL_DLLPUBLIC_RTTI +# endif +# define SAL_CALL +#else +# error("unknown platform") +#endif + +/** + Exporting the symbols necessary for exception handling on GCC. + + These macros are used for inline declarations of exception classes, as in + rtl/malformeduriexception.hxx. +*/ +#if defined(__GNUC__) +# if defined(DISABLE_DYNLOADING) +# define SAL_EXCEPTION_DLLPUBLIC_EXPORT __attribute__((visibility("default"))) +# else +# define SAL_EXCEPTION_DLLPUBLIC_EXPORT SAL_DLLPUBLIC_EXPORT +# endif +# define SAL_EXCEPTION_DLLPRIVATE SAL_DLLPRIVATE +#else +# define SAL_EXCEPTION_DLLPUBLIC_EXPORT +# define SAL_EXCEPTION_DLLPRIVATE +#endif + +/** Use this as markup for functions and methods whose return value must be + checked. + + Compilers that support a construct of this nature will emit a compile + time warning on unchecked return value. +*/ +#if defined LIBO_INTERNAL_ONLY && defined __cplusplus +#define SAL_WARN_UNUSED_RESULT [[nodiscard]] +#elif (defined __GNUC__ \ + && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1))) \ + || defined __clang__ +# define SAL_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) +#else +# define SAL_WARN_UNUSED_RESULT +#endif + +/** Use this for pure virtual classes, e.g. class SAL_NO_VTABLE Foo { ... + This hinders the compiler from setting a generic vtable stating that + a pure virtual function was called and thus slightly reduces code size. +*/ +#ifdef _MSC_VER +# define SAL_NO_VTABLE __declspec(novtable) +#else +# define SAL_NO_VTABLE +#endif + +#ifdef _WIN32 +# pragma pack(push, 8) +#endif + +/** This is the binary specification of a SAL sequence. +*/ +typedef struct _sal_Sequence +{ + /** reference count of sequence<br> + */ + sal_Int32 nRefCount; + /** element count<br> + */ + sal_Int32 nElements; + /** elements array<br> + */ + char elements[1]; +} sal_Sequence; + +#define SAL_SEQUENCE_HEADER_SIZE ((sal_Size) offsetof(sal_Sequence,elements)) + +#if defined( _WIN32) +#pragma pack(pop) +#endif + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/** Nothrow specification for C functions. + + This is a macro so it can expand to nothing in C code. +*/ +#if defined __cplusplus +#if __cplusplus >= 201103L +#define SAL_THROW_EXTERN_C() noexcept +#else +#define SAL_THROW_EXTERN_C() throw () +#endif +#else +#define SAL_THROW_EXTERN_C() +#endif + +#ifdef __cplusplus + +/** To markup destructors that coverity warns might throw exceptions + which won't throw in practice, or where std::terminate is + an acceptable response if they do +*/ +#if defined(LIBO_INTERNAL_ONLY) && defined(__COVERITY__) +# define COVERITY_NOEXCEPT_FALSE noexcept(false) +#else +# define COVERITY_NOEXCEPT_FALSE +#endif + +enum __sal_NoAcquire +{ + /** definition of a no acquire enum for ctors + */ + SAL_NO_ACQUIRE +}; + +namespace com { namespace sun { namespace star { } } } + +/** short-circuit extra-verbose API namespaces + + @since LibreOffice 4.0 +*/ +namespace css = ::com::sun::star; + +/** C++11 "= delete" feature. + + For LIBO_INTERNAL_ONLY, calling a deleted function will cause a compile-time + error, while otherwise it will only cause a link-time error as the declared + function is not defined. + + @since LibreOffice 4.1 +*/ +#if defined LIBO_INTERNAL_ONLY +#define SAL_DELETED_FUNCTION = delete +#else +#define SAL_DELETED_FUNCTION +#endif + +/** C++11 "override" feature. + + For LIBO_INTERNAL_ONLY, force the method to override an existing method in + parent, error out if the method with the correct signature does not exist. + + @since LibreOffice 4.1 +*/ +#if defined LIBO_INTERNAL_ONLY +#define SAL_OVERRIDE override +#else +#define SAL_OVERRIDE +#endif + +/** C++11 "constexpr" feature. + + For LIBO_INTERNAL_ONLY, declare that it's possible to evaluate the value + at compile time. + + @since LibreOffice 7.2 +*/ +#if defined LIBO_INTERNAL_ONLY +#define SAL_CONSTEXPR constexpr +#else +#define SAL_CONSTEXPR +#endif + +/** Macro for C++11 "noexcept" vs. "throw ()" exception specification. + + The latter has been removed completely from C++20. + + @since LibreOffice 7.2 + */ +#if __cplusplus >= 201103L +#define SAL_NOEXCEPT noexcept +#else +#define SAL_NOEXCEPT throw () +#endif + +#endif /* __cplusplus */ + +#ifdef __cplusplus + +namespace sal { + +/** + A static_cast between integral types, to avoid C++ compiler warnings. + + In C++ source code, use sal::static_int_cast<T>(n) instead of + static_cast<T>(n) whenever a compiler warning about integral type problems + shall be silenced. That way, source code that needs to be modified when the + type of any of the expressions involved in the compiler warning is changed + can be found more easily. + + Both template arguments T1 and T2 must be integral types. +*/ +template< typename T1, typename T2 > inline T1 static_int_cast(T2 n) { + return static_cast< T1 >(n); +} + +} + +#else /* __cplusplus */ + +/** + A cast between integer types, to avoid C compiler warnings. + + In C source code, use SAL_INT_CAST(type, expr) instead of ((type) (expr)) + whenever a compiler warning about integer type problems shall be silenced. + That way, source code that needs to be modified when the type of any of the + expressions involved in the compiler warning is changed can be found more + easily. + + The argument 'type' must be an integer type and the argument 'expr' must be + an integer expression. Both arguments are evaluated exactly once. +*/ +#define SAL_INT_CAST(type, expr) ((type) (expr)) + +#endif /* __cplusplus */ + +/** + Use as follows: + SAL_DEPRECATED("Don't use, it's evil.") void doit(int nPara); +*/ + +#if defined __GNUC__ || defined __clang__ +#if defined LIBO_INTERNAL_ONLY +# define SAL_DEPRECATED(message) __attribute__((deprecated(message))) +#else +# define SAL_DEPRECATED(message) __attribute__((deprecated)) +#endif +#elif defined(_MSC_VER) +# define SAL_DEPRECATED(message) __declspec(deprecated(message)) +#else +# define SAL_DEPRECATED(message) +#endif + +/** + This macro is used in cppumaker-generated include files, to tag entities that + are marked as @deprecated in UNOIDL. + + It causes deprecation warnings to be generated in external code, but for now + is silenced in internal code. It would need some substantial clean-up of + internal code to fix all warnings/errors generated by it. (Once that is + done, it can become a synonym for SAL_DEPRECATED under LIBO_INTERNAL_ONLY, + too. Completely removing the macro then would be incompatible, in case there + are include files still around generated with a cppumaker that emitted it.) + */ +#ifdef LIBO_INTERNAL_ONLY +# define SAL_DEPRECATED_INTERNAL(message) +#else +# define SAL_DEPRECATED_INTERNAL(message) SAL_DEPRECATED(message) +#endif + +/** + Use as follows: + SAL_WNODEPRECATED_DECLARATIONS_PUSH + \::std::auto_ptr<X> ... + SAL_WNODEPRECATED_DECLARATIONS_POP +*/ + +#if defined LIBO_INTERNAL_ONLY && defined __GNUC__ +#define SAL_WNODEPRECATED_DECLARATIONS_PUSH \ + _Pragma(SAL_STRINGIFY_ARG(GCC diagnostic push)) \ + _Pragma(SAL_STRINGIFY_ARG(GCC diagnostic ignored "-Wdeprecated-declarations")) +#define SAL_WNODEPRECATED_DECLARATIONS_POP \ + _Pragma(SAL_STRINGIFY_ARG(GCC diagnostic pop)) +#else +# define SAL_WNODEPRECATED_DECLARATIONS_PUSH +# define SAL_WNODEPRECATED_DECLARATIONS_POP +#endif + +/** + Use as follows: + + SAL_WNOUNREACHABLE_CODE_PUSH + + function definition + + SAL_WNOUNREACHABLE_CODE_POP + + Useful in cases where the compiler is "too clever" like when doing + link-time code generation, and noticing that a called function + always throws, and fixing the problem cleanly so that it produces + no warnings in normal non-LTO compilations either is not easy. + +*/ + +#ifdef _MSC_VER +#define SAL_WNOUNREACHABLE_CODE_PUSH \ + __pragma(warning(push)) \ + __pragma(warning(disable:4702)) \ + __pragma(warning(disable:4722)) +#define SAL_WNOUNREACHABLE_CODE_POP \ + __pragma(warning(pop)) +#else +/* Add definitions for GCC and Clang if needed */ +#define SAL_WNOUNREACHABLE_CODE_PUSH +#define SAL_WNOUNREACHABLE_CODE_POP +#endif + +/** Annotate unused but required C++ function parameters. + + An unused parameter is required if the function needs to adhere to a given + type (e.g., if its address is assigned to a function pointer of a specific + type, or if it is called from template code). This annotation helps static + analysis tools suppress false warnings. In the case of virtual functions + (where unused required parameters are common, too), the annotation is not + required (as static analysis tools can themselves derive the information + whether a function is virtual). + + Use the annotation in function definitions like + + void f(SAL_UNUSED_PARAMETER int) {} + + C does not allow unnamed parameters, anyway, so a function definition like + the above needs to be written there as + + void f(int dummy) { (void) dummy; / * avoid warnings * / } + + without a SAL_UNUSED_PARAMETER annotation. + + @since LibreOffice 3.6 + */ +#if defined __cplusplus +#if defined __GNUC__ || defined __clang__ +#define SAL_UNUSED_PARAMETER __attribute__ ((unused)) +#else +#define SAL_UNUSED_PARAMETER +#endif +#endif + +/** + + Annotate classes where a compiler should warn if an instance is unused. + + The compiler cannot warn about unused instances if they have non-trivial + or external constructors or destructors. Classes marked with SAL_WARN_UNUSED + will be warned about. + + @since LibreOffice 4.0 + +*/ + +#if defined LIBO_INTERNAL_ONLY && (defined __GNUC__ || defined __clang__) +#define SAL_WARN_UNUSED __attribute__((warn_unused)) +#else +#define SAL_WARN_UNUSED +#endif + +/// @cond INTERNAL + +#if defined __GNUC__ || defined __clang__ +// Macro to try to catch and warn on assignments inside expr. +# define SAL_DETAIL_BOOLEAN_EXPR(expr) \ + __extension__ ({ \ + int sal_boolean_var_; \ + if (expr) \ + sal_boolean_var_ = 1; \ + else \ + sal_boolean_var_ = 0; \ + sal_boolean_var_; \ + }) + +/** An optimization annotation: denotes that expression is likely to be true. + + Use it to annotate paths that we think are likely eg. + if (SAL_LIKELY(ptr != nullptr)) + // this path is the one that is ~always taken. + + @since LibreOffice 5.2 + + Returns: the boolean value of expr (expressed as either int 1 or 0) + */ +# define SAL_LIKELY(expr) __builtin_expect(SAL_DETAIL_BOOLEAN_EXPR((expr)), 1) + +/** An optimization annotation: denotes that expression is unlikely to be true. + + Use it to annotate paths that we think are likely eg. + if (SAL_UNLIKELY(ptr != nullptr)) + // this path is the one that is ~never taken. + + @since LibreOffice 5.2 + + Returns: the boolean value of expr (expressed as either int 1 or 0) + */ +# define SAL_UNLIKELY(expr) __builtin_expect(SAL_DETAIL_BOOLEAN_EXPR((expr)), 0) + +/** An optimization annotation: tells the compiler to work harder at this code + + If the SAL_HOT annotation is present on a function or a label then + subsequent code statements may have more aggressive compiler + optimization and in-lining work performed on them. + + In addition this code can end up in a special section, to be + grouped with other frequently used code. + + @since LibreOffice 5.2 + */ +# define SAL_HOT __attribute__((hot)) + +/** An optimization annotation: tells the compiler to work less on this code + + If the SAL_COLD annotation is present on a function or a label then + subsequent code statements are unlikely to be performed except in + exceptional circumstances, and optimizing for code-size rather + than performance is preferable. + + In addition this code can end up in a special section, to be grouped + with (and away from) other more frequently used code, to improve + locality of reference. + + @since LibreOffice 5.2 + */ +# define SAL_COLD __attribute__((cold)) +#else +# define SAL_LIKELY(expr) (expr) +# define SAL_UNLIKELY(expr) (expr) +# define SAL_HOT +# define SAL_COLD +#endif + +/// @endcond + +/// @cond INTERNAL +/** Annotate pointer-returning functions to indicate that such a pointer + is never nullptr. + + Note that MSVC supports this feature via it's SAL _Ret_notnull_ + annotation, but since it's in a completely different place on + the function declaration, it's a little hard to support both. + + @since LibreOffice 5.5 +*/ +#ifndef __has_attribute +#define __has_attribute(x) 0 +#endif + +#if defined LIBO_INTERNAL_ONLY && ((defined __GNUC__ && !defined __clang__) || (defined __clang__ && __has_attribute(returns_nonnull))) +#define SAL_RETURNS_NONNULL __attribute__((returns_nonnull)) +#else +#define SAL_RETURNS_NONNULL +#endif +/// @endcond + +#if defined LIBO_INTERNAL_ONLY +// An annotation mechanism used by some loplugins. The id argument must be an ordinary string +// literal. For Clang, this expands to a clang::annotate attribute with an annotation consisting of +// the concatenation of a "loplugin:" prefix and the given id suffix. For non-Clang, this expands +// to nothing to avoid e.g. -Wattributes from GCC's -Wall. +#if defined __clang__ +#define SAL_LOPLUGIN_ANNOTATE(id) [[clang::annotate("loplugin:" id)]] +#else +#define SAL_LOPLUGIN_ANNOTATE(id) +#endif +#endif + +#endif // INCLUDED_SAL_TYPES_H + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/sal/typesizes.h b/include/sal/typesizes.h new file mode 100644 index 0000000000..e981818b9c --- /dev/null +++ b/include/sal/typesizes.h @@ -0,0 +1,20 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +/* DO NOT INCLUDE THIS HEADER DIRECTLY! + * + * It is only needed to make the build work. config_typesizes.h is + * copied to SDK as sal/typesizes.h and this is how sal/types.h includes + * it. This means we need to have sal/typesizes.h available for build + * too. + */ + +#include "config_typesizes.h" + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |