diff options
author | wolfbeast <mcwerewolf@gmail.com> | 2018-10-08 08:17:47 +0200 |
---|---|---|
committer | wolfbeast <mcwerewolf@gmail.com> | 2018-10-08 08:17:47 +0200 |
commit | 8a63a2f4175112d96a49a9ad5882839da254b747 (patch) | |
tree | 202c782f572410c47c4ca1f23c68eda613d47c96 | |
parent | 24fb2aaa359cb4abf1248996758672d701db5e24 (diff) | |
parent | a844a9b08c661217c2bc14e424cdd70b5a42e681 (diff) | |
download | uxp-8a63a2f4175112d96a49a9ad5882839da254b747.tar.gz |
Merge branch 'master' of https://github.com/MoonchildProductions/UXP
25 files changed, 3400 insertions, 1020 deletions
diff --git a/application/basilisk/branding/official/branding.nsi b/application/basilisk/branding/official/branding.nsi index 58d7554dfe..250abd84d4 100644 --- a/application/basilisk/branding/official/branding.nsi +++ b/application/basilisk/branding/official/branding.nsi @@ -12,39 +12,5 @@ !define CompanyName "Moonchild Productions" !define URLInfoAbout "https://www.basilisk-browser.org" !define URLUpdateInfo "https://www.basilisk-browser.org/releasenotes.shtml" -!define HelpLink "https://www.basilisk-browser.org" - -; The OFFICIAL define is a workaround to support different urls for Release and -; Beta since they share the same branding when building with other branches that -; set the update channel to beta. -!define OFFICIAL -!define URLStubDownload "" -!define URLManualDownload "" -!define URLSystemRequirements "http://www.basilisk-browser.org/requirements.shtml" -!define Channel "release" - -# The installer's certificate name and issuer expected by the stub installer -!define CertNameDownload "" -!define CertIssuerDownload "" - -# Dialog units are used so the UI displays correctly with the system's DPI -# settings. -# The dialog units for the bitmap's dimensions should match exactly with the -# bitmap's width and height in pixels. -!define APPNAME_BMP_WIDTH_DU "134u" -!define APPNAME_BMP_HEIGHT_DU "36u" -!define INTRO_BLURB_WIDTH_DU "258u" -!define INTRO_BLURB_EDGE_DU "170u" -!define INTRO_BLURB_LTR_TOP_DU "20u" -!define INTRO_BLURB_RTL_TOP_DU "12u" - -# UI Colors that can be customized for each channel -!define FOOTER_CONTROL_TEXT_COLOR_NORMAL 0x000000 -!define FOOTER_CONTROL_TEXT_COLOR_FADED 0x666666 -!define FOOTER_BKGRD_COLOR 0xFFFFFF -!define INTRO_BLURB_TEXT_COLOR 0x666666 -!define INSTALL_BLURB_TEXT_COLOR 0x666666 -!define INSTALL_PROGRESS_TEXT_COLOR_NORMAL 0x666666 -!define COMMON_TEXT_COLOR_NORMAL 0x000000 -!define COMMON_TEXT_COLOR_FADED 0x666666 -!define COMMON_BKGRD_COLOR 0xF0F0F0 +!define HelpLink "https://www.basilisk-browser.org/contact.shtml" +!define URLSystemRequirements "https://www.basilisk-browser.org/requirements.shtml" diff --git a/application/basilisk/branding/unofficial/branding.nsi b/application/basilisk/branding/unofficial/branding.nsi index 77f08a4cb6..586dd00746 100644 --- a/application/basilisk/branding/unofficial/branding.nsi +++ b/application/basilisk/branding/unofficial/branding.nsi @@ -10,36 +10,7 @@ # instead of BrandFullName and typically should not be modified. !define BrandFullNameInternal "Serpent" !define CompanyName "Moonchild Productions" -!define URLInfoAbout "http://www.basilisk-browser.org" +!define URLInfoAbout "https://www.basilisk-browser.org" +!define URLUpdateInfo "https://www.basilisk-browser.org" !define HelpLink "https://forum.palemoon.org" - -!define URLStubDownload "" -!define URLManualDownload "" -!define URLSystemRequirements "" -!define Channel "unofficial" - -# The installer's certificate name and issuer expected by the stub installer -!define CertNameDownload "" -!define CertIssuerDownload "" - -# Dialog units are used so the UI displays correctly with the system's DPI -# settings. -# The dialog units for the bitmap's dimensions should match exactly with the -# bitmap's width and height in pixels. -!define APPNAME_BMP_WIDTH_DU 159u -!define APPNAME_BMP_HEIGHT_DU 50u -!define INTRO_BLURB_WIDTH_DU "230u" -!define INTRO_BLURB_EDGE_DU "198u" -!define INTRO_BLURB_LTR_TOP_DU "16u" -!define INTRO_BLURB_RTL_TOP_DU "11u" - -# UI Colors that can be customized for each channel -!define FOOTER_CONTROL_TEXT_COLOR_NORMAL 0x000000 -!define FOOTER_CONTROL_TEXT_COLOR_FADED 0x999999 -!define FOOTER_BKGRD_COLOR 0xFFFFFF -!define INTRO_BLURB_TEXT_COLOR 0xFFFFFF -!define INSTALL_BLURB_TEXT_COLOR 0xFFFFFF -!define INSTALL_PROGRESS_TEXT_COLOR_NORMAL 0xFFFFFF -!define COMMON_TEXT_COLOR_NORMAL 0xFFFFFF -!define COMMON_TEXT_COLOR_FADED 0xA1AAB3 -!define COMMON_BKGRD_COLOR 0x0F1B26 +!define URLSystemRequirements "https://www.basilisk-browser.org" diff --git a/application/basilisk/installer/windows/Makefile.in b/application/basilisk/installer/windows/Makefile.in index d5580b53d6..bab6ded1a1 100644 --- a/application/basilisk/installer/windows/Makefile.in +++ b/application/basilisk/installer/windows/Makefile.in @@ -79,10 +79,6 @@ $(CONFIG_DIR)/setup.exe:: $(PYTHON) $(topsrcdir)/toolkit/mozapps/installer/windows/nsis/preprocess-locale.py \ --preprocess-locale $(topsrcdir) \ $(PPL_LOCALE_ARGS) $(AB_CD) $(CONFIG_DIR) - $(PYTHON) $(topsrcdir)/toolkit/mozapps/installer/windows/nsis/preprocess-locale.py \ - --preprocess-single-file $(topsrcdir) \ - $(PPL_LOCALE_ARGS) $(CONFIG_DIR) \ - nsisstrings.properties nsisstrings.nlf GARBARGE_DIRS += instgen diff --git a/application/basilisk/installer/windows/nsis/defines.nsi.in b/application/basilisk/installer/windows/nsis/defines.nsi.in index 5ad9b79663..dbb58ca33a 100644 --- a/application/basilisk/installer/windows/nsis/defines.nsi.in +++ b/application/basilisk/installer/windows/nsis/defines.nsi.in @@ -3,23 +3,6 @@ # 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/. -# Defining FunnelcakeVersion will append the value of StubURLVersionAppend to -# StubURLVersion, append the value of URLManualDownloadAppend to -# URLManualDownload, and append the value of URLStubDownloadAppend to -# URLStubDownload. The value of FunnelcakeVersion should not be defined when it -# is not used and when it is defined its value should never be empty. -# !define FunnelcakeVersion "999" - -!ifdef FunnelcakeVersion -!define URLManualDownloadAppend "&f=${FunnelcakeVersion}" -!define URLStubDownloadAppend "-f${FunnelcakeVersion}" -!define StubURLVersionAppend "-${FunnelcakeVersion}" -!else -!define URLManualDownloadAppend "" -!define URLStubDownloadAppend "" -!define StubURLVersionAppend "" -!endif - # These defines should match application.ini settings !define AppName "Basilisk" !define AppVersion "@APP_VERSION@" @@ -84,13 +67,3 @@ VIAddVersionKey "FileVersion" "${AppVersion}" VIAddVersionKey "ProductVersion" "${AppVersion}" # Comments is not used but left below commented out for future reference # VIAddVersionKey "Comments" "Comments" - -# Control positions in Dialog Units so they are placed correctly with -# non-default DPI settings -!define OPTIONS_ITEM_EDGE_DU 90u -!define OPTIONS_ITEM_WIDTH_DU 356u -!define OPTIONS_SUBITEM_EDGE_DU 119u -!define OPTIONS_SUBITEM_WIDTH_DU 327u -!define INSTALL_BLURB_TOP_DU 78u -!define APPNAME_BMP_EDGE_DU 19u -!define APPNAME_BMP_TOP_DU 12u diff --git a/application/basilisk/locales/en-US/installer/nsisstrings.properties b/application/basilisk/locales/en-US/installer/nsisstrings.properties deleted file mode 100644 index 3894056969..0000000000 --- a/application/basilisk/locales/en-US/installer/nsisstrings.properties +++ /dev/null @@ -1,67 +0,0 @@ -# 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/. - -# LOCALIZATION NOTE: - -# This file must be saved as UTF8 - -# Accesskeys are defined by prefixing the letter that is to be used for the -# accesskey with an ampersand (e.g. &). - -# Do not replace $BrandShortName, $BrandFullName, or $BrandFullNameDA with a -# custom string and always use the same one as used by the en-US files. -# $BrandFullNameDA allows the string to contain an ampersand (e.g. DA stands -# for double ampersand) and prevents the letter following the ampersand from -# being used as an accesskey. - -# You can use \n to create a newline in the string but only when the string -# from en-US contains a \n. - -WIN_CAPTION=$BrandShortName Setup - -INTRO_BLURB1=Thanks for choosing $BrandFullName, the browser that chooses you above everything else. -INSTALL_BLURB1=You're about to enjoy the very latest in speed, flexibility and security so you're always in control. -INSTALL_BLURB2=That's because $BrandShortName is made by a non-profit to make browsing and the Web better for you. -INSTALL_BLURB3=You're also joining a global community of users, contributors and developers working to make the best browser in the world. - -WARN_MIN_SUPPORTED_OSVER_MSG=Sorry, $BrandShortName can't be installed. This version of $BrandShortName requires ${MinSupportedVer} or newer. Please click the OK button for additional information. -WARN_MIN_SUPPORTED_CPU_MSG=Sorry, $BrandShortName can't be installed. This version of $BrandShortName requires a processor with ${MinSupportedCPU} support. Please click the OK button for additional information. -WARN_MIN_SUPPORTED_OSVER_CPU_MSG=Sorry, $BrandShortName can't be installed. This version of $BrandShortName requires ${MinSupportedVer} or newer and a processor with ${MinSupportedCPU} support. Please click the OK button for additional information. -WARN_WRITE_ACCESS=You don't have access to write to the installation directory.\n\nClick OK to select a different directory. -WARN_DISK_SPACE=You don't have sufficient disk space to install to this location.\n\nClick OK to select a different location. -WARN_ROOT_INSTALL=Unable to install to the root of your disk.\n\nClick OK to select a different location. -WARN_MANUALLY_CLOSE_APP_LAUNCH=$BrandShortName is already running.\n\nPlease close $BrandShortName prior to launching the version you have just installed. - -ERROR_DOWNLOAD=Your download was interrupted.\n\nPlease click the OK button to continue. - -INSTALL_BUTTON=&Install -UPGRADE_BUTTON=&Upgrade -CANCEL_BUTTON=Cancel -OPTIONS_BUTTON=&Options - -MAKE_DEFAULT=&Make $BrandShortName my default browser -CREATE_SHORTCUTS=Create Shortcuts for $BrandShortName: -ADD_SC_TASKBAR=On my &Task bar -ADD_SC_QUICKLAUNCHBAR=On my &Quick Launch bar -ADD_CheckboxShortcutInStartMenu=In my &Start Menu Programs Folder -ADD_CheckboxShortcutOnDesktop=On my &Desktop -SPACE_REQUIRED=Space Required: -SPACE_AVAILABLE=Space Available: -ONE_MOMENT_INSTALL=One moment, $BrandShortName will launch as soon as the install is complete… -ONE_MOMENT_UPGRADE=One moment, $BrandShortName will launch as soon as the upgrade is complete… -INSTALL_MAINT_SERVICE=&Install the $BrandShortName background update service -SEND_PING=S&end information about this installation to Mozilla -BROWSE_BUTTON=B&rowse… -DEST_FOLDER=Destination Folder - -DOWNLOADING_LABEL=Downloading $BrandShortName… -INSTALLING_LABEL=Installing $BrandShortName… -UPGRADING_LABEL=Upgrading $BrandShortName… - -SELECT_FOLDER_TEXT=Select the folder to install $BrandShortName in. - -BYTE=B -KILO=K -MEGA=M -GIGA=G diff --git a/application/palemoon/branding/official/branding.nsi b/application/palemoon/branding/official/branding.nsi index 2b6dbe7bd7..3bceda9007 100644 --- a/application/palemoon/branding/official/branding.nsi +++ b/application/palemoon/branding/official/branding.nsi @@ -11,39 +11,6 @@ !define BrandFullNameInternal "Pale Moon" !define CompanyName "Moonchild Productions" !define URLInfoAbout "http://www.palemoon.org/" -!define URLUpdateInfo "http://www.palemoon.org/releasenotes-ng.shtml" - -; The OFFICIAL define is a workaround to support different urls for Release and -; Beta since they share the same branding when building with other branches that -; set the update channel to beta. -!define OFFICIAL -!define URLStubDownload "" -!define URLManualDownload "http://www.palemoon.org/download-ng.shtml" -!define Channel "release" - -# The installer's certificate name and issuer expected by the stub installer -# !define CertNameDownload "Mozilla Corporation" -# !define CertIssuerDownload "Thawte Code Signing CA - G2" - -# Dialog units are used so the UI displays correctly with the system's DPI -# settings. -# The dialog units for the bitmap's dimensions should match exactly with the -# bitmap's width and height in pixels. -!define APPNAME_BMP_WIDTH_DU "134u" -!define APPNAME_BMP_HEIGHT_DU "36u" -!define INTRO_BLURB_WIDTH_DU "258u" -!define INTRO_BLURB_EDGE_DU "170u" -!define INTRO_BLURB_LTR_TOP_DU "20u" -!define INTRO_BLURB_RTL_TOP_DU "12u" - -# UI Colors that can be customized for each channel -!define FOOTER_CONTROL_TEXT_COLOR_NORMAL 0x000033 -!define FOOTER_CONTROL_TEXT_COLOR_FADED 0x666699 -!define FOOTER_BKGRD_COLOR 0xFFFFFF -!define INTRO_BLURB_TEXT_COLOR 0x666699 -!define OPTIONS_TEXT_COLOR_NORMAL 0x000000 -!define OPTIONS_TEXT_COLOR_FADED 0x666699 -!define OPTIONS_BKGRD_COLOR 0xF0F0F0 -!define INSTALL_BLURB_TEXT_COLOR 0x666699 -!define INSTALL_PROGRESS_TEXT_COLOR_NORMAL 0x666699 -!define INSTALL_PROGRESS_TEXT_COLOR_FADED 0x9999C0 +!define URLUpdateInfo "http://www.palemoon.org/releasenotes.shtml" +!define HelpLink "http://www.palemoon.org/troubleshooting.shtml" +!define URLSystemRequirements "http://www.palemoon.org/download.shtml" diff --git a/application/palemoon/branding/unofficial/branding.nsi b/application/palemoon/branding/unofficial/branding.nsi index cf1642eafa..62ed242a25 100644 --- a/application/palemoon/branding/unofficial/branding.nsi +++ b/application/palemoon/branding/unofficial/branding.nsi @@ -12,29 +12,5 @@ !define CompanyName "Moonchild Productions" !define URLInfoAbout "http://www.palemoon.org" !define URLUpdateInfo "http://www.palemoon.org" - -!define URLManualDownload "http://www.palemoon.org/download-ng.shtml" -!define Channel "unofficial" - -# Dialog units are used so the UI displays correctly with the system's DPI -# settings. -# The dialog units for the bitmap's dimensions should match exactly with the -# bitmap's width and height in pixels. -!define APPNAME_BMP_WIDTH_DU 159u -!define APPNAME_BMP_HEIGHT_DU 26u -!define INTRO_BLURB_WIDTH_DU "230u" -!define INTRO_BLURB_EDGE_DU "198u" -!define INTRO_BLURB_LTR_TOP_DU "16u" -!define INTRO_BLURB_RTL_TOP_DU "11u" - -# UI Colors that can be customized for each channel -!define FOOTER_CONTROL_TEXT_COLOR_NORMAL 0x000000 -!define FOOTER_CONTROL_TEXT_COLOR_FADED 0x999999 -!define FOOTER_BKGRD_COLOR 0xFFFFFF -!define INTRO_BLURB_TEXT_COLOR 0xFFFFFF -!define OPTIONS_TEXT_COLOR_NORMAL 0xFFFFFF -!define OPTIONS_TEXT_COLOR_FADED 0xA1AAB3 -!define OPTIONS_BKGRD_COLOR 0x0F1B26 -!define INSTALL_BLURB_TEXT_COLOR 0xFFFFFF -!define INSTALL_PROGRESS_TEXT_COLOR_NORMAL 0xFFFFFF -!define INSTALL_PROGRESS_TEXT_COLOR_FADED 0xA1AAB3 +!define HelpLink "http://www.palemoon.org" +!define URLSystemRequirements "http://www.palemoon.org/download.shtml" diff --git a/application/palemoon/branding/unstable/branding.nsi b/application/palemoon/branding/unstable/branding.nsi index 4a9199b221..535cfde33c 100644 --- a/application/palemoon/branding/unstable/branding.nsi +++ b/application/palemoon/branding/unstable/branding.nsi @@ -11,36 +11,6 @@ !define BrandFullNameInternal "Pale Moon" !define CompanyName "Moonchild Productions" !define URLInfoAbout "http://www.palemoon.org/" -!define URLUpdateInfo "http://www.palemoon.org/unstable.shtml" - -; The OFFICIAL define is a workaround to support different urls for Release and -; Beta since they share the same branding when building with other branches that -; set the update channel to beta. -!define OFFICIAL -!define URLStubDownload "" -!define URLManualDownload "http://www.palemoon.org/unstable.shtml" -!define Channel "unstable" - - -# Dialog units are used so the UI displays correctly with the system's DPI -# settings. -# The dialog units for the bitmap's dimensions should match exactly with the -# bitmap's width and height in pixels. -!define APPNAME_BMP_WIDTH_DU "134u" -!define APPNAME_BMP_HEIGHT_DU "36u" -!define INTRO_BLURB_WIDTH_DU "258u" -!define INTRO_BLURB_EDGE_DU "170u" -!define INTRO_BLURB_LTR_TOP_DU "20u" -!define INTRO_BLURB_RTL_TOP_DU "12u" - -# UI Colors that can be customized for each channel -!define FOOTER_CONTROL_TEXT_COLOR_NORMAL 0x000033 -!define FOOTER_CONTROL_TEXT_COLOR_FADED 0x666699 -!define FOOTER_BKGRD_COLOR 0xFFFFFF -!define INTRO_BLURB_TEXT_COLOR 0x666699 -!define OPTIONS_TEXT_COLOR_NORMAL 0x000000 -!define OPTIONS_TEXT_COLOR_FADED 0x666699 -!define OPTIONS_BKGRD_COLOR 0xF0F0F0 -!define INSTALL_BLURB_TEXT_COLOR 0x666699 -!define INSTALL_PROGRESS_TEXT_COLOR_NORMAL 0x666699 -!define INSTALL_PROGRESS_TEXT_COLOR_FADED 0x9999C0 +!define URLUpdateInfo "http://www.palemoon.org/unstable/" +!define HelpLink "http://www.palemoon.org/unstable/" +!define URLSystemRequirements "http://www.palemoon.org/download.shtml" diff --git a/application/palemoon/installer/windows/Makefile.in b/application/palemoon/installer/windows/Makefile.in index 7ba70d9123..9b0f697c81 100644 --- a/application/palemoon/installer/windows/Makefile.in +++ b/application/palemoon/installer/windows/Makefile.in @@ -79,10 +79,6 @@ $(CONFIG_DIR)/setup.exe:: $(PYTHON) $(topsrcdir)/toolkit/mozapps/installer/windows/nsis/preprocess-locale.py \ --preprocess-locale $(topsrcdir) \ $(PPL_LOCALE_ARGS) $(AB_CD) $(CONFIG_DIR) - $(PYTHON) $(topsrcdir)/toolkit/mozapps/installer/windows/nsis/preprocess-locale.py \ - --preprocess-single-file $(topsrcdir) \ - $(PPL_LOCALE_ARGS) $(CONFIG_DIR) \ - nsisstrings.properties nsisstrings.nlf GARBARGE_DIRS += instgen diff --git a/application/palemoon/installer/windows/nsis/defines.nsi.in b/application/palemoon/installer/windows/nsis/defines.nsi.in index 97422c4f66..edef802a90 100644 --- a/application/palemoon/installer/windows/nsis/defines.nsi.in +++ b/application/palemoon/installer/windows/nsis/defines.nsi.in @@ -3,23 +3,6 @@ # 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/. -# Defining FunnelcakeVersion will append the value of StubURLVersionAppend to -# StubURLVersion, append the value of URLManualDownloadAppend to -# URLManualDownload, and append the value of URLStubDownloadAppend to -# URLStubDownload. The value of FunnelcakeVersion should not be defined when it -# is not used and when it is defined its value should never be empty. -# !define FunnelcakeVersion "999" - -!ifdef FunnelcakeVersion -!define URLManualDownloadAppend "&f=${FunnelcakeVersion}" -!define URLStubDownloadAppend "-f${FunnelcakeVersion}" -!define StubURLVersionAppend "-${FunnelcakeVersion}" -!else -!define URLManualDownloadAppend "" -!define URLStubDownloadAppend "" -!define StubURLVersionAppend "" -!endif - # These defines should match application.ini settings !define AppName "Pale Moon" !define AppVersion "@APP_VERSION@" @@ -84,13 +67,3 @@ VIAddVersionKey "FileVersion" "${AppVersion}" VIAddVersionKey "ProductVersion" "${AppVersion}" # Comments is not used but left below commented out for future reference # VIAddVersionKey "Comments" "Comments" - -# Control positions in Dialog Units so they are placed correctly with -# non-default DPI settings -!define OPTIONS_ITEM_EDGE_DU 90u -!define OPTIONS_ITEM_WIDTH_DU 356u -!define OPTIONS_SUBITEM_EDGE_DU 119u -!define OPTIONS_SUBITEM_WIDTH_DU 327u -!define INSTALL_BLURB_TOP_DU 78u -!define APPNAME_BMP_EDGE_DU 19u -!define APPNAME_BMP_TOP_DU 12u diff --git a/application/palemoon/locales/en-US/installer/nsisstrings.properties b/application/palemoon/locales/en-US/installer/nsisstrings.properties deleted file mode 100644 index fc2898860d..0000000000 --- a/application/palemoon/locales/en-US/installer/nsisstrings.properties +++ /dev/null @@ -1,67 +0,0 @@ -# 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/. - -# LOCALIZATION NOTE: - -# This file must be saved as UTF8 - -# Accesskeys are defined by prefixing the letter that is to be used for the -# accesskey with an ampersand (e.g. &). - -# Do not replace $BrandShortName, $BrandFullName, or $BrandFullNameDA with a -# custom string and always use the same one as used by the en-US files. -# $BrandFullNameDA allows the string to contain an ampersand (e.g. DA stands -# for double ampersand) and prevents the letter following the ampersand from -# being used as an accesskey. - -# You can use \n to create a newline in the string but only when the string -# from en-US contains a \n. - -WIN_CAPTION=$BrandShortName Setup - -INTRO_BLURB1=Thanks for choosing $BrandFullName, the browser that chooses you above everything else. -INSTALL_BLURB1=You're about to enjoy the very latest in speed, flexibility and security so you're always in control. -INSTALL_BLURB2=That's because $BrandShortName is made by a non-profit to make browsing and the Web better for you. -INSTALL_BLURB3=You're also joining a global community of users, contributors and developers working to make the best browser in the world. - -WARN_MIN_SUPPORTED_OSVER_MSG=Sorry, $BrandShortName can't be installed. This version of $BrandShortName requires ${MinSupportedVer} or newer. -WARN_MIN_SUPPORTED_CPU_MSG=Sorry, $BrandShortName can't be installed. This version of $BrandShortName requires a processor with ${MinSupportedCPU} support. -WARN_MIN_SUPPORTED_OSVER_CPU_MSG=Sorry, $BrandShortName can't be installed. This version of $BrandShortName requires ${MinSupportedVer} or newer and a processor with ${MinSupportedCPU} support. -WARN_WRITE_ACCESS=You don't have access to write to the installation directory.\n\nClick OK to select a different directory. -WARN_DISK_SPACE=You don't have sufficient disk space to install to this location.\n\nClick OK to select a different location. -WARN_ROOT_INSTALL=Unable to install to the root of your disk.\n\nClick OK to select a different location. -WARN_MANUALLY_CLOSE_APP_LAUNCH=$BrandShortName is already running.\n\nPlease close $BrandShortName prior to launching the version you have just installed. - -ERROR_DOWNLOAD=Your download was interrupted.\n\nPlease click the OK button to continue. - -INSTALL_BUTTON=&Install -UPGRADE_BUTTON=&Upgrade -CANCEL_BUTTON=Cancel -OPTIONS_BUTTON=&Options - -MAKE_DEFAULT=&Make $BrandShortName my default browser -CREATE_SHORTCUTS=Create Shortcuts for $BrandShortName: -ADD_SC_TASKBAR=On my &Task bar -ADD_SC_QUICKLAUNCHBAR=On my &Quick Launch bar -ADD_CheckboxShortcutInStartMenu=In my &Start Menu Programs Folder -ADD_CheckboxShortcutOnDesktop=On my &Desktop -SPACE_REQUIRED=Space Required: -SPACE_AVAILABLE=Space Available: -ONE_MOMENT_INSTALL=One moment, $BrandShortName will launch as soon as the install is complete… -ONE_MOMENT_UPGRADE=One moment, $BrandShortName will launch as soon as the upgrade is complete… -INSTALL_MAINT_SERVICE=&Install the $BrandShortName background update service -SEND_PING=S&end information about this installation to Mozilla -BROWSE_BUTTON=B&rowse… -DEST_FOLDER=Destination Folder - -DOWNLOADING_LABEL=Downloading $BrandShortName… -INSTALLING_LABEL=Installing $BrandShortName… -UPGRADING_LABEL=Upgrading $BrandShortName… - -SELECT_FOLDER_TEXT=Select the folder to install $BrandShortName in. - -BYTE=B -KILO=K -MEGA=M -GIGA=G diff --git a/media/ffvpx/README_MCP b/media/ffvpx/README_MCP index 4546d45a3d..26834d3e38 100644 --- a/media/ffvpx/README_MCP +++ b/media/ffvpx/README_MCP @@ -13,9 +13,6 @@ configuration files were generated as follow using the configure script: config*: replace: /HAVE_(MALLOC_H|ARC4RANDOM|LOCALTIME_R|MEMALIGN|POSIX_MEMALIGN)/d -config_darwin32.h: -add to configure command: --disable-asm --disable-x86asm --cc='clang -m32' - config_unix32.h: add to configure command: --disable-asm --disable-x86asm --cc='clang -m32' replace: s/HAVE_SYSCTL 1/HAVE_SYSCTL 0/ and s/HAVE_MEMALIGN 1/HAVE_MEMALIGN 0/ and s/HAVE_POSIX_MEMALIGN 1/HAVE_POSIX_MEMALIGN 0/ diff --git a/media/ffvpx/config.h b/media/ffvpx/config.h index dab01e05cd..fb2a3b5292 100644 --- a/media/ffvpx/config.h +++ b/media/ffvpx/config.h @@ -27,10 +27,7 @@ #define HAVE_LIBC_MSVCRT 0 #endif #elif defined(XP_DARWIN) -#if defined(HAVE_64BIT_BUILD) #include "config_darwin64.h" -#else -#include "config_darwin32.h" #endif #elif defined(XP_UNIX) #if defined(HAVE_64BIT_BUILD) diff --git a/media/ffvpx/config_darwin32.h b/media/ffvpx/config_darwin32.h deleted file mode 100644 index f92be8737d..0000000000 --- a/media/ffvpx/config_darwin32.h +++ /dev/null @@ -1,654 +0,0 @@ -/* Automatically generated by configure - do not modify! */ -#ifndef FFMPEG_CONFIG_H -#define FFMPEG_CONFIG_H -#define FFMPEG_CONFIGURATION "--disable-everything --disable-protocols --disable-demuxers --disable-muxers --disable-filters --disable-programs --disable-doc --disable-parsers --enable-parser=vp8 --enable-parser=vp9 --enable-decoder=vp8 --enable-decoder=vp9 --disable-static --enable-shared --disable-debug --disable-sdl --disable-libxcb --disable-securetransport --disable-iconv --disable-swresample --disable-swscale --disable-avdevice --disable-avfilter --disable-avformat --disable-d3d11va --disable-dxva2 --disable-vaapi --disable-vda --disable-vdpau --disable-videotoolbox --enable-asm --enable-yasm --disable-asm --disable-yasm --cc='clang -m32'" -#define FFMPEG_LICENSE "LGPL version 2.1 or later" -#define CONFIG_THIS_YEAR 2016 -#define FFMPEG_DATADIR "/usr/local/share/ffmpeg" -#define AVCONV_DATADIR "/usr/local/share/ffmpeg" -#define CC_IDENT "Apple LLVM version 7.0.2 (clang-700.1.81)" -#define av_restrict restrict -#define EXTERN_PREFIX "_" -#define EXTERN_ASM _ -#define BUILDSUF "" -#define SLIBSUF ".dylib" -#define HAVE_MMX2 HAVE_MMXEXT -#define SWS_MAX_FILTER_SIZE 256 -#define ARCH_AARCH64 0 -#define ARCH_ALPHA 0 -#define ARCH_ARM 0 -#define ARCH_AVR32 0 -#define ARCH_AVR32_AP 0 -#define ARCH_AVR32_UC 0 -#define ARCH_BFIN 0 -#define ARCH_IA64 0 -#define ARCH_M68K 0 -#define ARCH_MIPS 0 -#define ARCH_MIPS64 0 -#define ARCH_PARISC 0 -#define ARCH_PPC 0 -#define ARCH_PPC64 0 -#define ARCH_S390 0 -#define ARCH_SH4 0 -#define ARCH_SPARC 0 -#define ARCH_SPARC64 0 -#define ARCH_TILEGX 0 -#define ARCH_TILEPRO 0 -#define ARCH_TOMI 0 -#define ARCH_X86 0 -#define ARCH_X86_32 0 -#define ARCH_X86_64 0 -#define HAVE_ARMV5TE 0 -#define HAVE_ARMV6 0 -#define HAVE_ARMV6T2 0 -#define HAVE_ARMV8 0 -#define HAVE_NEON 0 -#define HAVE_VFP 0 -#define HAVE_VFPV3 0 -#define HAVE_SETEND 0 -#define HAVE_ALTIVEC 0 -#define HAVE_DCBZL 0 -#define HAVE_LDBRX 0 -#define HAVE_POWER8 0 -#define HAVE_PPC4XX 0 -#define HAVE_VSX 0 -#define HAVE_AESNI 0 -#define HAVE_AMD3DNOW 0 -#define HAVE_AMD3DNOWEXT 0 -#define HAVE_AVX 0 -#define HAVE_AVX2 0 -#define HAVE_FMA3 0 -#define HAVE_FMA4 0 -#define HAVE_MMX 0 -#define HAVE_MMXEXT 0 -#define HAVE_SSE 0 -#define HAVE_SSE2 0 -#define HAVE_SSE3 0 -#define HAVE_SSE4 0 -#define HAVE_SSE42 0 -#define HAVE_SSSE3 0 -#define HAVE_XOP 0 -#define HAVE_CPUNOP 0 -#define HAVE_I686 0 -#define HAVE_MIPSFPU 0 -#define HAVE_MIPS32R2 0 -#define HAVE_MIPS32R5 0 -#define HAVE_MIPS64R2 0 -#define HAVE_MIPS32R6 0 -#define HAVE_MIPS64R6 0 -#define HAVE_MIPSDSP 0 -#define HAVE_MIPSDSPR2 0 -#define HAVE_MSA 0 -#define HAVE_LOONGSON2 0 -#define HAVE_LOONGSON3 0 -#define HAVE_MMI 0 -#define HAVE_ARMV5TE_EXTERNAL 0 -#define HAVE_ARMV6_EXTERNAL 0 -#define HAVE_ARMV6T2_EXTERNAL 0 -#define HAVE_ARMV8_EXTERNAL 0 -#define HAVE_NEON_EXTERNAL 0 -#define HAVE_VFP_EXTERNAL 0 -#define HAVE_VFPV3_EXTERNAL 0 -#define HAVE_SETEND_EXTERNAL 0 -#define HAVE_ALTIVEC_EXTERNAL 0 -#define HAVE_DCBZL_EXTERNAL 0 -#define HAVE_LDBRX_EXTERNAL 0 -#define HAVE_POWER8_EXTERNAL 0 -#define HAVE_PPC4XX_EXTERNAL 0 -#define HAVE_VSX_EXTERNAL 0 -#define HAVE_AESNI_EXTERNAL 0 -#define HAVE_AMD3DNOW_EXTERNAL 0 -#define HAVE_AMD3DNOWEXT_EXTERNAL 0 -#define HAVE_AVX_EXTERNAL 0 -#define HAVE_AVX2_EXTERNAL 0 -#define HAVE_FMA3_EXTERNAL 0 -#define HAVE_FMA4_EXTERNAL 0 -#define HAVE_MMX_EXTERNAL 0 -#define HAVE_MMXEXT_EXTERNAL 0 -#define HAVE_SSE_EXTERNAL 0 -#define HAVE_SSE2_EXTERNAL 0 -#define HAVE_SSE3_EXTERNAL 0 -#define HAVE_SSE4_EXTERNAL 0 -#define HAVE_SSE42_EXTERNAL 0 -#define HAVE_SSSE3_EXTERNAL 0 -#define HAVE_XOP_EXTERNAL 0 -#define HAVE_CPUNOP_EXTERNAL 0 -#define HAVE_I686_EXTERNAL 0 -#define HAVE_MIPSFPU_EXTERNAL 0 -#define HAVE_MIPS32R2_EXTERNAL 0 -#define HAVE_MIPS32R5_EXTERNAL 0 -#define HAVE_MIPS64R2_EXTERNAL 0 -#define HAVE_MIPS32R6_EXTERNAL 0 -#define HAVE_MIPS64R6_EXTERNAL 0 -#define HAVE_MIPSDSP_EXTERNAL 0 -#define HAVE_MIPSDSPR2_EXTERNAL 0 -#define HAVE_MSA_EXTERNAL 0 -#define HAVE_LOONGSON2_EXTERNAL 0 -#define HAVE_LOONGSON3_EXTERNAL 0 -#define HAVE_MMI_EXTERNAL 0 -#define HAVE_ARMV5TE_INLINE 0 -#define HAVE_ARMV6_INLINE 0 -#define HAVE_ARMV6T2_INLINE 0 -#define HAVE_ARMV8_INLINE 0 -#define HAVE_NEON_INLINE 0 -#define HAVE_VFP_INLINE 0 -#define HAVE_VFPV3_INLINE 0 -#define HAVE_SETEND_INLINE 0 -#define HAVE_ALTIVEC_INLINE 0 -#define HAVE_DCBZL_INLINE 0 -#define HAVE_LDBRX_INLINE 0 -#define HAVE_POWER8_INLINE 0 -#define HAVE_PPC4XX_INLINE 0 -#define HAVE_VSX_INLINE 0 -#define HAVE_AESNI_INLINE 0 -#define HAVE_AMD3DNOW_INLINE 0 -#define HAVE_AMD3DNOWEXT_INLINE 0 -#define HAVE_AVX_INLINE 0 -#define HAVE_AVX2_INLINE 0 -#define HAVE_FMA3_INLINE 0 -#define HAVE_FMA4_INLINE 0 -#define HAVE_MMX_INLINE 0 -#define HAVE_MMXEXT_INLINE 0 -#define HAVE_SSE_INLINE 0 -#define HAVE_SSE2_INLINE 0 -#define HAVE_SSE3_INLINE 0 -#define HAVE_SSE4_INLINE 0 -#define HAVE_SSE42_INLINE 0 -#define HAVE_SSSE3_INLINE 0 -#define HAVE_XOP_INLINE 0 -#define HAVE_CPUNOP_INLINE 0 -#define HAVE_I686_INLINE 0 -#define HAVE_MIPSFPU_INLINE 0 -#define HAVE_MIPS32R2_INLINE 0 -#define HAVE_MIPS32R5_INLINE 0 -#define HAVE_MIPS64R2_INLINE 0 -#define HAVE_MIPS32R6_INLINE 0 -#define HAVE_MIPS64R6_INLINE 0 -#define HAVE_MIPSDSP_INLINE 0 -#define HAVE_MIPSDSPR2_INLINE 0 -#define HAVE_MSA_INLINE 0 -#define HAVE_LOONGSON2_INLINE 0 -#define HAVE_LOONGSON3_INLINE 0 -#define HAVE_MMI_INLINE 0 -#define HAVE_ALIGNED_STACK 0 -#define HAVE_FAST_64BIT 0 -#define HAVE_FAST_CLZ 0 -#define HAVE_FAST_CMOV 0 -#define HAVE_LOCAL_ALIGNED_8 1 -#define HAVE_LOCAL_ALIGNED_16 1 -#define HAVE_LOCAL_ALIGNED_32 1 -#define HAVE_SIMD_ALIGN_16 0 -#define HAVE_ATOMICS_GCC 1 -#define HAVE_ATOMICS_SUNCC 0 -#define HAVE_ATOMICS_WIN32 0 -#define HAVE_ATOMIC_CAS_PTR 0 -#define HAVE_ATOMIC_COMPARE_EXCHANGE 1 -#define HAVE_MACHINE_RW_BARRIER 0 -#define HAVE_MEMORYBARRIER 0 -#define HAVE_MM_EMPTY 1 -#define HAVE_RDTSC 0 -#define HAVE_SARESTART 1 -#define HAVE_SEM_TIMEDWAIT 1 -#define HAVE_SYNC_VAL_COMPARE_AND_SWAP 1 -#define HAVE_CABS 1 -#define HAVE_CEXP 1 -#define HAVE_INLINE_ASM 1 -#define HAVE_SYMVER 1 -#define HAVE_YASM 0 -#define HAVE_BIGENDIAN 0 -#define HAVE_FAST_UNALIGNED 0 -#define HAVE_ALSA_ASOUNDLIB_H 0 -#define HAVE_ALTIVEC_H 0 -#define HAVE_ARPA_INET_H 1 -#define HAVE_ASM_TYPES_H 0 -#define HAVE_CDIO_PARANOIA_H 0 -#define HAVE_CDIO_PARANOIA_PARANOIA_H 0 -#define HAVE_DISPATCH_DISPATCH_H 0 -#define HAVE_DEV_BKTR_IOCTL_BT848_H 0 -#define HAVE_DEV_BKTR_IOCTL_METEOR_H 0 -#define HAVE_DEV_IC_BT8XX_H 0 -#define HAVE_DEV_VIDEO_BKTR_IOCTL_BT848_H 0 -#define HAVE_DEV_VIDEO_METEOR_IOCTL_METEOR_H 0 -#define HAVE_DIRECT_H 0 -#define HAVE_DIRENT_H 1 -#define HAVE_DLFCN_H 1 -#define HAVE_D3D11_H 0 -#define HAVE_DXVA_H 0 -#define HAVE_ES2_GL_H 0 -#define HAVE_GSM_H 0 -#define HAVE_IO_H 0 -#define HAVE_MACH_MACH_TIME_H 1 -#define HAVE_MACHINE_IOCTL_BT848_H 0 -#define HAVE_MACHINE_IOCTL_METEOR_H 0 -#define HAVE_OPENCV2_CORE_CORE_C_H 0 -#define HAVE_OPENJPEG_2_1_OPENJPEG_H 0 -#define HAVE_OPENJPEG_2_0_OPENJPEG_H 0 -#define HAVE_OPENJPEG_1_5_OPENJPEG_H 0 -#define HAVE_OPENGL_GL3_H 0 -#define HAVE_POLL_H 1 -#define HAVE_SNDIO_H 0 -#define HAVE_SOUNDCARD_H 0 -#define HAVE_SYS_MMAN_H 1 -#define HAVE_SYS_PARAM_H 1 -#define HAVE_SYS_RESOURCE_H 1 -#define HAVE_SYS_SELECT_H 1 -#define HAVE_SYS_SOUNDCARD_H 0 -#define HAVE_SYS_TIME_H 1 -#define HAVE_SYS_UN_H 1 -#define HAVE_SYS_VIDEOIO_H 0 -#define HAVE_TERMIOS_H 1 -#define HAVE_UDPLITE_H 0 -#define HAVE_UNISTD_H 1 -#define HAVE_VALGRIND_VALGRIND_H 0 -#define HAVE_WINDOWS_H 0 -#define HAVE_WINSOCK2_H 0 -#define HAVE_INTRINSICS_NEON 0 -#define HAVE_ATANF 1 -#define HAVE_ATAN2F 1 -#define HAVE_CBRT 1 -#define HAVE_CBRTF 1 -#define HAVE_COPYSIGN 1 -#define HAVE_COSF 1 -#define HAVE_ERF 1 -#define HAVE_EXP2 1 -#define HAVE_EXP2F 1 -#define HAVE_EXPF 1 -#define HAVE_HYPOT 1 -#define HAVE_ISFINITE 1 -#define HAVE_ISINF 1 -#define HAVE_ISNAN 1 -#define HAVE_LDEXPF 1 -#define HAVE_LLRINT 1 -#define HAVE_LLRINTF 1 -#define HAVE_LOG2 1 -#define HAVE_LOG2F 1 -#define HAVE_LOG10F 1 -#define HAVE_LRINT 1 -#define HAVE_LRINTF 1 -#define HAVE_POWF 1 -#define HAVE_RINT 1 -#define HAVE_ROUND 1 -#define HAVE_ROUNDF 1 -#define HAVE_SINF 1 -#define HAVE_TRUNC 1 -#define HAVE_TRUNCF 1 -#define HAVE_ACCESS 1 -#define HAVE_ALIGNED_MALLOC 0 -#define HAVE_CLOCK_GETTIME 0 -#define HAVE_CLOSESOCKET 0 -#define HAVE_COMMANDLINETOARGVW 0 -#define HAVE_COTASKMEMFREE 0 -#define HAVE_CRYPTGENRANDOM 0 -#define HAVE_DLOPEN 1 -#define HAVE_FCNTL 1 -#define HAVE_FLT_LIM 1 -#define HAVE_FORK 1 -#define HAVE_GETADDRINFO 1 -#define HAVE_GETHRTIME 0 -#define HAVE_GETOPT 1 -#define HAVE_GETPROCESSAFFINITYMASK 0 -#define HAVE_GETPROCESSMEMORYINFO 0 -#define HAVE_GETPROCESSTIMES 0 -#define HAVE_GETRUSAGE 1 -#define HAVE_GETSYSTEMTIMEASFILETIME 0 -#define HAVE_GETTIMEOFDAY 1 -#define HAVE_GLOB 1 -#define HAVE_GLXGETPROCADDRESS 0 -#define HAVE_GMTIME_R 1 -#define HAVE_INET_ATON 1 -#define HAVE_ISATTY 1 -#define HAVE_JACK_PORT_GET_LATENCY_RANGE 0 -#define HAVE_KBHIT 0 -#define HAVE_LOADLIBRARY 0 -#define HAVE_LSTAT 1 -#define HAVE_LZO1X_999_COMPRESS 0 -#define HAVE_MACH_ABSOLUTE_TIME 1 -#define HAVE_MAPVIEWOFFILE 0 -#define HAVE_MKSTEMP 1 -#define HAVE_MMAP 1 -#define HAVE_MPROTECT 1 -#define HAVE_NANOSLEEP 1 -#define HAVE_PEEKNAMEDPIPE 0 -#define HAVE_PTHREAD_CANCEL 1 -#define HAVE_SCHED_GETAFFINITY 0 -#define HAVE_SETCONSOLETEXTATTRIBUTE 0 -#define HAVE_SETCONSOLECTRLHANDLER 0 -#define HAVE_SETMODE 0 -#define HAVE_SETRLIMIT 1 -#define HAVE_SLEEP 0 -#define HAVE_STRERROR_R 1 -#define HAVE_SYSCONF 1 -#define HAVE_USLEEP 1 -#define HAVE_UTGETOSTYPEFROMSTRING 1 -#define HAVE_VIRTUALALLOC 0 -#define HAVE_WGLGETPROCADDRESS 0 -#define HAVE_PTHREADS 1 -#define HAVE_OS2THREADS 0 -#define HAVE_W32THREADS 0 -#define HAVE_AS_DN_DIRECTIVE 0 -#define HAVE_AS_FUNC 0 -#define HAVE_AS_OBJECT_ARCH 0 -#define HAVE_ASM_MOD_Q 0 -#define HAVE_ATTRIBUTE_MAY_ALIAS 1 -#define HAVE_ATTRIBUTE_PACKED 1 -#define HAVE_EBP_AVAILABLE 1 -#define HAVE_EBX_AVAILABLE 1 -#define HAVE_GNU_AS 0 -#define HAVE_GNU_WINDRES 0 -#define HAVE_IBM_ASM 0 -#define HAVE_INLINE_ASM_DIRECT_SYMBOL_REFS 1 -#define HAVE_INLINE_ASM_LABELS 1 -#define HAVE_INLINE_ASM_NONLOCAL_LABELS 1 -#define HAVE_PRAGMA_DEPRECATED 1 -#define HAVE_RSYNC_CONTIMEOUT 0 -#define HAVE_SYMVER_ASM_LABEL 1 -#define HAVE_SYMVER_GNU_ASM 0 -#define HAVE_VFP_ARGS 0 -#define HAVE_XFORM_ASM 0 -#define HAVE_XMM_CLOBBERS 1 -#define HAVE_CONDITION_VARIABLE_PTR 0 -#define HAVE_SOCKLEN_T 1 -#define HAVE_STRUCT_ADDRINFO 1 -#define HAVE_STRUCT_GROUP_SOURCE_REQ 1 -#define HAVE_STRUCT_IP_MREQ_SOURCE 1 -#define HAVE_STRUCT_IPV6_MREQ 1 -#define HAVE_STRUCT_MSGHDR_MSG_FLAGS 1 -#define HAVE_STRUCT_POLLFD 1 -#define HAVE_STRUCT_RUSAGE_RU_MAXRSS 1 -#define HAVE_STRUCT_SCTP_EVENT_SUBSCRIBE 0 -#define HAVE_STRUCT_SOCKADDR_IN6 1 -#define HAVE_STRUCT_SOCKADDR_SA_LEN 1 -#define HAVE_STRUCT_SOCKADDR_STORAGE 1 -#define HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC 0 -#define HAVE_STRUCT_V4L2_FRMIVALENUM_DISCRETE 0 -#define HAVE_ATOMICS_NATIVE 1 -#define HAVE_DOS_PATHS 0 -#define HAVE_DXVA2_LIB 0 -#define HAVE_DXVA2API_COBJ 0 -#define HAVE_LIBC_MSVCRT 0 -#define HAVE_LIBDC1394_1 0 -#define HAVE_LIBDC1394_2 0 -#define HAVE_MAKEINFO 1 -#define HAVE_MAKEINFO_HTML 1 -#define HAVE_MMAL_PARAMETER_VIDEO_MAX_NUM_CALLBACKS 0 -#define HAVE_PERL 1 -#define HAVE_POD2MAN 1 -#define HAVE_SDL2 0 -#define HAVE_SECTION_DATA_REL_RO 0 -#define HAVE_TEXI2HTML 0 -#define HAVE_THREADS 1 -#define HAVE_VAAPI_DRM 0 -#define HAVE_VAAPI_X11 0 -#define HAVE_VDPAU_X11 0 -#define HAVE_WINRT 0 -#define HAVE_XLIB 0 -#define CONFIG_BSFS 0 -#define CONFIG_DECODERS 1 -#define CONFIG_PARSERS 1 -#define CONFIG_DOC 0 -#define CONFIG_HTMLPAGES 1 -#define CONFIG_MANPAGES 1 -#define CONFIG_PODPAGES 1 -#define CONFIG_TXTPAGES 1 -#define CONFIG_AVIO_DIR_CMD_EXAMPLE 1 -#define CONFIG_AVIO_READING_EXAMPLE 1 -#define CONFIG_DECODING_ENCODING_EXAMPLE 0 -#define CONFIG_DEMUXING_DECODING_EXAMPLE 0 -#define CONFIG_EXTRACT_MVS_EXAMPLE 0 -#define CONFIG_FILTER_AUDIO_EXAMPLE 0 -#define CONFIG_FILTERING_AUDIO_EXAMPLE 0 -#define CONFIG_FILTERING_VIDEO_EXAMPLE 0 -#define CONFIG_HTTP_MULTICLIENT_EXAMPLE 0 -#define CONFIG_METADATA_EXAMPLE 0 -#define CONFIG_MUXING_EXAMPLE 0 -#define CONFIG_QSVDEC_EXAMPLE 0 -#define CONFIG_REMUXING_EXAMPLE 0 -#define CONFIG_RESAMPLING_AUDIO_EXAMPLE 0 -#define CONFIG_SCALING_VIDEO_EXAMPLE 0 -#define CONFIG_TRANSCODE_AAC_EXAMPLE 0 -#define CONFIG_TRANSCODING_EXAMPLE 0 -#define CONFIG_AVISYNTH 0 -#define CONFIG_BZLIB 0 -#define CONFIG_CHROMAPRINT 0 -#define CONFIG_CRYSTALHD 0 -#define CONFIG_DECKLINK 0 -#define CONFIG_FREI0R 0 -#define CONFIG_GCRYPT 0 -#define CONFIG_GMP 0 -#define CONFIG_GNUTLS 0 -#define CONFIG_ICONV 0 -#define CONFIG_JNI 0 -#define CONFIG_LADSPA 0 -#define CONFIG_LIBASS 0 -#define CONFIG_LIBBLURAY 0 -#define CONFIG_LIBBS2B 0 -#define CONFIG_LIBCACA 0 -#define CONFIG_LIBCDIO 0 -#define CONFIG_LIBCELT 0 -#define CONFIG_LIBDC1394 0 -#define CONFIG_LIBEBUR128 0 -#define CONFIG_LIBFDK_AAC 0 -#define CONFIG_LIBFLITE 0 -#define CONFIG_LIBFONTCONFIG 0 -#define CONFIG_LIBFREETYPE 0 -#define CONFIG_LIBFRIBIDI 0 -#define CONFIG_LIBGME 0 -#define CONFIG_LIBGSM 0 -#define CONFIG_LIBIEC61883 0 -#define CONFIG_LIBILBC 0 -#define CONFIG_LIBKVAZAAR 0 -#define CONFIG_LIBMODPLUG 0 -#define CONFIG_LIBMP3LAME 0 -#define CONFIG_LIBNUT 0 -#define CONFIG_LIBOPENCORE_AMRNB 0 -#define CONFIG_LIBOPENCORE_AMRWB 0 -#define CONFIG_LIBOPENCV 0 -#define CONFIG_LIBOPENH264 0 -#define CONFIG_LIBOPENJPEG 0 -#define CONFIG_LIBOPENMPT 0 -#define CONFIG_LIBOPUS 0 -#define CONFIG_LIBPULSE 0 -#define CONFIG_LIBRTMP 0 -#define CONFIG_LIBRUBBERBAND 0 -#define CONFIG_LIBSCHROEDINGER 0 -#define CONFIG_LIBSHINE 0 -#define CONFIG_LIBSMBCLIENT 0 -#define CONFIG_LIBSNAPPY 0 -#define CONFIG_LIBSOXR 0 -#define CONFIG_LIBSPEEX 0 -#define CONFIG_LIBSSH 0 -#define CONFIG_LIBTESSERACT 0 -#define CONFIG_LIBTHEORA 0 -#define CONFIG_LIBTWOLAME 0 -#define CONFIG_LIBV4L2 0 -#define CONFIG_LIBVIDSTAB 0 -#define CONFIG_LIBVO_AMRWBENC 0 -#define CONFIG_LIBVORBIS 0 -#define CONFIG_LIBVPX 0 -#define CONFIG_LIBWAVPACK 0 -#define CONFIG_LIBWEBP 0 -#define CONFIG_LIBX264 0 -#define CONFIG_LIBX265 0 -#define CONFIG_LIBXAVS 0 -#define CONFIG_LIBXCB 0 -#define CONFIG_LIBXCB_SHM 0 -#define CONFIG_LIBXCB_SHAPE 0 -#define CONFIG_LIBXCB_XFIXES 0 -#define CONFIG_LIBXVID 0 -#define CONFIG_LIBZIMG 0 -#define CONFIG_LIBZMQ 0 -#define CONFIG_LIBZVBI 0 -#define CONFIG_LZMA 0 -#define CONFIG_MEDIACODEC 0 -#define CONFIG_NETCDF 0 -#define CONFIG_OPENAL 0 -#define CONFIG_OPENCL 0 -#define CONFIG_OPENGL 0 -#define CONFIG_OPENSSL 0 -#define CONFIG_SCHANNEL 0 -#define CONFIG_SDL 0 -#define CONFIG_SDL2 0 -#define CONFIG_SECURETRANSPORT 0 -#define CONFIG_VIDEOTOOLBOX 0 -#define CONFIG_X11GRAB 0 -#define CONFIG_XLIB 0 -#define CONFIG_ZLIB 0 -#define CONFIG_AUDIOTOOLBOX 0 -#define CONFIG_CUDA 0 -#define CONFIG_CUVID 0 -#define CONFIG_D3D11VA 0 -#define CONFIG_DXVA2 0 -#define CONFIG_LIBMFX 0 -#define CONFIG_LIBNPP 0 -#define CONFIG_MMAL 0 -#define CONFIG_NVENC 0 -#define CONFIG_OMX 0 -#define CONFIG_VAAPI 0 -#define CONFIG_VDA 0 -#define CONFIG_VDPAU 0 -#define CONFIG_XVMC 0 -#define CONFIG_FTRAPV 0 -#define CONFIG_GRAY 0 -#define CONFIG_HARDCODED_TABLES 0 -#define CONFIG_OMX_RPI 0 -#define CONFIG_RUNTIME_CPUDETECT 1 -#define CONFIG_SAFE_BITSTREAM_READER 1 -#define CONFIG_SHARED 1 -#define CONFIG_SMALL 0 -#define CONFIG_STATIC 0 -#define CONFIG_SWSCALE_ALPHA 1 -#define CONFIG_GPL 0 -#define CONFIG_NONFREE 0 -#define CONFIG_VERSION3 0 -#define CONFIG_AVCODEC 1 -#define CONFIG_AVDEVICE 0 -#define CONFIG_AVFILTER 0 -#define CONFIG_AVFORMAT 0 -#define CONFIG_AVRESAMPLE 0 -#define CONFIG_AVUTIL 1 -#define CONFIG_POSTPROC 0 -#define CONFIG_SWRESAMPLE 0 -#define CONFIG_SWSCALE 0 -#define CONFIG_FFPLAY 0 -#define CONFIG_FFPROBE 0 -#define CONFIG_FFSERVER 0 -#define CONFIG_FFMPEG 0 -#define CONFIG_DCT 0 -#define CONFIG_DWT 0 -#define CONFIG_ERROR_RESILIENCE 0 -#define CONFIG_FAAN 1 -#define CONFIG_FAST_UNALIGNED 0 -#define CONFIG_FFT 0 -#define CONFIG_LSP 0 -#define CONFIG_LZO 0 -#define CONFIG_MDCT 0 -#define CONFIG_PIXELUTILS 0 -#define CONFIG_NETWORK 0 -#define CONFIG_RDFT 0 -#define CONFIG_FONTCONFIG 0 -#define CONFIG_MEMALIGN_HACK 0 -#define CONFIG_MEMORY_POISONING 0 -#define CONFIG_NEON_CLOBBER_TEST 0 -#define CONFIG_PIC 1 -#define CONFIG_POD2MAN 1 -#define CONFIG_RAISE_MAJOR 0 -#define CONFIG_THUMB 0 -#define CONFIG_VALGRIND_BACKTRACE 0 -#define CONFIG_XMM_CLOBBER_TEST 0 -#define CONFIG_AANDCTTABLES 0 -#define CONFIG_AC3DSP 0 -#define CONFIG_AUDIO_FRAME_QUEUE 0 -#define CONFIG_AUDIODSP 0 -#define CONFIG_BLOCKDSP 0 -#define CONFIG_BSWAPDSP 0 -#define CONFIG_CABAC 0 -#define CONFIG_DIRAC_PARSE 0 -#define CONFIG_DVPROFILE 0 -#define CONFIG_EXIF 0 -#define CONFIG_FAANDCT 0 -#define CONFIG_FAANIDCT 0 -#define CONFIG_FDCTDSP 0 -#define CONFIG_FLACDSP 1 -#define CONFIG_FMTCONVERT 0 -#define CONFIG_G722DSP 0 -#define CONFIG_GOLOMB 1 -#define CONFIG_GPLV3 0 -#define CONFIG_H263DSP 0 -#define CONFIG_H264CHROMA 0 -#define CONFIG_H264DSP 0 -#define CONFIG_H264PRED 1 -#define CONFIG_H264QPEL 0 -#define CONFIG_HPELDSP 0 -#define CONFIG_HUFFMAN 0 -#define CONFIG_HUFFYUVDSP 0 -#define CONFIG_HUFFYUVENCDSP 0 -#define CONFIG_IDCTDSP 0 -#define CONFIG_IIRFILTER 0 -#define CONFIG_IMDCT15 0 -#define CONFIG_INTRAX8 0 -#define CONFIG_ISO_MEDIA 0 -#define CONFIG_IVIDSP 0 -#define CONFIG_JPEGTABLES 0 -#define CONFIG_LGPLV3 0 -#define CONFIG_LIBX262 0 -#define CONFIG_LLAUDDSP 0 -#define CONFIG_LLVIDDSP 0 -#define CONFIG_LPC 0 -#define CONFIG_LZF 0 -#define CONFIG_ME_CMP 0 -#define CONFIG_MPEG_ER 0 -#define CONFIG_MPEGAUDIO 0 -#define CONFIG_MPEGAUDIODSP 0 -#define CONFIG_MPEGVIDEO 0 -#define CONFIG_MPEGVIDEOENC 0 -#define CONFIG_MSS34DSP 0 -#define CONFIG_PIXBLOCKDSP 0 -#define CONFIG_QPELDSP 0 -#define CONFIG_QSV 0 -#define CONFIG_QSVDEC 0 -#define CONFIG_QSVENC 0 -#define CONFIG_RANGECODER 0 -#define CONFIG_RIFFDEC 0 -#define CONFIG_RIFFENC 0 -#define CONFIG_RTPDEC 0 -#define CONFIG_RTPENC_CHAIN 0 -#define CONFIG_RV34DSP 0 -#define CONFIG_SINEWIN 0 -#define CONFIG_SNAPPY 0 -#define CONFIG_SRTP 0 -#define CONFIG_STARTCODE 0 -#define CONFIG_TEXTUREDSP 0 -#define CONFIG_TEXTUREDSPENC 0 -#define CONFIG_TPELDSP 0 -#define CONFIG_VAAPI_ENCODE 0 -#define CONFIG_VC1DSP 0 -#define CONFIG_VIDEODSP 1 -#define CONFIG_VP3DSP 0 -#define CONFIG_VP56DSP 0 -#define CONFIG_VP8DSP 1 -#define CONFIG_VT_BT2020 0 -#define CONFIG_WMA_FREQS 0 -#define CONFIG_WMV2DSP 0 -#define CONFIG_AAC_ADTSTOASC_BSF 0 -#define CONFIG_CHOMP_BSF 0 -#define CONFIG_DUMP_EXTRADATA_BSF 0 -#define CONFIG_DCA_CORE_BSF 0 -#define CONFIG_H264_MP4TOANNEXB_BSF 0 -#define CONFIG_HEVC_MP4TOANNEXB_BSF 0 -#define CONFIG_IMX_DUMP_HEADER_BSF 0 -#define CONFIG_MJPEG2JPEG_BSF 0 -#define CONFIG_MJPEGA_DUMP_HEADER_BSF 0 -#define CONFIG_MP3_HEADER_DECOMPRESS_BSF 0 -#define CONFIG_MPEG4_UNPACK_BFRAMES_BSF 0 -#define CONFIG_MOV2TEXTSUB_BSF 0 -#define CONFIG_NOISE_BSF 0 -#define CONFIG_REMOVE_EXTRADATA_BSF 0 -#define CONFIG_TEXT2MOVSUB_BSF 0 -#define CONFIG_VP9_SUPERFRAME_BSF 0 -#define CONFIG_VP8_DECODER 1 -#define CONFIG_VP9_DECODER 1 -#define CONFIG_FLAC_DECODER 1 -#define CONFIG_FLAC_PARSER 1 -#define CONFIG_VP8_PARSER 1 -#define CONFIG_VP9_PARSER 1 -#endif /* FFMPEG_CONFIG_H */ diff --git a/media/ffvpx/ffvpxcommon.mozbuild b/media/ffvpx/ffvpxcommon.mozbuild index 620158694b..b6230bb9f7 100644 --- a/media/ffvpx/ffvpxcommon.mozbuild +++ b/media/ffvpx/ffvpxcommon.mozbuild @@ -21,7 +21,7 @@ if CONFIG['FFVPX_ASFLAGS']: else: ASFLAGS += ['-Pconfig_win64.asm'] elif CONFIG['OS_ARCH'] == 'Darwin': - # 32/64-bit macosx assemblers need to prefix symbols with an underscore. + # 64-bit macosx assemblers need to prefix symbols with an underscore. ASFLAGS += [ '-Pconfig_darwin64.asm', '-DPREFIX' diff --git a/mfbt/Casting.h b/mfbt/Casting.h index a7d0fb50d6..adf2c90456 100644 --- a/mfbt/Casting.h +++ b/mfbt/Casting.h @@ -238,6 +238,19 @@ AssertedCast(const From aFrom) return static_cast<To>(aFrom); } +/** + * Cast a value of integral type |From| to a value of integral type |To|, + * release asserting that the cast will be a safe cast per C++ (that is, that + * |to| is in the range of values permitted for the type |From|). + */ +template<typename To, typename From> +inline To +ReleaseAssertedCast(const From aFrom) +{ + MOZ_RELEASE_ASSERT((detail::IsInBounds<From, To>(aFrom))); + return static_cast<To>(aFrom); +} + } // namespace mozilla #endif /* mozilla_Casting_h */ diff --git a/mfbt/Range.h b/mfbt/Range.h index 47d91bb0cc..753fe07f89 100644 --- a/mfbt/Range.h +++ b/mfbt/Range.h @@ -9,6 +9,7 @@ #include "mozilla/RangedPtr.h" #include "mozilla/TypeTraits.h" +#include "mozilla/Span.h" #include <stddef.h> @@ -44,6 +45,19 @@ public: mEnd(aOther.mEnd) {} + MOZ_IMPLICIT Range(Span<T> aSpan) + : Range(aSpan.Elements(), aSpan.Length()) + { + } + + template<typename U, + class = typename EnableIf<IsConvertible<U (*)[], T (*)[]>::value, + int>::Type> + MOZ_IMPLICIT Range(const Span<U>& aSpan) + : Range(aSpan.Elements(), aSpan.Length()) + { + } + RangedPtr<T> begin() const { return mStart; } RangedPtr<T> end() const { return mEnd; } size_t length() const { return mEnd - mStart; } @@ -51,8 +65,26 @@ public: T& operator[](size_t aOffset) const { return mStart[aOffset]; } explicit operator bool() const { return mStart != nullptr; } + + operator Span<T>() { return Span<T>(mStart.get(), length()); } + + operator Span<const T>() const { return Span<T>(mStart.get(), length()); } }; +template<class T> +Span<T> +MakeSpan(Range<T>& aRange) +{ + return aRange; +} + +template<class T> +Span<const T> +MakeSpan(const Range<T>& aRange) +{ + return aRange; +} + } // namespace mozilla #endif /* mozilla_Range_h */ diff --git a/mfbt/Span.h b/mfbt/Span.h new file mode 100644 index 0000000000..f031a928bb --- /dev/null +++ b/mfbt/Span.h @@ -0,0 +1,1041 @@ +/////////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2015 Microsoft Corporation. All rights reserved. +// +// This code is licensed under the MIT License (MIT). +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +/////////////////////////////////////////////////////////////////////////////// + +// Adapted from https://github.com/Microsoft/GSL/blob/3819df6e378ffccf0e29465afe99c3b324c2aa70/include/gsl/span +// and https://github.com/Microsoft/GSL/blob/3819df6e378ffccf0e29465afe99c3b324c2aa70/include/gsl/gsl_util + +#ifndef mozilla_Span_h +#define mozilla_Span_h + +#include "mozilla/Array.h" +#include "mozilla/Assertions.h" +#include "mozilla/Casting.h" +#include "mozilla/IntegerTypeTraits.h" +#include "mozilla/Move.h" +#include "mozilla/TypeTraits.h" +#include "mozilla/UniquePtr.h" + +#include <algorithm> +#include <array> +#include <cstring> +#include <iterator> + +// Classifications for reasons why constexpr was removed in C++14 to C++11 +// conversion. Once we upgrade compilers, we can try defining each of these +// to constexpr to restore a category of constexprs at a time. +#define MOZ_SPAN_ASSERTION_CONSTEXPR +#define MOZ_SPAN_GCC_CONSTEXPR +#define MOZ_SPAN_EXPLICITLY_DEFAULTED_CONSTEXPR +#define MOZ_SPAN_CONSTEXPR_NOT_JUST_RETURN +#define MOZ_SPAN_NON_CONST_CONSTEXPR + +#ifdef _MSC_VER +#pragma warning(push) + +// turn off some warnings that are noisy about our MOZ_RELEASE_ASSERT statements +#pragma warning(disable : 4127) // conditional expression is constant + +// blanket turn off warnings from CppCoreCheck for now +// so people aren't annoyed by them when running the tool. +// more targeted suppressions will be added in a future update to the GSL +#pragma warning(disable : 26481 26482 26483 26485 26490 26491 26492 26493 26495) + +#if _MSC_VER < 1910 +#pragma push_macro("constexpr") +#define constexpr /*constexpr*/ + +#endif // _MSC_VER < 1910 +#endif // _MSC_VER + +namespace mozilla { + +// Stuff from gsl_util + +// narrow_cast(): a searchable way to do narrowing casts of values +template<class T, class U> +inline constexpr T +narrow_cast(U&& u) +{ + return static_cast<T>(mozilla::Forward<U>(u)); +} + +// end gsl_util + +// [views.constants], constants +// This was -1 in gsl::span, but using size_t for sizes instead of ptrdiff_t +// and reserving a magic value that realistically doesn't occur in +// compile-time-constant Span sizes makes things a lot less messy in terms of +// comparison between signed and unsigned. +constexpr const size_t dynamic_extent = mozilla::MaxValue<size_t>::value; + +template<class ElementType, size_t Extent = dynamic_extent> +class Span; + +// implementation details +namespace span_details { + +// C++14 types that we don't have because we build as C++11. +template<class T> +using remove_cv_t = typename mozilla::RemoveCV<T>::Type; +template<class T> +using remove_const_t = typename mozilla::RemoveConst<T>::Type; +template<bool B, class T, class F> +using conditional_t = typename mozilla::Conditional<B, T, F>::Type; +template<class T> +using add_pointer_t = typename mozilla::AddPointer<T>::Type; +template<bool B, class T = void> +using enable_if_t = typename mozilla::EnableIf<B, T>::Type; + +template<class T> +struct is_span_oracle : mozilla::FalseType +{ +}; + +template<class ElementType, size_t Extent> +struct is_span_oracle<mozilla::Span<ElementType, Extent>> : mozilla::TrueType +{ +}; + +template<class T> +struct is_span : public is_span_oracle<remove_cv_t<T>> +{ +}; + +template<class T> +struct is_std_array_oracle : mozilla::FalseType +{ +}; + +template<class ElementType, size_t Extent> +struct is_std_array_oracle<std::array<ElementType, Extent>> : mozilla::TrueType +{ +}; + +template<class T> +struct is_std_array : public is_std_array_oracle<remove_cv_t<T>> +{ +}; + +template<size_t From, size_t To> +struct is_allowed_extent_conversion + : public mozilla::IntegralConstant<bool, + From == To || + From == mozilla::dynamic_extent || + To == mozilla::dynamic_extent> +{ +}; + +template<class From, class To> +struct is_allowed_element_type_conversion + : public mozilla::IntegralConstant<bool, mozilla::IsConvertible<From (*)[], To (*)[]>::value> +{ +}; + +template<class Span, bool IsConst> +class span_iterator +{ + using element_type_ = typename Span::element_type; + +public: + using iterator_category = std::random_access_iterator_tag; + using value_type = remove_const_t<element_type_>; + using difference_type = typename Span::index_type; + + using reference = conditional_t<IsConst, const element_type_, element_type_>&; + using pointer = add_pointer_t<reference>; + + constexpr span_iterator() : span_iterator(nullptr, 0) {} + + MOZ_SPAN_ASSERTION_CONSTEXPR span_iterator(const Span* span, + typename Span::index_type index) + : span_(span) + , index_(index) + { + MOZ_RELEASE_ASSERT(span == nullptr || + (index_ >= 0 && index <= span_->Length())); + } + + friend class span_iterator<Span, true>; + constexpr MOZ_IMPLICIT span_iterator(const span_iterator<Span, false>& other) + : span_iterator(other.span_, other.index_) + { + } + + MOZ_SPAN_EXPLICITLY_DEFAULTED_CONSTEXPR span_iterator<Span, IsConst>& + operator=(const span_iterator<Span, IsConst>&) = default; + + MOZ_SPAN_GCC_CONSTEXPR reference operator*() const + { + MOZ_RELEASE_ASSERT(span_); + return (*span_)[index_]; + } + + MOZ_SPAN_GCC_CONSTEXPR pointer operator->() const + { + MOZ_RELEASE_ASSERT(span_); + return &((*span_)[index_]); + } + + MOZ_SPAN_NON_CONST_CONSTEXPR span_iterator& operator++() + { + MOZ_RELEASE_ASSERT(span_ && index_ >= 0 && index_ < span_->Length()); + ++index_; + return *this; + } + + MOZ_SPAN_NON_CONST_CONSTEXPR span_iterator operator++(int) + { + auto ret = *this; + ++(*this); + return ret; + } + + MOZ_SPAN_NON_CONST_CONSTEXPR span_iterator& operator--() + { + MOZ_RELEASE_ASSERT(span_ && index_ > 0 && index_ <= span_->Length()); + --index_; + return *this; + } + + MOZ_SPAN_NON_CONST_CONSTEXPR span_iterator operator--(int) + { + auto ret = *this; + --(*this); + return ret; + } + + MOZ_SPAN_CONSTEXPR_NOT_JUST_RETURN span_iterator + operator+(difference_type n) const + { + auto ret = *this; + return ret += n; + } + + MOZ_SPAN_GCC_CONSTEXPR span_iterator& operator+=(difference_type n) + { + MOZ_RELEASE_ASSERT(span_ && (index_ + n) >= 0 && + (index_ + n) <= span_->Length()); + index_ += n; + return *this; + } + + MOZ_SPAN_CONSTEXPR_NOT_JUST_RETURN span_iterator + operator-(difference_type n) const + { + auto ret = *this; + return ret -= n; + } + + MOZ_SPAN_NON_CONST_CONSTEXPR span_iterator& operator-=(difference_type n) + + { + return *this += -n; + } + + MOZ_SPAN_GCC_CONSTEXPR difference_type + operator-(const span_iterator& rhs) const + { + MOZ_RELEASE_ASSERT(span_ == rhs.span_); + return index_ - rhs.index_; + } + + constexpr reference operator[](difference_type n) const + { + return *(*this + n); + } + + constexpr friend bool operator==(const span_iterator& lhs, + const span_iterator& rhs) + { + return lhs.span_ == rhs.span_ && lhs.index_ == rhs.index_; + } + + constexpr friend bool operator!=(const span_iterator& lhs, + const span_iterator& rhs) + { + return !(lhs == rhs); + } + + MOZ_SPAN_GCC_CONSTEXPR friend bool operator<(const span_iterator& lhs, + const span_iterator& rhs) + { + MOZ_RELEASE_ASSERT(lhs.span_ == rhs.span_); + return lhs.index_ < rhs.index_; + } + + MOZ_SPAN_GCC_CONSTEXPR friend bool operator<=(const span_iterator& lhs, + const span_iterator& rhs) + { + return !(rhs < lhs); + } + + MOZ_SPAN_GCC_CONSTEXPR friend bool operator>(const span_iterator& lhs, + const span_iterator& rhs) + { + return rhs < lhs; + } + + MOZ_SPAN_GCC_CONSTEXPR friend bool operator>=(const span_iterator& lhs, + const span_iterator& rhs) + { + return !(rhs > lhs); + } + + void swap(span_iterator& rhs) + { + std::swap(index_, rhs.index_); + std::swap(span_, rhs.span_); + } + +protected: + const Span* span_; + size_t index_; +}; + +template<class Span, bool IsConst> +inline constexpr span_iterator<Span, IsConst> +operator+(typename span_iterator<Span, IsConst>::difference_type n, + const span_iterator<Span, IsConst>& rhs) +{ + return rhs + n; +} + +template<size_t Ext> +class extent_type +{ +public: + using index_type = size_t; + + static_assert(Ext >= 0, "A fixed-size Span must be >= 0 in size."); + + constexpr extent_type() {} + + template<index_type Other> + MOZ_SPAN_ASSERTION_CONSTEXPR MOZ_IMPLICIT extent_type(extent_type<Other> ext) + { + static_assert( + Other == Ext || Other == dynamic_extent, + "Mismatch between fixed-size extent and size of initializing data."); + MOZ_RELEASE_ASSERT(ext.size() == Ext); + } + + MOZ_SPAN_ASSERTION_CONSTEXPR MOZ_IMPLICIT extent_type(index_type length) + { + MOZ_RELEASE_ASSERT(length == Ext); + } + + constexpr index_type size() const { return Ext; } +}; + +template<> +class extent_type<dynamic_extent> +{ +public: + using index_type = size_t; + + template<index_type Other> + explicit constexpr extent_type(extent_type<Other> ext) + : size_(ext.size()) + { + } + + explicit constexpr extent_type(index_type length) + : size_(length) + { + } + + constexpr index_type size() const { return size_; } + +private: + index_type size_; +}; +} // namespace span_details + +/** + * Span - slices for C++ + * + * Span implements Rust's slice concept for C++. It's called "Span" instead of + * "Slice" to follow the naming used in C++ Core Guidelines. + * + * A Span wraps a pointer and a length that identify a non-owning view to a + * contiguous block of memory of objects of the same type. Various types, + * including (pre-decay) C arrays, XPCOM strings, nsTArray, mozilla::Array, + * mozilla::Range and contiguous standard-library containers, auto-convert + * into Spans when attempting to pass them as arguments to methods that take + * Spans. MakeSpan() functions can be used for explicit conversion in other + * contexts. (Span itself autoconverts into mozilla::Range.) + * + * Like Rust's slices, Span provides safety against out-of-bounds access by + * performing run-time bound checks. However, unlike Rust's slices, Span + * cannot provide safety against use-after-free. + * + * (Note: Span is like Rust's slice only conceptually. Due to the lack of + * ABI guarantees, you should still decompose spans/slices to raw pointer + * and length parts when crossing the FFI.) + * + * In addition to having constructors and MakeSpan() functions that take + * various well-known types, a Span for an arbitrary type can be constructed + * (via constructor or MakeSpan()) from a pointer and a length or a pointer + * and another pointer pointing just past the last element. + * + * A Span<const char> can be obtained for const char* pointing to a + * zero-terminated C string using the MakeCStringSpan() function. A + * corresponding implicit constructor does not exist in order to avoid + * accidental construction in cases where const char* does not point to a + * zero-terminated C string. + * + * Span has methods that follow the Mozilla naming style and methods that + * don't. The methods that follow the Mozilla naming style are meant to be + * used directly from Mozilla code. The methods that don't are meant for + * integration with C++11 range-based loops and with meta-programming that + * expects the same methods that are found on the standard-library + * containers. For example, to decompose a Span into its parts in Mozilla + * code, use Elements() and Length() (as with nsTArray) instead of data() + * and size() (as with std::vector). + * + * The pointer and length wrapped by a Span cannot be changed after a Span has + * been created. When new values are required, simply create a new Span. Span + * has a method called Subspan() that works analogously to the Substring() + * method of XPCOM strings taking a start index and an optional length. As a + * Mozilla extension (relative to Microsoft's gsl::span that mozilla::Span is + * based on), Span has methods From(start), To(end) and FromTo(start, end) + * that correspond to Rust's &slice[start..], &slice[..end] and + * &slice[start..end], respectively. (That is, the end index is the index of + * the first element not to be included in the new subspan.) + * + * When indicating a Span that's only read from, const goes inside the type + * parameter. Don't put const in front of Span. That is: + * size_t ReadsFromOneSpanAndWritesToAnother(Span<const uint8_t> aReadFrom, + * Span<uint8_t> aWrittenTo); + * + * Any Span<const T> can be viewed as Span<const uint8_t> using the function + * AsBytes(). Any Span<T> can be viewed as Span<uint8_t> using the function + * AsWritableBytes(). + */ +template<class ElementType, size_t Extent> +class Span +{ +public: + // constants and types + using element_type = ElementType; + using index_type = size_t; + using pointer = element_type*; + using reference = element_type&; + + using iterator = + span_details::span_iterator<Span<ElementType, Extent>, false>; + using const_iterator = + span_details::span_iterator<Span<ElementType, Extent>, true>; + using reverse_iterator = std::reverse_iterator<iterator>; + using const_reverse_iterator = std::reverse_iterator<const_iterator>; + + constexpr static const index_type extent = Extent; + + // [Span.cons], Span constructors, copy, assignment, and destructor + // "Dependent" is needed to make "span_details::enable_if_t<(Dependent || Extent == 0 || Extent == mozilla::MaxValue<size_t>::value)>" SFINAE, + // since "span_details::enable_if_t<(Extent == 0 || Extent == mozilla::MaxValue<size_t>::value)>" is ill-formed when Extent is neither of the extreme values. + /** + * Constructor with no args. + */ + template< + bool Dependent = false, + class = span_details::enable_if_t< + (Dependent || Extent == 0 || Extent == mozilla::MaxValue<size_t>::value)>> + constexpr Span() + : storage_(nullptr, span_details::extent_type<0>()) + { + } + + /** + * Constructor for nullptr. + */ + constexpr MOZ_IMPLICIT Span(std::nullptr_t) : Span() {} + + /** + * Constructor for pointer and length. + */ + constexpr Span(pointer aPtr, index_type aLength) + : storage_(aPtr, aLength) + { + } + + /** + * Constructor for start pointer and pointer past end. + */ + constexpr Span(pointer aStartPtr, pointer aEndPtr) + : storage_(aStartPtr, std::distance(aStartPtr, aEndPtr)) + { + } + + /** + * Constructor for C array. + */ + template<size_t N> + constexpr MOZ_IMPLICIT Span(element_type (&aArr)[N]) + : storage_(&aArr[0], span_details::extent_type<N>()) + { + } + + /** + * Constructor for std::array. + */ + template<size_t N, + class ArrayElementType = span_details::remove_const_t<element_type>> + constexpr MOZ_IMPLICIT Span(std::array<ArrayElementType, N>& aArr) + : storage_(&aArr[0], span_details::extent_type<N>()) + { + } + + /** + * Constructor for const std::array. + */ + template<size_t N> + constexpr MOZ_IMPLICIT Span( + const std::array<span_details::remove_const_t<element_type>, N>& aArr) + : storage_(&aArr[0], span_details::extent_type<N>()) + { + } + + /** + * Constructor for mozilla::Array. + */ + template<size_t N, + class ArrayElementType = span_details::remove_const_t<element_type>> + constexpr MOZ_IMPLICIT Span(mozilla::Array<ArrayElementType, N>& aArr) + : storage_(&aArr[0], span_details::extent_type<N>()) + { + } + + /** + * Constructor for const mozilla::Array. + */ + template<size_t N> + constexpr MOZ_IMPLICIT Span( + const mozilla::Array<span_details::remove_const_t<element_type>, N>& aArr) + : storage_(&aArr[0], span_details::extent_type<N>()) + { + } + + /** + * Constructor for mozilla::UniquePtr holding an array and length. + */ + template<class ArrayElementType = std::add_pointer<element_type>> + constexpr Span(const mozilla::UniquePtr<ArrayElementType>& aPtr, + index_type aLength) + : storage_(aPtr.get(), aLength) + { + } + + // NB: the SFINAE here uses .data() as a incomplete/imperfect proxy for the requirement + // on Container to be a contiguous sequence container. + /** + * Constructor for standard-library containers. + */ + template< + class Container, + class = span_details::enable_if_t< + !span_details::is_span<Container>::value && + !span_details::is_std_array<Container>::value && + mozilla::IsConvertible<typename Container::pointer, pointer>::value && + mozilla::IsConvertible<typename Container::pointer, + decltype(mozilla::DeclVal<Container>().data())>::value>> + constexpr MOZ_IMPLICIT Span(Container& cont) + : Span(cont.data(), ReleaseAssertedCast<index_type>(cont.size())) + { + } + + /** + * Constructor for standard-library containers (const version). + */ + template< + class Container, + class = span_details::enable_if_t< + mozilla::IsConst<element_type>::value && + !span_details::is_span<Container>::value && + mozilla::IsConvertible<typename Container::pointer, pointer>::value && + mozilla::IsConvertible<typename Container::pointer, + decltype(mozilla::DeclVal<Container>().data())>::value>> + constexpr MOZ_IMPLICIT Span(const Container& cont) + : Span(cont.data(), ReleaseAssertedCast<index_type>(cont.size())) + { + } + + /** + * Constructor from other Span. + */ + constexpr Span(const Span& other) = default; + + /** + * Constructor from other Span. + */ + constexpr Span(Span&& other) = default; + + /** + * Constructor from other Span with conversion of element type. + */ + template< + class OtherElementType, + size_t OtherExtent, + class = span_details::enable_if_t< + span_details::is_allowed_extent_conversion<OtherExtent, Extent>::value && + span_details::is_allowed_element_type_conversion<OtherElementType, + element_type>::value>> + constexpr MOZ_IMPLICIT Span(const Span<OtherElementType, OtherExtent>& other) + : storage_(other.data(), + span_details::extent_type<OtherExtent>(other.size())) + { + } + + /** + * Constructor from other Span with conversion of element type. + */ + template< + class OtherElementType, + size_t OtherExtent, + class = span_details::enable_if_t< + span_details::is_allowed_extent_conversion<OtherExtent, Extent>::value && + span_details::is_allowed_element_type_conversion<OtherElementType, + element_type>::value>> + constexpr MOZ_IMPLICIT Span(Span<OtherElementType, OtherExtent>&& other) + : storage_(other.data(), + span_details::extent_type<OtherExtent>(other.size())) + { + } + + ~Span() = default; + MOZ_SPAN_EXPLICITLY_DEFAULTED_CONSTEXPR Span& operator=(const Span& other) + = default; + + MOZ_SPAN_EXPLICITLY_DEFAULTED_CONSTEXPR Span& operator=(Span&& other) + = default; + + // [Span.sub], Span subviews + /** + * Subspan with first N elements with compile-time N. + */ + template<size_t Count> + MOZ_SPAN_GCC_CONSTEXPR Span<element_type, Count> First() const + { + MOZ_RELEASE_ASSERT(Count <= size()); + return { data(), Count }; + } + + /** + * Subspan with last N elements with compile-time N. + */ + template<size_t Count> + MOZ_SPAN_GCC_CONSTEXPR Span<element_type, Count> Last() const + { + MOZ_RELEASE_ASSERT(Count <= size()); + return { data() + (size() - Count), Count }; + } + + /** + * Subspan with compile-time start index and length. + */ + template<size_t Offset, size_t Count = dynamic_extent> + MOZ_SPAN_GCC_CONSTEXPR Span<element_type, Count> Subspan() const + { + MOZ_RELEASE_ASSERT(Offset <= size() && + (Count == dynamic_extent || (Offset + Count <= size()))); + return { data() + Offset, + Count == dynamic_extent ? size() - Offset : Count }; + } + + /** + * Subspan with first N elements with run-time N. + */ + MOZ_SPAN_GCC_CONSTEXPR Span<element_type, dynamic_extent> First( + index_type aCount) const + { + MOZ_RELEASE_ASSERT(aCount <= size()); + return { data(), aCount }; + } + + /** + * Subspan with last N elements with run-time N. + */ + MOZ_SPAN_GCC_CONSTEXPR Span<element_type, dynamic_extent> Last( + index_type aCount) const + { + MOZ_RELEASE_ASSERT(aCount <= size()); + return { data() + (size() - aCount), aCount }; + } + + /** + * Subspan with run-time start index and length. + */ + MOZ_SPAN_GCC_CONSTEXPR Span<element_type, dynamic_extent> Subspan( + index_type aStart, + index_type aLength = dynamic_extent) const + { + MOZ_RELEASE_ASSERT(aStart <= size() && + (aLength == dynamic_extent || + (aStart + aLength <= size()))); + return { data() + aStart, + aLength == dynamic_extent ? size() - aStart : aLength }; + } + + /** + * Subspan with run-time start index. (Rust's &foo[start..]) + */ + MOZ_SPAN_GCC_CONSTEXPR Span<element_type, dynamic_extent> From( + index_type aStart) const + { + return Subspan(aStart); + } + + /** + * Subspan with run-time exclusive end index. (Rust's &foo[..end]) + */ + MOZ_SPAN_GCC_CONSTEXPR Span<element_type, dynamic_extent> To( + index_type aEnd) const + { + return Subspan(0, aEnd); + } + + /** + * Subspan with run-time start index and exclusive end index. + * (Rust's &foo[start..end]) + */ + MOZ_SPAN_GCC_CONSTEXPR Span<element_type, dynamic_extent> FromTo( + index_type aStart, + index_type aEnd) const + { + MOZ_RELEASE_ASSERT(aStart <= aEnd); + return Subspan(aStart, aEnd - aStart); + } + + // [Span.obs], Span observers + /** + * Number of elements in the span. + */ + constexpr index_type Length() const { return size(); } + + /** + * Number of elements in the span (standard-libray duck typing version). + */ + constexpr index_type size() const { return storage_.size(); } + + /** + * Size of the span in bytes. + */ + constexpr index_type LengthBytes() const { return size_bytes(); } + + /** + * Size of the span in bytes (standard-library naming style version). + */ + constexpr index_type size_bytes() const + { + return size() * narrow_cast<index_type>(sizeof(element_type)); + } + + /** + * Checks if the the length of the span is zero. + */ + constexpr bool IsEmpty() const { return empty(); } + + /** + * Checks if the the length of the span is zero (standard-libray duck + * typing version). + */ + constexpr bool empty() const { return size() == 0; } + + // [Span.elem], Span element access + MOZ_SPAN_GCC_CONSTEXPR reference operator[](index_type idx) const + { + MOZ_RELEASE_ASSERT(idx < storage_.size()); + return data()[idx]; + } + + /** + * Access element of span by index (standard-library duck typing version). + */ + constexpr reference at(index_type idx) const { return this->operator[](idx); } + + constexpr reference operator()(index_type idx) const + { + return this->operator[](idx); + } + + /** + * Pointer to the first element of the span. + */ + constexpr pointer Elements() const { return data(); } + + /** + * Pointer to the first element of the span (standard-libray duck typing version). + */ + constexpr pointer data() const { return storage_.data(); } + + // [Span.iter], Span iterator support + iterator begin() const { return { this, 0 }; } + iterator end() const { return { this, Length() }; } + + const_iterator cbegin() const { return { this, 0 }; } + const_iterator cend() const { return { this, Length() }; } + + reverse_iterator rbegin() const + { + return reverse_iterator{ end() }; + } + reverse_iterator rend() const + { + return reverse_iterator{ begin() }; + } + + const_reverse_iterator crbegin() const + { + return const_reverse_iterator{ cend() }; + } + const_reverse_iterator crend() const + { + return const_reverse_iterator{ cbegin() }; + } + +private: + // this implementation detail class lets us take advantage of the + // empty base class optimization to pay for only storage of a single + // pointer in the case of fixed-size Spans + template<class ExtentType> + class storage_type : public ExtentType + { + public: + template<class OtherExtentType> + MOZ_SPAN_ASSERTION_CONSTEXPR storage_type(pointer elements, + OtherExtentType ext) + : ExtentType(ext) + , data_(elements) + { + MOZ_RELEASE_ASSERT( + (!elements && ExtentType::size() == 0) || + (elements && ExtentType::size() != mozilla::MaxValue<size_t>::value)); + } + + constexpr pointer data() const { return data_; } + + private: + pointer data_; + }; + + storage_type<span_details::extent_type<Extent>> storage_; +}; + +// [Span.comparison], Span comparison operators +template<class ElementType, size_t FirstExtent, size_t SecondExtent> +inline constexpr bool +operator==(const Span<ElementType, FirstExtent>& l, + const Span<ElementType, SecondExtent>& r) +{ + return (l.size() == r.size()) && std::equal(l.begin(), l.end(), r.begin()); +} + +template<class ElementType, size_t Extent> +inline constexpr bool +operator!=(const Span<ElementType, Extent>& l, + const Span<ElementType, Extent>& r) +{ + return !(l == r); +} + +template<class ElementType, size_t Extent> +inline constexpr bool +operator<(const Span<ElementType, Extent>& l, + const Span<ElementType, Extent>& r) +{ + return std::lexicographical_compare(l.begin(), l.end(), r.begin(), r.end()); +} + +template<class ElementType, size_t Extent> +inline constexpr bool +operator<=(const Span<ElementType, Extent>& l, + const Span<ElementType, Extent>& r) +{ + return !(l > r); +} + +template<class ElementType, size_t Extent> +inline constexpr bool +operator>(const Span<ElementType, Extent>& l, + const Span<ElementType, Extent>& r) +{ + return r < l; +} + +template<class ElementType, size_t Extent> +inline constexpr bool +operator>=(const Span<ElementType, Extent>& l, + const Span<ElementType, Extent>& r) +{ + return !(l < r); +} + +namespace span_details { +// if we only supported compilers with good constexpr support then +// this pair of classes could collapse down to a constexpr function + +// we should use a narrow_cast<> to go to size_t, but older compilers may not see it as +// constexpr +// and so will fail compilation of the template +template<class ElementType, size_t Extent> +struct calculate_byte_size + : mozilla::IntegralConstant<size_t, + static_cast<size_t>(sizeof(ElementType) * + static_cast<size_t>(Extent))> +{ +}; + +template<class ElementType> +struct calculate_byte_size<ElementType, dynamic_extent> + : mozilla::IntegralConstant<size_t, dynamic_extent> +{ +}; +} + +// [Span.objectrep], views of object representation +/** + * View span as Span<const uint8_t>. + */ +template<class ElementType, size_t Extent> +Span<const uint8_t, + span_details::calculate_byte_size<ElementType, Extent>::value> +AsBytes(Span<ElementType, Extent> s) +{ + return { reinterpret_cast<const uint8_t*>(s.data()), s.size_bytes() }; +} + +/** + * View span as Span<uint8_t>. + */ +template<class ElementType, + size_t Extent, + class = span_details::enable_if_t<!mozilla::IsConst<ElementType>::value>> +Span<uint8_t, span_details::calculate_byte_size<ElementType, Extent>::value> +AsWritableBytes(Span<ElementType, Extent> s) +{ + return { reinterpret_cast<uint8_t*>(s.data()), s.size_bytes() }; +} + +// +// MakeSpan() - Utility functions for creating Spans +// +/** + * Create span from pointer and length. + */ +template<class ElementType> +Span<ElementType> +MakeSpan(ElementType* aPtr, typename Span<ElementType>::index_type aLength) +{ + return Span<ElementType>(aPtr, aLength); +} + +/** + * Create span from start pointer and pointer past end. + */ +template<class ElementType> +Span<ElementType> +MakeSpan(ElementType* aStartPtr, ElementType* aEndPtr) +{ + return Span<ElementType>(aStartPtr, aEndPtr); +} + +/** + * Create span from C array. + */ +template<class ElementType, size_t N> +Span<ElementType> MakeSpan(ElementType (&aArr)[N]) +{ + return Span<ElementType>(aArr); +} + +/** + * Create span from mozilla::Array. + */ +template<class ElementType, size_t N> +Span<ElementType> +MakeSpan(mozilla::Array<ElementType, N>& aArr) +{ + return aArr; +} + +/** + * Create span from const mozilla::Array. + */ +template<class ElementType, size_t N> +Span<const ElementType> +MakeSpan(const mozilla::Array<ElementType, N>& arr) +{ + return arr; +} + +/** + * Create span from standard-library container. + */ +template<class Container> +Span<typename Container::value_type> +MakeSpan(Container& cont) +{ + return Span<typename Container::value_type>(cont); +} + +/** + * Create span from standard-library container (const version). + */ +template<class Container> +Span<const typename Container::value_type> +MakeSpan(const Container& cont) +{ + return Span<const typename Container::value_type>(cont); +} + +/** + * Create span from smart pointer and length. + */ +template<class Ptr> +Span<typename Ptr::element_type> +MakeSpan(Ptr& aPtr, size_t aLength) +{ + return Span<typename Ptr::element_type>(aPtr, aLength); +} + +/** + * Create span from C string. + */ +inline Span<const char> +MakeCStringSpan(const char* aStr) +{ + return Span<const char>(aStr, std::strlen(aStr)); +} + +} // namespace mozilla + +#ifdef _MSC_VER +#if _MSC_VER < 1910 +#undef constexpr +#pragma pop_macro("constexpr") + +#endif // _MSC_VER < 1910 + +#pragma warning(pop) +#endif // _MSC_VER + +#undef MOZ_SPAN_ASSERTION_CONSTEXPR +#undef MOZ_SPAN_GCC_CONSTEXPR +#undef MOZ_SPAN_EXPLICITLY_DEFAULTED_CONSTEXPR +#undef MOZ_SPAN_CONSTEXPR_NOT_JUST_RETURN +#undef MOZ_SPAN_NON_CONST_CONSTEXPR + +#endif // mozilla_Span_h diff --git a/mfbt/moz.build b/mfbt/moz.build index 897a686f48..ea3c3b7017 100644 --- a/mfbt/moz.build +++ b/mfbt/moz.build @@ -82,6 +82,7 @@ EXPORTS.mozilla = [ 'SegmentedVector.h', 'SHA1.h', 'SizePrintfMacros.h', + 'Span.h', 'SplayTree.h', 'Sprintf.h', 'StaticAnalysisFunctions.h', diff --git a/mfbt/tests/gtest/TestSpan.cpp b/mfbt/tests/gtest/TestSpan.cpp new file mode 100644 index 0000000000..f3aa000a43 --- /dev/null +++ b/mfbt/tests/gtest/TestSpan.cpp @@ -0,0 +1,2079 @@ +/////////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2015 Microsoft Corporation. All rights reserved. +// +// This code is licensed under the MIT License (MIT). +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +/////////////////////////////////////////////////////////////////////////////// + +// Adapted from https://github.com/Microsoft/GSL/blob/3819df6e378ffccf0e29465afe99c3b324c2aa70/tests/Span_tests.cpp + +#include "gtest/gtest.h" + +#include "mozilla/Span.h" + +#include "nsString.h" +#include "nsTArray.h" +#include "mozilla/Range.h" +#include "mozilla/TypeTraits.h" + +#define SPAN_TEST(name) TEST(SpanTest, name) +#define CHECK_THROW(a, b) + +using namespace std; +using namespace mozilla; + +static_assert(IsConvertible<Range<int>, Span<const int>>::value, + "Range should convert into const"); +static_assert(IsConvertible<Range<const int>, Span<const int>>::value, + "const Range should convert into const"); +static_assert(!IsConvertible<Range<const int>, Span<int>>::value, + "Range should not drop const in conversion"); +static_assert(IsConvertible<Span<int>, Range<const int>>::value, + "Span should convert into const"); +static_assert(IsConvertible<Span<const int>, Range<const int>>::value, + "const Span should convert into const"); +static_assert(!IsConvertible<Span<const int>, Range<int>>::value, + "Span should not drop const in conversion"); +static_assert(IsConvertible<Span<const int>, Span<const int>>::value, + "const Span should convert into const"); +static_assert(IsConvertible<Span<int>, Span<const int>>::value, + "Span should convert into const"); +static_assert(!IsConvertible<Span<const int>, Span<int>>::value, + "Span should not drop const in conversion"); +static_assert(IsConvertible<const nsTArray<int>, Span<const int>>::value, + "const nsTArray should convert into const"); +static_assert(IsConvertible<nsTArray<int>, Span<const int>>::value, + "nsTArray should convert into const"); +static_assert(!IsConvertible<const nsTArray<int>, Span<int>>::value, + "nsTArray should not drop const in conversion"); +static_assert(IsConvertible<nsTArray<const int>, Span<const int>>::value, + "nsTArray should convert into const"); +static_assert(!IsConvertible<nsTArray<const int>, Span<int>>::value, + "nsTArray should not drop const in conversion"); + +namespace { +struct BaseClass +{ +}; +struct DerivedClass : BaseClass +{ +}; +} + +void +AssertSpanOfThreeInts(Span<const int> s) +{ + ASSERT_EQ(s.size(), 3U); + ASSERT_EQ(s[0], 1); + ASSERT_EQ(s[1], 2); + ASSERT_EQ(s[2], 3); +} + +void +AssertSpanOfThreeChars(Span<const char> s) +{ + ASSERT_EQ(s.size(), 3U); + ASSERT_EQ(s[0], 'a'); + ASSERT_EQ(s[1], 'b'); + ASSERT_EQ(s[2], 'c'); +} + +void +AssertSpanOfThreeChar16s(Span<const char16_t> s) +{ + ASSERT_EQ(s.size(), 3U); + ASSERT_EQ(s[0], 'a'); + ASSERT_EQ(s[1], 'b'); + ASSERT_EQ(s[2], 'c'); +} + +void +AssertSpanOfThreeCharsViaString(const nsACString& aStr) +{ + AssertSpanOfThreeChars(aStr); +} + +void +AssertSpanOfThreeChar16sViaString(const nsAString& aStr) +{ + AssertSpanOfThreeChar16s(aStr); +} + +SPAN_TEST(default_constructor) +{ + { + Span<int> s; + ASSERT_EQ(s.Length(), 0U); + ASSERT_EQ(s.data(), nullptr); + + Span<const int> cs; + ASSERT_EQ(cs.Length(), 0U); + ASSERT_EQ(cs.data(), nullptr); + } + + { + Span<int, 0> s; + ASSERT_EQ(s.Length(), 0U); + ASSERT_EQ(s.data(), nullptr); + + Span<const int, 0> cs; + ASSERT_EQ(cs.Length(), 0U); + ASSERT_EQ(cs.data(), nullptr); + } + + { +#ifdef CONFIRM_COMPILATION_ERRORS + Span<int, 1> s; + ASSERT_EQ(s.Length(), 1U); + ASSERT_EQ(s.data(), nullptr); // explains why it can't compile +#endif + } + + { + Span<int> s{}; + ASSERT_EQ(s.Length(), 0U); + ASSERT_EQ(s.data(), nullptr); + + Span<const int> cs{}; + ASSERT_EQ(cs.Length(), 0U); + ASSERT_EQ(cs.data(), nullptr); + } +} + +SPAN_TEST(size_optimization) +{ + { + Span<int> s; + ASSERT_EQ(sizeof(s), sizeof(int*) + sizeof(size_t)); + } + + { + Span<int, 0> s; + ASSERT_EQ(sizeof(s), sizeof(int*)); + } +} + +SPAN_TEST(from_nullptr_constructor) +{ + { + Span<int> s = nullptr; + ASSERT_EQ(s.Length(), 0U); + ASSERT_EQ(s.data(), nullptr); + + Span<const int> cs = nullptr; + ASSERT_EQ(cs.Length(), 0U); + ASSERT_EQ(cs.data(), nullptr); + } + + { + Span<int, 0> s = nullptr; + ASSERT_EQ(s.Length(), 0U); + ASSERT_EQ(s.data(), nullptr); + + Span<const int, 0> cs = nullptr; + ASSERT_EQ(cs.Length(), 0U); + ASSERT_EQ(cs.data(), nullptr); + } + + { +#ifdef CONFIRM_COMPILATION_ERRORS + Span<int, 1> s = nullptr; + ASSERT_EQ(s.Length(), 1U); + ASSERT_EQ(s.data(), nullptr); // explains why it can't compile +#endif + } + + { + Span<int> s{ nullptr }; + ASSERT_EQ(s.Length(), 0U); + ASSERT_EQ(s.data(), nullptr); + + Span<const int> cs{ nullptr }; + ASSERT_EQ(cs.Length(), 0U); + ASSERT_EQ(cs.data(), nullptr); + } + + { + Span<int*> s{ nullptr }; + ASSERT_EQ(s.Length(), 0U); + ASSERT_EQ(s.data(), nullptr); + + Span<const int*> cs{ nullptr }; + ASSERT_EQ(cs.Length(), 0U); + ASSERT_EQ(cs.data(), nullptr); + } +} + +SPAN_TEST(from_nullptr_length_constructor) +{ + { + Span<int> s{ nullptr, static_cast<Span<int>::index_type>(0) }; + ASSERT_EQ(s.Length(), 0U); + ASSERT_EQ(s.data(), nullptr); + + Span<const int> cs{ nullptr, static_cast<Span<int>::index_type>(0) }; + ASSERT_EQ(cs.Length(), 0U); + ASSERT_EQ(cs.data(), nullptr); + } + + { + Span<int, 0> s{ nullptr, static_cast<Span<int>::index_type>(0) }; + ASSERT_EQ(s.Length(), 0U); + ASSERT_EQ(s.data(), nullptr); + + Span<const int, 0> cs{ nullptr, static_cast<Span<int>::index_type>(0) }; + ASSERT_EQ(cs.Length(), 0U); + ASSERT_EQ(cs.data(), nullptr); + } + +#if 0 + { + auto workaround_macro = []() { Span<int, 1> s{ nullptr, static_cast<Span<int>::index_type>(0) }; }; + CHECK_THROW(workaround_macro(), fail_fast); + } + + { + auto workaround_macro = []() { Span<int> s{nullptr, 1}; }; + CHECK_THROW(workaround_macro(), fail_fast); + + auto const_workaround_macro = []() { Span<const int> cs{nullptr, 1}; }; + CHECK_THROW(const_workaround_macro(), fail_fast); + } + + { + auto workaround_macro = []() { Span<int, 0> s{nullptr, 1}; }; + CHECK_THROW(workaround_macro(), fail_fast); + + auto const_workaround_macro = []() { Span<const int, 0> s{nullptr, 1}; }; + CHECK_THROW(const_workaround_macro(), fail_fast); + } +#endif + { + Span<int*> s{ nullptr, static_cast<Span<int>::index_type>(0) }; + ASSERT_EQ(s.Length(), 0U); + ASSERT_EQ(s.data(), nullptr); + + Span<const int*> cs{ nullptr, static_cast<Span<int>::index_type>(0) }; + ASSERT_EQ(cs.Length(), 0U); + ASSERT_EQ(cs.data(), nullptr); + } +} + +SPAN_TEST(from_pointer_length_constructor) +{ + int arr[4] = { 1, 2, 3, 4 }; + + { + Span<int> s{ &arr[0], 2 }; + ASSERT_EQ(s.Length(), 2U); + ASSERT_EQ(s.data(), &arr[0]); + ASSERT_EQ(s[0], 1); + ASSERT_EQ(s[1], 2); + } + + { + Span<int, 2> s{ &arr[0], 2 }; + ASSERT_EQ(s.Length(), 2U); + ASSERT_EQ(s.data(), &arr[0]); + ASSERT_EQ(s[0], 1); + ASSERT_EQ(s[1], 2); + } + + { + int* p = nullptr; + Span<int> s{ p, static_cast<Span<int>::index_type>(0) }; + ASSERT_EQ(s.Length(), 0U); + ASSERT_EQ(s.data(), nullptr); + } + +#if 0 + { + int* p = nullptr; + auto workaround_macro = [=]() { Span<int> s{p, 2}; }; + CHECK_THROW(workaround_macro(), fail_fast); + } +#endif + + { + auto s = MakeSpan(&arr[0], 2); + ASSERT_EQ(s.Length(), 2U); + ASSERT_EQ(s.data(), &arr[0]); + ASSERT_EQ(s[0], 1); + ASSERT_EQ(s[1], 2); + } + + { + int* p = nullptr; + auto s = MakeSpan(p, static_cast<Span<int>::index_type>(0)); + ASSERT_EQ(s.Length(), 0U); + ASSERT_EQ(s.data(), nullptr); + } + +#if 0 + { + int* p = nullptr; + auto workaround_macro = [=]() { MakeSpan(p, 2); }; + CHECK_THROW(workaround_macro(), fail_fast); + } +#endif +} + +SPAN_TEST(from_pointer_pointer_constructor) +{ + int arr[4] = { 1, 2, 3, 4 }; + + { + Span<int> s{ &arr[0], &arr[2] }; + ASSERT_EQ(s.Length(), 2U); + ASSERT_EQ(s.data(), &arr[0]); + ASSERT_EQ(s[0], 1); + ASSERT_EQ(s[1], 2); + } + + { + Span<int, 2> s{ &arr[0], &arr[2] }; + ASSERT_EQ(s.Length(), 2U); + ASSERT_EQ(s.data(), &arr[0]); + ASSERT_EQ(s[0], 1); + ASSERT_EQ(s[1], 2); + } + + { + Span<int> s{ &arr[0], &arr[0] }; + ASSERT_EQ(s.Length(), 0U); + ASSERT_EQ(s.data(), &arr[0]); + } + + { + Span<int, 0> s{ &arr[0], &arr[0] }; + ASSERT_EQ(s.Length(), 0U); + ASSERT_EQ(s.data(), &arr[0]); + } + + // this will fail the std::distance() precondition, which asserts on MSVC debug builds + //{ + // auto workaround_macro = [&]() { Span<int> s{&arr[1], &arr[0]}; }; + // CHECK_THROW(workaround_macro(), fail_fast); + //} + + // this will fail the std::distance() precondition, which asserts on MSVC debug builds + //{ + // int* p = nullptr; + // auto workaround_macro = [&]() { Span<int> s{&arr[0], p}; }; + // CHECK_THROW(workaround_macro(), fail_fast); + //} + + { + int* p = nullptr; + Span<int> s{ p, p }; + ASSERT_EQ(s.Length(), 0U); + ASSERT_EQ(s.data(), nullptr); + } + + { + int* p = nullptr; + Span<int, 0> s{ p, p }; + ASSERT_EQ(s.Length(), 0U); + ASSERT_EQ(s.data(), nullptr); + } + + // this will fail the std::distance() precondition, which asserts on MSVC debug builds + //{ + // int* p = nullptr; + // auto workaround_macro = [&]() { Span<int> s{&arr[0], p}; }; + // CHECK_THROW(workaround_macro(), fail_fast); + //} + + { + auto s = MakeSpan(&arr[0], &arr[2]); + ASSERT_EQ(s.Length(), 2U); + ASSERT_EQ(s.data(), &arr[0]); + ASSERT_EQ(s[0], 1); + ASSERT_EQ(s[1], 2); + } + + { + auto s = MakeSpan(&arr[0], &arr[0]); + ASSERT_EQ(s.Length(), 0U); + ASSERT_EQ(s.data(), &arr[0]); + } + + { + int* p = nullptr; + auto s = MakeSpan(p, p); + ASSERT_EQ(s.Length(), 0U); + ASSERT_EQ(s.data(), nullptr); + } +} + +SPAN_TEST(from_array_constructor) +{ + int arr[5] = { 1, 2, 3, 4, 5 }; + + { + Span<int> s{ arr }; + ASSERT_EQ(s.Length(), 5U); + ASSERT_EQ(s.data(), &arr[0]); + } + + { + Span<int, 5> s{ arr }; + ASSERT_EQ(s.Length(), 5U); + ASSERT_EQ(s.data(), &arr[0]); + } + + int arr2d[2][3] = { { 1, 2, 3 }, { 4, 5, 6 } }; + +#ifdef CONFIRM_COMPILATION_ERRORS + { + Span<int, 6> s{ arr }; + } + + { + Span<int, 0> s{ arr }; + ASSERT_EQ(s.Length(), 0U); + ASSERT_EQ(s.data(), &arr[0]); + } + + { + Span<int> s{ arr2d }; + ASSERT_EQ(s.Length(), 6U); + ASSERT_EQ(s.data(), &arr2d[0][0]); + ASSERT_EQ(s[0], 1); + ASSERT_EQ(s[5], 6); + } + + { + Span<int, 0> s{ arr2d }; + ASSERT_EQ(s.Length(), 0U); + ASSERT_EQ(s.data(), &arr2d[0][0]); + } + + { + Span<int, 6> s{ arr2d }; + } +#endif + { + Span<int[3]> s{ &(arr2d[0]), 1 }; + ASSERT_EQ(s.Length(), 1U); + ASSERT_EQ(s.data(), &arr2d[0]); + } + + int arr3d[2][3][2] = { { { 1, 2 }, { 3, 4 }, { 5, 6 } }, + { { 7, 8 }, { 9, 10 }, { 11, 12 } } }; + +#ifdef CONFIRM_COMPILATION_ERRORS + { + Span<int> s{ arr3d }; + ASSERT_EQ(s.Length(), 12U); + ASSERT_EQ(s.data(), &arr3d[0][0][0]); + ASSERT_EQ(s[0], 1); + ASSERT_EQ(s[11], 12); + } + + { + Span<int, 0> s{ arr3d }; + ASSERT_EQ(s.Length(), 0U); + ASSERT_EQ(s.data(), &arr3d[0][0][0]); + } + + { + Span<int, 11> s{ arr3d }; + } + + { + Span<int, 12> s{ arr3d }; + ASSERT_EQ(s.Length(), 12U); + ASSERT_EQ(s.data(), &arr3d[0][0][0]); + ASSERT_EQ(s[0], 1); + ASSERT_EQ(s[5], 6); + } +#endif + { + Span<int[3][2]> s{ &arr3d[0], 1 }; + ASSERT_EQ(s.Length(), 1U); + ASSERT_EQ(s.data(), &arr3d[0]); + } + + { + auto s = MakeSpan(arr); + ASSERT_EQ(s.Length(), 5U); + ASSERT_EQ(s.data(), &arr[0]); + } + + { + auto s = MakeSpan(&(arr2d[0]), 1); + ASSERT_EQ(s.Length(), 1U); + ASSERT_EQ(s.data(), &arr2d[0]); + } + + { + auto s = MakeSpan(&arr3d[0], 1); + ASSERT_EQ(s.Length(), 1U); + ASSERT_EQ(s.data(), &arr3d[0]); + } +} + +SPAN_TEST(from_dynamic_array_constructor) +{ + double(*arr)[3][4] = new double[100][3][4]; + + { + Span<double> s(&arr[0][0][0], 10); + ASSERT_EQ(s.Length(), 10U); + ASSERT_EQ(s.data(), &arr[0][0][0]); + } + + { + auto s = MakeSpan(&arr[0][0][0], 10); + ASSERT_EQ(s.Length(), 10U); + ASSERT_EQ(s.data(), &arr[0][0][0]); + } + + delete[] arr; +} + +SPAN_TEST(from_std_array_constructor) +{ + std::array<int, 4> arr = { { 1, 2, 3, 4 } }; + + { + Span<int> s{ arr }; + ASSERT_EQ(s.size(), narrow_cast<size_t>(arr.size())); + ASSERT_EQ(s.data(), arr.data()); + + Span<const int> cs{ arr }; + ASSERT_EQ(cs.size(), narrow_cast<size_t>(arr.size())); + ASSERT_EQ(cs.data(), arr.data()); + } + + { + Span<int, 4> s{ arr }; + ASSERT_EQ(s.size(), narrow_cast<size_t>(arr.size())); + ASSERT_EQ(s.data(), arr.data()); + + Span<const int, 4> cs{ arr }; + ASSERT_EQ(cs.size(), narrow_cast<size_t>(arr.size())); + ASSERT_EQ(cs.data(), arr.data()); + } + +#ifdef CONFIRM_COMPILATION_ERRORS + { + Span<int, 2> s{ arr }; + ASSERT_EQ(s.size(), 2U); + ASSERT_EQ(s.data(), arr.data()); + + Span<const int, 2> cs{ arr }; + ASSERT_EQ(cs.size(), 2U); + ASSERT_EQ(cs.data(), arr.data()); + } + + { + Span<int, 0> s{ arr }; + ASSERT_EQ(s.size(), 0U); + ASSERT_EQ(s.data(), arr.data()); + + Span<const int, 0> cs{ arr }; + ASSERT_EQ(cs.size(), 0U); + ASSERT_EQ(cs.data(), arr.data()); + } + + { + Span<int, 5> s{ arr }; + } + + { + auto get_an_array = []() -> std::array<int, 4> { return { 1, 2, 3, 4 }; }; + auto take_a_Span = [](Span<int> s) { static_cast<void>(s); }; + // try to take a temporary std::array + take_a_Span(get_an_array()); + } +#endif + + { + auto get_an_array = []() -> std::array<int, 4> { + return { { 1, 2, 3, 4 } }; + }; + auto take_a_Span = [](Span<const int> s) { static_cast<void>(s); }; + // try to take a temporary std::array + take_a_Span(get_an_array()); + } + + { + auto s = MakeSpan(arr); + ASSERT_EQ(s.size(), narrow_cast<size_t>(arr.size())); + ASSERT_EQ(s.data(), arr.data()); + } +} + +SPAN_TEST(from_const_std_array_constructor) +{ + const std::array<int, 4> arr = { { 1, 2, 3, 4 } }; + + { + Span<const int> s{ arr }; + ASSERT_EQ(s.size(), narrow_cast<size_t>(arr.size())); + ASSERT_EQ(s.data(), arr.data()); + } + + { + Span<const int, 4> s{ arr }; + ASSERT_EQ(s.size(), narrow_cast<size_t>(arr.size())); + ASSERT_EQ(s.data(), arr.data()); + } + +#ifdef CONFIRM_COMPILATION_ERRORS + { + Span<const int, 2> s{ arr }; + ASSERT_EQ(s.size(), 2U); + ASSERT_EQ(s.data(), arr.data()); + } + + { + Span<const int, 0> s{ arr }; + ASSERT_EQ(s.size(), 0U); + ASSERT_EQ(s.data(), arr.data()); + } + + { + Span<const int, 5> s{ arr }; + } +#endif + + { + auto get_an_array = []() -> const std::array<int, 4> { + return { { 1, 2, 3, 4 } }; + }; + auto take_a_Span = [](Span<const int> s) { static_cast<void>(s); }; + // try to take a temporary std::array + take_a_Span(get_an_array()); + } + + { + auto s = MakeSpan(arr); + ASSERT_EQ(s.size(), narrow_cast<size_t>(arr.size())); + ASSERT_EQ(s.data(), arr.data()); + } +} + +SPAN_TEST(from_std_array_const_constructor) +{ + std::array<const int, 4> arr = { { 1, 2, 3, 4 } }; + + { + Span<const int> s{ arr }; + ASSERT_EQ(s.size(), narrow_cast<size_t>(arr.size())); + ASSERT_EQ(s.data(), arr.data()); + } + + { + Span<const int, 4> s{ arr }; + ASSERT_EQ(s.size(), narrow_cast<size_t>(arr.size())); + ASSERT_EQ(s.data(), arr.data()); + } + +#ifdef CONFIRM_COMPILATION_ERRORS + { + Span<const int, 2> s{ arr }; + ASSERT_EQ(s.size(), 2U); + ASSERT_EQ(s.data(), arr.data()); + } + + { + Span<const int, 0> s{ arr }; + ASSERT_EQ(s.size(), 0U); + ASSERT_EQ(s.data(), arr.data()); + } + + { + Span<const int, 5> s{ arr }; + } + + { + Span<int, 4> s{ arr }; + } +#endif + + { + auto s = MakeSpan(arr); + ASSERT_EQ(s.size(), narrow_cast<size_t>(arr.size())); + ASSERT_EQ(s.data(), arr.data()); + } +} + +SPAN_TEST(from_mozilla_array_constructor) +{ + mozilla::Array<int, 4> arr(1, 2, 3, 4); + + { + Span<int> s{ arr }; + ASSERT_EQ(s.size(), narrow_cast<size_t>(arr.cend() - arr.cbegin())); + ASSERT_EQ(s.data(), &arr[0]); + + Span<const int> cs{ arr }; + ASSERT_EQ(cs.size(), narrow_cast<size_t>(arr.cend() - arr.cbegin())); + ASSERT_EQ(cs.data(), &arr[0]); + } + + { + Span<int, 4> s{ arr }; + ASSERT_EQ(s.size(), narrow_cast<size_t>(arr.cend() - arr.cbegin())); + ASSERT_EQ(s.data(), &arr[0]); + + Span<const int, 4> cs{ arr }; + ASSERT_EQ(cs.size(), narrow_cast<size_t>(arr.cend() - arr.cbegin())); + ASSERT_EQ(cs.data(), &arr[0]); + } + +#ifdef CONFIRM_COMPILATION_ERRORS + { + Span<int, 2> s{ arr }; + ASSERT_EQ(s.size(), 2U); + ASSERT_EQ(s.data(), &arr[0]); + + Span<const int, 2> cs{ arr }; + ASSERT_EQ(cs.size(), 2U); + ASSERT_EQ(cs.data(), &arr[0]); + } + + { + Span<int, 0> s{ arr }; + ASSERT_EQ(s.size(), 0U); + ASSERT_EQ(s.data(), &arr[0]); + + Span<const int, 0> cs{ arr }; + ASSERT_EQ(cs.size(), 0U); + ASSERT_EQ(cs.data(), &arr[0]); + } + + { + Span<int, 5> s{ arr }; + } + + { + auto get_an_array = []() -> mozilla::Array<int, 4> { + return { 1, 2, 3, 4 }; + }; + auto take_a_Span = [](Span<int> s) { static_cast<void>(s); }; + // try to take a temporary mozilla::Array + take_a_Span(get_an_array()); + } +#endif + + { + auto get_an_array = []() -> mozilla::Array<int, 4> { + return { 1, 2, 3, 4 }; + }; + auto take_a_Span = [](Span<const int> s) { static_cast<void>(s); }; + // try to take a temporary mozilla::Array + take_a_Span(get_an_array()); + } + + { + auto s = MakeSpan(arr); + ASSERT_EQ(s.size(), narrow_cast<size_t>(arr.cend() - arr.cbegin())); + ASSERT_EQ(s.data(), &arr[0]); + } +} + +SPAN_TEST(from_const_mozilla_array_constructor) +{ + const mozilla::Array<int, 4> arr(1, 2, 3, 4); + + { + Span<const int> s{ arr }; + ASSERT_EQ(s.size(), narrow_cast<size_t>(arr.cend() - arr.cbegin())); + ASSERT_EQ(s.data(), &arr[0]); + } + + { + Span<const int, 4> s{ arr }; + ASSERT_EQ(s.size(), narrow_cast<size_t>(arr.cend() - arr.cbegin())); + ASSERT_EQ(s.data(), &arr[0]); + } + +#ifdef CONFIRM_COMPILATION_ERRORS + { + Span<const int, 2> s{ arr }; + ASSERT_EQ(s.size(), 2U); + ASSERT_EQ(s.data(), &arr[0]); + } + + { + Span<const int, 0> s{ arr }; + ASSERT_EQ(s.size(), 0U); + ASSERT_EQ(s.data(), &arr[0]); + } + + { + Span<const int, 5> s{ arr }; + } +#endif + +#if 0 + { + auto get_an_array = []() -> const mozilla::Array<int, 4> { + return { 1, 2, 3, 4 }; + }; + auto take_a_Span = [](Span<const int> s) { static_cast<void>(s); }; + // try to take a temporary mozilla::Array + take_a_Span(get_an_array()); + } +#endif + + { + auto s = MakeSpan(arr); + ASSERT_EQ(s.size(), narrow_cast<size_t>(arr.cend() - arr.cbegin())); + ASSERT_EQ(s.data(), &arr[0]); + } +} + +SPAN_TEST(from_mozilla_array_const_constructor) +{ + mozilla::Array<const int, 4> arr(1, 2, 3, 4); + + { + Span<const int> s{ arr }; + ASSERT_EQ(s.size(), narrow_cast<size_t>(arr.cend() - arr.cbegin())); + ASSERT_EQ(s.data(), &arr[0]); + } + + { + Span<const int, 4> s{ arr }; + ASSERT_EQ(s.size(), narrow_cast<size_t>(arr.cend() - arr.cbegin())); + ASSERT_EQ(s.data(), &arr[0]); + } + +#ifdef CONFIRM_COMPILATION_ERRORS + { + Span<const int, 2> s{ arr }; + ASSERT_EQ(s.size(), 2U); + ASSERT_EQ(s.data(), &arr[0]); + } + + { + Span<const int, 0> s{ arr }; + ASSERT_EQ(s.size(), 0U); + ASSERT_EQ(s.data(), &arr[0]); + } + + { + Span<const int, 5> s{ arr }; + } + + { + Span<int, 4> s{ arr }; + } +#endif + + { + auto s = MakeSpan(arr); + ASSERT_EQ(s.size(), narrow_cast<size_t>(arr.cend() - arr.cbegin())); + ASSERT_EQ(s.data(), &arr[0]); + } +} + +SPAN_TEST(from_container_constructor) +{ + std::vector<int> v = { 1, 2, 3 }; + const std::vector<int> cv = v; + + { + AssertSpanOfThreeInts(v); + + Span<int> s{ v }; + ASSERT_EQ(s.size(), narrow_cast<size_t>(v.size())); + ASSERT_EQ(s.data(), v.data()); + + Span<const int> cs{ v }; + ASSERT_EQ(cs.size(), narrow_cast<size_t>(v.size())); + ASSERT_EQ(cs.data(), v.data()); + } + + std::string str = "hello"; + const std::string cstr = "hello"; + + { +#ifdef CONFIRM_COMPILATION_ERRORS + Span<char> s{ str }; + ASSERT_EQ(s.size(), narrow_cast<size_t>(str.size())); + ASSERT_EQ(s.data(), str.data()); +#endif + Span<const char> cs{ str }; + ASSERT_EQ(cs.size(), narrow_cast<size_t>(str.size())); + ASSERT_EQ(cs.data(), str.data()); + } + + { +#ifdef CONFIRM_COMPILATION_ERRORS + Span<char> s{ cstr }; +#endif + Span<const char> cs{ cstr }; + ASSERT_EQ(cs.size(), narrow_cast<size_t>(cstr.size())); + ASSERT_EQ(cs.data(), cstr.data()); + } + + { +#ifdef CONFIRM_COMPILATION_ERRORS + auto get_temp_vector = []() -> std::vector<int> { return {}; }; + auto use_Span = [](Span<int> s) { static_cast<void>(s); }; + use_Span(get_temp_vector()); +#endif + } + + { + auto get_temp_vector = []() -> std::vector<int> { return {}; }; + auto use_Span = [](Span<const int> s) { static_cast<void>(s); }; + use_Span(get_temp_vector()); + } + + { +#ifdef CONFIRM_COMPILATION_ERRORS + auto get_temp_string = []() -> std::string { return {}; }; + auto use_Span = [](Span<char> s) { static_cast<void>(s); }; + use_Span(get_temp_string()); +#endif + } + + { + auto get_temp_string = []() -> std::string { return {}; }; + auto use_Span = [](Span<const char> s) { static_cast<void>(s); }; + use_Span(get_temp_string()); + } + + { +#ifdef CONFIRM_COMPILATION_ERRORS + auto get_temp_vector = []() -> const std::vector<int> { return {}; }; + auto use_Span = [](Span<const char> s) { static_cast<void>(s); }; + use_Span(get_temp_vector()); +#endif + } + + { + auto get_temp_string = []() -> const std::string { return {}; }; + auto use_Span = [](Span<const char> s) { static_cast<void>(s); }; + use_Span(get_temp_string()); + } + + { +#ifdef CONFIRM_COMPILATION_ERRORS + std::map<int, int> m; + Span<int> s{ m }; +#endif + } + + { + auto s = MakeSpan(v); + ASSERT_EQ(s.size(), narrow_cast<size_t>(v.size())); + ASSERT_EQ(s.data(), v.data()); + + auto cs = MakeSpan(cv); + ASSERT_EQ(cs.size(), narrow_cast<size_t>(cv.size())); + ASSERT_EQ(cs.data(), cv.data()); + } +} + +SPAN_TEST(from_xpcom_collections) +{ + { + nsTArray<int> v; + v.AppendElement(1); + v.AppendElement(2); + v.AppendElement(3); + + AssertSpanOfThreeInts(v); + + Span<int> s{ v }; + ASSERT_EQ(s.size(), narrow_cast<size_t>(v.Length())); + ASSERT_EQ(s.data(), v.Elements()); + ASSERT_EQ(s[2], 3); + + Span<const int> cs{ v }; + ASSERT_EQ(cs.size(), narrow_cast<size_t>(v.Length())); + ASSERT_EQ(cs.data(), v.Elements()); + ASSERT_EQ(cs[2], 3); + } + { + nsTArray<int> v; + v.AppendElement(1); + v.AppendElement(2); + v.AppendElement(3); + + AssertSpanOfThreeInts(v); + + auto s = MakeSpan(v); + ASSERT_EQ(s.size(), narrow_cast<size_t>(v.Length())); + ASSERT_EQ(s.data(), v.Elements()); + ASSERT_EQ(s[2], 3); + } + { + AutoTArray<int, 5> v; + v.AppendElement(1); + v.AppendElement(2); + v.AppendElement(3); + + AssertSpanOfThreeInts(v); + + Span<int> s{ v }; + ASSERT_EQ(s.size(), narrow_cast<size_t>(v.Length())); + ASSERT_EQ(s.data(), v.Elements()); + ASSERT_EQ(s[2], 3); + + Span<const int> cs{ v }; + ASSERT_EQ(cs.size(), narrow_cast<size_t>(v.Length())); + ASSERT_EQ(cs.data(), v.Elements()); + ASSERT_EQ(cs[2], 3); + } + { + AutoTArray<int, 5> v; + v.AppendElement(1); + v.AppendElement(2); + v.AppendElement(3); + + AssertSpanOfThreeInts(v); + + auto s = MakeSpan(v); + ASSERT_EQ(s.size(), narrow_cast<size_t>(v.Length())); + ASSERT_EQ(s.data(), v.Elements()); + ASSERT_EQ(s[2], 3); + } + { + FallibleTArray<int> v; + *(v.AppendElement(fallible)) = 1; + *(v.AppendElement(fallible)) = 2; + *(v.AppendElement(fallible)) = 3; + + AssertSpanOfThreeInts(v); + + Span<int> s{ v }; + ASSERT_EQ(s.size(), narrow_cast<size_t>(v.Length())); + ASSERT_EQ(s.data(), v.Elements()); + ASSERT_EQ(s[2], 3); + + Span<const int> cs{ v }; + ASSERT_EQ(cs.size(), narrow_cast<size_t>(v.Length())); + ASSERT_EQ(cs.data(), v.Elements()); + ASSERT_EQ(cs[2], 3); + } + { + FallibleTArray<int> v; + *(v.AppendElement(fallible)) = 1; + *(v.AppendElement(fallible)) = 2; + *(v.AppendElement(fallible)) = 3; + + AssertSpanOfThreeInts(v); + + auto s = MakeSpan(v); + ASSERT_EQ(s.size(), narrow_cast<size_t>(v.Length())); + ASSERT_EQ(s.data(), v.Elements()); + ASSERT_EQ(s[2], 3); + } + { + nsAutoString str; + str.AssignLiteral("abc"); + + AssertSpanOfThreeChar16s(str); + AssertSpanOfThreeChar16sViaString(str); + + Span<char16_t> s{ str }; + ASSERT_EQ(s.size(), narrow_cast<size_t>(str.Length())); + ASSERT_EQ(s.data(), str.BeginWriting()); + ASSERT_EQ(s[2], 'c'); + + Span<const char16_t> cs{ str }; + ASSERT_EQ(cs.size(), narrow_cast<size_t>(str.Length())); + ASSERT_EQ(cs.data(), str.BeginReading()); + ASSERT_EQ(cs[2], 'c'); + } + { + nsAutoString str; + str.AssignLiteral("abc"); + + AssertSpanOfThreeChar16s(str); + AssertSpanOfThreeChar16sViaString(str); + + auto s = MakeSpan(str); + ASSERT_EQ(s.size(), narrow_cast<size_t>(str.Length())); + ASSERT_EQ(s.data(), str.BeginWriting()); + ASSERT_EQ(s[2], 'c'); + } + { + nsAutoCString str; + str.AssignLiteral("abc"); + + AssertSpanOfThreeChars(str); + AssertSpanOfThreeCharsViaString(str); + + Span<uint8_t> s{ str }; + ASSERT_EQ(s.size(), narrow_cast<size_t>(str.Length())); + ASSERT_EQ(s.data(), reinterpret_cast<uint8_t*>(str.BeginWriting())); + ASSERT_EQ(s[2], 'c'); + + Span<const uint8_t> cs{ str }; + ASSERT_EQ(cs.size(), narrow_cast<size_t>(str.Length())); + ASSERT_EQ(cs.data(), reinterpret_cast<const uint8_t*>(str.BeginReading())); + ASSERT_EQ(cs[2], 'c'); + } + { + nsAutoCString str; + str.AssignLiteral("abc"); + + AssertSpanOfThreeChars(str); + AssertSpanOfThreeCharsViaString(str); + + auto s = MakeSpan(str); + ASSERT_EQ(s.size(), narrow_cast<size_t>(str.Length())); + ASSERT_EQ(s.data(), str.BeginWriting()); + ASSERT_EQ(s[2], 'c'); + } + { + nsTArray<int> v; + v.AppendElement(1); + v.AppendElement(2); + v.AppendElement(3); + + Range<int> r(v.Elements(), v.Length()); + + AssertSpanOfThreeInts(r); + + Span<int> s{ r }; + ASSERT_EQ(s.size(), narrow_cast<size_t>(v.Length())); + ASSERT_EQ(s.data(), v.Elements()); + ASSERT_EQ(s[2], 3); + + Span<const int> cs{ r }; + ASSERT_EQ(cs.size(), narrow_cast<size_t>(v.Length())); + ASSERT_EQ(cs.data(), v.Elements()); + ASSERT_EQ(cs[2], 3); + } + { + nsTArray<int> v; + v.AppendElement(1); + v.AppendElement(2); + v.AppendElement(3); + + Range<int> r(v.Elements(), v.Length()); + + AssertSpanOfThreeInts(r); + + auto s = MakeSpan(r); + ASSERT_EQ(s.size(), narrow_cast<size_t>(v.Length())); + ASSERT_EQ(s.data(), v.Elements()); + ASSERT_EQ(s[2], 3); + } +} + +SPAN_TEST(from_cstring) +{ + { + const char* str = "abc"; + + auto cs = MakeCStringSpan(str); + ASSERT_EQ(cs.size(), 3U); + ASSERT_EQ(cs.data(), str); + ASSERT_EQ(cs[2], 'c'); + } +} + +SPAN_TEST(from_convertible_Span_constructor){ + { + Span<DerivedClass> avd; + Span<const DerivedClass> avcd = avd; + static_cast<void>(avcd); + } + + { +#ifdef CONFIRM_COMPILATION_ERRORS + Span<DerivedClass> avd; + Span<BaseClass> avb = avd; + static_cast<void>(avb); +#endif + } + +#ifdef CONFIRM_COMPILATION_ERRORS + { + Span<int> s; + Span<unsigned int> s2 = s; + static_cast<void>(s2); + } + + { + Span<int> s; + Span<const unsigned int> s2 = s; + static_cast<void>(s2); + } + + { + Span<int> s; + Span<short> s2 = s; + static_cast<void>(s2); + } +#endif +} + +SPAN_TEST(copy_move_and_assignment) +{ + Span<int> s1; + ASSERT_TRUE(s1.empty()); + + int arr[] = { 3, 4, 5 }; + + Span<const int> s2 = arr; + ASSERT_EQ(s2.Length(), 3U); + ASSERT_EQ(s2.data(), &arr[0]); + + s2 = s1; + ASSERT_TRUE(s2.empty()); + + auto get_temp_Span = [&]() -> Span<int> { return { &arr[1], 2 }; }; + auto use_Span = [&](Span<const int> s) { + ASSERT_EQ(s.Length(), 2U); + ASSERT_EQ(s.data(), &arr[1]); + }; + use_Span(get_temp_Span()); + + s1 = get_temp_Span(); + ASSERT_EQ(s1.Length(), 2U); + ASSERT_EQ(s1.data(), &arr[1]); +} + +SPAN_TEST(first) +{ + int arr[5] = { 1, 2, 3, 4, 5 }; + + { + Span<int, 5> av = arr; + ASSERT_EQ(av.First<2>().Length(), 2U); + ASSERT_EQ(av.First(2).Length(), 2U); + } + + { + Span<int, 5> av = arr; + ASSERT_EQ(av.First<0>().Length(), 0U); + ASSERT_EQ(av.First(0).Length(), 0U); + } + + { + Span<int, 5> av = arr; + ASSERT_EQ(av.First<5>().Length(), 5U); + ASSERT_EQ(av.First(5).Length(), 5U); + } + +#if 0 + { + Span<int, 5> av = arr; +#ifdef CONFIRM_COMPILATION_ERRORS + ASSERT_EQ(av.First<6>().Length() , 6U); + ASSERT_EQ(av.First<-1>().Length() , -1); +#endif + CHECK_THROW(av.First(6).Length(), fail_fast); + } +#endif + + { + Span<int> av; + ASSERT_EQ(av.First<0>().Length(), 0U); + ASSERT_EQ(av.First(0).Length(), 0U); + } +} + +SPAN_TEST(last) +{ + int arr[5] = { 1, 2, 3, 4, 5 }; + + { + Span<int, 5> av = arr; + ASSERT_EQ(av.Last<2>().Length(), 2U); + ASSERT_EQ(av.Last(2).Length(), 2U); + } + + { + Span<int, 5> av = arr; + ASSERT_EQ(av.Last<0>().Length(), 0U); + ASSERT_EQ(av.Last(0).Length(), 0U); + } + + { + Span<int, 5> av = arr; + ASSERT_EQ(av.Last<5>().Length(), 5U); + ASSERT_EQ(av.Last(5).Length(), 5U); + } + +#if 0 + { + Span<int, 5> av = arr; +#ifdef CONFIRM_COMPILATION_ERRORS + ASSERT_EQ(av.Last<6>().Length() , 6U); +#endif + CHECK_THROW(av.Last(6).Length(), fail_fast); + } +#endif + + { + Span<int> av; + ASSERT_EQ(av.Last<0>().Length(), 0U); + ASSERT_EQ(av.Last(0).Length(), 0U); + } +} + +SPAN_TEST(from_to) +{ + int arr[5] = { 1, 2, 3, 4, 5 }; + + { + Span<int, 5> av = arr; + ASSERT_EQ(av.From(3).Length(), 2U); + ASSERT_EQ(av.From(2)[1], 4); + } + + { + Span<int, 5> av = arr; + ASSERT_EQ(av.From(5).Length(), 0U); + } + + { + Span<int, 5> av = arr; + ASSERT_EQ(av.From(0).Length(), 5U); + } + + { + Span<int, 5> av = arr; + ASSERT_EQ(av.To(3).Length(), 3U); + ASSERT_EQ(av.To(3)[1], 2); + } + + { + Span<int, 5> av = arr; + ASSERT_EQ(av.To(0).Length(), 0U); + } + + { + Span<int, 5> av = arr; + ASSERT_EQ(av.To(5).Length(), 5U); + } + + { + Span<int, 5> av = arr; + ASSERT_EQ(av.FromTo(1, 4).Length(), 3U); + ASSERT_EQ(av.FromTo(1, 4)[1], 3); + } + + { + Span<int, 5> av = arr; + ASSERT_EQ(av.FromTo(2, 2).Length(), 0U); + } + + { + Span<int, 5> av = arr; + ASSERT_EQ(av.FromTo(0, 5).Length(), 5U); + } +} + +SPAN_TEST(Subspan) +{ + int arr[5] = { 1, 2, 3, 4, 5 }; + + { + Span<int, 5> av = arr; + ASSERT_EQ((av.Subspan<2, 2>().Length()), 2U); + ASSERT_EQ(av.Subspan(2, 2).Length(), 2U); + ASSERT_EQ(av.Subspan(2, 3).Length(), 3U); + } + + { + Span<int, 5> av = arr; + ASSERT_EQ((av.Subspan<0, 0>().Length()), 0U); + ASSERT_EQ(av.Subspan(0, 0).Length(), 0U); + } + + { + Span<int, 5> av = arr; + ASSERT_EQ((av.Subspan<0, 5>().Length()), 5U); + ASSERT_EQ(av.Subspan(0, 5).Length(), 5U); + CHECK_THROW(av.Subspan(0, 6).Length(), fail_fast); + CHECK_THROW(av.Subspan(1, 5).Length(), fail_fast); + } + + { + Span<int, 5> av = arr; + ASSERT_EQ((av.Subspan<4, 0>().Length()), 0U); + ASSERT_EQ(av.Subspan(4, 0).Length(), 0U); + ASSERT_EQ(av.Subspan(5, 0).Length(), 0U); + CHECK_THROW(av.Subspan(6, 0).Length(), fail_fast); + } + + { + Span<int> av; + ASSERT_EQ((av.Subspan<0, 0>().Length()), 0U); + ASSERT_EQ(av.Subspan(0, 0).Length(), 0U); + CHECK_THROW((av.Subspan<1, 0>().Length()), fail_fast); + } + + { + Span<int> av; + ASSERT_EQ(av.Subspan(0).Length(), 0U); + CHECK_THROW(av.Subspan(1).Length(), fail_fast); + } + + { + Span<int> av = arr; + ASSERT_EQ(av.Subspan(0).Length(), 5U); + ASSERT_EQ(av.Subspan(1).Length(), 4U); + ASSERT_EQ(av.Subspan(4).Length(), 1U); + ASSERT_EQ(av.Subspan(5).Length(), 0U); + CHECK_THROW(av.Subspan(6).Length(), fail_fast); + auto av2 = av.Subspan(1); + for (int i = 0; i < 4; ++i) + ASSERT_EQ(av2[i], i + 2); + } + + { + Span<int, 5> av = arr; + ASSERT_EQ(av.Subspan(0).Length(), 5U); + ASSERT_EQ(av.Subspan(1).Length(), 4U); + ASSERT_EQ(av.Subspan(4).Length(), 1U); + ASSERT_EQ(av.Subspan(5).Length(), 0U); + CHECK_THROW(av.Subspan(6).Length(), fail_fast); + auto av2 = av.Subspan(1); + for (int i = 0; i < 4; ++i) + ASSERT_EQ(av2[i], i + 2); + } +} + +SPAN_TEST(at_call) +{ + int arr[4] = { 1, 2, 3, 4 }; + + { + Span<int> s = arr; + ASSERT_EQ(s.at(0), 1); + CHECK_THROW(s.at(5), fail_fast); + } + + { + int arr2d[2] = { 1, 6 }; + Span<int, 2> s = arr2d; + ASSERT_EQ(s.at(0), 1); + ASSERT_EQ(s.at(1), 6); + CHECK_THROW(s.at(2), fail_fast); + } +} + +SPAN_TEST(operator_function_call) +{ + int arr[4] = { 1, 2, 3, 4 }; + + { + Span<int> s = arr; + ASSERT_EQ(s(0), 1); + CHECK_THROW(s(5), fail_fast); + } + + { + int arr2d[2] = { 1, 6 }; + Span<int, 2> s = arr2d; + ASSERT_EQ(s(0), 1); + ASSERT_EQ(s(1), 6); + CHECK_THROW(s(2), fail_fast); + } +} + +SPAN_TEST(iterator_default_init) +{ + Span<int>::iterator it1; + Span<int>::iterator it2; + ASSERT_EQ(it1, it2); +} + +SPAN_TEST(const_iterator_default_init) +{ + Span<int>::const_iterator it1; + Span<int>::const_iterator it2; + ASSERT_EQ(it1, it2); +} + +SPAN_TEST(iterator_conversions) +{ + Span<int>::iterator badIt; + Span<int>::const_iterator badConstIt; + ASSERT_EQ(badIt, badConstIt); + + int a[] = { 1, 2, 3, 4 }; + Span<int> s = a; + + auto it = s.begin(); + auto cit = s.cbegin(); + + ASSERT_EQ(it, cit); + ASSERT_EQ(cit, it); + + Span<int>::const_iterator cit2 = it; + ASSERT_EQ(cit2, cit); + + Span<int>::const_iterator cit3 = it + 4; + ASSERT_EQ(cit3, s.cend()); +} + +SPAN_TEST(iterator_comparisons) +{ + int a[] = { 1, 2, 3, 4 }; + { + Span<int> s = a; + Span<int>::iterator it = s.begin(); + auto it2 = it + 1; + Span<int>::const_iterator cit = s.cbegin(); + + ASSERT_EQ(it, cit); + ASSERT_EQ(cit, it); + ASSERT_EQ(it, it); + ASSERT_EQ(cit, cit); + ASSERT_EQ(cit, s.begin()); + ASSERT_EQ(s.begin(), cit); + ASSERT_EQ(s.cbegin(), cit); + ASSERT_EQ(it, s.begin()); + ASSERT_EQ(s.begin(), it); + + ASSERT_NE(it, it2); + ASSERT_NE(it2, it); + ASSERT_NE(it, s.end()); + ASSERT_NE(it2, s.end()); + ASSERT_NE(s.end(), it); + ASSERT_NE(it2, cit); + ASSERT_NE(cit, it2); + + ASSERT_LT(it, it2); + ASSERT_LE(it, it2); + ASSERT_LE(it2, s.end()); + ASSERT_LT(it, s.end()); + ASSERT_LE(it, cit); + ASSERT_LE(cit, it); + ASSERT_LT(cit, it2); + ASSERT_LE(cit, it2); + ASSERT_LT(cit, s.end()); + ASSERT_LE(cit, s.end()); + + ASSERT_GT(it2, it); + ASSERT_GE(it2, it); + ASSERT_GT(s.end(), it2); + ASSERT_GE(s.end(), it2); + ASSERT_GT(it2, cit); + ASSERT_GE(it2, cit); + } +} + +SPAN_TEST(begin_end) +{ + { + int a[] = { 1, 2, 3, 4 }; + Span<int> s = a; + + Span<int>::iterator it = s.begin(); + Span<int>::iterator it2 = std::begin(s); + ASSERT_EQ(it, it2); + + it = s.end(); + it2 = std::end(s); + ASSERT_EQ(it, it2); + } + + { + int a[] = { 1, 2, 3, 4 }; + Span<int> s = a; + + auto it = s.begin(); + auto first = it; + ASSERT_EQ(it, first); + ASSERT_EQ(*it, 1); + + auto beyond = s.end(); + ASSERT_NE(it, beyond); + CHECK_THROW(*beyond, fail_fast); + + ASSERT_EQ(beyond - first, 4U); + ASSERT_EQ(first - first, 0U); + ASSERT_EQ(beyond - beyond, 0U); + + ++it; + ASSERT_EQ(it - first, 1U); + ASSERT_EQ(*it, 2); + *it = 22; + ASSERT_EQ(*it, 22); + ASSERT_EQ(beyond - it, 3U); + + it = first; + ASSERT_EQ(it, first); + while (it != s.end()) { + *it = 5; + ++it; + } + + ASSERT_EQ(it, beyond); + ASSERT_EQ(it - beyond, 0U); + + for (auto& n : s) { + ASSERT_EQ(n, 5); + } + } +} + +SPAN_TEST(cbegin_cend) +{ +#if 0 + { + int a[] = { 1, 2, 3, 4 }; + Span<int> s = a; + + Span<int>::const_iterator cit = s.cbegin(); + Span<int>::const_iterator cit2 = std::cbegin(s); + ASSERT_EQ(cit , cit2); + + cit = s.cend(); + cit2 = std::cend(s); + ASSERT_EQ(cit , cit2); + } +#endif + { + int a[] = { 1, 2, 3, 4 }; + Span<int> s = a; + + auto it = s.cbegin(); + auto first = it; + ASSERT_EQ(it, first); + ASSERT_EQ(*it, 1); + + auto beyond = s.cend(); + ASSERT_NE(it, beyond); + CHECK_THROW(*beyond, fail_fast); + + ASSERT_EQ(beyond - first, 4U); + ASSERT_EQ(first - first, 0U); + ASSERT_EQ(beyond - beyond, 0U); + + ++it; + ASSERT_EQ(it - first, 1U); + ASSERT_EQ(*it, 2); + ASSERT_EQ(beyond - it, 3U); + + int last = 0; + it = first; + ASSERT_EQ(it, first); + while (it != s.cend()) { + ASSERT_EQ(*it, last + 1); + + last = *it; + ++it; + } + + ASSERT_EQ(it, beyond); + ASSERT_EQ(it - beyond, 0U); + } +} + +SPAN_TEST(rbegin_rend) +{ + { + int a[] = { 1, 2, 3, 4 }; + Span<int> s = a; + + auto it = s.rbegin(); + auto first = it; + ASSERT_EQ(it, first); + ASSERT_EQ(*it, 4); + + auto beyond = s.rend(); + ASSERT_NE(it, beyond); + CHECK_THROW(*beyond, fail_fast); + + ASSERT_EQ(beyond - first, 4U); + ASSERT_EQ(first - first, 0U); + ASSERT_EQ(beyond - beyond, 0U); + + ++it; + ASSERT_EQ(it - first, 1U); + ASSERT_EQ(*it, 3); + *it = 22; + ASSERT_EQ(*it, 22); + ASSERT_EQ(beyond - it, 3U); + + it = first; + ASSERT_EQ(it, first); + while (it != s.rend()) { + *it = 5; + ++it; + } + + ASSERT_EQ(it, beyond); + ASSERT_EQ(it - beyond, 0U); + + for (auto& n : s) { + ASSERT_EQ(n, 5); + } + } +} + +SPAN_TEST(crbegin_crend) +{ + { + int a[] = { 1, 2, 3, 4 }; + Span<int> s = a; + + auto it = s.crbegin(); + auto first = it; + ASSERT_EQ(it, first); + ASSERT_EQ(*it, 4); + + auto beyond = s.crend(); + ASSERT_NE(it, beyond); + CHECK_THROW(*beyond, fail_fast); + + ASSERT_EQ(beyond - first, 4U); + ASSERT_EQ(first - first, 0U); + ASSERT_EQ(beyond - beyond, 0U); + + ++it; + ASSERT_EQ(it - first, 1U); + ASSERT_EQ(*it, 3); + ASSERT_EQ(beyond - it, 3U); + + it = first; + ASSERT_EQ(it, first); + int last = 5; + while (it != s.crend()) { + ASSERT_EQ(*it, last - 1); + last = *it; + + ++it; + } + + ASSERT_EQ(it, beyond); + ASSERT_EQ(it - beyond, 0U); + } +} + +SPAN_TEST(comparison_operators) +{ + { + Span<int> s1 = nullptr; + Span<int> s2 = nullptr; + ASSERT_EQ(s1, s2); + ASSERT_FALSE(s1 != s2); + ASSERT_FALSE(s1 < s2); + ASSERT_LE(s1, s2); + ASSERT_FALSE(s1 > s2); + ASSERT_GE(s1, s2); + ASSERT_EQ(s2, s1); + ASSERT_FALSE(s2 != s1); + ASSERT_FALSE(s2 < s1); + ASSERT_LE(s2, s1); + ASSERT_FALSE(s2 > s1); + ASSERT_GE(s2, s1); + } + + { + int arr[] = { 2, 1 }; + Span<int> s1 = arr; + Span<int> s2 = arr; + + ASSERT_EQ(s1, s2); + ASSERT_FALSE(s1 != s2); + ASSERT_FALSE(s1 < s2); + ASSERT_LE(s1, s2); + ASSERT_FALSE(s1 > s2); + ASSERT_GE(s1, s2); + ASSERT_EQ(s2, s1); + ASSERT_FALSE(s2 != s1); + ASSERT_FALSE(s2 < s1); + ASSERT_LE(s2, s1); + ASSERT_FALSE(s2 > s1); + ASSERT_GE(s2, s1); + } + + { + int arr[] = { 2, 1 }; // bigger + + Span<int> s1 = nullptr; + Span<int> s2 = arr; + + ASSERT_NE(s1, s2); + ASSERT_NE(s2, s1); + ASSERT_NE(s1, s2); + ASSERT_NE(s2, s1); + ASSERT_LT(s1, s2); + ASSERT_FALSE(s2 < s1); + ASSERT_LE(s1, s2); + ASSERT_FALSE(s2 <= s1); + ASSERT_GT(s2, s1); + ASSERT_FALSE(s1 > s2); + ASSERT_GE(s2, s1); + ASSERT_FALSE(s1 >= s2); + } + + { + int arr1[] = { 1, 2 }; + int arr2[] = { 1, 2 }; + Span<int> s1 = arr1; + Span<int> s2 = arr2; + + ASSERT_EQ(s1, s2); + ASSERT_FALSE(s1 != s2); + ASSERT_FALSE(s1 < s2); + ASSERT_LE(s1, s2); + ASSERT_FALSE(s1 > s2); + ASSERT_GE(s1, s2); + ASSERT_EQ(s2, s1); + ASSERT_FALSE(s2 != s1); + ASSERT_FALSE(s2 < s1); + ASSERT_LE(s2, s1); + ASSERT_FALSE(s2 > s1); + ASSERT_GE(s2, s1); + } + + { + int arr[] = { 1, 2, 3 }; + + AssertSpanOfThreeInts(arr); + + Span<int> s1 = { &arr[0], 2 }; // shorter + Span<int> s2 = arr; // longer + + ASSERT_NE(s1, s2); + ASSERT_NE(s2, s1); + ASSERT_NE(s1, s2); + ASSERT_NE(s2, s1); + ASSERT_LT(s1, s2); + ASSERT_FALSE(s2 < s1); + ASSERT_LE(s1, s2); + ASSERT_FALSE(s2 <= s1); + ASSERT_GT(s2, s1); + ASSERT_FALSE(s1 > s2); + ASSERT_GE(s2, s1); + ASSERT_FALSE(s1 >= s2); + } + + { + int arr1[] = { 1, 2 }; // smaller + int arr2[] = { 2, 1 }; // bigger + + Span<int> s1 = arr1; + Span<int> s2 = arr2; + + ASSERT_NE(s1, s2); + ASSERT_NE(s2, s1); + ASSERT_NE(s1, s2); + ASSERT_NE(s2, s1); + ASSERT_LT(s1, s2); + ASSERT_FALSE(s2 < s1); + ASSERT_LE(s1, s2); + ASSERT_FALSE(s2 <= s1); + ASSERT_GT(s2, s1); + ASSERT_FALSE(s1 > s2); + ASSERT_GE(s2, s1); + ASSERT_FALSE(s1 >= s2); + } +} + +SPAN_TEST(as_bytes) +{ + int a[] = { 1, 2, 3, 4 }; + + { + Span<const int> s = a; + ASSERT_EQ(s.Length(), 4U); + Span<const uint8_t> bs = AsBytes(s); + ASSERT_EQ(static_cast<const void*>(bs.data()), + static_cast<const void*>(s.data())); + ASSERT_EQ(bs.Length(), s.LengthBytes()); + } + + { + Span<int> s; + auto bs = AsBytes(s); + ASSERT_EQ(bs.Length(), s.Length()); + ASSERT_EQ(bs.Length(), 0U); + ASSERT_EQ(bs.size_bytes(), 0U); + ASSERT_EQ(static_cast<const void*>(bs.data()), + static_cast<const void*>(s.data())); + ASSERT_EQ(bs.data(), nullptr); + } + + { + Span<int> s = a; + auto bs = AsBytes(s); + ASSERT_EQ(static_cast<const void*>(bs.data()), + static_cast<const void*>(s.data())); + ASSERT_EQ(bs.Length(), s.LengthBytes()); + } +} + +SPAN_TEST(as_writable_bytes) +{ + int a[] = { 1, 2, 3, 4 }; + + { +#ifdef CONFIRM_COMPILATION_ERRORS + // you should not be able to get writeable bytes for const objects + Span<const int> s = a; + ASSERT_EQ(s.Length(), 4U); + Span<const byte> bs = AsWritableBytes(s); + ASSERT_EQ(static_cast<void*>(bs.data()), static_cast<void*>(s.data())); + ASSERT_EQ(bs.Length(), s.LengthBytes()); +#endif + } + + { + Span<int> s; + auto bs = AsWritableBytes(s); + ASSERT_EQ(bs.Length(), s.Length()); + ASSERT_EQ(bs.Length(), 0U); + ASSERT_EQ(bs.size_bytes(), 0U); + ASSERT_EQ(static_cast<void*>(bs.data()), static_cast<void*>(s.data())); + ASSERT_EQ(bs.data(), nullptr); + } + + { + Span<int> s = a; + auto bs = AsWritableBytes(s); + ASSERT_EQ(static_cast<void*>(bs.data()), static_cast<void*>(s.data())); + ASSERT_EQ(bs.Length(), s.LengthBytes()); + } +} + +SPAN_TEST(fixed_size_conversions) +{ + int arr[] = { 1, 2, 3, 4 }; + + // converting to an Span from an equal size array is ok + Span<int, 4> s4 = arr; + ASSERT_EQ(s4.Length(), 4U); + + // converting to dynamic_range is always ok + { + Span<int> s = s4; + ASSERT_EQ(s.Length(), s4.Length()); + static_cast<void>(s); + } + +// initialization or assignment to static Span that REDUCES size is NOT ok +#ifdef CONFIRM_COMPILATION_ERRORS + { + Span<int, 2> s = arr; + } + { + Span<int, 2> s2 = s4; + static_cast<void>(s2); + } +#endif + +#if 0 + // even when done dynamically + { + Span<int> s = arr; + auto f = [&]() { + Span<int, 2> s2 = s; + static_cast<void>(s2); + }; + CHECK_THROW(f(), fail_fast); + } +#endif + + // but doing so explicitly is ok + + // you can convert statically + { + Span<int, 2> s2 = { arr, 2 }; + static_cast<void>(s2); + } + { + Span<int, 1> s1 = s4.First<1>(); + static_cast<void>(s1); + } + + // ...or dynamically + { + // NB: implicit conversion to Span<int,1> from Span<int> + Span<int, 1> s1 = s4.First(1); + static_cast<void>(s1); + } + +#if 0 + // initialization or assignment to static Span that requires size INCREASE is not ok. + int arr2[2] = {1, 2}; +#endif + +#ifdef CONFIRM_COMPILATION_ERRORS + { + Span<int, 4> s3 = arr2; + } + { + Span<int, 2> s2 = arr2; + Span<int, 4> s4a = s2; + } +#endif + +#if 0 + { + auto f = [&]() { + Span<int, 4> _s4 = {arr2, 2}; + static_cast<void>(_s4); + }; + CHECK_THROW(f(), fail_fast); + } + + // this should fail - we are trying to assign a small dynamic Span to a fixed_size larger one + Span<int> av = arr2; + auto f = [&]() { + Span<int, 4> _s4 = av; + static_cast<void>(_s4); + }; + CHECK_THROW(f(), fail_fast); +#endif +} + +#if 0 + SPAN_TEST(interop_with_std_regex) + { + char lat[] = { '1', '2', '3', '4', '5', '6', 'E', 'F', 'G' }; + Span<char> s = lat; + auto f_it = s.begin() + 7; + + std::match_results<Span<char>::iterator> match; + + std::regex_match(s.begin(), s.end(), match, std::regex(".*")); + ASSERT_EQ(match.ready()); + ASSERT_TRUE(!match.empty()); + ASSERT_TRUE(match[0].matched); + ASSERT_TRUE(match[0].first , s.begin()); + ASSERT_EQ(match[0].second , s.end()); + + std::regex_search(s.begin(), s.end(), match, std::regex("F")); + ASSERT_TRUE(match.ready()); + ASSERT_TRUE(!match.empty()); + ASSERT_TRUE(match[0].matched); + ASSERT_EQ(match[0].first , f_it); + ASSERT_EQ(match[0].second , (f_it + 1)); + } + +SPAN_TEST(interop_with_gsl_at) +{ + int arr[5] = { 1, 2, 3, 4, 5 }; + Span<int> s{ arr }; + ASSERT_EQ(at(s, 0) , 1 ); +ASSERT_EQ(at(s, 1) , 2U); +} +#endif + +SPAN_TEST(default_constructible) +{ + ASSERT_TRUE((std::is_default_constructible<Span<int>>::value)); + ASSERT_TRUE((std::is_default_constructible<Span<int, 0>>::value)); + ASSERT_TRUE((!std::is_default_constructible<Span<int, 42>>::value)); +} diff --git a/mfbt/tests/gtest/moz.build b/mfbt/tests/gtest/moz.build new file mode 100644 index 0000000000..bd559d60b9 --- /dev/null +++ b/mfbt/tests/gtest/moz.build @@ -0,0 +1,15 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# 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/. + +UNIFIED_SOURCES += [ + 'TestSpan.cpp', +] + +#LOCAL_INCLUDES += [ +# '../../base', +#] + +FINAL_LIBRARY = 'xul-gtest' diff --git a/mfbt/tests/moz.build b/mfbt/tests/moz.build index bd25ab1d0b..e69de5d75e 100644 --- a/mfbt/tests/moz.build +++ b/mfbt/tests/moz.build @@ -4,6 +4,11 @@ # 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/. +if not CONFIG['JS_STANDALONE']: + TEST_DIRS += [ + 'gtest', + ] + CppUnitTests([ 'TestArray', 'TestArrayUtils', diff --git a/toolkit/content/license.html b/toolkit/content/license.html index a348fdfa60..7221a8ae23 100644 --- a/toolkit/content/license.html +++ b/toolkit/content/license.html @@ -97,6 +97,7 @@ <li><a href="about:license#gears">Google Gears License</a></li> <li><a href="about:license#gears-istumbler">Google Gears/iStumbler License</a></li> <li><a href="about:license#vp8">Google VP8 License</a></li> + <li><a href="about:license#gsl">GSL License</a></li> <li><a href="about:license#gyp">gyp License</a></li> <li><a href="about:license#halloc">halloc License</a></li> <li><a href="about:license#harfbuzz">HarfBuzz License</a></li> @@ -3285,6 +3286,38 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. <hr> + <h1><a id="gsl"></a>GSL License</h1> + + <p>This license applies to <span class="path">mfbt/Span.h</span> and + <span class="path">mfbt/tests/gtest/TestSpan.cpp</span>.</p> + <!-- https://github.com/Microsoft/GSL/blob/3819df6e378ffccf0e29465afe99c3b324c2aa70/LICENSE --> +<pre> +Copyright (c) 2015 Microsoft Corporation. All rights reserved. + +This code is licensed under the MIT License (MIT). + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +</pre> + + + <hr> + <h1><a id="gyp"></a>gyp License</h1> <p>This license applies to certain files in the directory diff --git a/xpcom/glue/nsTArray.h b/xpcom/glue/nsTArray.h index ca74a41f76..c86772a8e9 100644 --- a/xpcom/glue/nsTArray.h +++ b/xpcom/glue/nsTArray.h @@ -19,6 +19,7 @@ #include "mozilla/Move.h" #include "mozilla/ReverseIterator.h" #include "mozilla/TypeTraits.h" +#include "mozilla/Span.h" #include <string.h> @@ -1112,6 +1113,18 @@ public: const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } const_reverse_iterator crend() const { return rend(); } + // Span integration + + operator mozilla::Span<elem_type>() + { + return mozilla::Span<elem_type>(Elements(), Length()); + } + + operator mozilla::Span<const elem_type>() const + { + return mozilla::Span<const elem_type>(Elements(), Length()); + } + // // Search methods // @@ -1336,6 +1349,16 @@ protected: return ReplaceElementsAt<Item, ActualAlloc>( aStart, aCount, aArray.Elements(), aArray.Length()); } + + template<class Item, typename ActualAlloc = Alloc> + elem_type* ReplaceElementsAt(index_type aStart, + size_type aCount, + mozilla::Span<const Item> aSpan) + { + return ReplaceElementsAt<Item, ActualAlloc>( + aStart, aCount, aSpan.Elements(), aSpan.Length()); + } + public: template<class Item> @@ -1347,6 +1370,15 @@ public: return ReplaceElementsAt<Item, FallibleAlloc>(aStart, aCount, aArray); } + template<class Item> + MOZ_MUST_USE elem_type* ReplaceElementsAt(index_type aStart, + size_type aCount, + mozilla::Span<const Item> aSpan, + const mozilla::fallible_t&) + { + return ReplaceElementsAt<Item, FallibleAlloc>(aStart, aCount, aSpan); + } + // A variation on the ReplaceElementsAt method defined above. protected: template<class Item, typename ActualAlloc = Alloc> @@ -1399,6 +1431,15 @@ protected: return ReplaceElementsAt<Item, ActualAlloc>( aIndex, 0, aArray.Elements(), aArray.Length()); } + + template<class Item, typename ActualAlloc = Alloc> + elem_type* InsertElementsAt(index_type aIndex, + mozilla::Span<const Item> aSpan) + { + return ReplaceElementsAt<Item, ActualAlloc>( + aIndex, 0, aSpan.Elements(), aSpan.Length()); + } + public: template<class Item, class Allocator> @@ -1425,6 +1466,14 @@ public: return InsertElementAt<FallibleAlloc>(aIndex); } + template<class Item> + MOZ_MUST_USE elem_type* InsertElementsAt(index_type aIndex, + mozilla::Span<const Item> aSpan, + const mozilla::fallible_t&) + { + return InsertElementsAt<Item, FallibleAlloc>(aIndex, aSpan); + } + // Insert a new element, move constructing if possible. protected: template<class Item, typename ActualAlloc = Alloc> @@ -1526,6 +1575,13 @@ protected: template<class Item, typename ActualAlloc = Alloc> elem_type* AppendElements(const Item* aArray, size_type aArrayLen); + template<class Item, typename ActualAlloc = Alloc> + elem_type* AppendElements(mozilla::Span<const Item> aSpan) + { + return AppendElements<Item, FallibleAlloc>(aSpan.Elements(), + aSpan.Length()); + } + public: template<class Item> @@ -1536,6 +1592,15 @@ public: return AppendElements<Item, FallibleAlloc>(aArray, aArrayLen); } + template<class Item> + /* MOZ_MUST_USE */ + elem_type* AppendElements(mozilla::Span<const Item> aSpan, + const mozilla::fallible_t&) + { + return AppendElements<Item, FallibleAlloc>(aSpan.Elements(), + aSpan.Length()); + } + // A variation on the AppendElements method defined above. protected: template<class Item, class Allocator, typename ActualAlloc = Alloc> @@ -2347,6 +2412,25 @@ struct nsTArray_CopyChooser<AutoTArray<E, N>> typedef nsTArray_CopyWithConstructors<AutoTArray<E, N>> Type; }; +// Span integration +namespace mozilla { + +template<class ElementType, class TArrayAlloc> +Span<ElementType> +MakeSpan(nsTArray_Impl<ElementType, TArrayAlloc>& aTArray) +{ + return aTArray; +} + +template<class ElementType, class TArrayAlloc> +Span<const ElementType> +MakeSpan(const nsTArray_Impl<ElementType, TArrayAlloc>& aTArray) +{ + return aTArray; +} + +} // namespace mozilla + // Assert that AutoTArray doesn't have any extra padding inside. // // It's important that the data stored in this auto array takes up a multiple of diff --git a/xpcom/string/nsTSubstring.h b/xpcom/string/nsTSubstring.h index a08036b1f0..53b4fb9a82 100644 --- a/xpcom/string/nsTSubstring.h +++ b/xpcom/string/nsTSubstring.h @@ -7,6 +7,8 @@ #include "mozilla/Casting.h" #include "mozilla/MemoryReporting.h" +#include "mozilla/IntegerTypeTraits.h" +#include "mozilla/Span.h" #ifndef MOZILLA_INTERNAL_API #error Cannot use internal string classes without MOZILLA_INTERNAL_API defined. Use the frozen header nsStringAPI.h instead. @@ -798,6 +800,68 @@ public: } #endif + /** + * Span integration + */ + + operator mozilla::Span<char_type>() + { + return mozilla::MakeSpan(BeginWriting(), Length()); + } + + operator mozilla::Span<const char_type>() const + { + return mozilla::MakeSpan(BeginReading(), Length()); + } + + void Append(mozilla::Span<const char_type> aSpan) + { + auto len = aSpan.Length(); + MOZ_RELEASE_ASSERT(len <= mozilla::MaxValue<size_type>::value); + Append(aSpan.Elements(), len); + } + + MOZ_MUST_USE bool Append(mozilla::Span<const char_type> aSpan, + const fallible_t& aFallible) + { + auto len = aSpan.Length(); + if (len > mozilla::MaxValue<size_type>::value) { + return false; + } + return Append(aSpan.Elements(), len, aFallible); + } + +#if !defined(CharT_is_PRUnichar) + operator mozilla::Span<uint8_t>() + { + return mozilla::MakeSpan(reinterpret_cast<uint8_t*>(BeginWriting()), + Length()); + } + + operator mozilla::Span<const uint8_t>() const + { + return mozilla::MakeSpan(reinterpret_cast<const uint8_t*>(BeginReading()), + Length()); + } + + void Append(mozilla::Span<const uint8_t> aSpan) + { + auto len = aSpan.Length(); + MOZ_RELEASE_ASSERT(len <= mozilla::MaxValue<size_type>::value); + Append(reinterpret_cast<const char*>(aSpan.Elements()), len); + } + + MOZ_MUST_USE bool Append(mozilla::Span<const uint8_t> aSpan, + const fallible_t& aFallible) + { + auto len = aSpan.Length(); + if (len > mozilla::MaxValue<size_type>::value) { + return false; + } + return Append( + reinterpret_cast<const char*>(aSpan.Elements()), len, aFallible); + } +#endif /** * string data is never null, but can be marked void. if true, the @@ -1184,3 +1248,22 @@ operator>(const nsTSubstring_CharT::base_string_type& aLhs, { return Compare(aLhs, aRhs) > 0; } + +/** + * Span integration + */ +namespace mozilla { + +inline Span<CharT> +MakeSpan(nsTSubstring_CharT& aString) +{ + return aString; +} + +inline Span<const CharT> +MakeSpan(const nsTSubstring_CharT& aString) +{ + return aString; +} + +} // namespace mozilla |