mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Merge branch 'development'
This commit is contained in:
@@ -28,6 +28,11 @@ AlignConsecutiveMacros:
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveShortCaseStatements:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCaseColons: false
|
||||
AlignEscapedNewlines: Left
|
||||
AlignOperands: Align
|
||||
AlignTrailingComments:
|
||||
@@ -141,6 +146,7 @@ IntegerLiteralSeparator:
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
KeepEmptyLinesAtEOF: false
|
||||
LambdaBodyIndentation: Signature
|
||||
LineEnding: DeriveLF
|
||||
MacroBlockBegin: ''
|
||||
@@ -201,6 +207,7 @@ RawStringFormats:
|
||||
ReferenceAlignment: Pointer
|
||||
ReflowComments: true
|
||||
RemoveBracesLLVM: false
|
||||
RemoveParentheses: Leave
|
||||
RemoveSemicolon: false
|
||||
RequiresClausePosition: OwnLine
|
||||
RequiresExpressionIndentation: OuterScope
|
||||
@@ -218,6 +225,7 @@ SpaceBeforeCaseColon: false
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeJsonColon: false
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeParensOptions:
|
||||
AfterControlStatements: true
|
||||
@@ -232,23 +240,28 @@ SpaceBeforeParensOptions:
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceBeforeSquareBrackets: false
|
||||
SpaceInEmptyBlock: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 2
|
||||
SpacesInAngles: Never
|
||||
SpacesInConditionalStatement: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInLineCommentPrefix:
|
||||
Minimum: 1
|
||||
Maximum: -1
|
||||
SpacesInParentheses: false
|
||||
SpacesInParens: Never
|
||||
SpacesInParensOptions:
|
||||
InCStyleCasts: false
|
||||
InConditionalStatements: false
|
||||
InEmptyParentheses: false
|
||||
Other: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: c++20
|
||||
StatementAttributeLikeMacros:
|
||||
- Q_EMIT
|
||||
StatementMacros:
|
||||
- Q_UNUSED
|
||||
- QT_REQUIRE_VERSION
|
||||
TabWidth: 8
|
||||
UseTab: Never
|
||||
VerilogBreakBetweenInstancePorts: true
|
||||
WhitespaceSensitiveMacros:
|
||||
- BOOST_PP_STRINGIZE
|
||||
- CF_SWIFT_NAME
|
||||
|
||||
12
.github/workflows/cmake.yml
vendored
12
.github/workflows/cmake.yml
vendored
@@ -16,11 +16,11 @@ jobs:
|
||||
name: Linux
|
||||
container: wpilib/roborio-cross-ubuntu:2024-22.04
|
||||
flags: "-DCMAKE_BUILD_TYPE=Release -DWITH_EXAMPLES=ON"
|
||||
- os: macOS-12
|
||||
- os: macOS-14
|
||||
name: macOS
|
||||
container: ""
|
||||
env: "PATH=\"/usr/local/opt/protobuf@3/bin:$PATH\""
|
||||
flags: "-DCMAKE_BUILD_TYPE=Release -DWITH_JAVA=OFF -DWITH_EXAMPLES=ON -DCMAKE_LIBRARY_PATH=/usr/local/opt/protobuf@3/lib -DProtobuf_INCLUDE_DIR=/usr/local/opt/protobuf@3/include -DProtobuf_PROTOC_EXECUTABLE=/usr/local/opt/protobuf@3/bin/protoc"
|
||||
env: "PATH=\"/opt/homebrew/opt/protobuf@3/bin:$PATH\""
|
||||
flags: "-DCMAKE_BUILD_TYPE=Release -DWITH_JAVA=OFF -DWITH_EXAMPLES=ON -DCMAKE_LIBRARY_PATH=/opt/homebrew/opt/protobuf@3/lib -DProtobuf_INCLUDE_DIR=/opt/homebrew/opt/protobuf@3/include -DProtobuf_PROTOC_EXECUTABLE=/opt/homebrew/opt/protobuf@3/bin/protoc"
|
||||
|
||||
name: "Build - ${{ matrix.name }}"
|
||||
runs-on: ${{ matrix.os }}
|
||||
@@ -34,15 +34,15 @@ jobs:
|
||||
if: runner.os == 'Linux'
|
||||
run: wget https://github.com/HebiRobotics/QuickBuffers/releases/download/1.3.3/protoc-gen-quickbuf_1.3.3_amd64.deb && sudo apt install ./protoc-gen-quickbuf_1.3.3_amd64.deb
|
||||
|
||||
- name: Install opencv (macOS)
|
||||
- name: Install dependencies (macOS)
|
||||
run: brew install opencv protobuf@3 ninja
|
||||
if: runner.os == 'macOS'
|
||||
|
||||
- name: Set up Python 3.8 (macOS)
|
||||
- name: Set up Python 3.10 (macOS)
|
||||
if: runner.os == 'macOS'
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: 3.8
|
||||
python-version: '3.10'
|
||||
|
||||
- name: Run sccache-cache
|
||||
uses: mozilla-actions/sccache-action@v0.0.3
|
||||
|
||||
6
.github/workflows/comment-command.yml
vendored
6
.github/workflows/comment-command.yml
vendored
@@ -33,17 +33,17 @@ jobs:
|
||||
env:
|
||||
GITHUB_TOKEN: "${{ secrets.COMMENT_COMMAND_PAT_TOKEN }}"
|
||||
NUMBER: ${{ github.event.issue.number }}
|
||||
- name: Set up Python 3.8
|
||||
- name: Set up Python 3.10
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: 3.8
|
||||
python-version: '3.10'
|
||||
- name: Setup Java
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: 'zulu'
|
||||
java-version: 17
|
||||
- name: Install wpiformat
|
||||
run: pip3 install wpiformat==2024.32
|
||||
run: pip3 install wpiformat==2024.33
|
||||
- name: Run wpiformat
|
||||
run: wpiformat
|
||||
- name: Run spotlessApply
|
||||
|
||||
4
.github/workflows/gradle.yml
vendored
4
.github/workflows/gradle.yml
vendored
@@ -94,9 +94,9 @@ jobs:
|
||||
task: "copyAllOutputs"
|
||||
outputs: "build/allOutputs"
|
||||
build-dir: "c:\\work"
|
||||
- os: macOS-12
|
||||
- os: macOS-14
|
||||
artifact-name: macOS
|
||||
architecture: x64
|
||||
architecture: aarch64
|
||||
task: "build"
|
||||
outputs: "build/allOutputs"
|
||||
build-dir: "."
|
||||
|
||||
10
.github/workflows/lint-format.yml
vendored
10
.github/workflows/lint-format.yml
vendored
@@ -22,12 +22,12 @@ jobs:
|
||||
run: |
|
||||
git checkout -b pr
|
||||
git branch -f main origin/main
|
||||
- name: Set up Python 3.8
|
||||
- name: Set up Python 3.10
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: 3.8
|
||||
python-version: '3.10'
|
||||
- name: Install wpiformat
|
||||
run: pip3 install wpiformat==2024.32
|
||||
run: pip3 install wpiformat==2024.33
|
||||
- name: Run
|
||||
run: wpiformat
|
||||
- name: Check output
|
||||
@@ -61,10 +61,10 @@ jobs:
|
||||
git config --global --add safe.directory /__w/allwpilib/allwpilib
|
||||
git checkout -b pr
|
||||
git branch -f main origin/main
|
||||
- name: Set up Python 3.8
|
||||
- name: Set up Python 3.10
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: 3.8
|
||||
python-version: '3.10'
|
||||
- name: Install wpiformat
|
||||
run: pip3 install wpiformat
|
||||
- name: Create compile_commands.json
|
||||
|
||||
@@ -366,6 +366,8 @@ public final class CameraServer {
|
||||
}
|
||||
case kCv:
|
||||
return "cv:";
|
||||
case kRaw:
|
||||
return "raw:";
|
||||
default:
|
||||
return "unknown:";
|
||||
}
|
||||
|
||||
@@ -113,6 +113,8 @@ static std::string_view MakeSourceValue(CS_Source source,
|
||||
}
|
||||
case CS_SOURCE_CV:
|
||||
return "cv:";
|
||||
case CS_SOURCE_RAW:
|
||||
return "raw:";
|
||||
default:
|
||||
return "unknown:";
|
||||
}
|
||||
|
||||
@@ -190,12 +190,12 @@ struct RelayHandle {
|
||||
HAL_RelayHandle handle = 0;
|
||||
};
|
||||
|
||||
#define ASSERT_LAST_ERROR_STATUS(status, x) \
|
||||
do { \
|
||||
ASSERT_EQ(status, HAL_USE_LAST_ERROR); \
|
||||
[[maybe_unused]] const char* lastErrorMessageInMacro = \
|
||||
HAL_GetLastError(&status); \
|
||||
ASSERT_EQ(status, x); \
|
||||
#define ASSERT_LAST_ERROR_STATUS(status, x) \
|
||||
do { \
|
||||
ASSERT_EQ(status, HAL_USE_LAST_ERROR); \
|
||||
[[maybe_unused]] \
|
||||
const char* lastErrorMessageInMacro = HAL_GetLastError(&status); \
|
||||
ASSERT_EQ(status, x); \
|
||||
} while (0)
|
||||
|
||||
} // namespace hlt
|
||||
|
||||
@@ -212,6 +212,7 @@ public class CameraServerJNI {
|
||||
* Creates a raw source.
|
||||
*
|
||||
* @param name Source name.
|
||||
* @param isCv true for a Cv source.
|
||||
* @param pixelFormat Pixel format.
|
||||
* @param width Image width.
|
||||
* @param height Image height.
|
||||
@@ -219,7 +220,7 @@ public class CameraServerJNI {
|
||||
* @return Raw source handle.
|
||||
*/
|
||||
public static native int createRawSource(
|
||||
String name, int pixelFormat, int width, int height, int fps);
|
||||
String name, boolean isCv, int pixelFormat, int width, int height, int fps);
|
||||
|
||||
//
|
||||
// Source Functions
|
||||
@@ -630,9 +631,10 @@ public class CameraServerJNI {
|
||||
* Creates a raw sink.
|
||||
*
|
||||
* @param name Sink name.
|
||||
* @param isCv true for a Cv source.
|
||||
* @return Raw sink handle.
|
||||
*/
|
||||
public static native int createRawSink(String name);
|
||||
public static native int createRawSink(String name, boolean isCv);
|
||||
|
||||
//
|
||||
// Sink Functions
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
package edu.wpi.first.cscore;
|
||||
|
||||
import edu.wpi.first.util.PixelFormat;
|
||||
import edu.wpi.first.util.RawFrame;
|
||||
import java.nio.ByteBuffer;
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.core.Mat;
|
||||
|
||||
/**
|
||||
@@ -12,15 +15,57 @@ import org.opencv.core.Mat;
|
||||
* OpenCV builds. For an alternate OpenCV, see the documentation how to build your own with RawSink.
|
||||
*/
|
||||
public class CvSink extends ImageSink {
|
||||
private final RawFrame m_frame = new RawFrame();
|
||||
private Mat m_tmpMat;
|
||||
private ByteBuffer m_origByteBuffer;
|
||||
private int m_width;
|
||||
private int m_height;
|
||||
private PixelFormat m_pixelFormat;
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if (m_tmpMat != null) {
|
||||
m_tmpMat.release();
|
||||
}
|
||||
m_frame.close();
|
||||
super.close();
|
||||
}
|
||||
|
||||
private int getCVFormat(PixelFormat pixelFormat) {
|
||||
int type = 0;
|
||||
switch (pixelFormat) {
|
||||
case kYUYV:
|
||||
case kRGB565:
|
||||
case kY16:
|
||||
case kUYVY:
|
||||
type = CvType.CV_8UC2;
|
||||
break;
|
||||
case kBGR:
|
||||
type = CvType.CV_8UC3;
|
||||
break;
|
||||
case kBGRA:
|
||||
type = CvType.CV_8UC4;
|
||||
break;
|
||||
case kGray:
|
||||
case kMJPEG:
|
||||
default:
|
||||
type = CvType.CV_8UC1;
|
||||
break;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a sink for accepting OpenCV images. WaitForFrame() must be called on the created sink to
|
||||
* Create a sink for accepting OpenCV images. grabFrame() must be called on the created sink to
|
||||
* get each new image.
|
||||
*
|
||||
* @param name Source name (arbitrary unique identifier)
|
||||
* @param pixelFormat Source pixel format
|
||||
*/
|
||||
public CvSink(String name, PixelFormat pixelFormat) {
|
||||
super(CameraServerCvJNI.createCvSink(name, pixelFormat.getValue()));
|
||||
super(CameraServerJNI.createRawSink(name, true));
|
||||
m_pixelFormat = pixelFormat;
|
||||
OpenCvLoader.forceStaticLoad();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,22 +78,9 @@ public class CvSink extends ImageSink {
|
||||
this(name, PixelFormat.kBGR);
|
||||
}
|
||||
|
||||
/// Create a sink for accepting OpenCV images in a separate thread.
|
||||
/// A thread will be created that calls WaitForFrame() and calls the
|
||||
/// processFrame() callback each time a new frame arrives.
|
||||
/// @param name Source name (arbitrary unique identifier)
|
||||
/// @param processFrame Frame processing function; will be called with a
|
||||
/// time=0 if an error occurred. processFrame should call GetImage()
|
||||
/// or GetError() as needed, but should not call (except in very
|
||||
/// unusual circumstances) WaitForImage().
|
||||
// public CvSink(wpi::StringRef name,
|
||||
// std::function<void(uint64_t time)> processFrame) {
|
||||
// super(CameraServerJNI.createCvSinkCallback(name, processFrame));
|
||||
// }
|
||||
|
||||
/**
|
||||
* Wait for the next frame and get the image. Times out (returning 0) after 0.225 seconds. The
|
||||
* provided image will have three 3-bit channels stored in BGR order.
|
||||
* provided image will have the pixelFormat this class was constructed with.
|
||||
*
|
||||
* @param image Where to store the image.
|
||||
* @return Frame time, or 0 on error (call GetError() to obtain the error message)
|
||||
@@ -59,7 +91,7 @@ public class CvSink extends ImageSink {
|
||||
|
||||
/**
|
||||
* Wait for the next frame and get the image. Times out (returning 0) after timeout seconds. The
|
||||
* provided image will have three 3-bit channels stored in BGR order.
|
||||
* provided image will have the pixelFormat this class was constructed with.
|
||||
*
|
||||
* @param image Where to store the image.
|
||||
* @param timeout Retrieval timeout in seconds.
|
||||
@@ -67,18 +99,140 @@ public class CvSink extends ImageSink {
|
||||
* is in 1 us increments.
|
||||
*/
|
||||
public long grabFrame(Mat image, double timeout) {
|
||||
return CameraServerCvJNI.grabSinkFrameTimeout(m_handle, image.nativeObj, timeout);
|
||||
long rv = grabFrameDirect(timeout);
|
||||
if (rv <= 0) {
|
||||
return rv;
|
||||
}
|
||||
m_tmpMat.copyTo(image);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for the next frame and get the image. May block forever. The provided image will have
|
||||
* three 3-bit channels stored in BGR order.
|
||||
* Wait for the next frame and get the image. May block forever. The provided image will have the
|
||||
* pixelFormat this class was constructed with.
|
||||
*
|
||||
* @param image Where to store the image.
|
||||
* @return Frame time, or 0 on error (call GetError() to obtain the error message); the frame time
|
||||
* is in 1 us increments.
|
||||
*/
|
||||
public long grabFrameNoTimeout(Mat image) {
|
||||
return CameraServerCvJNI.grabSinkFrame(m_handle, image.nativeObj);
|
||||
long rv = grabFrameNoTimeoutDirect();
|
||||
if (rv <= 0) {
|
||||
return rv;
|
||||
}
|
||||
m_tmpMat.copyTo(image);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the direct backing mat for this sink.
|
||||
*
|
||||
* <p>This mat can be invalidated any time any of the grab* methods are called, or when the CvSink
|
||||
* is closed.
|
||||
*
|
||||
* @return The backing mat.
|
||||
*/
|
||||
public Mat getDirectMat() {
|
||||
return m_tmpMat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for the next frame and store the image. Times out (returning 0) after 0.225 seconds. The
|
||||
* provided image will have the pixelFormat this class was constructed with. Use getDirectMat() to
|
||||
* grab the image.
|
||||
*
|
||||
* @return Frame time, or 0 on error (call GetError() to obtain the error message)
|
||||
*/
|
||||
public long grabFrameDirect() {
|
||||
return grabFrameDirect(0.225);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for the next frame and store the image. Times out (returning 0) after timeout seconds. The
|
||||
* provided image will have the pixelFormat this class was constructed with. Use getDirectMat() to
|
||||
* grab the image.
|
||||
*
|
||||
* @param timeout Retrieval timeout in seconds.
|
||||
* @return Frame time, or 0 on error (call GetError() to obtain the error message); the frame time
|
||||
* is in 1 us increments.
|
||||
*/
|
||||
@SuppressWarnings("PMD.CompareObjectsWithEquals")
|
||||
public long grabFrameDirect(double timeout) {
|
||||
m_frame.setInfo(0, 0, 0, m_pixelFormat);
|
||||
long rv =
|
||||
CameraServerJNI.grabRawSinkFrameTimeout(m_handle, m_frame, m_frame.getNativeObj(), timeout);
|
||||
if (rv <= 0) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (m_frame.getData() != m_origByteBuffer
|
||||
|| m_width != m_frame.getWidth()
|
||||
|| m_height != m_frame.getHeight()
|
||||
|| m_pixelFormat != m_frame.getPixelFormat()) {
|
||||
m_origByteBuffer = m_frame.getData();
|
||||
m_height = m_frame.getHeight();
|
||||
m_width = m_frame.getWidth();
|
||||
m_pixelFormat = m_frame.getPixelFormat();
|
||||
if (m_frame.getStride() == 0) {
|
||||
m_tmpMat =
|
||||
new Mat(
|
||||
m_frame.getHeight(),
|
||||
m_frame.getWidth(),
|
||||
getCVFormat(m_pixelFormat),
|
||||
m_origByteBuffer);
|
||||
} else {
|
||||
m_tmpMat =
|
||||
new Mat(
|
||||
m_frame.getHeight(),
|
||||
m_frame.getWidth(),
|
||||
getCVFormat(m_pixelFormat),
|
||||
m_origByteBuffer,
|
||||
m_frame.getStride());
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for the next frame and store the image. May block forever. The provided image will have
|
||||
* the pixelFormat this class was constructed with. Use getDirectMat() to grab the image.
|
||||
*
|
||||
* @return Frame time, or 0 on error (call GetError() to obtain the error message); the frame time
|
||||
* is in 1 us increments.
|
||||
*/
|
||||
@SuppressWarnings("PMD.CompareObjectsWithEquals")
|
||||
public long grabFrameNoTimeoutDirect() {
|
||||
m_frame.setInfo(0, 0, 0, m_pixelFormat);
|
||||
long rv = CameraServerJNI.grabRawSinkFrame(m_handle, m_frame, m_frame.getNativeObj());
|
||||
if (rv <= 0) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (m_frame.getData() != m_origByteBuffer
|
||||
|| m_width != m_frame.getWidth()
|
||||
|| m_height != m_frame.getHeight()
|
||||
|| m_pixelFormat != m_frame.getPixelFormat()) {
|
||||
m_origByteBuffer = m_frame.getData();
|
||||
m_height = m_frame.getHeight();
|
||||
m_width = m_frame.getWidth();
|
||||
m_pixelFormat = m_frame.getPixelFormat();
|
||||
if (m_frame.getStride() == 0) {
|
||||
m_tmpMat =
|
||||
new Mat(
|
||||
m_frame.getHeight(),
|
||||
m_frame.getWidth(),
|
||||
getCVFormat(m_pixelFormat),
|
||||
m_origByteBuffer);
|
||||
} else {
|
||||
m_tmpMat =
|
||||
new Mat(
|
||||
m_frame.getHeight(),
|
||||
m_frame.getWidth(),
|
||||
getCVFormat(m_pixelFormat),
|
||||
m_origByteBuffer,
|
||||
m_frame.getStride());
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,9 @@ public class CvSource extends ImageSource {
|
||||
*/
|
||||
public CvSource(String name, VideoMode mode) {
|
||||
super(
|
||||
CameraServerCvJNI.createCvSource(
|
||||
name, mode.pixelFormat.getValue(), mode.width, mode.height, mode.fps));
|
||||
CameraServerJNI.createRawSource(
|
||||
name, true, mode.pixelFormat.getValue(), mode.width, mode.height, mode.fps));
|
||||
OpenCvLoader.forceStaticLoad();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,19 +35,147 @@ public class CvSource extends ImageSource {
|
||||
* @param fps fps
|
||||
*/
|
||||
public CvSource(String name, PixelFormat pixelFormat, int width, int height, int fps) {
|
||||
super(CameraServerCvJNI.createCvSource(name, pixelFormat.getValue(), width, height, fps));
|
||||
super(CameraServerJNI.createRawSource(name, true, pixelFormat.getValue(), width, height, fps));
|
||||
OpenCvLoader.forceStaticLoad();
|
||||
}
|
||||
|
||||
/**
|
||||
* Put an OpenCV image and notify sinks
|
||||
*
|
||||
* <p>The image format is guessed from the number of channels. The channel mapping is as follows.
|
||||
* 1: kGray 2: kYUYV 3: BGR 4: BGRA Any other channel numbers will throw an error. If your image
|
||||
* is an in alternate format, use the overload that takes a PixelFormat.
|
||||
*
|
||||
* @param image OpenCV Image
|
||||
*/
|
||||
public void putFrame(Mat image) {
|
||||
// We only support 8 bit channels
|
||||
boolean cleanupRequired = false;
|
||||
Mat finalImage;
|
||||
if (image.depth() == 0) {
|
||||
finalImage = image;
|
||||
} else {
|
||||
finalImage = new Mat();
|
||||
image.convertTo(finalImage, 0);
|
||||
cleanupRequired = true;
|
||||
}
|
||||
|
||||
try {
|
||||
int channels = finalImage.channels();
|
||||
PixelFormat format;
|
||||
if (channels == 1) {
|
||||
// 1 channel is assumed Graysacle
|
||||
format = PixelFormat.kGray;
|
||||
} else if (channels == 2) {
|
||||
// 2 channels is assumed YUYV
|
||||
format = PixelFormat.kYUYV;
|
||||
} else if (channels == 3) {
|
||||
// 3 channels is assumed BGR
|
||||
format = PixelFormat.kBGR;
|
||||
} else if (channels == 4) {
|
||||
// 4 channels is assumed BGRA
|
||||
format = PixelFormat.kBGRA;
|
||||
} else {
|
||||
throw new VideoException("Unable to get pixel format for " + channels + " channels");
|
||||
}
|
||||
|
||||
putFrame(finalImage, format, true);
|
||||
} finally {
|
||||
if (cleanupRequired) {
|
||||
finalImage.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Put an OpenCV image and notify sinks.
|
||||
*
|
||||
* <p>Only 8-bit single-channel or 3-channel (with BGR channel order) images are supported. If the
|
||||
* format, depth or channel order is different, use Mat.convertTo() and/or cvtColor() to convert
|
||||
* it first.
|
||||
* <p>The format of the Mat must match the PixelFormat. You will corrupt memory if they dont. With
|
||||
* skipVerification false, we will verify the number of channels matches the pixel format. If
|
||||
* skipVerification is true, this step is skipped and is passed straight through.
|
||||
*
|
||||
* @param image OpenCV image
|
||||
* @param format The pixel format of the image
|
||||
* @param skipVerification skip verifying pixel format
|
||||
*/
|
||||
public void putFrame(Mat image) {
|
||||
CameraServerCvJNI.putSourceFrame(m_handle, image.nativeObj);
|
||||
public void putFrame(Mat image, PixelFormat format, boolean skipVerification) {
|
||||
// We only support 8-bit images, convert if necessary
|
||||
boolean cleanupRequired = false;
|
||||
Mat finalImage;
|
||||
if (image.depth() == 0) {
|
||||
finalImage = image;
|
||||
} else {
|
||||
finalImage = new Mat();
|
||||
image.convertTo(finalImage, 0);
|
||||
cleanupRequired = true;
|
||||
}
|
||||
|
||||
try {
|
||||
if (!skipVerification) {
|
||||
verifyFormat(finalImage, format);
|
||||
}
|
||||
long step = image.step1() * image.elemSize1();
|
||||
CameraServerJNI.putRawSourceFrameData(
|
||||
m_handle,
|
||||
finalImage.dataAddr(),
|
||||
(int) finalImage.total() * finalImage.channels(),
|
||||
finalImage.width(),
|
||||
finalImage.height(),
|
||||
(int) step,
|
||||
format.getValue());
|
||||
|
||||
} finally {
|
||||
if (cleanupRequired) {
|
||||
finalImage.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void verifyFormat(Mat image, PixelFormat pixelFormat) {
|
||||
int channels = image.channels();
|
||||
switch (pixelFormat) {
|
||||
case kBGR:
|
||||
if (channels == 3) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case kBGRA:
|
||||
if (channels == 4) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case kGray:
|
||||
if (channels == 1) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case kRGB565:
|
||||
if (channels == 2) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case kUYVY:
|
||||
if (channels == 2) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case kY16:
|
||||
if (channels == 2) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case kYUYV:
|
||||
if (channels == 2) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case kMJPEG:
|
||||
if (channels == 1) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,11 +9,13 @@ import java.io.IOException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import org.opencv.core.Core;
|
||||
|
||||
/** CameraServer CV JNI. */
|
||||
public class CameraServerCvJNI {
|
||||
static boolean libraryLoaded = false;
|
||||
/** OpenCV Native Loader. */
|
||||
public final class OpenCvLoader {
|
||||
@SuppressWarnings("PMD.MutableStaticState")
|
||||
static boolean libraryLoaded;
|
||||
|
||||
static RuntimeLoader<Core> loader = null;
|
||||
@SuppressWarnings("PMD.MutableStaticState")
|
||||
static RuntimeLoader<Core> loader;
|
||||
|
||||
/** Sets whether JNI should be loaded in the static block. */
|
||||
public static class Helper {
|
||||
@@ -45,7 +47,6 @@ public class CameraServerCvJNI {
|
||||
String opencvName = Core.NATIVE_LIBRARY_NAME;
|
||||
if (Helper.getExtractOnStaticLoad()) {
|
||||
try {
|
||||
CameraServerJNI.forceLoad();
|
||||
loader =
|
||||
new RuntimeLoader<>(opencvName, RuntimeLoader.getDefaultExtractionRoot(), Core.class);
|
||||
loader.loadLibraryHashed();
|
||||
@@ -57,6 +58,15 @@ public class CameraServerCvJNI {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces a static load.
|
||||
*
|
||||
* @return a garbage value
|
||||
*/
|
||||
public static int forceStaticLoad() {
|
||||
return libraryLoaded ? 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Force load the library.
|
||||
*
|
||||
@@ -66,7 +76,6 @@ public class CameraServerCvJNI {
|
||||
if (libraryLoaded) {
|
||||
return;
|
||||
}
|
||||
CameraServerJNI.forceLoad();
|
||||
loader =
|
||||
new RuntimeLoader<>(
|
||||
Core.NATIVE_LIBRARY_NAME, RuntimeLoader.getDefaultExtractionRoot(), Core.class);
|
||||
@@ -74,64 +83,6 @@ public class CameraServerCvJNI {
|
||||
libraryLoaded = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a CV source.
|
||||
*
|
||||
* @param name Name.
|
||||
* @param pixelFormat OpenCV pixel format.
|
||||
* @param width Image width.
|
||||
* @param height Image height.
|
||||
* @param fps Frames per second.
|
||||
* @return CV source.
|
||||
*/
|
||||
public static native int createCvSource(
|
||||
String name, int pixelFormat, int width, int height, int fps);
|
||||
|
||||
/**
|
||||
* Put source frame.
|
||||
*
|
||||
* @param source Source handle.
|
||||
* @param imageNativeObj Image native object handle.
|
||||
*/
|
||||
public static native void putSourceFrame(int source, long imageNativeObj);
|
||||
|
||||
/**
|
||||
* Creates a CV sink.
|
||||
*
|
||||
* @param name Name.
|
||||
* @param pixelFormat OpenCV pixel format.
|
||||
* @return CV sink handle.
|
||||
*/
|
||||
public static native int createCvSink(String name, int pixelFormat);
|
||||
|
||||
// /**
|
||||
// * Creates a CV sink callback.
|
||||
// *
|
||||
// * @param name Name.
|
||||
// * @param processFrame Process frame callback.
|
||||
// */
|
||||
// public static native int createCvSinkCallback(String name,
|
||||
// void (*processFrame)(long time));
|
||||
|
||||
/**
|
||||
* Returns sink frame handle.
|
||||
*
|
||||
* @param sink Sink handle.
|
||||
* @param imageNativeObj Image native object handle.
|
||||
* @return Sink frame handle.
|
||||
*/
|
||||
public static native long grabSinkFrame(int sink, long imageNativeObj);
|
||||
|
||||
/**
|
||||
* Returns sink frame timeout in microseconds.
|
||||
*
|
||||
* @param sink Sink handle.
|
||||
* @param imageNativeObj Image native object handle.
|
||||
* @param timeout Timeout in seconds.
|
||||
* @return Sink frame timeout in microseconds.
|
||||
*/
|
||||
public static native long grabSinkFrameTimeout(int sink, long imageNativeObj, double timeout);
|
||||
|
||||
/** Utility class. */
|
||||
private CameraServerCvJNI() {}
|
||||
private OpenCvLoader() {}
|
||||
}
|
||||
@@ -48,6 +48,8 @@ public class VideoSink implements AutoCloseable {
|
||||
return Kind.kMjpeg;
|
||||
case 4:
|
||||
return Kind.kCv;
|
||||
case 8:
|
||||
return Kind.kRaw;
|
||||
default:
|
||||
return Kind.kUnknown;
|
||||
}
|
||||
|
||||
@@ -86,6 +86,8 @@ public class VideoSource implements AutoCloseable {
|
||||
return Kind.kHttp;
|
||||
case 4:
|
||||
return Kind.kCv;
|
||||
case 8:
|
||||
return Kind.kRaw;
|
||||
default:
|
||||
return Kind.kUnknown;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public class RawSink extends ImageSink {
|
||||
* @param name Source name (arbitrary unique identifier)
|
||||
*/
|
||||
public RawSink(String name) {
|
||||
super(CameraServerJNI.createRawSink(name));
|
||||
super(CameraServerJNI.createRawSink(name, false));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,7 +26,7 @@ public class RawSource extends ImageSource {
|
||||
public RawSource(String name, VideoMode mode) {
|
||||
super(
|
||||
CameraServerJNI.createRawSource(
|
||||
name, mode.pixelFormat.getValue(), mode.width, mode.height, mode.fps));
|
||||
name, false, mode.pixelFormat.getValue(), mode.width, mode.height, mode.fps));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,7 +39,7 @@ public class RawSource extends ImageSource {
|
||||
* @param fps fps
|
||||
*/
|
||||
public RawSource(String name, PixelFormat pixelFormat, int width, int height, int fps) {
|
||||
super(CameraServerJNI.createRawSource(name, pixelFormat.getValue(), width, height, fps));
|
||||
super(CameraServerJNI.createRawSource(name, false, pixelFormat.getValue(), width, height, fps));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -104,3 +104,140 @@ void ConfigurableSourceImpl::SetEnumPropertyChoices(
|
||||
prop->name, property, CS_PROP_ENUM,
|
||||
prop->value, {});
|
||||
}
|
||||
|
||||
namespace cs {
|
||||
static constexpr unsigned SourceMask = CS_SOURCE_CV | CS_SOURCE_RAW;
|
||||
|
||||
void NotifySourceError(CS_Source source, std::string_view msg,
|
||||
CS_Status* status) {
|
||||
auto data = Instance::GetInstance().GetSource(source);
|
||||
if (!data || (data->kind & SourceMask) == 0) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return;
|
||||
}
|
||||
static_cast<ConfigurableSourceImpl&>(*data->source).NotifyError(msg);
|
||||
}
|
||||
|
||||
void SetSourceConnected(CS_Source source, bool connected, CS_Status* status) {
|
||||
auto data = Instance::GetInstance().GetSource(source);
|
||||
if (!data || (data->kind & SourceMask) == 0) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return;
|
||||
}
|
||||
static_cast<ConfigurableSourceImpl&>(*data->source).SetConnected(connected);
|
||||
}
|
||||
|
||||
void SetSourceDescription(CS_Source source, std::string_view description,
|
||||
CS_Status* status) {
|
||||
auto data = Instance::GetInstance().GetSource(source);
|
||||
if (!data || (data->kind & SourceMask) == 0) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return;
|
||||
}
|
||||
static_cast<ConfigurableSourceImpl&>(*data->source)
|
||||
.SetDescription(description);
|
||||
}
|
||||
|
||||
CS_Property CreateSourceProperty(CS_Source source, std::string_view name,
|
||||
CS_PropertyKind kind, int minimum, int maximum,
|
||||
int step, int defaultValue, int value,
|
||||
CS_Status* status) {
|
||||
auto data = Instance::GetInstance().GetSource(source);
|
||||
if (!data || (data->kind & SourceMask) == 0) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return -1;
|
||||
}
|
||||
int property = static_cast<ConfigurableSourceImpl&>(*data->source)
|
||||
.CreateProperty(name, kind, minimum, maximum, step,
|
||||
defaultValue, value);
|
||||
return Handle{source, property, Handle::kProperty};
|
||||
}
|
||||
|
||||
CS_Property CreateSourcePropertyCallback(
|
||||
CS_Source source, std::string_view name, CS_PropertyKind kind, int minimum,
|
||||
int maximum, int step, int defaultValue, int value,
|
||||
std::function<void(CS_Property property)> onChange, CS_Status* status) {
|
||||
auto data = Instance::GetInstance().GetSource(source);
|
||||
if (!data || (data->kind & SourceMask) == 0) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return -1;
|
||||
}
|
||||
int property = static_cast<ConfigurableSourceImpl&>(*data->source)
|
||||
.CreateProperty(name, kind, minimum, maximum, step,
|
||||
defaultValue, value, onChange);
|
||||
return Handle{source, property, Handle::kProperty};
|
||||
}
|
||||
|
||||
void SetSourceEnumPropertyChoices(CS_Source source, CS_Property property,
|
||||
std::span<const std::string> choices,
|
||||
CS_Status* status) {
|
||||
auto data = Instance::GetInstance().GetSource(source);
|
||||
if (!data || (data->kind & SourceMask) == 0) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return;
|
||||
}
|
||||
|
||||
// Get property index; also validate the source owns this property
|
||||
Handle handle{property};
|
||||
int i = handle.GetParentIndex();
|
||||
if (i < 0) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return;
|
||||
}
|
||||
auto data2 = Instance::GetInstance().GetSource(Handle{i, Handle::kSource});
|
||||
if (!data2 || data->source.get() != data2->source.get()) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return;
|
||||
}
|
||||
int propertyIndex = handle.GetIndex();
|
||||
static_cast<ConfigurableSourceImpl&>(*data->source)
|
||||
.SetEnumPropertyChoices(propertyIndex, choices, status);
|
||||
}
|
||||
|
||||
} // namespace cs
|
||||
|
||||
extern "C" {
|
||||
void CS_NotifySourceError(CS_Source source, const char* msg,
|
||||
CS_Status* status) {
|
||||
return cs::NotifySourceError(source, msg, status);
|
||||
}
|
||||
|
||||
void CS_SetSourceConnected(CS_Source source, CS_Bool connected,
|
||||
CS_Status* status) {
|
||||
return cs::SetSourceConnected(source, connected, status);
|
||||
}
|
||||
|
||||
void CS_SetSourceDescription(CS_Source source, const char* description,
|
||||
CS_Status* status) {
|
||||
return cs::SetSourceDescription(source, description, status);
|
||||
}
|
||||
|
||||
CS_Property CS_CreateSourceProperty(CS_Source source, const char* name,
|
||||
enum CS_PropertyKind kind, int minimum,
|
||||
int maximum, int step, int defaultValue,
|
||||
int value, CS_Status* status) {
|
||||
return cs::CreateSourceProperty(source, name, kind, minimum, maximum, step,
|
||||
defaultValue, value, status);
|
||||
}
|
||||
|
||||
CS_Property CS_CreateSourcePropertyCallback(
|
||||
CS_Source source, const char* name, enum CS_PropertyKind kind, int minimum,
|
||||
int maximum, int step, int defaultValue, int value, void* data,
|
||||
void (*onChange)(void* data, CS_Property property), CS_Status* status) {
|
||||
return cs::CreateSourcePropertyCallback(
|
||||
source, name, kind, minimum, maximum, step, defaultValue, value,
|
||||
[=](CS_Property property) { onChange(data, property); }, status);
|
||||
}
|
||||
|
||||
void CS_SetSourceEnumPropertyChoices(CS_Source source, CS_Property property,
|
||||
const char** choices, int count,
|
||||
CS_Status* status) {
|
||||
wpi::SmallVector<std::string, 8> vec;
|
||||
vec.reserve(count);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
vec.push_back(choices[i]);
|
||||
}
|
||||
return cs::SetSourceEnumPropertyChoices(source, property, vec, status);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -33,7 +33,7 @@ class ConfigurableSourceImpl : public SourceImpl {
|
||||
void NumSinksChanged() override;
|
||||
void NumSinksEnabledChanged() override;
|
||||
|
||||
// OpenCV-specific functions
|
||||
// Frame based specific functions
|
||||
void NotifyError(std::string_view msg);
|
||||
int CreateProperty(std::string_view name, CS_PropertyKind kind, int minimum,
|
||||
int maximum, int step, int defaultValue, int value);
|
||||
|
||||
@@ -1,270 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "CvSinkImpl.h"
|
||||
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
#include <wpi/SmallString.h>
|
||||
|
||||
#include "Handle.h"
|
||||
#include "Instance.h"
|
||||
#include "Log.h"
|
||||
#include "Notifier.h"
|
||||
#include "c_util.h"
|
||||
#include "cscore_cpp.h"
|
||||
|
||||
using namespace cs;
|
||||
|
||||
CvSinkImpl::CvSinkImpl(std::string_view name, wpi::Logger& logger,
|
||||
Notifier& notifier, Telemetry& telemetry,
|
||||
VideoMode::PixelFormat pixelFormat)
|
||||
: SinkImpl{name, logger, notifier, telemetry}, m_pixelFormat{pixelFormat} {
|
||||
m_active = true;
|
||||
// m_thread = std::thread(&CvSinkImpl::ThreadMain, this);
|
||||
}
|
||||
|
||||
CvSinkImpl::CvSinkImpl(std::string_view name, wpi::Logger& logger,
|
||||
Notifier& notifier, Telemetry& telemetry,
|
||||
VideoMode::PixelFormat pixelFormat,
|
||||
std::function<void(uint64_t time)> processFrame)
|
||||
: SinkImpl{name, logger, notifier, telemetry}, m_pixelFormat{pixelFormat} {}
|
||||
|
||||
CvSinkImpl::~CvSinkImpl() {
|
||||
Stop();
|
||||
}
|
||||
|
||||
void CvSinkImpl::Stop() {
|
||||
m_active = false;
|
||||
|
||||
// wake up any waiters by forcing an empty frame to be sent
|
||||
if (auto source = GetSource()) {
|
||||
source->Wakeup();
|
||||
}
|
||||
|
||||
// join thread
|
||||
if (m_thread.joinable()) {
|
||||
m_thread.join();
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t CvSinkImpl::GrabFrame(cv::Mat& image) {
|
||||
SetEnabled(true);
|
||||
|
||||
auto source = GetSource();
|
||||
if (!source) {
|
||||
// Source disconnected; sleep for one second
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto frame = source->GetNextFrame(); // blocks
|
||||
if (!frame) {
|
||||
// Bad frame; sleep for 20 ms so we don't consume all processor time.
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
||||
return 0; // signal error
|
||||
}
|
||||
|
||||
if (!frame.GetCv(image, m_pixelFormat)) {
|
||||
// Shouldn't happen, but just in case...
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
||||
return 0;
|
||||
}
|
||||
|
||||
return frame.GetTime();
|
||||
}
|
||||
|
||||
uint64_t CvSinkImpl::GrabFrame(cv::Mat& image, double timeout) {
|
||||
SetEnabled(true);
|
||||
|
||||
auto source = GetSource();
|
||||
if (!source) {
|
||||
// Source disconnected; sleep for one second
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto frame = source->GetNextFrame(timeout); // blocks
|
||||
if (!frame) {
|
||||
// Bad frame; sleep for 20 ms so we don't consume all processor time.
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
||||
return 0; // signal error
|
||||
}
|
||||
|
||||
if (!frame.GetCv(image, m_pixelFormat)) {
|
||||
// Shouldn't happen, but just in case...
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
||||
return 0;
|
||||
}
|
||||
|
||||
return frame.GetTime();
|
||||
}
|
||||
|
||||
// Send HTTP response and a stream of JPG-frames
|
||||
void CvSinkImpl::ThreadMain() {
|
||||
Enable();
|
||||
while (m_active) {
|
||||
auto source = GetSource();
|
||||
if (!source) {
|
||||
// Source disconnected; sleep for one second
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
continue;
|
||||
}
|
||||
SDEBUG4("waiting for frame");
|
||||
Frame frame = source->GetNextFrame(); // blocks
|
||||
if (!m_active) {
|
||||
break;
|
||||
}
|
||||
if (!frame) {
|
||||
// Bad frame; sleep for 10 ms so we don't consume all processor time.
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
continue;
|
||||
}
|
||||
// TODO m_processFrame();
|
||||
}
|
||||
Disable();
|
||||
}
|
||||
|
||||
namespace cs {
|
||||
|
||||
CS_Sink CreateCvSink(std::string_view name, VideoMode::PixelFormat pixelFormat,
|
||||
CS_Status* status) {
|
||||
auto& inst = Instance::GetInstance();
|
||||
return inst.CreateSink(
|
||||
CS_SINK_CV, std::make_shared<CvSinkImpl>(name, inst.logger, inst.notifier,
|
||||
inst.telemetry, pixelFormat));
|
||||
}
|
||||
|
||||
CS_Sink CreateCvSinkCallback(std::string_view name,
|
||||
VideoMode::PixelFormat pixelFormat,
|
||||
std::function<void(uint64_t time)> processFrame,
|
||||
CS_Status* status) {
|
||||
auto& inst = Instance::GetInstance();
|
||||
return inst.CreateSink(
|
||||
CS_SINK_CV,
|
||||
std::make_shared<CvSinkImpl>(name, inst.logger, inst.notifier,
|
||||
inst.telemetry, pixelFormat, processFrame));
|
||||
}
|
||||
|
||||
static constexpr unsigned SinkMask = CS_SINK_CV | CS_SINK_RAW;
|
||||
|
||||
void SetSinkDescription(CS_Sink sink, std::string_view description,
|
||||
CS_Status* status) {
|
||||
auto data = Instance::GetInstance().GetSink(sink);
|
||||
if (!data || (data->kind & SinkMask) == 0) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return;
|
||||
}
|
||||
static_cast<CvSinkImpl&>(*data->sink).SetDescription(description);
|
||||
}
|
||||
|
||||
uint64_t GrabSinkFrame(CS_Sink sink, cv::Mat& image, CS_Status* status) {
|
||||
auto data = Instance::GetInstance().GetSink(sink);
|
||||
if (!data || data->kind != CS_SINK_CV) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return 0;
|
||||
}
|
||||
return static_cast<CvSinkImpl&>(*data->sink).GrabFrame(image);
|
||||
}
|
||||
|
||||
uint64_t GrabSinkFrameTimeout(CS_Sink sink, cv::Mat& image, double timeout,
|
||||
CS_Status* status) {
|
||||
auto data = Instance::GetInstance().GetSink(sink);
|
||||
if (!data || data->kind != CS_SINK_CV) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return 0;
|
||||
}
|
||||
return static_cast<CvSinkImpl&>(*data->sink).GrabFrame(image, timeout);
|
||||
}
|
||||
|
||||
std::string GetSinkError(CS_Sink sink, CS_Status* status) {
|
||||
auto data = Instance::GetInstance().GetSink(sink);
|
||||
if (!data || (data->kind & SinkMask) == 0) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return std::string{};
|
||||
}
|
||||
return static_cast<CvSinkImpl&>(*data->sink).GetError();
|
||||
}
|
||||
|
||||
std::string_view GetSinkError(CS_Sink sink, wpi::SmallVectorImpl<char>& buf,
|
||||
CS_Status* status) {
|
||||
auto data = Instance::GetInstance().GetSink(sink);
|
||||
if (!data || (data->kind & SinkMask) == 0) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return {};
|
||||
}
|
||||
return static_cast<CvSinkImpl&>(*data->sink).GetError(buf);
|
||||
}
|
||||
|
||||
void SetSinkEnabled(CS_Sink sink, bool enabled, CS_Status* status) {
|
||||
auto data = Instance::GetInstance().GetSink(sink);
|
||||
if (!data || (data->kind & SinkMask) == 0) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return;
|
||||
}
|
||||
static_cast<CvSinkImpl&>(*data->sink).SetEnabled(enabled);
|
||||
}
|
||||
|
||||
} // namespace cs
|
||||
|
||||
extern "C" {
|
||||
|
||||
CS_Sink CS_CreateCvSink(const char* name, enum WPI_PixelFormat pixelFormat,
|
||||
CS_Status* status) {
|
||||
return cs::CreateCvSink(
|
||||
name, static_cast<VideoMode::PixelFormat>(pixelFormat), status);
|
||||
}
|
||||
|
||||
CS_Sink CS_CreateCvSinkCallback(const char* name,
|
||||
enum WPI_PixelFormat pixelFormat, void* data,
|
||||
void (*processFrame)(void* data, uint64_t time),
|
||||
CS_Status* status) {
|
||||
return cs::CreateCvSinkCallback(
|
||||
name, static_cast<VideoMode::PixelFormat>(pixelFormat),
|
||||
[=](uint64_t time) { processFrame(data, time); }, status);
|
||||
}
|
||||
|
||||
void CS_SetSinkDescription(CS_Sink sink, const char* description,
|
||||
CS_Status* status) {
|
||||
return cs::SetSinkDescription(sink, description, status);
|
||||
}
|
||||
|
||||
#if CV_VERSION_MAJOR < 4
|
||||
uint64_t CS_GrabSinkFrame(CS_Sink sink, struct CvMat* image,
|
||||
CS_Status* status) {
|
||||
auto mat = cv::cvarrToMat(image);
|
||||
return cs::GrabSinkFrame(sink, mat, status);
|
||||
}
|
||||
|
||||
uint64_t CS_GrabSinkFrameTimeout(CS_Sink sink, struct CvMat* image,
|
||||
double timeout, CS_Status* status) {
|
||||
auto mat = cv::cvarrToMat(image);
|
||||
return cs::GrabSinkFrameTimeout(sink, mat, timeout, status);
|
||||
}
|
||||
#endif // CV_VERSION_MAJOR < 4
|
||||
|
||||
uint64_t CS_GrabSinkFrameCpp(CS_Sink sink, cv::Mat* image, CS_Status* status) {
|
||||
return cs::GrabSinkFrame(sink, *image, status);
|
||||
}
|
||||
|
||||
uint64_t CS_GrabSinkFrameTimeoutCpp(CS_Sink sink, cv::Mat* image,
|
||||
double timeout, CS_Status* status) {
|
||||
return cs::GrabSinkFrameTimeout(sink, *image, timeout, status);
|
||||
}
|
||||
|
||||
char* CS_GetSinkError(CS_Sink sink, CS_Status* status) {
|
||||
wpi::SmallString<128> buf;
|
||||
auto str = cs::GetSinkError(sink, buf, status);
|
||||
if (*status != 0) {
|
||||
return nullptr;
|
||||
}
|
||||
return cs::ConvertToC(str);
|
||||
}
|
||||
|
||||
void CS_SetSinkEnabled(CS_Sink sink, CS_Bool enabled, CS_Status* status) {
|
||||
return cs::SetSinkEnabled(sink, enabled, status);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
@@ -1,50 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#ifndef CSCORE_CVSINKIMPL_H_
|
||||
#define CSCORE_CVSINKIMPL_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
#include <string_view>
|
||||
#include <thread>
|
||||
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <wpi/condition_variable.h>
|
||||
|
||||
#include "Frame.h"
|
||||
#include "SinkImpl.h"
|
||||
|
||||
namespace cs {
|
||||
|
||||
class SourceImpl;
|
||||
|
||||
class CvSinkImpl : public SinkImpl {
|
||||
public:
|
||||
CvSinkImpl(std::string_view name, wpi::Logger& logger, Notifier& notifier,
|
||||
Telemetry& telemetry, VideoMode::PixelFormat pixelFormat);
|
||||
CvSinkImpl(std::string_view name, wpi::Logger& logger, Notifier& notifier,
|
||||
Telemetry& telemetry, VideoMode::PixelFormat pixelFormat,
|
||||
std::function<void(uint64_t time)> processFrame);
|
||||
~CvSinkImpl() override;
|
||||
|
||||
void Stop();
|
||||
|
||||
uint64_t GrabFrame(cv::Mat& image);
|
||||
uint64_t GrabFrame(cv::Mat& image, double timeout);
|
||||
|
||||
private:
|
||||
void ThreadMain();
|
||||
|
||||
std::atomic_bool m_active; // set to false to terminate threads
|
||||
std::thread m_thread;
|
||||
std::function<void(uint64_t time)> m_processFrame;
|
||||
VideoMode::PixelFormat m_pixelFormat;
|
||||
};
|
||||
|
||||
} // namespace cs
|
||||
|
||||
#endif // CSCORE_CVSINKIMPL_H_
|
||||
@@ -1,232 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "CvSourceImpl.h"
|
||||
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
#include <wpi/timestamp.h>
|
||||
|
||||
#include "Handle.h"
|
||||
#include "Instance.h"
|
||||
#include "Log.h"
|
||||
#include "Notifier.h"
|
||||
#include "c_util.h"
|
||||
#include "cscore_cpp.h"
|
||||
|
||||
using namespace cs;
|
||||
|
||||
CvSourceImpl::CvSourceImpl(std::string_view name, wpi::Logger& logger,
|
||||
Notifier& notifier, Telemetry& telemetry,
|
||||
const VideoMode& mode)
|
||||
: ConfigurableSourceImpl{name, logger, notifier, telemetry, mode} {}
|
||||
|
||||
CvSourceImpl::~CvSourceImpl() = default;
|
||||
|
||||
void CvSourceImpl::PutFrame(cv::Mat& image) {
|
||||
// We only support 8-bit images; convert if necessary.
|
||||
cv::Mat finalImage;
|
||||
if (image.depth() == CV_8U) {
|
||||
finalImage = image;
|
||||
} else {
|
||||
image.convertTo(finalImage, CV_8U);
|
||||
}
|
||||
|
||||
std::unique_ptr<Image> dest;
|
||||
switch (image.channels()) {
|
||||
case 1:
|
||||
dest =
|
||||
AllocImage(VideoMode::kGray, image.cols, image.rows, image.total());
|
||||
finalImage.copyTo(dest->AsMat());
|
||||
break;
|
||||
case 3:
|
||||
dest = AllocImage(VideoMode::kBGR, image.cols, image.rows,
|
||||
image.total() * 3);
|
||||
finalImage.copyTo(dest->AsMat());
|
||||
break;
|
||||
case 4:
|
||||
dest = AllocImage(VideoMode::kBGR, image.cols, image.rows,
|
||||
image.total() * 3);
|
||||
cv::cvtColor(finalImage, dest->AsMat(), cv::COLOR_BGRA2BGR);
|
||||
break;
|
||||
default:
|
||||
SERROR("PutFrame: {}-channel images not supported", image.channels());
|
||||
return;
|
||||
}
|
||||
SourceImpl::PutFrame(std::move(dest), wpi::Now());
|
||||
}
|
||||
|
||||
namespace cs {
|
||||
|
||||
CS_Source CreateCvSource(std::string_view name, const VideoMode& mode,
|
||||
CS_Status* status) {
|
||||
auto& inst = Instance::GetInstance();
|
||||
return inst.CreateSource(CS_SOURCE_CV, std::make_shared<CvSourceImpl>(
|
||||
name, inst.logger, inst.notifier,
|
||||
inst.telemetry, mode));
|
||||
}
|
||||
|
||||
void PutSourceFrame(CS_Source source, cv::Mat& image, CS_Status* status) {
|
||||
auto data = Instance::GetInstance().GetSource(source);
|
||||
if (!data || data->kind != CS_SOURCE_CV) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return;
|
||||
}
|
||||
static_cast<CvSourceImpl&>(*data->source).PutFrame(image);
|
||||
}
|
||||
|
||||
static constexpr unsigned SourceMask = CS_SINK_CV | CS_SINK_RAW;
|
||||
|
||||
void NotifySourceError(CS_Source source, std::string_view msg,
|
||||
CS_Status* status) {
|
||||
auto data = Instance::GetInstance().GetSource(source);
|
||||
if (!data || (data->kind & SourceMask) == 0) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return;
|
||||
}
|
||||
static_cast<CvSourceImpl&>(*data->source).NotifyError(msg);
|
||||
}
|
||||
|
||||
void SetSourceConnected(CS_Source source, bool connected, CS_Status* status) {
|
||||
auto data = Instance::GetInstance().GetSource(source);
|
||||
if (!data || (data->kind & SourceMask) == 0) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return;
|
||||
}
|
||||
static_cast<CvSourceImpl&>(*data->source).SetConnected(connected);
|
||||
}
|
||||
|
||||
void SetSourceDescription(CS_Source source, std::string_view description,
|
||||
CS_Status* status) {
|
||||
auto data = Instance::GetInstance().GetSource(source);
|
||||
if (!data || (data->kind & SourceMask) == 0) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return;
|
||||
}
|
||||
static_cast<CvSourceImpl&>(*data->source).SetDescription(description);
|
||||
}
|
||||
|
||||
CS_Property CreateSourceProperty(CS_Source source, std::string_view name,
|
||||
CS_PropertyKind kind, int minimum, int maximum,
|
||||
int step, int defaultValue, int value,
|
||||
CS_Status* status) {
|
||||
auto data = Instance::GetInstance().GetSource(source);
|
||||
if (!data || (data->kind & SourceMask) == 0) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return -1;
|
||||
}
|
||||
int property = static_cast<CvSourceImpl&>(*data->source)
|
||||
.CreateProperty(name, kind, minimum, maximum, step,
|
||||
defaultValue, value);
|
||||
return Handle{source, property, Handle::kProperty};
|
||||
}
|
||||
|
||||
CS_Property CreateSourcePropertyCallback(
|
||||
CS_Source source, std::string_view name, CS_PropertyKind kind, int minimum,
|
||||
int maximum, int step, int defaultValue, int value,
|
||||
std::function<void(CS_Property property)> onChange, CS_Status* status) {
|
||||
auto data = Instance::GetInstance().GetSource(source);
|
||||
if (!data || (data->kind & SourceMask) == 0) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return -1;
|
||||
}
|
||||
int property = static_cast<CvSourceImpl&>(*data->source)
|
||||
.CreateProperty(name, kind, minimum, maximum, step,
|
||||
defaultValue, value, onChange);
|
||||
return Handle{source, property, Handle::kProperty};
|
||||
}
|
||||
|
||||
void SetSourceEnumPropertyChoices(CS_Source source, CS_Property property,
|
||||
std::span<const std::string> choices,
|
||||
CS_Status* status) {
|
||||
auto data = Instance::GetInstance().GetSource(source);
|
||||
if (!data || (data->kind & SourceMask) == 0) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return;
|
||||
}
|
||||
|
||||
// Get property index; also validate the source owns this property
|
||||
Handle handle{property};
|
||||
int i = handle.GetParentIndex();
|
||||
if (i < 0) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return;
|
||||
}
|
||||
auto data2 = Instance::GetInstance().GetSource(Handle{i, Handle::kSource});
|
||||
if (!data2 || data->source.get() != data2->source.get()) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return;
|
||||
}
|
||||
int propertyIndex = handle.GetIndex();
|
||||
static_cast<CvSourceImpl&>(*data->source)
|
||||
.SetEnumPropertyChoices(propertyIndex, choices, status);
|
||||
}
|
||||
|
||||
} // namespace cs
|
||||
|
||||
extern "C" {
|
||||
|
||||
CS_Source CS_CreateCvSource(const char* name, const CS_VideoMode* mode,
|
||||
CS_Status* status) {
|
||||
return cs::CreateCvSource(name, static_cast<const cs::VideoMode&>(*mode),
|
||||
status);
|
||||
}
|
||||
|
||||
#if CV_VERSION_MAJOR < 4
|
||||
void CS_PutSourceFrame(CS_Source source, struct CvMat* image,
|
||||
CS_Status* status) {
|
||||
auto mat = cv::cvarrToMat(image);
|
||||
return cs::PutSourceFrame(source, mat, status);
|
||||
}
|
||||
#endif // CV_VERSION_MAJOR < 4
|
||||
|
||||
void CS_PutSourceFrameCpp(CS_Source source, cv::Mat* image, CS_Status* status) {
|
||||
return cs::PutSourceFrame(source, *image, status);
|
||||
}
|
||||
|
||||
void CS_NotifySourceError(CS_Source source, const char* msg,
|
||||
CS_Status* status) {
|
||||
return cs::NotifySourceError(source, msg, status);
|
||||
}
|
||||
|
||||
void CS_SetSourceConnected(CS_Source source, CS_Bool connected,
|
||||
CS_Status* status) {
|
||||
return cs::SetSourceConnected(source, connected, status);
|
||||
}
|
||||
|
||||
void CS_SetSourceDescription(CS_Source source, const char* description,
|
||||
CS_Status* status) {
|
||||
return cs::SetSourceDescription(source, description, status);
|
||||
}
|
||||
|
||||
CS_Property CS_CreateSourceProperty(CS_Source source, const char* name,
|
||||
enum CS_PropertyKind kind, int minimum,
|
||||
int maximum, int step, int defaultValue,
|
||||
int value, CS_Status* status) {
|
||||
return cs::CreateSourceProperty(source, name, kind, minimum, maximum, step,
|
||||
defaultValue, value, status);
|
||||
}
|
||||
|
||||
CS_Property CS_CreateSourcePropertyCallback(
|
||||
CS_Source source, const char* name, enum CS_PropertyKind kind, int minimum,
|
||||
int maximum, int step, int defaultValue, int value, void* data,
|
||||
void (*onChange)(void* data, CS_Property property), CS_Status* status) {
|
||||
return cs::CreateSourcePropertyCallback(
|
||||
source, name, kind, minimum, maximum, step, defaultValue, value,
|
||||
[=](CS_Property property) { onChange(data, property); }, status);
|
||||
}
|
||||
|
||||
void CS_SetSourceEnumPropertyChoices(CS_Source source, CS_Property property,
|
||||
const char** choices, int count,
|
||||
CS_Status* status) {
|
||||
wpi::SmallVector<std::string, 8> vec;
|
||||
vec.reserve(count);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
vec.push_back(choices[i]);
|
||||
}
|
||||
return cs::SetSourceEnumPropertyChoices(source, property, vec, status);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
@@ -1,37 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#ifndef CSCORE_CVSOURCEIMPL_H_
|
||||
#define CSCORE_CVSOURCEIMPL_H_
|
||||
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <opencv2/core/core.hpp>
|
||||
|
||||
#include "ConfigurableSourceImpl.h"
|
||||
#include "SourceImpl.h"
|
||||
|
||||
namespace cs {
|
||||
|
||||
class CvSourceImpl : public ConfigurableSourceImpl {
|
||||
public:
|
||||
CvSourceImpl(std::string_view name, wpi::Logger& logger, Notifier& notifier,
|
||||
Telemetry& telemetry, const VideoMode& mode);
|
||||
~CvSourceImpl() override;
|
||||
|
||||
// OpenCV-specific functions
|
||||
void PutFrame(cv::Mat& image);
|
||||
|
||||
private:
|
||||
std::atomic_bool m_connected{true};
|
||||
};
|
||||
|
||||
} // namespace cs
|
||||
|
||||
#endif // CSCORE_CVSOURCEIMPL_H_
|
||||
@@ -314,6 +314,54 @@ Image* Frame::ConvertImpl(Image* image, VideoMode::PixelFormat pixelFormat,
|
||||
}
|
||||
}
|
||||
break;
|
||||
case VideoMode::kBGRA:
|
||||
// If source is RGB565, YUYV, UYVY, Gray or Y16, need to convert to BGR
|
||||
// first
|
||||
if (cur->pixelFormat == VideoMode::kRGB565) {
|
||||
// Check to see if BGR version already exists...
|
||||
if (Image* newImage =
|
||||
GetExistingImage(cur->width, cur->height, VideoMode::kBGR)) {
|
||||
cur = newImage;
|
||||
} else {
|
||||
cur = ConvertRGB565ToBGR(cur);
|
||||
}
|
||||
} else if (cur->pixelFormat == VideoMode::kYUYV) {
|
||||
// Check to see if BGR version already exists...
|
||||
if (Image* newImage =
|
||||
GetExistingImage(cur->width, cur->height, VideoMode::kBGR)) {
|
||||
cur = newImage;
|
||||
} else {
|
||||
cur = ConvertYUYVToBGR(cur);
|
||||
}
|
||||
} else if (cur->pixelFormat == VideoMode::kUYVY) {
|
||||
// Check to see if BGR version already exists...
|
||||
if (Image* newImage =
|
||||
GetExistingImage(cur->width, cur->height, VideoMode::kBGR)) {
|
||||
cur = newImage;
|
||||
} else {
|
||||
cur = ConvertUYVYToBGR(cur);
|
||||
}
|
||||
} else if (cur->pixelFormat == VideoMode::kGray) {
|
||||
// Check to see if BGR version already exists...
|
||||
if (Image* newImage =
|
||||
GetExistingImage(cur->width, cur->height, VideoMode::kBGR)) {
|
||||
cur = newImage;
|
||||
} else {
|
||||
cur = ConvertGrayToBGR(cur);
|
||||
}
|
||||
} else if (cur->pixelFormat == VideoMode::kY16) {
|
||||
// Check to see if BGR version already exists...
|
||||
if (Image* newImage =
|
||||
GetExistingImage(cur->width, cur->height, VideoMode::kBGR)) {
|
||||
cur = newImage;
|
||||
} else if (Image* newImage = GetExistingImage(cur->width, cur->height,
|
||||
VideoMode::kGray)) {
|
||||
cur = ConvertGrayToBGR(newImage);
|
||||
} else {
|
||||
cur = ConvertGrayToBGR(ConvertY16ToGray(cur));
|
||||
}
|
||||
}
|
||||
return ConvertBGRToBGRA(cur);
|
||||
case VideoMode::kYUYV:
|
||||
case VideoMode::kUYVY:
|
||||
default:
|
||||
@@ -664,6 +712,28 @@ Image* Frame::ConvertY16ToGray(Image* image) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
Image* Frame::ConvertBGRToBGRA(Image* image) {
|
||||
if (!image || image->pixelFormat != VideoMode::kBGR) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Allocate a RGB565 image
|
||||
auto newImage =
|
||||
m_impl->source.AllocImage(VideoMode::kBGRA, image->width, image->height,
|
||||
image->width * image->height * 4);
|
||||
|
||||
// Convert
|
||||
cv::cvtColor(image->AsMat(), newImage->AsMat(), cv::COLOR_BGR2BGRA);
|
||||
|
||||
// Save the result
|
||||
Image* rv = newImage.release();
|
||||
if (m_impl) {
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
m_impl->images.push_back(rv);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
Image* Frame::GetImageImpl(int width, int height,
|
||||
VideoMode::PixelFormat pixelFormat,
|
||||
int requiredJpegQuality, int defaultJpegQuality) {
|
||||
@@ -727,3 +797,16 @@ void Frame::ReleaseFrame() {
|
||||
m_impl->source.ReleaseFrameImpl(std::unique_ptr<Impl>(m_impl));
|
||||
m_impl = nullptr;
|
||||
}
|
||||
|
||||
namespace cs {
|
||||
std::unique_ptr<Image> CreateImageFromBGRA(cs::SourceImpl* source, size_t width,
|
||||
size_t height, size_t stride,
|
||||
const uint8_t* data) {
|
||||
cv::Mat finalImage{static_cast<int>(height), static_cast<int>(width), CV_8UC4,
|
||||
const_cast<uint8_t*>(data), stride};
|
||||
std::unique_ptr<Image> dest = source->AllocImage(
|
||||
VideoMode::PixelFormat::kBGR, width, height, width * height * 3);
|
||||
cv::cvtColor(finalImage, dest->AsMat(), cv::COLOR_BGRA2BGR);
|
||||
return dest;
|
||||
}
|
||||
} // namespace cs
|
||||
|
||||
@@ -22,6 +22,10 @@ namespace cs {
|
||||
|
||||
class SourceImpl;
|
||||
|
||||
std::unique_ptr<Image> CreateImageFromBGRA(cs::SourceImpl* source, size_t width,
|
||||
size_t height, size_t stride,
|
||||
const uint8_t* data);
|
||||
|
||||
class Frame {
|
||||
friend class SourceImpl;
|
||||
|
||||
@@ -206,6 +210,7 @@ class Frame {
|
||||
Image* ConvertGrayToMJPEG(Image* image, int quality);
|
||||
Image* ConvertGrayToY16(Image* image);
|
||||
Image* ConvertY16ToGray(Image* image);
|
||||
Image* ConvertBGRToBGRA(Image* image);
|
||||
|
||||
Image* GetImage(int width, int height, VideoMode::PixelFormat pixelFormat) {
|
||||
if (pixelFormat == VideoMode::kMJPEG) {
|
||||
|
||||
@@ -63,6 +63,9 @@ class Image {
|
||||
case VideoMode::kBGR:
|
||||
type = CV_8UC3;
|
||||
break;
|
||||
case VideoMode::kBGRA:
|
||||
type = CV_8UC4;
|
||||
break;
|
||||
case VideoMode::kGray:
|
||||
case VideoMode::kMJPEG:
|
||||
default:
|
||||
@@ -81,6 +84,8 @@ class Image {
|
||||
return 2 * width;
|
||||
case VideoMode::kBGR:
|
||||
return 3 * width;
|
||||
case VideoMode::kBGRA:
|
||||
return 4 * width;
|
||||
case VideoMode::kGray:
|
||||
return width;
|
||||
case VideoMode::kMJPEG:
|
||||
|
||||
@@ -438,9 +438,7 @@ void MjpegServerImpl::ConnThread::SendHTML(wpi::raw_ostream& os,
|
||||
|
||||
os << "<p>Supported Video Modes:</p>\n";
|
||||
os << "<table cols=\"4\" style=\"border: 1px solid black\">\n";
|
||||
os << "<tr><th>Pixel Format</th>"
|
||||
<< "<th>Width</th>"
|
||||
<< "<th>Height</th>"
|
||||
os << "<tr><th>Pixel Format</th>" << "<th>Width</th>" << "<th>Height</th>"
|
||||
<< "<th>FPS</th></tr>";
|
||||
for (auto mode : source.EnumerateVideoModes(&status)) {
|
||||
os << "<tr><td>";
|
||||
@@ -457,6 +455,9 @@ void MjpegServerImpl::ConnThread::SendHTML(wpi::raw_ostream& os,
|
||||
case VideoMode::kBGR:
|
||||
os << "BGR";
|
||||
break;
|
||||
case VideoMode::kBGRA:
|
||||
os << "BGRA";
|
||||
break;
|
||||
case VideoMode::kGray:
|
||||
os << "gray";
|
||||
break;
|
||||
@@ -878,8 +879,7 @@ void MjpegServerImpl::ConnThread::ProcessRequest() {
|
||||
ProcessCommand(os, *source, parameters, true);
|
||||
} else {
|
||||
SendHeader(os, 200, "OK", "text/plain");
|
||||
os << "Ignored due to no connected source."
|
||||
<< "\r\n";
|
||||
os << "Ignored due to no connected source." << "\r\n";
|
||||
SDEBUG("Ignored due to no connected source.");
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -143,25 +143,28 @@ void RawSinkImpl::ThreadMain() {
|
||||
}
|
||||
|
||||
namespace cs {
|
||||
CS_Sink CreateRawSink(std::string_view name, CS_Status* status) {
|
||||
static constexpr unsigned SinkMask = CS_SINK_CV | CS_SINK_RAW;
|
||||
|
||||
CS_Sink CreateRawSink(std::string_view name, bool isCv, CS_Status* status) {
|
||||
auto& inst = Instance::GetInstance();
|
||||
return inst.CreateSink(CS_SINK_RAW,
|
||||
return inst.CreateSink(isCv ? CS_SINK_CV : CS_SINK_RAW,
|
||||
std::make_shared<RawSinkImpl>(
|
||||
name, inst.logger, inst.notifier, inst.telemetry));
|
||||
}
|
||||
|
||||
CS_Sink CreateRawSinkCallback(std::string_view name,
|
||||
CS_Sink CreateRawSinkCallback(std::string_view name, bool isCv,
|
||||
std::function<void(uint64_t time)> processFrame,
|
||||
CS_Status* status) {
|
||||
auto& inst = Instance::GetInstance();
|
||||
return inst.CreateSink(CS_SINK_RAW, std::make_shared<RawSinkImpl>(
|
||||
name, inst.logger, inst.notifier,
|
||||
inst.telemetry, processFrame));
|
||||
return inst.CreateSink(
|
||||
isCv ? CS_SINK_CV : CS_SINK_RAW,
|
||||
std::make_shared<RawSinkImpl>(name, inst.logger, inst.notifier,
|
||||
inst.telemetry, processFrame));
|
||||
}
|
||||
|
||||
uint64_t GrabSinkFrame(CS_Sink sink, WPI_RawFrame& image, CS_Status* status) {
|
||||
auto data = Instance::GetInstance().GetSink(sink);
|
||||
if (!data || data->kind != CS_SINK_RAW) {
|
||||
if (!data || (data->kind & SinkMask) == 0) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return 0;
|
||||
}
|
||||
@@ -171,25 +174,26 @@ uint64_t GrabSinkFrame(CS_Sink sink, WPI_RawFrame& image, CS_Status* status) {
|
||||
uint64_t GrabSinkFrameTimeout(CS_Sink sink, WPI_RawFrame& image, double timeout,
|
||||
CS_Status* status) {
|
||||
auto data = Instance::GetInstance().GetSink(sink);
|
||||
if (!data || data->kind != CS_SINK_RAW) {
|
||||
if (!data || (data->kind & SinkMask) == 0) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return 0;
|
||||
}
|
||||
return static_cast<RawSinkImpl&>(*data->sink).GrabFrame(image, timeout);
|
||||
}
|
||||
|
||||
} // namespace cs
|
||||
|
||||
extern "C" {
|
||||
CS_Sink CS_CreateRawSink(const char* name, CS_Status* status) {
|
||||
return cs::CreateRawSink(name, status);
|
||||
CS_Sink CS_CreateRawSink(const char* name, CS_Bool isCv, CS_Status* status) {
|
||||
return cs::CreateRawSink(name, isCv, status);
|
||||
}
|
||||
|
||||
CS_Sink CS_CreateRawSinkCallback(const char* name, void* data,
|
||||
CS_Sink CS_CreateRawSinkCallback(const char* name, CS_Bool isCv, void* data,
|
||||
void (*processFrame)(void* data,
|
||||
uint64_t time),
|
||||
CS_Status* status) {
|
||||
return cs::CreateRawSinkCallback(
|
||||
name, [=](uint64_t time) { processFrame(data, time); }, status);
|
||||
name, isCv, [=](uint64_t time) { processFrame(data, time); }, status);
|
||||
}
|
||||
|
||||
uint64_t CS_GrabRawSinkFrame(CS_Sink sink, struct WPI_RawFrame* image,
|
||||
@@ -201,4 +205,5 @@ uint64_t CS_GrabRawSinkFrameTimeout(CS_Sink sink, struct WPI_RawFrame* image,
|
||||
double timeout, CS_Status* status) {
|
||||
return cs::GrabSinkFrameTimeout(sink, *image, timeout, status);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -22,62 +22,46 @@ RawSourceImpl::RawSourceImpl(std::string_view name, wpi::Logger& logger,
|
||||
RawSourceImpl::~RawSourceImpl() = default;
|
||||
|
||||
void RawSourceImpl::PutFrame(const WPI_RawFrame& image) {
|
||||
int type;
|
||||
switch (image.pixelFormat) {
|
||||
case VideoMode::kYUYV:
|
||||
case VideoMode::kRGB565:
|
||||
case VideoMode::kY16:
|
||||
case VideoMode::kUYVY:
|
||||
type = CV_8UC2;
|
||||
break;
|
||||
case VideoMode::kBGR:
|
||||
type = CV_8UC3;
|
||||
break;
|
||||
case VideoMode::kGray:
|
||||
case VideoMode::kMJPEG:
|
||||
default:
|
||||
type = CV_8UC1;
|
||||
break;
|
||||
}
|
||||
cv::Mat finalImage{image.height, image.width, type, image.data,
|
||||
static_cast<size_t>(image.stride)};
|
||||
std::unique_ptr<Image> dest =
|
||||
AllocImage(static_cast<VideoMode::PixelFormat>(image.pixelFormat),
|
||||
image.width, image.height, image.size);
|
||||
finalImage.copyTo(dest->AsMat());
|
||||
|
||||
SourceImpl::PutFrame(std::move(dest), wpi::Now());
|
||||
auto currentTime = wpi::Now();
|
||||
std::string_view data_view{reinterpret_cast<char*>(image.data), image.size};
|
||||
SourceImpl::PutFrame(static_cast<VideoMode::PixelFormat>(image.pixelFormat),
|
||||
image.width, image.height, data_view, currentTime);
|
||||
}
|
||||
|
||||
namespace cs {
|
||||
CS_Source CreateRawSource(std::string_view name, const VideoMode& mode,
|
||||
CS_Status* status) {
|
||||
static constexpr unsigned SourceMask = CS_SOURCE_CV | CS_SOURCE_RAW;
|
||||
|
||||
CS_Source CreateRawSource(std::string_view name, bool isCv,
|
||||
const VideoMode& mode, CS_Status* status) {
|
||||
auto& inst = Instance::GetInstance();
|
||||
return inst.CreateSource(CS_SOURCE_RAW, std::make_shared<RawSourceImpl>(
|
||||
name, inst.logger, inst.notifier,
|
||||
inst.telemetry, mode));
|
||||
return inst.CreateSource(
|
||||
isCv ? CS_SOURCE_CV : CS_SOURCE_RAW,
|
||||
std::make_shared<RawSourceImpl>(name, inst.logger, inst.notifier,
|
||||
inst.telemetry, mode));
|
||||
}
|
||||
|
||||
void PutSourceFrame(CS_Source source, const WPI_RawFrame& image,
|
||||
CS_Status* status) {
|
||||
auto data = Instance::GetInstance().GetSource(source);
|
||||
if (!data || data->kind != CS_SOURCE_RAW) {
|
||||
if (!data || (data->kind & SourceMask) == 0) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return;
|
||||
}
|
||||
static_cast<RawSourceImpl&>(*data->source).PutFrame(image);
|
||||
}
|
||||
|
||||
} // namespace cs
|
||||
|
||||
extern "C" {
|
||||
CS_Source CS_CreateRawSource(const char* name, const CS_VideoMode* mode,
|
||||
CS_Status* status) {
|
||||
return cs::CreateRawSource(name, static_cast<const cs::VideoMode&>(*mode),
|
||||
status);
|
||||
CS_Source CS_CreateRawSource(const char* name, CS_Bool isCv,
|
||||
const CS_VideoMode* mode, CS_Status* status) {
|
||||
return cs::CreateRawSource(name, isCv,
|
||||
static_cast<const cs::VideoMode&>(*mode), status);
|
||||
}
|
||||
|
||||
void CS_PutRawSourceFrame(CS_Source source, const struct WPI_RawFrame* image,
|
||||
CS_Status* status) {
|
||||
return cs::PutSourceFrame(source, *image, status);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
|
||||
#include "SinkImpl.h"
|
||||
|
||||
#include <wpi/SmallString.h>
|
||||
#include <wpi/json.h>
|
||||
|
||||
#include "Instance.h"
|
||||
#include "Notifier.h"
|
||||
#include "SourceImpl.h"
|
||||
#include "c_util.h"
|
||||
|
||||
using namespace cs;
|
||||
|
||||
@@ -195,3 +197,67 @@ void SinkImpl::UpdatePropertyValue(int property, bool setString, int value,
|
||||
}
|
||||
|
||||
void SinkImpl::SetSourceImpl(std::shared_ptr<SourceImpl> source) {}
|
||||
|
||||
namespace cs {
|
||||
static constexpr unsigned SinkMask = CS_SINK_CV | CS_SINK_RAW;
|
||||
|
||||
void SetSinkDescription(CS_Sink sink, std::string_view description,
|
||||
CS_Status* status) {
|
||||
auto data = Instance::GetInstance().GetSink(sink);
|
||||
if (!data || (data->kind & SinkMask) == 0) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return;
|
||||
}
|
||||
data->sink->SetDescription(description);
|
||||
}
|
||||
|
||||
std::string GetSinkError(CS_Sink sink, CS_Status* status) {
|
||||
auto data = Instance::GetInstance().GetSink(sink);
|
||||
if (!data || (data->kind & SinkMask) == 0) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return std::string{};
|
||||
}
|
||||
return data->sink->GetError();
|
||||
}
|
||||
|
||||
std::string_view GetSinkError(CS_Sink sink, wpi::SmallVectorImpl<char>& buf,
|
||||
CS_Status* status) {
|
||||
auto data = Instance::GetInstance().GetSink(sink);
|
||||
if (!data || (data->kind & SinkMask) == 0) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return {};
|
||||
}
|
||||
return data->sink->GetError(buf);
|
||||
}
|
||||
|
||||
void SetSinkEnabled(CS_Sink sink, bool enabled, CS_Status* status) {
|
||||
auto data = Instance::GetInstance().GetSink(sink);
|
||||
if (!data || (data->kind & SinkMask) == 0) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return;
|
||||
}
|
||||
data->sink->SetEnabled(enabled);
|
||||
}
|
||||
|
||||
} // namespace cs
|
||||
|
||||
extern "C" {
|
||||
void CS_SetSinkDescription(CS_Sink sink, const char* description,
|
||||
CS_Status* status) {
|
||||
return cs::SetSinkDescription(sink, description, status);
|
||||
}
|
||||
|
||||
char* CS_GetSinkError(CS_Sink sink, CS_Status* status) {
|
||||
wpi::SmallString<128> buf;
|
||||
auto str = cs::GetSinkError(sink, buf, status);
|
||||
if (*status != 0) {
|
||||
return nullptr;
|
||||
}
|
||||
return cs::ConvertToC(str);
|
||||
}
|
||||
|
||||
void CS_SetSinkEnabled(CS_Sink sink, CS_Bool enabled, CS_Status* status) {
|
||||
return cs::SetSinkEnabled(sink, enabled, status);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -196,6 +196,8 @@ bool SourceImpl::SetConfigJson(const wpi::json& config, CS_Status* status) {
|
||||
mode.pixelFormat = cs::VideoMode::kRGB565;
|
||||
} else if (wpi::equals_lower(str, "bgr")) {
|
||||
mode.pixelFormat = cs::VideoMode::kBGR;
|
||||
} else if (wpi::equals_lower(str, "bgra")) {
|
||||
mode.pixelFormat = cs::VideoMode::kBGRA;
|
||||
} else if (wpi::equals_lower(str, "gray")) {
|
||||
mode.pixelFormat = cs::VideoMode::kGray;
|
||||
} else if (wpi::equals_lower(str, "y16")) {
|
||||
@@ -361,6 +363,9 @@ wpi::json SourceImpl::GetConfigJsonObject(CS_Status* status) {
|
||||
case VideoMode::kBGR:
|
||||
pixelFormat = "bgr";
|
||||
break;
|
||||
case VideoMode::kBGRA:
|
||||
pixelFormat = "bgra";
|
||||
break;
|
||||
case VideoMode::kGray:
|
||||
pixelFormat = "gray";
|
||||
break;
|
||||
@@ -450,6 +455,15 @@ std::unique_ptr<Image> SourceImpl::AllocImage(
|
||||
|
||||
void SourceImpl::PutFrame(VideoMode::PixelFormat pixelFormat, int width,
|
||||
int height, std::string_view data, Frame::Time time) {
|
||||
if (pixelFormat == VideoMode::PixelFormat::kBGRA) {
|
||||
// Write BGRA as BGR to save a copy
|
||||
auto image =
|
||||
CreateImageFromBGRA(this, width, height, width * 4,
|
||||
reinterpret_cast<const uint8_t*>(data.data()));
|
||||
PutFrame(std::move(image), time);
|
||||
return;
|
||||
}
|
||||
|
||||
auto image = AllocImage(pixelFormat, width, height, data.size());
|
||||
|
||||
// Copy in image data
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <wpi/MemAlloc.h>
|
||||
#include <wpi/SmallString.h>
|
||||
|
||||
|
||||
@@ -6,14 +6,12 @@
|
||||
#include <span>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <opencv2/core/core.hpp>
|
||||
|
||||
#define WPI_RAWFRAME_JNI
|
||||
#include <wpi/RawFrame.h>
|
||||
#include <wpi/SmallString.h>
|
||||
#include <wpi/jni_util.h>
|
||||
|
||||
#include "cscore_cv.h"
|
||||
#include "cscore_raw.h"
|
||||
#include "cscore_runloop.h"
|
||||
#include "edu_wpi_first_cscore_CameraServerJNI.h"
|
||||
@@ -82,32 +80,6 @@ static void ListenerOnExit() {
|
||||
jvm->DetachCurrentThread();
|
||||
}
|
||||
|
||||
/// throw java exception
|
||||
static void ThrowJavaException(JNIEnv* env, const std::exception* e) {
|
||||
wpi::SmallString<128> what;
|
||||
jclass je = nullptr;
|
||||
|
||||
if (e) {
|
||||
const char* exception_type = "std::exception";
|
||||
|
||||
if (dynamic_cast<const cv::Exception*>(e)) {
|
||||
exception_type = "cv::Exception";
|
||||
je = env->FindClass("org/opencv/core/CvException");
|
||||
}
|
||||
|
||||
what = exception_type;
|
||||
what += ": ";
|
||||
what += e->what();
|
||||
} else {
|
||||
what = "unknown exception";
|
||||
}
|
||||
|
||||
if (!je) {
|
||||
je = exceptionEx;
|
||||
}
|
||||
env->ThrowNew(je, what.c_str());
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) {
|
||||
@@ -593,40 +565,15 @@ Java_edu_wpi_first_cscore_CameraServerJNI_createHttpCameraMulti
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_cscore_CameraServerCvJNI
|
||||
* Method: createCvSource
|
||||
* Signature: (Ljava/lang/String;IIII)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_cscore_CameraServerCvJNI_createCvSource
|
||||
(JNIEnv* env, jclass, jstring name, jint pixelFormat, jint width, jint height,
|
||||
jint fps)
|
||||
{
|
||||
if (!name) {
|
||||
nullPointerEx.Throw(env, "name cannot be null");
|
||||
return 0;
|
||||
}
|
||||
CS_Status status = 0;
|
||||
auto val = cs::CreateCvSource(
|
||||
JStringRef{env, name}.str(),
|
||||
cs::VideoMode{static_cast<cs::VideoMode::PixelFormat>(pixelFormat),
|
||||
static_cast<int>(width), static_cast<int>(height),
|
||||
static_cast<int>(fps)},
|
||||
&status);
|
||||
CheckStatus(env, status);
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_cscore_CameraServerJNI
|
||||
* Method: createRawSource
|
||||
* Signature: (Ljava/lang/String;IIII)I
|
||||
* Signature: (Ljava/lang/String;ZIIII)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_cscore_CameraServerJNI_createRawSource
|
||||
(JNIEnv* env, jclass, jstring name, jint pixelFormat, jint width, jint height,
|
||||
jint fps)
|
||||
(JNIEnv* env, jclass, jstring name, jboolean isCv, jint pixelFormat,
|
||||
jint width, jint height, jint fps)
|
||||
{
|
||||
if (!name) {
|
||||
nullPointerEx.Throw(env, "name cannot be null");
|
||||
@@ -634,7 +581,7 @@ Java_edu_wpi_first_cscore_CameraServerJNI_createRawSource
|
||||
}
|
||||
CS_Status status = 0;
|
||||
auto val = cs::CreateRawSource(
|
||||
JStringRef{env, name}.str(),
|
||||
JStringRef{env, name}.str(), isCv,
|
||||
cs::VideoMode{static_cast<cs::VideoMode::PixelFormat>(pixelFormat),
|
||||
static_cast<int>(width), static_cast<int>(height),
|
||||
static_cast<int>(fps)},
|
||||
@@ -1202,27 +1149,6 @@ Java_edu_wpi_first_cscore_CameraServerJNI_getHttpCameraUrls
|
||||
return MakeJStringArray(env, arr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_cscore_CameraServerCvJNI
|
||||
* Method: putSourceFrame
|
||||
* Signature: (IJ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_cscore_CameraServerCvJNI_putSourceFrame
|
||||
(JNIEnv* env, jclass, jint source, jlong imageNativeObj)
|
||||
{
|
||||
try {
|
||||
cv::Mat& image = *((cv::Mat*)imageNativeObj);
|
||||
CS_Status status = 0;
|
||||
cs::PutSourceFrame(source, image, &status);
|
||||
CheckStatus(env, status);
|
||||
} catch (const std::exception& e) {
|
||||
ThrowJavaException(env, &e);
|
||||
} catch (...) {
|
||||
ThrowJavaException(env, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_cscore_CameraServerJNI
|
||||
* Method: putRawSourceFrame
|
||||
@@ -1421,42 +1347,21 @@ Java_edu_wpi_first_cscore_CameraServerJNI_createMjpegServer
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_cscore_CameraServerCvJNI
|
||||
* Method: createCvSink
|
||||
* Signature: (Ljava/lang/String;I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_cscore_CameraServerCvJNI_createCvSink
|
||||
(JNIEnv* env, jclass, jstring name, jint pixelFormat)
|
||||
{
|
||||
if (!name) {
|
||||
nullPointerEx.Throw(env, "name cannot be null");
|
||||
return 0;
|
||||
}
|
||||
CS_Status status = 0;
|
||||
auto val = cs::CreateCvSink(
|
||||
JStringRef{env, name}.str(),
|
||||
static_cast<cs::VideoMode::PixelFormat>(pixelFormat), &status);
|
||||
CheckStatus(env, status);
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_cscore_CameraServerJNI
|
||||
* Method: createRawSink
|
||||
* Signature: (Ljava/lang/String;)I
|
||||
* Signature: (Ljava/lang/String;Z)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_cscore_CameraServerJNI_createRawSink
|
||||
(JNIEnv* env, jclass, jstring name)
|
||||
(JNIEnv* env, jclass, jstring name, jboolean isCv)
|
||||
{
|
||||
if (!name) {
|
||||
nullPointerEx.Throw(env, "name cannot be null");
|
||||
return 0;
|
||||
}
|
||||
CS_Status status = 0;
|
||||
auto val = cs::CreateRawSink(JStringRef{env, name}.str(), &status);
|
||||
auto val = cs::CreateRawSink(JStringRef{env, name}.str(), isCv, &status);
|
||||
CheckStatus(env, status);
|
||||
return val;
|
||||
}
|
||||
@@ -1707,54 +1612,6 @@ Java_edu_wpi_first_cscore_CameraServerJNI_setSinkDescription
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_cscore_CameraServerCvJNI
|
||||
* Method: grabSinkFrame
|
||||
* Signature: (IJ)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_edu_wpi_first_cscore_CameraServerCvJNI_grabSinkFrame
|
||||
(JNIEnv* env, jclass, jint sink, jlong imageNativeObj)
|
||||
{
|
||||
try {
|
||||
cv::Mat& image = *((cv::Mat*)imageNativeObj);
|
||||
CS_Status status = 0;
|
||||
auto rv = cs::GrabSinkFrame(sink, image, &status);
|
||||
CheckStatus(env, status);
|
||||
return rv;
|
||||
} catch (const std::exception& e) {
|
||||
ThrowJavaException(env, &e);
|
||||
return 0;
|
||||
} catch (...) {
|
||||
ThrowJavaException(env, nullptr);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_cscore_CameraServerCvJNI
|
||||
* Method: grabSinkFrameTimeout
|
||||
* Signature: (IJD)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_edu_wpi_first_cscore_CameraServerCvJNI_grabSinkFrameTimeout
|
||||
(JNIEnv* env, jclass, jint sink, jlong imageNativeObj, jdouble timeout)
|
||||
{
|
||||
try {
|
||||
cv::Mat& image = *((cv::Mat*)imageNativeObj);
|
||||
CS_Status status = 0;
|
||||
auto rv = cs::GrabSinkFrameTimeout(sink, image, timeout, &status);
|
||||
CheckStatus(env, status);
|
||||
return rv;
|
||||
} catch (const std::exception& e) {
|
||||
ThrowJavaException(env, &e);
|
||||
return 0;
|
||||
} catch (...) {
|
||||
ThrowJavaException(env, nullptr);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_cscore_CameraServerJNI
|
||||
* Method: grabRawSinkFrame
|
||||
|
||||
@@ -347,7 +347,7 @@ char** CS_GetHttpCameraUrls(CS_Source source, int* count, CS_Status* status);
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @defgroup cscore_opencv_source_cfunc OpenCV Source Functions
|
||||
* @defgroup cscore_frame_source_cfunc Frame Source Functions
|
||||
* @{
|
||||
*/
|
||||
void CS_NotifySourceError(CS_Source source, const char* msg, CS_Status* status);
|
||||
@@ -409,7 +409,7 @@ int CS_GetMjpegServerPort(CS_Sink sink, CS_Status* status);
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @defgroup cscore_opencv_sink_cfunc OpenCV Sink Functions
|
||||
* @defgroup cscore_frame_sink_cfunc Frame Sink Functions
|
||||
* @{
|
||||
*/
|
||||
void CS_SetSinkDescription(CS_Sink sink, const char* description,
|
||||
|
||||
@@ -68,7 +68,8 @@ struct VideoMode : public CS_VideoMode {
|
||||
kBGR = WPI_PIXFMT_BGR,
|
||||
kGray = WPI_PIXFMT_GRAY,
|
||||
kY16 = WPI_PIXFMT_Y16,
|
||||
kUYVY = WPI_PIXFMT_UYVY
|
||||
kUYVY = WPI_PIXFMT_UYVY,
|
||||
kBGRA = WPI_PIXFMT_BGRA,
|
||||
};
|
||||
VideoMode() {
|
||||
pixelFormat = 0;
|
||||
@@ -294,7 +295,7 @@ std::vector<std::string> GetHttpCameraUrls(CS_Source source, CS_Status* status);
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @defgroup cscore_opencv_source_func OpenCV Source Functions
|
||||
* @defgroup cscore_frame_source_func Frame Source Functions
|
||||
* @{
|
||||
*/
|
||||
void NotifySourceError(CS_Source source, std::string_view msg,
|
||||
@@ -365,7 +366,7 @@ int GetMjpegServerPort(CS_Sink sink, CS_Status* status);
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @defgroup cscore_opencv_sink_func OpenCV Sink Functions
|
||||
* @defgroup cscore_frame_sink_func Frame Sink Functions
|
||||
* @{
|
||||
*/
|
||||
void SetSinkDescription(CS_Sink sink, std::string_view description,
|
||||
|
||||
@@ -7,72 +7,17 @@
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "cscore_c.h"
|
||||
|
||||
#ifdef CSCORE_CSCORE_RAW_CV_H_
|
||||
#error "Cannot include both cscore_cv.h and cscore_raw_cv.h in the same file"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include "cscore_oo.h" // NOLINT(build/include_order)
|
||||
|
||||
#endif
|
||||
|
||||
#if CV_VERSION_MAJOR < 4
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" { // NOLINT(build/include_order)
|
||||
#endif
|
||||
|
||||
struct CvMat;
|
||||
|
||||
void CS_PutSourceFrame(CS_Source source, struct CvMat* image,
|
||||
CS_Status* status);
|
||||
|
||||
uint64_t CS_GrabSinkFrame(CS_Sink sink, struct CvMat* image, CS_Status* status);
|
||||
uint64_t CS_GrabSinkFrameTimeout(CS_Sink sink, struct CvMat* image,
|
||||
double timeout, CS_Status* status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // CV_VERSION_MAJOR < 4
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <opencv2/core/mat.hpp>
|
||||
|
||||
#include "cscore_oo.h"
|
||||
|
||||
namespace cv {
|
||||
class Mat;
|
||||
} // namespace cv
|
||||
#include "cscore_raw.h"
|
||||
|
||||
namespace cs {
|
||||
|
||||
/**
|
||||
* @defgroup cscore_cpp_opencv_special cscore C functions taking a cv::Mat*
|
||||
*
|
||||
* These are needed for specific interop implementations.
|
||||
* @{
|
||||
*/
|
||||
extern "C" {
|
||||
uint64_t CS_GrabSinkFrameCpp(CS_Sink sink, cv::Mat* image, CS_Status* status);
|
||||
uint64_t CS_GrabSinkFrameTimeoutCpp(CS_Sink sink, cv::Mat* image,
|
||||
double timeout, CS_Status* status);
|
||||
void CS_PutSourceFrameCpp(CS_Source source, cv::Mat* image, CS_Status* status);
|
||||
} // extern "C"
|
||||
/** @} */
|
||||
|
||||
void PutSourceFrame(CS_Source source, cv::Mat& image, CS_Status* status);
|
||||
uint64_t GrabSinkFrame(CS_Sink sink, cv::Mat& image, CS_Status* status);
|
||||
uint64_t GrabSinkFrameTimeout(CS_Sink sink, cv::Mat& image, double timeout,
|
||||
CS_Status* status);
|
||||
|
||||
/**
|
||||
* A source for user code to provide OpenCV images as video frames.
|
||||
* These sources require the WPILib OpenCV builds.
|
||||
* For an alternate OpenCV, include "cscore_raw_cv.h" instead, and
|
||||
* include your Mat header before that header.
|
||||
*
|
||||
* This is not dependent on any opencv binary ABI, and can be used
|
||||
* with versions of most versions of OpenCV.
|
||||
*/
|
||||
class CvSource : public ImageSource {
|
||||
public:
|
||||
@@ -87,7 +32,7 @@ class CvSource : public ImageSource {
|
||||
CvSource(std::string_view name, const VideoMode& mode);
|
||||
|
||||
/**
|
||||
* Create an OpenCV source.
|
||||
* Create an OpenCV source.
|
||||
*
|
||||
* @param name Source name (arbitrary unique identifier)
|
||||
* @param pixelFormat Pixel format
|
||||
@@ -99,26 +44,48 @@ class CvSource : public ImageSource {
|
||||
int height, int fps);
|
||||
|
||||
/**
|
||||
* Put an OpenCV image and notify sinks.
|
||||
* Put an OpenCV image and notify sinks
|
||||
*
|
||||
* <p>Only 8-bit single-channel or 3-channel (with BGR channel order) images
|
||||
* are supported. If the format, depth or channel order is different, use
|
||||
* cv::Mat::convertTo() and/or cv::cvtColor() to convert it first.
|
||||
* <p>
|
||||
* The image format is guessed from the number of channels. The channel
|
||||
* mapping is as follows. 1: kGray 2: kYUYV 3: BGR 4: BGRA Any other channel
|
||||
* numbers will throw an error. If your image is an in alternate format, use
|
||||
* the overload that takes a PixelFormat.
|
||||
*
|
||||
* @param image OpenCV image
|
||||
* @param image OpenCV Image
|
||||
*/
|
||||
void PutFrame(cv::Mat& image);
|
||||
|
||||
/**
|
||||
* Put an OpenCV image and notify sinks.
|
||||
*
|
||||
* <p>
|
||||
* The format of the Mat must match the PixelFormat. You will corrupt memory
|
||||
* if they dont. With skipVerification false, we will verify the number of
|
||||
* channels matches the pixel format. If skipVerification is true, this step
|
||||
* is skipped and is passed straight through.
|
||||
*
|
||||
* @param image OpenCV image
|
||||
* @param pixelFormat The pixel format of the image
|
||||
* @param skipVerification skip verifying pixel format
|
||||
*/
|
||||
void PutFrame(cv::Mat& image, VideoMode::PixelFormat pixelFormat,
|
||||
bool skipVerification);
|
||||
|
||||
private:
|
||||
static bool VerifyFormat(cv::Mat& image, VideoMode::PixelFormat pixelFormat);
|
||||
};
|
||||
|
||||
/**
|
||||
* A sink for user code to accept video frames as OpenCV images.
|
||||
* These sinks require the WPILib OpenCV builds.
|
||||
* For an alternate OpenCV, include "cscore_raw_cv.h" instead, and
|
||||
* include your Mat header before that header.
|
||||
* A source for user code to accept video frames as OpenCV images.
|
||||
*
|
||||
* This is not dependent on any opencv binary ABI, and can be used
|
||||
* with versions of most versions of OpenCV.
|
||||
*/
|
||||
class CvSink : public ImageSink {
|
||||
public:
|
||||
CvSink() = default;
|
||||
CvSink(const CvSink& sink);
|
||||
|
||||
/**
|
||||
* Create a sink for accepting OpenCV images.
|
||||
@@ -127,89 +94,277 @@ class CvSink : public ImageSink {
|
||||
* image.
|
||||
*
|
||||
* @param name Source name (arbitrary unique identifier)
|
||||
* @param pixelFormat Source pixel format
|
||||
* @param pixelFormat The pixel format to read
|
||||
*/
|
||||
explicit CvSink(std::string_view name, VideoMode::PixelFormat pixelFormat =
|
||||
VideoMode::PixelFormat::kBGR);
|
||||
|
||||
/**
|
||||
* Create a sink for accepting OpenCV images in a separate thread.
|
||||
* Wait for the next frame and get the image.
|
||||
* Times out (returning 0) after timeout seconds.
|
||||
* The provided image will have the pixelFormat this class was constructed
|
||||
* with.
|
||||
*
|
||||
* <p>A thread will be created that calls WaitForFrame() and calls the
|
||||
* processFrame() callback each time a new frame arrives.
|
||||
*
|
||||
* @param name Source name (arbitrary unique identifier)
|
||||
* @param processFrame Frame processing function; will be called with a
|
||||
* time=0 if an error occurred. processFrame should call GetImage()
|
||||
* or GetError() as needed, but should not call (except in very
|
||||
* unusual circumstances) WaitForImage().
|
||||
* @param pixelFormat Source pixel format
|
||||
* @return Frame time, or 0 on error (call GetError() to obtain the error
|
||||
* message); the frame time is in the same time base as wpi::Now(),
|
||||
* and is in 1 us increments.
|
||||
*/
|
||||
CvSink(std::string_view name, std::function<void(uint64_t time)> processFrame,
|
||||
VideoMode::PixelFormat pixelFormat = VideoMode::PixelFormat::kBGR);
|
||||
[[nodiscard]]
|
||||
uint64_t GrabFrame(cv::Mat& image, double timeout = 0.225);
|
||||
|
||||
/**
|
||||
* Wait for the next frame and get the image. May block forever.
|
||||
* The provided image will have the pixelFormat this class was constructed
|
||||
* with.
|
||||
*
|
||||
* @return Frame time, or 0 on error (call GetError() to obtain the error
|
||||
* message); the frame time is in the same time base as wpi::Now(),
|
||||
* and is in 1 us increments.
|
||||
*/
|
||||
[[nodiscard]]
|
||||
uint64_t GrabFrameNoTimeout(cv::Mat& image);
|
||||
|
||||
/**
|
||||
* Wait for the next frame and get the image.
|
||||
* Times out (returning 0) after timeout seconds.
|
||||
* The provided image will have three 8-bit channels stored in BGR order.
|
||||
* The provided image will have the pixelFormat this class was constructed
|
||||
* with. The data is backed by data in the CvSink. It will be invalidated by
|
||||
* any grabFrame*() call on the sink.
|
||||
*
|
||||
* @return Frame time, or 0 on error (call GetError() to obtain the error
|
||||
* message); the frame time is in the same time base as wpi::Now(),
|
||||
* and is in 1 us increments.
|
||||
*/
|
||||
[[nodiscard]]
|
||||
uint64_t GrabFrame(cv::Mat& image, double timeout = 0.225) const;
|
||||
uint64_t GrabFrameDirect(cv::Mat& image, double timeout = 0.225);
|
||||
|
||||
/**
|
||||
* Wait for the next frame and get the image. May block forever.
|
||||
* The provided image will have three 8-bit channels stored in BGR order.
|
||||
* The provided image will have the pixelFormat this class was constructed
|
||||
* with. The data is backed by data in the CvSink. It will be invalidated by
|
||||
* any grabFrame*() call on the sink.
|
||||
*
|
||||
* @return Frame time, or 0 on error (call GetError() to obtain the error
|
||||
* message); the frame time is in the same time base as wpi::Now(),
|
||||
* and is in 1 us increments.
|
||||
*/
|
||||
[[nodiscard]]
|
||||
uint64_t GrabFrameNoTimeout(cv::Mat& image) const;
|
||||
uint64_t GrabFrameNoTimeoutDirect(cv::Mat& image);
|
||||
|
||||
private:
|
||||
constexpr int GetCvFormat(WPI_PixelFormat pixelFormat);
|
||||
|
||||
wpi::RawFrame rawFrame;
|
||||
VideoMode::PixelFormat pixelFormat;
|
||||
};
|
||||
|
||||
inline CvSource::CvSource(std::string_view name, const VideoMode& mode) {
|
||||
m_handle = CreateCvSource(name, mode, &m_status);
|
||||
m_handle = CreateRawSource(name, true, mode, &m_status);
|
||||
}
|
||||
|
||||
inline CvSource::CvSource(std::string_view name, VideoMode::PixelFormat format,
|
||||
int width, int height, int fps) {
|
||||
m_handle =
|
||||
CreateCvSource(name, VideoMode{format, width, height, fps}, &m_status);
|
||||
m_handle = CreateRawSource(name, true, VideoMode{format, width, height, fps},
|
||||
&m_status);
|
||||
}
|
||||
|
||||
inline bool CvSource::VerifyFormat(cv::Mat& image,
|
||||
VideoMode::PixelFormat pixelFormat) {
|
||||
int channels = image.channels();
|
||||
switch (pixelFormat) {
|
||||
case VideoMode::PixelFormat::kBGR:
|
||||
if (channels == 3) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case VideoMode::PixelFormat::kBGRA:
|
||||
if (channels == 4) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case VideoMode::PixelFormat::kGray:
|
||||
if (channels == 1) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case VideoMode::PixelFormat::kRGB565:
|
||||
if (channels == 2) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case VideoMode::PixelFormat::kUYVY:
|
||||
if (channels == 2) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case VideoMode::PixelFormat::kY16:
|
||||
if (channels == 2) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case VideoMode::PixelFormat::kYUYV:
|
||||
if (channels == 2) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case VideoMode::PixelFormat::kMJPEG:
|
||||
if (channels == 1) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
inline void CvSource::PutFrame(cv::Mat& image) {
|
||||
// We only support 8-bit images; convert if necessary.
|
||||
cv::Mat finalImage;
|
||||
if (image.depth() == CV_8U) {
|
||||
finalImage = image;
|
||||
} else {
|
||||
image.convertTo(finalImage, CV_8U);
|
||||
}
|
||||
|
||||
int channels = finalImage.channels();
|
||||
VideoMode::PixelFormat format;
|
||||
if (channels == 1) {
|
||||
// 1 channel is assumed Graysacle
|
||||
format = VideoMode::PixelFormat::kGray;
|
||||
} else if (channels == 2) {
|
||||
// 2 channels is assumed YUYV
|
||||
format = VideoMode::PixelFormat::kYUYV;
|
||||
} else if (channels == 3) {
|
||||
// 3 channels is assumed BGR
|
||||
format = VideoMode::PixelFormat::kBGR;
|
||||
} else if (channels == 4) {
|
||||
// 4 channels is assumed BGRA
|
||||
format = VideoMode::PixelFormat::kBGRA;
|
||||
} else {
|
||||
// TODO Error
|
||||
return;
|
||||
}
|
||||
|
||||
PutFrame(finalImage, format, true);
|
||||
}
|
||||
|
||||
inline void CvSource::PutFrame(cv::Mat& image,
|
||||
VideoMode::PixelFormat pixelFormat,
|
||||
bool skipVerification) {
|
||||
// We only support 8-bit images; convert if necessary.
|
||||
cv::Mat finalImage;
|
||||
if (image.depth() == CV_8U) {
|
||||
finalImage = image;
|
||||
} else {
|
||||
image.convertTo(finalImage, CV_8U);
|
||||
}
|
||||
|
||||
if (!skipVerification) {
|
||||
if (!VerifyFormat(finalImage, pixelFormat)) {
|
||||
// TODO Error
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
WPI_RawFrame frame; // use WPI_Frame because we don't want the destructor
|
||||
frame.data = finalImage.data;
|
||||
frame.freeFunc = nullptr;
|
||||
frame.freeCbData = nullptr;
|
||||
frame.size = finalImage.total() * finalImage.channels();
|
||||
frame.width = finalImage.cols;
|
||||
frame.height = finalImage.rows;
|
||||
frame.stride = finalImage.step;
|
||||
frame.pixelFormat = pixelFormat;
|
||||
m_status = 0;
|
||||
PutSourceFrame(m_handle, image, &m_status);
|
||||
PutSourceFrame(m_handle, frame, &m_status);
|
||||
}
|
||||
|
||||
inline CvSink::CvSink(std::string_view name,
|
||||
VideoMode::PixelFormat pixelFormat) {
|
||||
m_handle = CreateCvSink(name, pixelFormat, &m_status);
|
||||
m_handle = CreateRawSink(name, true, &m_status);
|
||||
this->pixelFormat = pixelFormat;
|
||||
}
|
||||
|
||||
inline CvSink::CvSink(std::string_view name,
|
||||
std::function<void(uint64_t time)> processFrame,
|
||||
VideoMode::PixelFormat pixelFormat) {
|
||||
m_handle = CreateCvSinkCallback(name, pixelFormat, processFrame, &m_status);
|
||||
inline CvSink::CvSink(const CvSink& sink)
|
||||
: ImageSink{sink}, pixelFormat{sink.pixelFormat} {}
|
||||
|
||||
inline uint64_t CvSink::GrabFrame(cv::Mat& image, double timeout) {
|
||||
cv::Mat tmpnam;
|
||||
auto retVal = GrabFrameDirect(tmpnam);
|
||||
if (retVal <= 0) {
|
||||
return retVal;
|
||||
}
|
||||
tmpnam.copyTo(image);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
inline uint64_t CvSink::GrabFrame(cv::Mat& image, double timeout) const {
|
||||
m_status = 0;
|
||||
return GrabSinkFrameTimeout(m_handle, image, timeout, &m_status);
|
||||
inline uint64_t CvSink::GrabFrameNoTimeout(cv::Mat& image) {
|
||||
cv::Mat tmpnam;
|
||||
auto retVal = GrabFrameNoTimeoutDirect(tmpnam);
|
||||
if (retVal <= 0) {
|
||||
return retVal;
|
||||
}
|
||||
tmpnam.copyTo(image);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
inline uint64_t CvSink::GrabFrameNoTimeout(cv::Mat& image) const {
|
||||
m_status = 0;
|
||||
return GrabSinkFrame(m_handle, image, &m_status);
|
||||
inline constexpr int CvSink::GetCvFormat(WPI_PixelFormat pixelFormat) {
|
||||
int type = 0;
|
||||
switch (pixelFormat) {
|
||||
case WPI_PIXFMT_YUYV:
|
||||
case WPI_PIXFMT_RGB565:
|
||||
case WPI_PIXFMT_Y16:
|
||||
case WPI_PIXFMT_UYVY:
|
||||
type = CV_8UC2;
|
||||
break;
|
||||
case WPI_PIXFMT_BGR:
|
||||
type = CV_8UC3;
|
||||
break;
|
||||
case WPI_PIXFMT_BGRA:
|
||||
type = CV_8UC4;
|
||||
break;
|
||||
case WPI_PIXFMT_GRAY:
|
||||
case WPI_PIXFMT_MJPEG:
|
||||
default:
|
||||
type = CV_8UC1;
|
||||
break;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
inline uint64_t CvSink::GrabFrameDirect(cv::Mat& image, double timeout) {
|
||||
rawFrame.height = 0;
|
||||
rawFrame.width = 0;
|
||||
rawFrame.stride = 0;
|
||||
rawFrame.pixelFormat = pixelFormat;
|
||||
auto timestamp = GrabSinkFrameTimeout(m_handle, rawFrame, timeout, &m_status);
|
||||
if (m_status != CS_OK) {
|
||||
return 0;
|
||||
}
|
||||
image =
|
||||
cv::Mat{rawFrame.height, rawFrame.width,
|
||||
GetCvFormat(static_cast<WPI_PixelFormat>(rawFrame.pixelFormat)),
|
||||
rawFrame.data, static_cast<size_t>(rawFrame.stride)};
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
inline uint64_t CvSink::GrabFrameNoTimeoutDirect(cv::Mat& image) {
|
||||
rawFrame.height = 0;
|
||||
rawFrame.width = 0;
|
||||
rawFrame.stride = 0;
|
||||
rawFrame.pixelFormat = pixelFormat;
|
||||
auto timestamp = GrabSinkFrame(m_handle, rawFrame, &m_status);
|
||||
if (m_status != CS_OK) {
|
||||
return 0;
|
||||
}
|
||||
image =
|
||||
cv::Mat{rawFrame.height, rawFrame.width,
|
||||
GetCvFormat(static_cast<WPI_PixelFormat>(rawFrame.pixelFormat)),
|
||||
rawFrame.data, static_cast<size_t>(rawFrame.stride)};
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
} // namespace cs
|
||||
|
||||
#endif
|
||||
|
||||
#endif // CSCORE_CSCORE_CV_H_
|
||||
|
||||
@@ -221,7 +221,9 @@ class VideoSource {
|
||||
/// HTTP video source.
|
||||
kHttp = CS_SOURCE_HTTP,
|
||||
/// CV video source.
|
||||
kCv = CS_SOURCE_CV
|
||||
kCv = CS_SOURCE_CV,
|
||||
/// Raw video source.
|
||||
kRaw = CS_SOURCE_RAW,
|
||||
};
|
||||
|
||||
/** Connection strategy. Used for SetConnectionStrategy(). */
|
||||
@@ -856,7 +858,9 @@ class VideoSink {
|
||||
/// MJPEG video sink.
|
||||
kMjpeg = CS_SINK_MJPEG,
|
||||
/// CV video sink.
|
||||
kCv = CS_SINK_CV
|
||||
kCv = CS_SINK_CV,
|
||||
/// Raw video sink.
|
||||
kRaw = CS_SINK_RAW,
|
||||
};
|
||||
|
||||
VideoSink() noexcept = default;
|
||||
|
||||
@@ -28,9 +28,9 @@ uint64_t CS_GrabRawSinkFrame(CS_Sink sink, struct WPI_RawFrame* rawImage,
|
||||
uint64_t CS_GrabRawSinkFrameTimeout(CS_Sink sink, struct WPI_RawFrame* rawImage,
|
||||
double timeout, CS_Status* status);
|
||||
|
||||
CS_Sink CS_CreateRawSink(const char* name, CS_Status* status);
|
||||
CS_Sink CS_CreateRawSink(const char* name, CS_Bool isCv, CS_Status* status);
|
||||
|
||||
CS_Sink CS_CreateRawSinkCallback(const char* name, void* data,
|
||||
CS_Sink CS_CreateRawSinkCallback(const char* name, CS_Bool isCv, void* data,
|
||||
void (*processFrame)(void* data,
|
||||
uint64_t time),
|
||||
CS_Status* status);
|
||||
@@ -38,8 +38,8 @@ CS_Sink CS_CreateRawSinkCallback(const char* name, void* data,
|
||||
void CS_PutRawSourceFrame(CS_Source source, const struct WPI_RawFrame* image,
|
||||
CS_Status* status);
|
||||
|
||||
CS_Source CS_CreateRawSource(const char* name, const CS_VideoMode* mode,
|
||||
CS_Status* status);
|
||||
CS_Source CS_CreateRawSource(const char* name, CS_Bool isCv,
|
||||
const CS_VideoMode* mode, CS_Status* status);
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -54,11 +54,11 @@ namespace cs {
|
||||
* @{
|
||||
*/
|
||||
|
||||
CS_Source CreateRawSource(std::string_view name, const VideoMode& mode,
|
||||
CS_Status* status);
|
||||
CS_Source CreateRawSource(std::string_view name, bool isCv,
|
||||
const VideoMode& mode, CS_Status* status);
|
||||
|
||||
CS_Sink CreateRawSink(std::string_view name, CS_Status* status);
|
||||
CS_Sink CreateRawSinkCallback(std::string_view name,
|
||||
CS_Sink CreateRawSink(std::string_view name, bool isCv, CS_Status* status);
|
||||
CS_Sink CreateRawSinkCallback(std::string_view name, bool isCv,
|
||||
std::function<void(uint64_t time)> processFrame,
|
||||
CS_Status* status);
|
||||
|
||||
@@ -166,14 +166,14 @@ class RawSink : public ImageSink {
|
||||
};
|
||||
|
||||
inline RawSource::RawSource(std::string_view name, const VideoMode& mode) {
|
||||
m_handle = CreateRawSource(name, mode, &m_status);
|
||||
m_handle = CreateRawSource(name, false, mode, &m_status);
|
||||
}
|
||||
|
||||
inline RawSource::RawSource(std::string_view name,
|
||||
VideoMode::PixelFormat format, int width,
|
||||
int height, int fps) {
|
||||
m_handle =
|
||||
CreateRawSource(name, VideoMode{format, width, height, fps}, &m_status);
|
||||
m_handle = CreateRawSource(name, false, VideoMode{format, width, height, fps},
|
||||
&m_status);
|
||||
}
|
||||
|
||||
inline void RawSource::PutFrame(wpi::RawFrame& image) {
|
||||
@@ -182,12 +182,12 @@ inline void RawSource::PutFrame(wpi::RawFrame& image) {
|
||||
}
|
||||
|
||||
inline RawSink::RawSink(std::string_view name) {
|
||||
m_handle = CreateRawSink(name, &m_status);
|
||||
m_handle = CreateRawSink(name, false, &m_status);
|
||||
}
|
||||
|
||||
inline RawSink::RawSink(std::string_view name,
|
||||
std::function<void(uint64_t time)> processFrame) {
|
||||
m_handle = CreateRawSinkCallback(name, processFrame, &m_status);
|
||||
m_handle = CreateRawSinkCallback(name, false, processFrame, &m_status);
|
||||
}
|
||||
|
||||
inline uint64_t RawSink::GrabFrame(wpi::RawFrame& image, double timeout) const {
|
||||
|
||||
@@ -1,228 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#ifndef CSCORE_CSCORE_RAW_CV_H_
|
||||
#define CSCORE_CSCORE_RAW_CV_H_
|
||||
|
||||
#ifdef CSCORE_CSCORE_CV_H_
|
||||
#error "Cannot include both cscore_cv.h and cscore_raw_cv.h in the same file"
|
||||
#endif
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <opencv2/core/mat.hpp>
|
||||
|
||||
#include "cscore_raw.h"
|
||||
|
||||
namespace cs {
|
||||
/**
|
||||
* A source for using the raw frame API to provide opencv images.
|
||||
*
|
||||
* If you are using the WPILib OpenCV builds, do not use this, and
|
||||
* instead include "cscore_cv.h" to get a more performant version.
|
||||
*
|
||||
* This is not dependent on any opencv binary ABI, and can be used
|
||||
* with versions of OpenCV that are not 3. If using OpenCV 3, use
|
||||
* CvSource.
|
||||
*/
|
||||
class RawCvSource : public RawSource {
|
||||
public:
|
||||
RawCvSource() = default;
|
||||
|
||||
/**
|
||||
* Create a Raw OpenCV source.
|
||||
*
|
||||
* @param name Source name (arbitrary unique identifier)
|
||||
* @param mode Video mode being generated
|
||||
*/
|
||||
RawCvSource(std::string_view name, const VideoMode& mode);
|
||||
|
||||
/**
|
||||
* Create a Raw OpenCV source.
|
||||
*
|
||||
* @param name Source name (arbitrary unique identifier)
|
||||
* @param pixelFormat Pixel format
|
||||
* @param width width
|
||||
* @param height height
|
||||
* @param fps fps
|
||||
*/
|
||||
RawCvSource(std::string_view name, VideoMode::PixelFormat pixelFormat,
|
||||
int width, int height, int fps);
|
||||
|
||||
/**
|
||||
* Put an OpenCV image and notify sinks.
|
||||
*
|
||||
* <p>Only 8-bit single-channel or 3-channel (with BGR channel order) images
|
||||
* are supported. If the format, depth or channel order is different, use
|
||||
* cv::Mat::convertTo() and/or cv::cvtColor() to convert it first.
|
||||
*
|
||||
* @param image OpenCV image
|
||||
*/
|
||||
void PutFrame(cv::Mat& image);
|
||||
|
||||
private:
|
||||
wpi::RawFrame rawFrame;
|
||||
};
|
||||
|
||||
/**
|
||||
* A sink for user code to accept raw video frames as OpenCV images.
|
||||
*
|
||||
* If you are using the WPILib OpenCV builds, do not use this, and
|
||||
* instead include "cscore_cv.h" to get a more performant version.
|
||||
*
|
||||
* This is not dependent on any opencv binary ABI, and can be used
|
||||
* with versions of OpenCV that are not 3. If using OpenCV 3, use
|
||||
* CvSink.
|
||||
*/
|
||||
class RawCvSink : public RawSink {
|
||||
public:
|
||||
RawCvSink() = default;
|
||||
|
||||
/**
|
||||
* Create a sink for accepting OpenCV images.
|
||||
*
|
||||
* <p>WaitForFrame() must be called on the created sink to get each new
|
||||
* image.
|
||||
*
|
||||
* @param name Source name (arbitrary unique identifier)
|
||||
*/
|
||||
explicit RawCvSink(std::string_view name);
|
||||
|
||||
/**
|
||||
* Create a sink for accepting OpenCV images in a separate thread.
|
||||
*
|
||||
* <p>A thread will be created that calls WaitForFrame() and calls the
|
||||
* processFrame() callback each time a new frame arrives.
|
||||
*
|
||||
* @param name Source name (arbitrary unique identifier)
|
||||
* @param processFrame Frame processing function; will be called with a
|
||||
* time=0 if an error occurred. processFrame should call GetImage()
|
||||
* or GetError() as needed, but should not call (except in very
|
||||
* unusual circumstances) WaitForImage().
|
||||
*/
|
||||
RawCvSink(std::string_view name,
|
||||
std::function<void(uint64_t time)> processFrame);
|
||||
|
||||
/**
|
||||
* Wait for the next frame and get the image.
|
||||
* Times out (returning 0) after timeout seconds.
|
||||
* The provided image will have three 8-bit channels stored in BGR order.
|
||||
*
|
||||
* @return Frame time, or 0 on error (call GetError() to obtain the error
|
||||
* message); the frame time is in the same time base as wpi::Now(),
|
||||
* and is in 1 us increments.
|
||||
*/
|
||||
[[nodiscard]]
|
||||
uint64_t GrabFrame(cv::Mat& image, double timeout = 0.225);
|
||||
|
||||
/**
|
||||
* Wait for the next frame and get the image. May block forever.
|
||||
* The provided image will have three 8-bit channels stored in BGR order.
|
||||
*
|
||||
* @return Frame time, or 0 on error (call GetError() to obtain the error
|
||||
* message); the frame time is in the same time base as wpi::Now(),
|
||||
* and is in 1 us increments.
|
||||
*/
|
||||
[[nodiscard]]
|
||||
uint64_t GrabFrameNoTimeout(cv::Mat& image);
|
||||
|
||||
/**
|
||||
* Wait for the next frame and get the image.
|
||||
* Times out (returning 0) after timeout seconds.
|
||||
* The provided image will have three 8-bit channels stored in BGR order.
|
||||
*
|
||||
* @return Frame time, or 0 on error (call GetError() to obtain the error
|
||||
* message); the frame time is in the same time base as wpi::Now(),
|
||||
* and is in 1 us increments.
|
||||
*/
|
||||
[[nodiscard]]
|
||||
uint64_t GrabFrameDirect(cv::Mat& image, double timeout = 0.225);
|
||||
|
||||
/**
|
||||
* Wait for the next frame and get the image. May block forever.
|
||||
* The provided image will have three 8-bit channels stored in BGR order.
|
||||
*
|
||||
* @return Frame time, or 0 on error (call GetError() to obtain the error
|
||||
* message); the frame time is in the same time base as wpi::Now(),
|
||||
* and is in 1 us increments.
|
||||
*/
|
||||
[[nodiscard]]
|
||||
uint64_t GrabFrameNoTimeoutDirect(cv::Mat& image);
|
||||
|
||||
private:
|
||||
wpi::RawFrame rawFrame;
|
||||
};
|
||||
|
||||
inline RawCvSource::RawCvSource(std::string_view name, const VideoMode& mode)
|
||||
: RawSource{name, mode} {}
|
||||
|
||||
inline RawCvSource::RawCvSource(std::string_view name,
|
||||
VideoMode::PixelFormat format, int width,
|
||||
int height, int fps)
|
||||
: RawSource{name, format, width, height, fps} {}
|
||||
|
||||
inline void RawCvSource::PutFrame(cv::Mat& image) {
|
||||
m_status = 0;
|
||||
rawFrame.data = reinterpret_cast<char*>(image.data);
|
||||
rawFrame.width = image.cols;
|
||||
rawFrame.height = image.rows;
|
||||
rawFrame.totalData = image.total() * image.channels();
|
||||
rawFrame.pixelFormat =
|
||||
image.channels() == 3 ? WPI_PIXFMT_BGR : WPI_PIXFMT_GRAY;
|
||||
PutSourceFrame(m_handle, rawFrame, &m_status);
|
||||
}
|
||||
|
||||
inline RawCvSink::RawCvSink(std::string_view name) : RawSink{name} {}
|
||||
|
||||
inline RawCvSink::RawCvSink(std::string_view name,
|
||||
std::function<void(uint64_t time)> processFrame)
|
||||
: RawSink{name, processFrame} {}
|
||||
|
||||
inline uint64_t RawCvSink::GrabFrame(cv::Mat& image, double timeout) {
|
||||
cv::Mat tmpnam;
|
||||
auto retVal = GrabFrameDirect(tmpnam);
|
||||
if (retVal <= 0) {
|
||||
return retVal;
|
||||
}
|
||||
tmpnam.copyTo(image);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
inline uint64_t RawCvSink::GrabFrameNoTimeout(cv::Mat& image) {
|
||||
cv::Mat tmpnam;
|
||||
auto retVal = GrabFrameNoTimeoutDirect(tmpnam);
|
||||
if (retVal <= 0) {
|
||||
return retVal;
|
||||
}
|
||||
tmpnam.copyTo(image);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
inline uint64_t RawCvSink::GrabFrameDirect(cv::Mat& image, double timeout) {
|
||||
rawFrame.height = 0;
|
||||
rawFrame.width = 0;
|
||||
rawFrame.pixelFormat = WPI_PixelFormat::WPI_PIXFMT_BGR;
|
||||
m_status = RawSink::GrabFrame(rawFrame, timeout);
|
||||
if (m_status <= 0) {
|
||||
return m_status;
|
||||
}
|
||||
image = cv::Mat{rawFrame.height, rawFrame.width, CV_8UC3, rawFrame.data};
|
||||
return m_status;
|
||||
}
|
||||
|
||||
inline uint64_t RawCvSink::GrabFrameNoTimeoutDirect(cv::Mat& image) {
|
||||
rawFrame.height = 0;
|
||||
rawFrame.width = 0;
|
||||
rawFrame.pixelFormat = WPI_PixelFormat::WPI_PIXFMT_BGR;
|
||||
m_status = RawSink::GrabFrameNoTimeout(rawFrame);
|
||||
if (m_status <= 0) {
|
||||
return m_status;
|
||||
}
|
||||
image = cv::Mat{rawFrame.height, rawFrame.width, CV_8UC3, rawFrame.data};
|
||||
return m_status;
|
||||
}
|
||||
|
||||
} // namespace cs
|
||||
|
||||
#endif // CSCORE_CSCORE_RAW_CV_H_
|
||||
@@ -80,6 +80,8 @@ static VideoMode::PixelFormat ToPixelFormat(__u32 pixelFormat) {
|
||||
return VideoMode::kRGB565;
|
||||
case V4L2_PIX_FMT_BGR24:
|
||||
return VideoMode::kBGR;
|
||||
case V4L2_PIX_FMT_ABGR32:
|
||||
return VideoMode::kBGRA;
|
||||
case V4L2_PIX_FMT_GREY:
|
||||
return VideoMode::kGray;
|
||||
case V4L2_PIX_FMT_Y16:
|
||||
@@ -102,6 +104,8 @@ static __u32 FromPixelFormat(VideoMode::PixelFormat pixelFormat) {
|
||||
return V4L2_PIX_FMT_RGB565;
|
||||
case VideoMode::kBGR:
|
||||
return V4L2_PIX_FMT_BGR24;
|
||||
case VideoMode::kBGRA:
|
||||
return V4L2_PIX_FMT_ABGR32;
|
||||
case VideoMode::kGray:
|
||||
return V4L2_PIX_FMT_GREY;
|
||||
case VideoMode::kY16:
|
||||
|
||||
@@ -7,9 +7,6 @@
|
||||
|
||||
#include <wpi/timestamp.h>
|
||||
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
|
||||
@implementation UsbCameraDelegate
|
||||
|
||||
- (id)init {
|
||||
@@ -24,6 +21,8 @@
|
||||
(void)sampleBuffer;
|
||||
(void)connection;
|
||||
|
||||
auto currentTime = wpi::Now();
|
||||
|
||||
auto sharedThis = self.cppImpl.lock();
|
||||
if (!sharedThis) {
|
||||
return;
|
||||
@@ -52,16 +51,12 @@
|
||||
return;
|
||||
}
|
||||
|
||||
size_t currSize = width * 3 * height;
|
||||
|
||||
auto tmpMat = cv::Mat(height, width, CV_8UC4, baseaddress, rowBytes);
|
||||
auto image = sharedThis->AllocImage(cs::VideoMode::PixelFormat::kBGR, width,
|
||||
height, currSize);
|
||||
cv::cvtColor(tmpMat, image->AsMat(), cv::COLOR_BGRA2BGR);
|
||||
std::unique_ptr<cs::Image> image = cs::CreateImageFromBGRA(
|
||||
sharedThis.get(), width, height, rowBytes, reinterpret_cast<uint8_t*>(baseaddress));
|
||||
|
||||
CVPixelBufferUnlockBaseAddress(imageBuffer, 0);
|
||||
|
||||
sharedThis->objcPutFrame(std::move(image), wpi::Now());
|
||||
sharedThis->objcPutFrame(std::move(image), currentTime);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include "Instance.h"
|
||||
#include "c_util.h"
|
||||
#include "cscore_cpp.h"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "UsbCameraImpl.h"
|
||||
|
||||
namespace cs {
|
||||
@@ -135,7 +134,11 @@ std::vector<UsbCameraInfo> EnumerateUsbCameras(CS_Status* status) {
|
||||
std::vector<UsbCameraInfo> retval;
|
||||
NSArray<AVCaptureDeviceType>* deviceTypes = @[
|
||||
AVCaptureDeviceTypeBuiltInWideAngleCamera,
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 140000
|
||||
AVCaptureDeviceTypeExternal
|
||||
#else
|
||||
AVCaptureDeviceTypeExternalUnknown
|
||||
#endif
|
||||
];
|
||||
AVCaptureDeviceDiscoverySession* session = [AVCaptureDeviceDiscoverySession
|
||||
discoverySessionWithDeviceTypes:deviceTypes
|
||||
|
||||
@@ -76,7 +76,11 @@ using namespace cs;
|
||||
if ([device.deviceType
|
||||
isEqualToString:AVCaptureDeviceTypeBuiltInWideAngleCamera] ||
|
||||
[device.deviceType
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 140000
|
||||
isEqualToString:AVCaptureDeviceTypeExternal]) {
|
||||
#else
|
||||
isEqualToString:AVCaptureDeviceTypeExternalUnknown]) {
|
||||
#endif
|
||||
self.notifier->NotifyUsbCamerasChanged();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -21,9 +21,6 @@
|
||||
#include <Dbt.h>
|
||||
#include <Dshow.h>
|
||||
#include <Windows.h>
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
#include <wpi/ConvertUTF.h>
|
||||
#include <wpi/MemAlloc.h>
|
||||
#include <wpi/SmallString.h>
|
||||
@@ -284,6 +281,8 @@ void UsbCameraImpl::ProcessFrame(IMFSample* videoSample,
|
||||
return;
|
||||
}
|
||||
|
||||
auto currentTime = wpi::Now();
|
||||
|
||||
ComPtr<IMFMediaBuffer> buf;
|
||||
|
||||
if (!SUCCEEDED(videoSample->ConvertToContiguousBuffer(buf.GetAddressOf()))) {
|
||||
@@ -339,56 +338,9 @@ void UsbCameraImpl::ProcessFrame(IMFSample* videoSample,
|
||||
}
|
||||
}
|
||||
|
||||
cv::Mat tmpMat;
|
||||
std::unique_ptr<Image> dest;
|
||||
bool doFinalSet = true;
|
||||
|
||||
switch (mode.pixelFormat) {
|
||||
case cs::VideoMode::PixelFormat::kMJPEG: {
|
||||
// Special case
|
||||
PutFrame(VideoMode::kMJPEG, mode.width, mode.height,
|
||||
{reinterpret_cast<char*>(ptr), length}, wpi::Now());
|
||||
doFinalSet = false;
|
||||
break;
|
||||
}
|
||||
case cs::VideoMode::PixelFormat::kGray:
|
||||
tmpMat = cv::Mat(mode.height, mode.width, CV_8UC1, ptr, pitch);
|
||||
dest = AllocImage(VideoMode::kGray, tmpMat.cols, tmpMat.rows,
|
||||
tmpMat.total());
|
||||
tmpMat.copyTo(dest->AsMat());
|
||||
break;
|
||||
case cs::VideoMode::PixelFormat::kY16:
|
||||
tmpMat = cv::Mat(mode.height, mode.width, CV_8UC2, ptr, pitch);
|
||||
dest =
|
||||
AllocImage(VideoMode::kY16, tmpMat.cols, tmpMat.rows, tmpMat.total());
|
||||
tmpMat.copyTo(dest->AsMat());
|
||||
break;
|
||||
case cs::VideoMode::PixelFormat::kBGR:
|
||||
tmpMat = cv::Mat(mode.height, mode.width, CV_8UC3, ptr, pitch);
|
||||
dest = AllocImage(VideoMode::kBGR, tmpMat.cols, tmpMat.rows,
|
||||
tmpMat.total() * 3);
|
||||
tmpMat.copyTo(dest->AsMat());
|
||||
break;
|
||||
case cs::VideoMode::PixelFormat::kYUYV:
|
||||
tmpMat = cv::Mat(mode.height, mode.width, CV_8UC2, ptr, pitch);
|
||||
dest = AllocImage(VideoMode::kYUYV, tmpMat.cols, tmpMat.rows,
|
||||
tmpMat.total() * 2);
|
||||
tmpMat.copyTo(dest->AsMat());
|
||||
break;
|
||||
case cs::VideoMode::PixelFormat::kUYVY:
|
||||
tmpMat = cv::Mat(mode.height, mode.width, CV_8UC2, ptr, pitch);
|
||||
dest = AllocImage(VideoMode::kUYVY, tmpMat.cols, tmpMat.rows,
|
||||
tmpMat.total() * 2);
|
||||
tmpMat.copyTo(dest->AsMat());
|
||||
break;
|
||||
default:
|
||||
doFinalSet = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (doFinalSet) {
|
||||
PutFrame(std::move(dest), wpi::Now());
|
||||
}
|
||||
std::string_view data_view{reinterpret_cast<char*>(ptr), length};
|
||||
SourceImpl::PutFrame(static_cast<VideoMode::PixelFormat>(mode.pixelFormat),
|
||||
mode.width, mode.height, data_view, currentTime);
|
||||
|
||||
if (buffer2d) {
|
||||
buffer2d->Unlock2D();
|
||||
@@ -480,8 +432,6 @@ static cs::VideoMode::PixelFormat GetFromGUID(const GUID& guid) {
|
||||
return cs::VideoMode::PixelFormat::kY16;
|
||||
} else if (IsEqualGUID(guid, MFVideoFormat_YUY2)) {
|
||||
return cs::VideoMode::PixelFormat::kYUYV;
|
||||
} else if (IsEqualGUID(guid, MFVideoFormat_RGB24)) {
|
||||
return cs::VideoMode::PixelFormat::kBGR;
|
||||
} else if (IsEqualGUID(guid, MFVideoFormat_MJPG)) {
|
||||
return cs::VideoMode::PixelFormat::kMJPEG;
|
||||
} else if (IsEqualGUID(guid, MFVideoFormat_RGB565)) {
|
||||
|
||||
@@ -180,12 +180,10 @@ doxygen {
|
||||
warn_if_undocumented false
|
||||
warn_no_paramdoc true
|
||||
|
||||
//enable doxygen preprocessor expansion of WPI_DEPRECATED to fix MotorController docs
|
||||
enable_preprocessing true
|
||||
macro_expansion true
|
||||
expand_only_predef true
|
||||
predefined "WPI_DEPRECATED(x)=[[deprecated(x)]]\"\\\n" +
|
||||
"\"__cplusplus\"\\\n" +
|
||||
predefined "__cplusplus\"\\\n" +
|
||||
"\"HAL_ENUM(name)=enum name : int32_t"
|
||||
|
||||
if (project.hasProperty('docWarningsAsErrors')) {
|
||||
|
||||
@@ -323,8 +323,7 @@ NetworkServer::NetworkServer(std::string_view persistentFilename,
|
||||
HandleLocal();
|
||||
|
||||
// load persistent file first, then initialize
|
||||
uv::QueueWork(
|
||||
m_loop, [this] { LoadPersistent(); }, [this] { Init(); });
|
||||
uv::QueueWork(m_loop, [this] { LoadPersistent(); }, [this] { Init(); });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ void WebSocketConnection::SendPing(uint64_t time) {
|
||||
WPI_DEBUG4(m_logger, "conn: sending ping {}", time);
|
||||
auto buf = AllocBuf();
|
||||
buf.len = 8;
|
||||
wpi::support::endian::write64<wpi::support::native>(buf.base, time);
|
||||
wpi::support::endian::write64<wpi::endianness::native>(buf.base, time);
|
||||
m_ws.SendPing({buf}, [selfweak = weak_from_this()](auto bufs, auto err) {
|
||||
if (auto self = selfweak.lock()) {
|
||||
self->m_err = err;
|
||||
|
||||
@@ -228,7 +228,8 @@ class StructArraySubscriber : public Subscriber {
|
||||
|
||||
private:
|
||||
ValueType m_defaultValue;
|
||||
[[no_unique_address]] std::tuple<I...> m_info;
|
||||
[[no_unique_address]]
|
||||
std::tuple<I...> m_info;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -387,7 +388,8 @@ class StructArrayPublisher : public Publisher {
|
||||
private:
|
||||
wpi::StructArrayBuffer<T, I...> m_buf;
|
||||
std::atomic_bool m_schemaPublished{false};
|
||||
[[no_unique_address]] std::tuple<I...> m_info;
|
||||
[[no_unique_address]]
|
||||
std::tuple<I...> m_info;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -702,7 +704,8 @@ class StructArrayTopic final : public Topic {
|
||||
}
|
||||
|
||||
private:
|
||||
[[no_unique_address]] std::tuple<I...> m_info;
|
||||
[[no_unique_address]]
|
||||
std::tuple<I...> m_info;
|
||||
};
|
||||
|
||||
} // namespace nt
|
||||
|
||||
@@ -180,7 +180,8 @@ class StructSubscriber : public Subscriber {
|
||||
|
||||
private:
|
||||
ValueType m_defaultValue;
|
||||
[[no_unique_address]] std::tuple<I...> m_info;
|
||||
[[no_unique_address]]
|
||||
std::tuple<I...> m_info;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -301,7 +302,8 @@ class StructPublisher : public Publisher {
|
||||
|
||||
private:
|
||||
std::atomic_bool m_schemaPublished{false};
|
||||
[[no_unique_address]] std::tuple<I...> m_info;
|
||||
[[no_unique_address]]
|
||||
std::tuple<I...> m_info;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -522,7 +524,8 @@ class StructTopic final : public Topic {
|
||||
}
|
||||
|
||||
private:
|
||||
[[no_unique_address]] std::tuple<I...> m_info;
|
||||
[[no_unique_address]]
|
||||
std::tuple<I...> m_info;
|
||||
};
|
||||
|
||||
} // namespace nt
|
||||
|
||||
@@ -155,4 +155,13 @@
|
||||
<Bug pattern="RV_RETURN_VALUE_OF_PUTIFABSENT_IGNORED" />
|
||||
<Class name="edu.wpi.first.networktables.NetworkTableInstance" />
|
||||
</Match>
|
||||
<!--
|
||||
Strict reading of Object.equals() contract means that whenever equals() behaviour is defined, all implementations
|
||||
need to adhere to it. The only reason to override the method (assuming correct API design, of course) is to provide
|
||||
a more efficient implementation. This rule would be forcing a @SuppressFBWarnings on perfectly compliant classes.
|
||||
More information at https://github.com/spotbugs/spotbugs/issues/511
|
||||
-->
|
||||
<Match>
|
||||
<Bug pattern="EQ_DOESNT_OVERRIDE_EQUALS" />
|
||||
</Match>
|
||||
</FindBugsFilter>
|
||||
|
||||
@@ -14,8 +14,8 @@ TEST(OLSTest, TwoVariablesTwoPoints) {
|
||||
auto [coeffs, rSquared, rmse] = sysid::OLS(X, y);
|
||||
EXPECT_EQ(coeffs.size(), 2u);
|
||||
|
||||
EXPECT_DOUBLE_EQ(coeffs[0], 1.0);
|
||||
EXPECT_DOUBLE_EQ(coeffs[1], 2.0);
|
||||
EXPECT_NEAR(coeffs[0], 1.0, 1e-12);
|
||||
EXPECT_NEAR(coeffs[1], 2.0, 1e-12);
|
||||
EXPECT_DOUBLE_EQ(rSquared, 1.0);
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ TEST(OLSTest, TwoVariablesFivePoints) {
|
||||
auto [coeffs, rSquared, rmse] = sysid::OLS(X, y);
|
||||
EXPECT_EQ(coeffs.size(), 2u);
|
||||
|
||||
EXPECT_DOUBLE_EQ(coeffs[0], 0.30487804878048774);
|
||||
EXPECT_DOUBLE_EQ(coeffs[1], 1.5182926829268293);
|
||||
EXPECT_NEAR(coeffs[0], 0.30487804878048774, 1e-12);
|
||||
EXPECT_NEAR(coeffs[1], 1.5182926829268293, 1e-12);
|
||||
EXPECT_DOUBLE_EQ(rSquared, 0.91906029466386019);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,40 +1,40 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sat, 7 May 2022 22:09:18 -0400
|
||||
Subject: [PATCH 01/34] Remove StringRef, ArrayRef, and Optional
|
||||
Subject: [PATCH 01/35] Remove StringRef, ArrayRef, and Optional
|
||||
|
||||
---
|
||||
llvm/include/llvm/ADT/PointerUnion.h | 1 -
|
||||
llvm/include/llvm/ADT/SmallSet.h | 2 +-
|
||||
llvm/include/llvm/ADT/SmallString.h | 77 ++++++++++---------
|
||||
llvm/include/llvm/ADT/SmallVector.h | 7 +-
|
||||
llvm/include/llvm/ADT/StringMap.h | 38 ++++-----
|
||||
llvm/include/llvm/ADT/StringMapEntry.h | 20 ++---
|
||||
llvm/include/llvm/Support/Chrono.h | 10 +--
|
||||
llvm/include/llvm/Support/Compiler.h | 2 +-
|
||||
llvm/include/llvm/Support/ConvertUTF.h | 31 ++++----
|
||||
llvm/include/llvm/Support/ErrorHandling.h | 9 +--
|
||||
.../llvm/Support/SmallVectorMemoryBuffer.h | 6 +-
|
||||
llvm/include/llvm/Support/VersionTuple.h | 6 --
|
||||
.../llvm/Support/Windows/WindowsSupport.h | 4 +-
|
||||
llvm/include/llvm/Support/raw_ostream.h | 46 ++++++-----
|
||||
llvm/include/llvm/Support/xxhash.h | 16 ++--
|
||||
llvm/lib/Support/ConvertUTFWrapper.cpp | 38 ++++-----
|
||||
llvm/lib/Support/ErrorHandling.cpp | 13 ++--
|
||||
llvm/lib/Support/SmallVector.cpp | 5 +-
|
||||
llvm/lib/Support/StringMap.cpp | 12 +--
|
||||
llvm/lib/Support/raw_ostream.cpp | 25 +++---
|
||||
llvm/lib/Support/xxhash.cpp | 10 +--
|
||||
llvm/unittests/ADT/DenseMapTest.cpp | 29 +------
|
||||
llvm/unittests/ADT/FunctionExtrasTest.cpp | 12 +--
|
||||
llvm/unittests/ADT/HashingTest.cpp | 2 +-
|
||||
llvm/unittests/ADT/SmallPtrSetTest.cpp | 1 -
|
||||
llvm/unittests/ADT/SmallStringTest.cpp | 50 ++++++------
|
||||
llvm/unittests/ADT/SmallVectorTest.cpp | 30 ++------
|
||||
llvm/unittests/ADT/StringMapTest.cpp | 32 ++++----
|
||||
llvm/unittests/Support/ConvertUTFTest.cpp | 41 +++++-----
|
||||
llvm/unittests/Support/xxhashTest.cpp | 4 +-
|
||||
30 files changed, 264 insertions(+), 315 deletions(-)
|
||||
llvm/include/llvm/ADT/PointerUnion.h | 1 -
|
||||
llvm/include/llvm/ADT/SmallSet.h | 2 +-
|
||||
llvm/include/llvm/ADT/SmallString.h | 103 ++++++++++--------
|
||||
llvm/include/llvm/ADT/SmallVector.h | 7 +-
|
||||
llvm/include/llvm/ADT/StringMap.h | 38 +++----
|
||||
llvm/include/llvm/ADT/StringMapEntry.h | 20 ++--
|
||||
llvm/include/llvm/Support/Chrono.h | 10 +-
|
||||
llvm/include/llvm/Support/Compiler.h | 2 +-
|
||||
llvm/include/llvm/Support/ConvertUTF.h | 31 +++---
|
||||
llvm/include/llvm/Support/ErrorHandling.h | 9 +-
|
||||
.../llvm/Support/SmallVectorMemoryBuffer.h | 6 +-
|
||||
llvm/include/llvm/Support/VersionTuple.h | 6 -
|
||||
.../llvm/Support/Windows/WindowsSupport.h | 4 +-
|
||||
llvm/include/llvm/Support/raw_ostream.h | 46 +++++---
|
||||
llvm/include/llvm/Support/xxhash.h | 16 +--
|
||||
llvm/lib/Support/ConvertUTFWrapper.cpp | 38 +++----
|
||||
llvm/lib/Support/ErrorHandling.cpp | 13 +--
|
||||
llvm/lib/Support/SmallVector.cpp | 5 +-
|
||||
llvm/lib/Support/StringMap.cpp | 12 +-
|
||||
llvm/lib/Support/raw_ostream.cpp | 25 ++---
|
||||
llvm/lib/Support/xxhash.cpp | 10 +-
|
||||
llvm/unittests/ADT/DenseMapTest.cpp | 29 +----
|
||||
llvm/unittests/ADT/FunctionExtrasTest.cpp | 12 +-
|
||||
llvm/unittests/ADT/HashingTest.cpp | 2 +-
|
||||
llvm/unittests/ADT/SmallPtrSetTest.cpp | 1 -
|
||||
llvm/unittests/ADT/SmallStringTest.cpp | 50 ++++-----
|
||||
llvm/unittests/ADT/SmallVectorTest.cpp | 30 +----
|
||||
llvm/unittests/ADT/StringMapTest.cpp | 32 +++---
|
||||
llvm/unittests/Support/ConvertUTFTest.cpp | 41 ++++---
|
||||
llvm/unittests/Support/xxhashTest.cpp | 4 +-
|
||||
30 files changed, 282 insertions(+), 323 deletions(-)
|
||||
|
||||
diff --git a/llvm/include/llvm/ADT/PointerUnion.h b/llvm/include/llvm/ADT/PointerUnion.h
|
||||
index 7d4ed02b622626bb8043acb57b8ce7ed97a5f949..8ac68dbc0a791b8ac0e0ca865e69024cb642aa70 100644
|
||||
@@ -67,7 +67,7 @@ index a16e8ac6f07552d98250e808190b00ee270f12b3..aeee5f97799aea7e7588d7afba1e47b4
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
diff --git a/llvm/include/llvm/ADT/SmallString.h b/llvm/include/llvm/ADT/SmallString.h
|
||||
index 0052c86fb37b82dcdf577a7acf06e3a47f54da61..4d673cc8b1c49cf8a3f19653de53881cd12662ee 100644
|
||||
index a5b9eec50c8257348743f1e32ebd9a9dabd53b25..45fbf13a43a081731186b0f41c553413b0e36e0f 100644
|
||||
--- a/llvm/include/llvm/ADT/SmallString.h
|
||||
+++ b/llvm/include/llvm/ADT/SmallString.h
|
||||
@@ -15,8 +15,9 @@
|
||||
@@ -141,155 +141,176 @@ index 0052c86fb37b82dcdf577a7acf06e3a47f54da61..4d673cc8b1c49cf8a3f19653de53881c
|
||||
std::copy(Ref.begin(), Ref.end(), this->begin() + CurrentSize);
|
||||
CurrentSize += Ref.size();
|
||||
}
|
||||
@@ -89,30 +90,30 @@ public:
|
||||
@@ -89,26 +90,30 @@ public:
|
||||
|
||||
/// Check for string equality. This is more efficient than compare() when
|
||||
/// the relative ordering of inequal strings isn't needed.
|
||||
- bool equals(StringRef RHS) const {
|
||||
+ bool equals(std::string_view RHS) const {
|
||||
return str().equals(RHS);
|
||||
}
|
||||
- [[nodiscard]] bool equals(StringRef RHS) const { return str().equals(RHS); }
|
||||
+ [[nodiscard]] bool equals(std::string_view RHS) const {
|
||||
+ return str().equals(RHS);
|
||||
+ }
|
||||
|
||||
/// Check for string equality, ignoring case.
|
||||
- bool equals_insensitive(StringRef RHS) const {
|
||||
+ bool equals_insensitive(std::string_view RHS) const {
|
||||
- [[nodiscard]] bool equals_insensitive(StringRef RHS) const {
|
||||
+ [[nodiscard]] bool equals_insensitive(std::string_view RHS) const {
|
||||
return str().equals_insensitive(RHS);
|
||||
}
|
||||
|
||||
/// compare - Compare two strings; the result is negative, zero, or positive
|
||||
/// if this string is lexicographically less than, equal to, or greater than
|
||||
/// the \p RHS.
|
||||
- int compare(StringRef RHS) const {
|
||||
+ int compare(std::string_view RHS) const {
|
||||
return str().compare(RHS);
|
||||
}
|
||||
- [[nodiscard]] int compare(StringRef RHS) const { return str().compare(RHS); }
|
||||
+ [[nodiscard]] int compare(std::string_view RHS) const {
|
||||
+ return str().compare(RHS);
|
||||
+ }
|
||||
|
||||
/// compare_insensitive - Compare two strings, ignoring case.
|
||||
- int compare_insensitive(StringRef RHS) const {
|
||||
+ int compare_insensitive(std::string_view RHS) const {
|
||||
- [[nodiscard]] int compare_insensitive(StringRef RHS) const {
|
||||
+ [[nodiscard]] int compare_insensitive(std::string_view RHS) const {
|
||||
return str().compare_insensitive(RHS);
|
||||
}
|
||||
|
||||
/// compare_numeric - Compare two strings, treating sequences of digits as
|
||||
/// numbers.
|
||||
- int compare_numeric(StringRef RHS) const {
|
||||
+ int compare_numeric(std::string_view RHS) const {
|
||||
- [[nodiscard]] int compare_numeric(StringRef RHS) const {
|
||||
+ [[nodiscard]] int compare_numeric(std::string_view RHS) const {
|
||||
return str().compare_numeric(RHS);
|
||||
}
|
||||
|
||||
@@ -121,12 +122,12 @@ public:
|
||||
@@ -116,14 +121,14 @@ public:
|
||||
/// @name String Predicates
|
||||
/// @{
|
||||
|
||||
/// startswith - Check if this string starts with the given \p Prefix.
|
||||
- bool startswith(StringRef Prefix) const {
|
||||
+ bool startswith(std::string_view Prefix) const {
|
||||
return str().startswith(Prefix);
|
||||
- /// starts_with - Check if this string starts with the given \p Prefix.
|
||||
- [[nodiscard]] bool starts_with(StringRef Prefix) const {
|
||||
- return str().starts_with(Prefix);
|
||||
+ /// startswith - Check if this string starts with the given \p Prefix.
|
||||
+ [[nodiscard]] bool startswith(std::string_view Prefix) const {
|
||||
+ return str().startswith(Prefix);
|
||||
}
|
||||
|
||||
/// endswith - Check if this string ends with the given \p Suffix.
|
||||
- bool endswith(StringRef Suffix) const {
|
||||
+ bool endswith(std::string_view Suffix) const {
|
||||
return str().endswith(Suffix);
|
||||
- /// ends_with - Check if this string ends with the given \p Suffix.
|
||||
- [[nodiscard]] bool ends_with(StringRef Suffix) const {
|
||||
- return str().ends_with(Suffix);
|
||||
+ /// endswith - Check if this string ends with the given \p Suffix.
|
||||
+ [[nodiscard]] bool endswith(std::string_view Suffix) const {
|
||||
+ return str().endswith(Suffix);
|
||||
}
|
||||
|
||||
@@ -146,7 +147,7 @@ public:
|
||||
/// @}
|
||||
@@ -142,7 +147,7 @@ public:
|
||||
///
|
||||
/// \returns The index of the first occurrence of \p Str, or npos if not
|
||||
/// found.
|
||||
- size_t find(StringRef Str, size_t From = 0) const {
|
||||
+ size_t find(std::string_view Str, size_t From = 0) const {
|
||||
- [[nodiscard]] size_t find(StringRef Str, size_t From = 0) const {
|
||||
+ [[nodiscard]] size_t find(std::string_view Str, size_t From = 0) const {
|
||||
return str().find(Str, From);
|
||||
}
|
||||
|
||||
@@ -154,7 +155,7 @@ public:
|
||||
@@ -150,7 +155,8 @@ public:
|
||||
///
|
||||
/// \returns The index of the last occurrence of \p C, or npos if not
|
||||
/// found.
|
||||
- size_t rfind(char C, size_t From = StringRef::npos) const {
|
||||
+ size_t rfind(char C, size_t From = std::string_view::npos) const {
|
||||
- [[nodiscard]] size_t rfind(char C, size_t From = StringRef::npos) const {
|
||||
+ [[nodiscard]] size_t rfind(char C,
|
||||
+ size_t From = std::string_view::npos) const {
|
||||
return str().rfind(C, From);
|
||||
}
|
||||
|
||||
@@ -162,7 +163,7 @@ public:
|
||||
@@ -158,7 +164,9 @@ public:
|
||||
///
|
||||
/// \returns The index of the last occurrence of \p Str, or npos if not
|
||||
/// found.
|
||||
- size_t rfind(StringRef Str) const {
|
||||
+ size_t rfind(std::string_view Str) const {
|
||||
return str().rfind(Str);
|
||||
}
|
||||
- [[nodiscard]] size_t rfind(StringRef Str) const { return str().rfind(Str); }
|
||||
+ [[nodiscard]] size_t rfind(std::string_view Str) const {
|
||||
+ return str().rfind(Str);
|
||||
+ }
|
||||
|
||||
@@ -176,7 +177,7 @@ public:
|
||||
/// Find the first character in the string that is \p C, or npos if not
|
||||
/// found. Same as find.
|
||||
@@ -170,7 +178,8 @@ public:
|
||||
/// not found.
|
||||
///
|
||||
/// Complexity: O(size() + Chars.size())
|
||||
- size_t find_first_of(StringRef Chars, size_t From = 0) const {
|
||||
+ size_t find_first_of(std::string_view Chars, size_t From = 0) const {
|
||||
- [[nodiscard]] size_t find_first_of(StringRef Chars, size_t From = 0) const {
|
||||
+ [[nodiscard]] size_t find_first_of(std::string_view Chars,
|
||||
+ size_t From = 0) const {
|
||||
return str().find_first_of(Chars, From);
|
||||
}
|
||||
|
||||
@@ -190,13 +191,13 @@ public:
|
||||
@@ -184,15 +193,15 @@ public:
|
||||
/// \p Chars, or npos if not found.
|
||||
///
|
||||
/// Complexity: O(size() + Chars.size())
|
||||
- size_t find_first_not_of(StringRef Chars, size_t From = 0) const {
|
||||
+ size_t find_first_not_of(std::string_view Chars, size_t From = 0) const {
|
||||
- [[nodiscard]] size_t find_first_not_of(StringRef Chars,
|
||||
+ [[nodiscard]] size_t find_first_not_of(std::string_view Chars,
|
||||
size_t From = 0) const {
|
||||
return str().find_first_not_of(Chars, From);
|
||||
}
|
||||
|
||||
/// Find the last character in the string that is \p C, or npos if not
|
||||
/// found.
|
||||
- size_t find_last_of(char C, size_t From = StringRef::npos) const {
|
||||
+ size_t find_last_of(char C, size_t From = std::string_view::npos) const {
|
||||
- [[nodiscard]] size_t find_last_of(char C,
|
||||
- size_t From = StringRef::npos) const {
|
||||
+ [[nodiscard]] size_t find_last_of(
|
||||
+ char C, size_t From = std::string_view::npos) const {
|
||||
return str().find_last_of(C, From);
|
||||
}
|
||||
|
||||
@@ -205,7 +206,7 @@ public:
|
||||
@@ -200,8 +209,8 @@ public:
|
||||
/// found.
|
||||
///
|
||||
/// Complexity: O(size() + Chars.size())
|
||||
size_t find_last_of(
|
||||
- StringRef Chars, size_t From = StringRef::npos) const {
|
||||
- [[nodiscard]] size_t find_last_of(StringRef Chars,
|
||||
- size_t From = StringRef::npos) const {
|
||||
+ [[nodiscard]] size_t find_last_of(
|
||||
+ std::string_view Chars, size_t From = std::string_view::npos) const {
|
||||
return str().find_last_of(Chars, From);
|
||||
}
|
||||
|
||||
@@ -220,7 +221,7 @@ public:
|
||||
@@ -214,7 +223,9 @@ public:
|
||||
|
||||
/// Return the number of non-overlapped occurrences of \p Str in the
|
||||
/// string.
|
||||
- size_t count(StringRef Str) const {
|
||||
+ size_t count(std::string_view Str) const {
|
||||
return str().count(Str);
|
||||
}
|
||||
- [[nodiscard]] size_t count(StringRef Str) const { return str().count(Str); }
|
||||
+ [[nodiscard]] size_t count(std::string_view Str) const {
|
||||
+ return str().count(Str);
|
||||
+ }
|
||||
|
||||
@@ -237,7 +238,7 @@ public:
|
||||
/// @}
|
||||
/// @name Substring Operations
|
||||
@@ -229,8 +240,8 @@ public:
|
||||
/// \param N The number of characters to included in the substring. If \p N
|
||||
/// exceeds the number of characters remaining in the string, the string
|
||||
/// suffix (starting with \p Start) will be returned.
|
||||
- StringRef substr(size_t Start, size_t N = StringRef::npos) const {
|
||||
+ std::string_view substr(size_t Start, size_t N = std::string_view::npos) const {
|
||||
- [[nodiscard]] StringRef substr(size_t Start,
|
||||
- size_t N = StringRef::npos) const {
|
||||
+ [[nodiscard]] std::string_view substr(
|
||||
+ size_t Start, size_t N = std::string_view::npos) const {
|
||||
return str().substr(Start, N);
|
||||
}
|
||||
|
||||
@@ -251,14 +252,14 @@ public:
|
||||
@@ -244,15 +255,15 @@ public:
|
||||
/// substring. If this is npos, or less than \p Start, or exceeds the
|
||||
/// number of characters remaining in the string, the string suffix
|
||||
/// (starting with \p Start) will be returned.
|
||||
- StringRef slice(size_t Start, size_t End) const {
|
||||
+ std::string_view slice(size_t Start, size_t End) const {
|
||||
- [[nodiscard]] StringRef slice(size_t Start, size_t End) const {
|
||||
+ [[nodiscard]] std::string_view slice(size_t Start, size_t End) const {
|
||||
return str().slice(Start, End);
|
||||
}
|
||||
|
||||
// Extra methods.
|
||||
|
||||
- /// Explicit conversion to StringRef.
|
||||
- StringRef str() const { return StringRef(this->data(), this->size()); }
|
||||
- [[nodiscard]] StringRef str() const {
|
||||
- return StringRef(this->data(), this->size());
|
||||
+ /// Explicit conversion to std::string_view.
|
||||
+ std::string_view str() const { return std::string_view(this->begin(), this->size()); }
|
||||
+ [[nodiscard]] std::string_view str() const {
|
||||
+ return std::string_view(this->begin(), this->size());
|
||||
}
|
||||
|
||||
// TODO: Make this const, if it's safe...
|
||||
const char* c_str() {
|
||||
@@ -267,20 +268,20 @@ public:
|
||||
@@ -262,20 +273,20 @@ public:
|
||||
return this->data();
|
||||
}
|
||||
|
||||
@@ -315,7 +336,7 @@ index 0052c86fb37b82dcdf577a7acf06e3a47f54da61..4d673cc8b1c49cf8a3f19653de53881c
|
||||
return *this;
|
||||
}
|
||||
diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h
|
||||
index 53a107b1574c6a35c66c7fe3c61deb2ffc84b991..4559864ed231206b098936dae4fc378bfa986371 100644
|
||||
index 09676d792dfebd88e5c8eace666b3ab0044a962e..c96fd0e4956ee6d586f85dc79623de137e781ce0 100644
|
||||
--- a/llvm/include/llvm/ADT/SmallVector.h
|
||||
+++ b/llvm/include/llvm/ADT/SmallVector.h
|
||||
@@ -27,13 +27,12 @@
|
||||
@@ -333,7 +354,7 @@ index 53a107b1574c6a35c66c7fe3c61deb2ffc84b991..4559864ed231206b098936dae4fc378b
|
||||
template <typename IteratorT> class iterator_range;
|
||||
|
||||
template <class Iterator>
|
||||
@@ -117,7 +116,7 @@ template <class T, typename = void> struct SmallVectorAlignmentAndSize {
|
||||
@@ -127,7 +126,7 @@ template <class T, typename = void> struct SmallVectorAlignmentAndSize {
|
||||
};
|
||||
|
||||
/// This is the part of SmallVectorTemplateBase which does not depend on whether
|
||||
@@ -342,7 +363,7 @@ index 53a107b1574c6a35c66c7fe3c61deb2ffc84b991..4559864ed231206b098936dae4fc378b
|
||||
/// to avoid unnecessarily requiring T to be complete.
|
||||
template <typename T, typename = void>
|
||||
class SmallVectorTemplateCommon
|
||||
@@ -1233,7 +1232,7 @@ public:
|
||||
@@ -1242,7 +1241,7 @@ public:
|
||||
|
||||
template <typename U,
|
||||
typename = std::enable_if_t<std::is_convertible<U, T>::value>>
|
||||
@@ -576,10 +597,10 @@ index 98b51cc1aebd59eba20076e6d8a4eebc0eebb982..388e81c361642113937f7d5680de73a5
|
||||
|
||||
#endif // LLVM_ADT_STRINGMAPENTRY_H
|
||||
diff --git a/llvm/include/llvm/Support/Chrono.h b/llvm/include/llvm/Support/Chrono.h
|
||||
index 9c2bd45d2803e56ed316d8552d899d87f2fbbb07..a7dea19d9193bcff4bc6b553b80a10b2bc7b64af 100644
|
||||
index 71859af7c7e4a595140475daf356744f52d14d24..9c9ba7002310eba5113c14957f769702c61f4326 100644
|
||||
--- a/llvm/include/llvm/Support/Chrono.h
|
||||
+++ b/llvm/include/llvm/Support/Chrono.h
|
||||
@@ -70,7 +70,7 @@ raw_ostream &operator<<(raw_ostream &OS, sys::TimePoint<> TP);
|
||||
@@ -91,7 +91,7 @@ raw_ostream &operator<<(raw_ostream &OS, sys::UtcTime<> TP);
|
||||
template <>
|
||||
struct format_provider<sys::TimePoint<>> {
|
||||
static void format(const sys::TimePoint<> &TP, llvm::raw_ostream &OS,
|
||||
@@ -587,8 +608,8 @@ index 9c2bd45d2803e56ed316d8552d899d87f2fbbb07..a7dea19d9193bcff4bc6b553b80a10b2
|
||||
+ std::string_view Style);
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
@@ -122,7 +122,7 @@ private:
|
||||
template <> struct format_provider<sys::UtcTime<std::chrono::seconds>> {
|
||||
@@ -148,7 +148,7 @@ private:
|
||||
return duration_cast<duration<InternalRep, AsPeriod>>(D).count();
|
||||
}
|
||||
|
||||
@@ -597,7 +618,7 @@ index 9c2bd45d2803e56ed316d8552d899d87f2fbbb07..a7dea19d9193bcff4bc6b553b80a10b2
|
||||
const Dur &D) {
|
||||
using namespace std::chrono;
|
||||
if (Style.consume_front("ns"))
|
||||
@@ -140,7 +140,7 @@ private:
|
||||
@@ -166,7 +166,7 @@ private:
|
||||
return {D.count(), detail::unit<Period>::value};
|
||||
}
|
||||
|
||||
@@ -606,7 +627,7 @@ index 9c2bd45d2803e56ed316d8552d899d87f2fbbb07..a7dea19d9193bcff4bc6b553b80a10b2
|
||||
if (Style.empty())
|
||||
return true;
|
||||
if (Style.consume_front("-"))
|
||||
@@ -152,9 +152,9 @@ private:
|
||||
@@ -178,9 +178,9 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -619,10 +640,10 @@ index 9c2bd45d2803e56ed316d8552d899d87f2fbbb07..a7dea19d9193bcff4bc6b553b80a10b2
|
||||
bool show_unit = consumeShowUnit(Style);
|
||||
|
||||
diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
|
||||
index 10d5cec231a523c943c37a5464cb3943627239a9..92376629c607461061bc60597a47aed1e535af52 100644
|
||||
index 8c315d255bb772d9e3c100adbd2c07b61283219b..6789f0413d8dc94cb465b6e66506b036449ee186 100644
|
||||
--- a/llvm/include/llvm/Support/Compiler.h
|
||||
+++ b/llvm/include/llvm/Support/Compiler.h
|
||||
@@ -300,7 +300,7 @@
|
||||
@@ -319,7 +319,7 @@
|
||||
#endif
|
||||
|
||||
/// LLVM_GSL_POINTER - Apply this to non-owning classes like
|
||||
@@ -800,18 +821,18 @@ index f7f2d4e54e705d6f29812dc93d1fb0a3ca2dee12..b5e321b5f74ce35940649b9d1342b3cd
|
||||
BufferKind getBufferKind() const override { return MemoryBuffer_Malloc; }
|
||||
|
||||
diff --git a/llvm/include/llvm/Support/VersionTuple.h b/llvm/include/llvm/Support/VersionTuple.h
|
||||
index 828a6db54708dfa9a1a4b4456a92945a92ad80cb..953b40701dc934c1a356b5413c9c6c692d5f5679 100644
|
||||
index 0a4623f049d28825530bf50c8acfe85deaed96ba..e1cdce77ce8659305c99a21e01f9b3cc3481a5fd 100644
|
||||
--- a/llvm/include/llvm/Support/VersionTuple.h
|
||||
+++ b/llvm/include/llvm/Support/VersionTuple.h
|
||||
@@ -25,7 +25,6 @@ namespace llvm {
|
||||
template <typename HasherT, support::endianness Endianness>
|
||||
class HashBuilderImpl;
|
||||
@@ -23,7 +23,6 @@
|
||||
namespace llvm {
|
||||
template <typename HasherT, llvm::endianness Endianness> class HashBuilder;
|
||||
class raw_ostream;
|
||||
-class StringRef;
|
||||
|
||||
/// Represents a version number in the form major[.minor[.subminor[.build]]].
|
||||
class VersionTuple {
|
||||
@@ -182,11 +181,6 @@ public:
|
||||
@@ -180,11 +179,6 @@ public:
|
||||
|
||||
/// Retrieve a string representation of the version number.
|
||||
std::string getAsString() const;
|
||||
@@ -846,7 +867,7 @@ index d3aacd14b2097b1e7e13c1003987c1fd52e0cf76..aabdb2f14668a990329b57f5454a0d7d
|
||||
|
||||
template <typename HandleTraits>
|
||||
diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h
|
||||
index 1e01eb9ea19c4187302a91457b6d34fbe5b67584..2463f1af612a78cafafe3c0e16d496e607cdc322 100644
|
||||
index 42663a9adf2e51ae36209faf7d465094adbf0943..9345348d9ba555022b31f94299684316ffa15939 100644
|
||||
--- a/llvm/include/llvm/Support/raw_ostream.h
|
||||
+++ b/llvm/include/llvm/Support/raw_ostream.h
|
||||
@@ -14,13 +14,12 @@
|
||||
@@ -944,9 +965,9 @@ index 1e01eb9ea19c4187302a91457b6d34fbe5b67584..2463f1af612a78cafafe3c0e16d496e6
|
||||
- raw_fd_stream(StringRef Filename, std::error_code &EC);
|
||||
+ raw_fd_stream(std::string_view Filename, std::error_code &EC);
|
||||
|
||||
/// This reads the \p Size bytes into a buffer pointed by \p Ptr.
|
||||
///
|
||||
@@ -693,8 +703,8 @@ public:
|
||||
raw_fd_stream(int fd, bool shouldClose);
|
||||
|
||||
@@ -695,8 +705,8 @@ public:
|
||||
|
||||
void flush() = delete;
|
||||
|
||||
@@ -957,7 +978,7 @@ index 1e01eb9ea19c4187302a91457b6d34fbe5b67584..2463f1af612a78cafafe3c0e16d496e6
|
||||
|
||||
void reserveExtraSpace(uint64_t ExtraSize) override {
|
||||
OS.reserve(tell() + ExtraSize);
|
||||
@@ -751,7 +761,7 @@ class Error;
|
||||
@@ -753,7 +763,7 @@ class Error;
|
||||
/// for other names. For raw_fd_ostream instances, the stream writes to
|
||||
/// a temporary file. The final output file is atomically replaced with the
|
||||
/// temporary file after the \p Write function is finished.
|
||||
@@ -1178,7 +1199,7 @@ index b8b3b7424ac6b1de782e739782f9671194ce77a1..0aa13a0f78eb370b2a673ca4a773f268
|
||||
(void)written; // If something went wrong, we deliberately just give up.
|
||||
}
|
||||
diff --git a/llvm/lib/Support/SmallVector.cpp b/llvm/lib/Support/SmallVector.cpp
|
||||
index f7e7e80332cc337f6dfa388d1e218e6f3ec95cf2..6cefdff7c28060ca18b522acf5279af3a206e23a 100644
|
||||
index b6ce37842040b36fc79770ca0296255f2bb42a1a..4f6fee18b659adcbfd79822832f914170cbb1635 100644
|
||||
--- a/llvm/lib/Support/SmallVector.cpp
|
||||
+++ b/llvm/lib/Support/SmallVector.cpp
|
||||
@@ -11,7 +11,6 @@
|
||||
@@ -1265,10 +1286,10 @@ index 67c05a87959cf0c243d17646ae2f28f6c9f0d708..7be219323f6d76f32a9a841115f2f146
|
||||
if (Bucket == -1)
|
||||
return nullptr;
|
||||
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
|
||||
index a4fc605019c211f93dde009e89e7a79b07400aa3..9966a0056ae4f24a7a38346ee1c2f5d83ac20248 100644
|
||||
index 3d3a564af51d120786b358b96a3c90e2b7fbf9f3..220d850b9bc69f8fc2fba7cd23629eca487cde23 100644
|
||||
--- a/llvm/lib/Support/raw_ostream.cpp
|
||||
+++ b/llvm/lib/Support/raw_ostream.cpp
|
||||
@@ -166,7 +166,7 @@ raw_ostream &raw_ostream::write_uuid(const uuid_t UUID) {
|
||||
@@ -167,7 +167,7 @@ raw_ostream &raw_ostream::write_uuid(const uuid_t UUID) {
|
||||
}
|
||||
|
||||
|
||||
@@ -1277,7 +1298,7 @@ index a4fc605019c211f93dde009e89e7a79b07400aa3..9966a0056ae4f24a7a38346ee1c2f5d8
|
||||
bool UseHexEscapes) {
|
||||
for (unsigned char c : Str) {
|
||||
switch (c) {
|
||||
@@ -569,7 +569,7 @@ void format_object_base::home() {
|
||||
@@ -570,7 +570,7 @@ void format_object_base::home() {
|
||||
// raw_fd_ostream
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@@ -1286,7 +1307,7 @@ index a4fc605019c211f93dde009e89e7a79b07400aa3..9966a0056ae4f24a7a38346ee1c2f5d8
|
||||
sys::fs::CreationDisposition Disp, sys::fs::FileAccess Access,
|
||||
sys::fs::OpenFlags Flags) {
|
||||
assert((Access & sys::fs::FA_Write) &&
|
||||
@@ -595,25 +595,25 @@ static int getFD(StringRef Filename, std::error_code &EC,
|
||||
@@ -596,25 +596,25 @@ static int getFD(StringRef Filename, std::error_code &EC,
|
||||
return FD;
|
||||
}
|
||||
|
||||
@@ -1317,7 +1338,7 @@ index a4fc605019c211f93dde009e89e7a79b07400aa3..9966a0056ae4f24a7a38346ee1c2f5d8
|
||||
sys::fs::CreationDisposition Disp,
|
||||
sys::fs::FileAccess Access,
|
||||
sys::fs::OpenFlags Flags)
|
||||
@@ -685,8 +685,7 @@ raw_fd_ostream::~raw_fd_ostream() {
|
||||
@@ -686,8 +686,7 @@ raw_fd_ostream::~raw_fd_ostream() {
|
||||
// has_error() and clear the error flag with clear_error() before
|
||||
// destructing raw_ostream objects which may have errors.
|
||||
if (has_error())
|
||||
@@ -1327,7 +1348,7 @@ index a4fc605019c211f93dde009e89e7a79b07400aa3..9966a0056ae4f24a7a38346ee1c2f5d8
|
||||
/*gen_crash_diag=*/false);
|
||||
}
|
||||
|
||||
@@ -705,7 +704,7 @@ raw_fd_ostream::~raw_fd_ostream() {
|
||||
@@ -706,7 +705,7 @@ raw_fd_ostream::~raw_fd_ostream() {
|
||||
// the input is UTF-8 or transcode from the local codepage to UTF-8 before
|
||||
// quoting it. If they don't, this may mess up the encoding, but this is still
|
||||
// probably the best compromise we can make.
|
||||
@@ -1336,7 +1357,7 @@ index a4fc605019c211f93dde009e89e7a79b07400aa3..9966a0056ae4f24a7a38346ee1c2f5d8
|
||||
SmallVector<wchar_t, 256> WideText;
|
||||
|
||||
// Fall back to ::write if it wasn't valid UTF-8.
|
||||
@@ -748,7 +747,7 @@ void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) {
|
||||
@@ -749,7 +748,7 @@ void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) {
|
||||
// If this is a Windows console device, try re-encoding from UTF-8 to UTF-16
|
||||
// and using WriteConsoleW. If that fails, fall back to plain write().
|
||||
if (IsWindowsConsole)
|
||||
@@ -1345,7 +1366,7 @@ index a4fc605019c211f93dde009e89e7a79b07400aa3..9966a0056ae4f24a7a38346ee1c2f5d8
|
||||
return;
|
||||
#endif
|
||||
|
||||
@@ -919,7 +918,7 @@ raw_ostream &llvm::nulls() {
|
||||
@@ -925,7 +924,7 @@ raw_ostream &llvm::nulls() {
|
||||
// File Streams
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@@ -1354,7 +1375,7 @@ index a4fc605019c211f93dde009e89e7a79b07400aa3..9966a0056ae4f24a7a38346ee1c2f5d8
|
||||
: raw_fd_ostream(getFD(Filename, EC, sys::fs::CD_CreateAlways,
|
||||
sys::fs::FA_Write | sys::fs::FA_Read,
|
||||
sys::fs::OF_None),
|
||||
@@ -997,7 +996,7 @@ void buffer_ostream::anchor() {}
|
||||
@@ -998,7 +997,7 @@ void buffer_ostream::anchor() {}
|
||||
|
||||
void buffer_unique_ostream::anchor() {}
|
||||
|
||||
@@ -1493,7 +1514,7 @@ index fc856a976946bf6decda9b6724cac66afc7bdcd6..aff9d61c7f0d48834123b04b74a2e4f7
|
||||
TEST(UniqueFunctionTest, SFINAE) {
|
||||
EXPECT_EQ("not a function", returns("boo!"));
|
||||
diff --git a/llvm/unittests/ADT/HashingTest.cpp b/llvm/unittests/ADT/HashingTest.cpp
|
||||
index 01a8a962b8e2e33ca8f189c049e9548ced42ec3a..62aff9c3b21eea785ca71c6e290c9c4f3a20ae00 100644
|
||||
index ab13ee833ce556945fb9526fd13d8bd5f3e5c95a..3e80467ebd0efddcf2cbbe003bb91f1475ca9cb3 100644
|
||||
--- a/llvm/unittests/ADT/HashingTest.cpp
|
||||
+++ b/llvm/unittests/ADT/HashingTest.cpp
|
||||
@@ -295,7 +295,7 @@ TEST(HashingTest, HashCombineRangeGoldenTest) {
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sat, 7 May 2022 22:12:41 -0400
|
||||
Subject: [PATCH 02/34] Wrap std::min/max calls in parens, for Windows warnings
|
||||
Subject: [PATCH 02/35] Wrap std::min/max calls in parens, for Windows warnings
|
||||
|
||||
---
|
||||
llvm/include/llvm/ADT/DenseMap.h | 4 ++--
|
||||
llvm/include/llvm/ADT/SmallVector.h | 12 ++++++------
|
||||
llvm/include/llvm/ADT/SmallVector.h | 6 +++---
|
||||
llvm/include/llvm/Support/ConvertUTF.h | 2 +-
|
||||
llvm/include/llvm/Support/MathExtras.h | 18 +++++++++---------
|
||||
4 files changed, 18 insertions(+), 18 deletions(-)
|
||||
4 files changed, 15 insertions(+), 15 deletions(-)
|
||||
|
||||
diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h
|
||||
index 3ef6a7cd1b4b587e61fcb9475d9f3516018bf2ee..108193f04486425f3b7f039cd9d2004be6facafb 100644
|
||||
@@ -33,10 +33,10 @@ index 3ef6a7cd1b4b587e61fcb9475d9f3516018bf2ee..108193f04486425f3b7f039cd9d2004b
|
||||
this->BaseT::initEmpty();
|
||||
return;
|
||||
diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h
|
||||
index 4559864ed231206b098936dae4fc378bfa986371..84f4d0931a30f4be29549354c85cb4c0489e14c9 100644
|
||||
index c96fd0e4956ee6d586f85dc79623de137e781ce0..d7600fe209a58deb07c63e2553f9dad62e06e973 100644
|
||||
--- a/llvm/include/llvm/ADT/SmallVector.h
|
||||
+++ b/llvm/include/llvm/ADT/SmallVector.h
|
||||
@@ -55,12 +55,12 @@ protected:
|
||||
@@ -55,7 +55,7 @@ protected:
|
||||
|
||||
/// The maximum value of the Size_T used.
|
||||
static constexpr size_t SizeTypeMax() {
|
||||
@@ -45,22 +45,7 @@ index 4559864ed231206b098936dae4fc378bfa986371..84f4d0931a30f4be29549354c85cb4c0
|
||||
}
|
||||
|
||||
SmallVectorBase() = delete;
|
||||
SmallVectorBase(void *FirstEl, size_t TotalCapacity)
|
||||
- : BeginX(FirstEl), Capacity(TotalCapacity) {}
|
||||
+ : BeginX(FirstEl), Capacity(static_cast<unsigned>(TotalCapacity)) {}
|
||||
|
||||
/// This is a helper for \a grow() that's out of line to reduce code
|
||||
/// duplication. This function will report a fatal error if it can't grow at
|
||||
@@ -99,7 +99,7 @@ protected:
|
||||
/// This does not construct or destroy any elements in the vector.
|
||||
void set_size(size_t N) {
|
||||
assert(N <= capacity());
|
||||
- Size = N;
|
||||
+ Size = static_cast<unsigned>(N);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -279,7 +279,7 @@ public:
|
||||
@@ -289,7 +289,7 @@ public:
|
||||
|
||||
size_type size_in_bytes() const { return size() * sizeof(T); }
|
||||
size_type max_size() const {
|
||||
@@ -69,16 +54,7 @@ index 4559864ed231206b098936dae4fc378bfa986371..84f4d0931a30f4be29549354c85cb4c0
|
||||
}
|
||||
|
||||
size_t capacity_in_bytes() const { return capacity() * sizeof(T); }
|
||||
@@ -467,7 +467,7 @@ void SmallVectorTemplateBase<T, TriviallyCopyable>::takeAllocationForGrow(
|
||||
free(this->begin());
|
||||
|
||||
this->BeginX = NewElts;
|
||||
- this->Capacity = NewCapacity;
|
||||
+ this->Capacity = static_cast<unsigned>(NewCapacity);
|
||||
}
|
||||
|
||||
/// SmallVectorTemplateBase<TriviallyCopyable = true> - This is where we put
|
||||
@@ -712,7 +712,7 @@ public:
|
||||
@@ -721,7 +721,7 @@ public:
|
||||
}
|
||||
|
||||
// Assign over existing elements.
|
||||
@@ -101,7 +77,7 @@ index 5c0e3009c25446a34882fb98329b1d955231bb39..72321022beb373945f7935ed72944fd6
|
||||
/* Some fundamental constants */
|
||||
#define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
|
||||
diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h
|
||||
index dc095941fdc8a9f2b3b822e6e014f0640676c0d3..0bd572d07fcbf2ff56998dbf366215068b62f527 100644
|
||||
index aa4f4d2ed42e262f27e3f7f5ce275baf7e556c2d..5cabfdd6493fee33fbc74b831dc1fa3c91ba725d 100644
|
||||
--- a/llvm/include/llvm/Support/MathExtras.h
|
||||
+++ b/llvm/include/llvm/Support/MathExtras.h
|
||||
@@ -311,26 +311,26 @@ template <> constexpr inline size_t CTLog2<1>() { return 0; }
|
||||
@@ -135,7 +111,7 @@ index dc095941fdc8a9f2b3b822e6e014f0640676c0d3..0bd572d07fcbf2ff56998dbf36621506
|
||||
}
|
||||
|
||||
/// A and B are either alignments or offsets. Return the minimum alignment that
|
||||
@@ -479,7 +479,7 @@ SaturatingAdd(T X, T Y, bool *ResultOverflowed = nullptr) {
|
||||
@@ -482,7 +482,7 @@ SaturatingAdd(T X, T Y, bool *ResultOverflowed = nullptr) {
|
||||
T Z = X + Y;
|
||||
Overflowed = (Z < X || Z < Y);
|
||||
if (Overflowed)
|
||||
@@ -144,7 +120,7 @@ index dc095941fdc8a9f2b3b822e6e014f0640676c0d3..0bd572d07fcbf2ff56998dbf36621506
|
||||
else
|
||||
return Z;
|
||||
}
|
||||
@@ -492,7 +492,7 @@ std::enable_if_t<std::is_unsigned_v<T>, T> SaturatingAdd(T X, T Y, T Z,
|
||||
@@ -495,7 +495,7 @@ std::enable_if_t<std::is_unsigned_v<T>, T> SaturatingAdd(T X, T Y, T Z,
|
||||
bool Overflowed = false;
|
||||
T XY = SaturatingAdd(X, Y, &Overflowed);
|
||||
if (Overflowed)
|
||||
@@ -153,7 +129,7 @@ index dc095941fdc8a9f2b3b822e6e014f0640676c0d3..0bd572d07fcbf2ff56998dbf36621506
|
||||
return SaturatingAdd(XY, Z, Args...);
|
||||
}
|
||||
|
||||
@@ -516,7 +516,7 @@ SaturatingMultiply(T X, T Y, bool *ResultOverflowed = nullptr) {
|
||||
@@ -519,7 +519,7 @@ SaturatingMultiply(T X, T Y, bool *ResultOverflowed = nullptr) {
|
||||
// Special case: if X or Y is 0, Log2_64 gives -1, and Log2Z
|
||||
// will necessarily be less than Log2Max as desired.
|
||||
int Log2Z = Log2_64(X) + Log2_64(Y);
|
||||
@@ -162,7 +138,7 @@ index dc095941fdc8a9f2b3b822e6e014f0640676c0d3..0bd572d07fcbf2ff56998dbf36621506
|
||||
int Log2Max = Log2_64(Max);
|
||||
if (Log2Z < Log2Max) {
|
||||
return X * Y;
|
||||
@@ -636,9 +636,9 @@ std::enable_if_t<std::is_signed_v<T>, T> MulOverflow(T X, T Y, T &Result) {
|
||||
@@ -639,9 +639,9 @@ std::enable_if_t<std::is_signed_v<T>, T> MulOverflow(T X, T Y, T &Result) {
|
||||
// Check how the max allowed absolute value (2^n for negative, 2^(n-1) for
|
||||
// positive) divided by an argument compares to the other.
|
||||
if (IsNegative)
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sat, 7 May 2022 22:13:55 -0400
|
||||
Subject: [PATCH 03/34] Change unique_function storage size
|
||||
Subject: [PATCH 03/35] Change unique_function storage size
|
||||
|
||||
---
|
||||
llvm/include/llvm/ADT/FunctionExtras.h | 4 ++--
|
||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/llvm/include/llvm/ADT/FunctionExtras.h b/llvm/include/llvm/ADT/FunctionExtras.h
|
||||
index 4cf1de488c7bde2692d4878ccb4c4d60241e3a66..9d10b16e3cbe9c0df818a3254fcd3a6032d54b39 100644
|
||||
index c0bc30c7450fe4b2bc6b9b448824eedc8b132e52..5641a913d0a35ee2911cf872ad90c3dc864f20f5 100644
|
||||
--- a/llvm/include/llvm/ADT/FunctionExtras.h
|
||||
+++ b/llvm/include/llvm/ADT/FunctionExtras.h
|
||||
@@ -78,7 +78,7 @@ using EnableIfCallable = std::enable_if_t<std::disjunction<
|
||||
@@ -79,7 +79,7 @@ using EnableIfCallable = std::enable_if_t<std::disjunction<
|
||||
|
||||
template <typename ReturnT, typename... ParamTs> class UniqueFunctionBase {
|
||||
protected:
|
||||
@@ -20,7 +20,7 @@ index 4cf1de488c7bde2692d4878ccb4c4d60241e3a66..9d10b16e3cbe9c0df818a3254fcd3a60
|
||||
|
||||
template <typename T, class = void>
|
||||
struct IsSizeLessThanThresholdT : std::false_type {};
|
||||
@@ -157,7 +157,7 @@ protected:
|
||||
@@ -158,7 +158,7 @@ protected:
|
||||
"Should always use all of the out-of-line storage for inline storage!");
|
||||
|
||||
// For in-line storage, we just provide an aligned character buffer. We
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sat, 7 May 2022 22:17:19 -0400
|
||||
Subject: [PATCH 04/34] Threading updates
|
||||
Subject: [PATCH 04/35] Threading updates
|
||||
|
||||
- Remove guards for threads and exception
|
||||
- Prefer scope gaurd over lock gaurd
|
||||
@@ -12,10 +12,10 @@ Subject: [PATCH 04/34] Threading updates
|
||||
3 files changed, 11 insertions(+), 43 deletions(-)
|
||||
|
||||
diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
|
||||
index 92376629c607461061bc60597a47aed1e535af52..2662839b27bf368cd5da0668099c4b44cbc6435d 100644
|
||||
index 6789f0413d8dc94cb465b6e66506b036449ee186..e608f8ea3a837a04d9c29c8bb7a1fab527d512bb 100644
|
||||
--- a/llvm/include/llvm/Support/Compiler.h
|
||||
+++ b/llvm/include/llvm/Support/Compiler.h
|
||||
@@ -530,7 +530,6 @@ void AnnotateIgnoreWritesEnd(const char *file, int line);
|
||||
@@ -555,7 +555,6 @@ void AnnotateIgnoreWritesEnd(const char *file, int line);
|
||||
/// initialize to some constant value. In almost all circumstances this is most
|
||||
/// appropriate for use with a pointer, integer, or small aggregation of
|
||||
/// pointers and integers.
|
||||
@@ -23,7 +23,7 @@ index 92376629c607461061bc60597a47aed1e535af52..2662839b27bf368cd5da0668099c4b44
|
||||
#if __has_feature(cxx_thread_local) || defined(_MSC_VER)
|
||||
#define LLVM_THREAD_LOCAL thread_local
|
||||
#else
|
||||
@@ -538,11 +537,6 @@ void AnnotateIgnoreWritesEnd(const char *file, int line);
|
||||
@@ -563,11 +562,6 @@ void AnnotateIgnoreWritesEnd(const char *file, int line);
|
||||
// we only need the restricted functionality that provides.
|
||||
#define LLVM_THREAD_LOCAL __thread
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sat, 7 May 2022 22:28:13 -0400
|
||||
Subject: [PATCH 05/34] \#ifdef guard safety
|
||||
Subject: [PATCH 05/35] \#ifdef guard safety
|
||||
|
||||
Prevents redefinition if someone is pulling in real LLVM, since the macros are in global namespace
|
||||
---
|
||||
@@ -9,7 +9,7 @@ Prevents redefinition if someone is pulling in real LLVM, since the macros are i
|
||||
1 file changed, 42 insertions(+)
|
||||
|
||||
diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
|
||||
index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e848519998685b 100644
|
||||
index e608f8ea3a837a04d9c29c8bb7a1fab527d512bb..8f68d79898fe0247f9e17709bf1c1ec2a451c037 100644
|
||||
--- a/llvm/include/llvm/Support/Compiler.h
|
||||
+++ b/llvm/include/llvm/Support/Compiler.h
|
||||
@@ -90,6 +90,7 @@
|
||||
@@ -50,7 +50,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851
|
||||
|
||||
#if defined(__clang__)
|
||||
#define LLVM_DEPRECATED(MSG, FIX) __attribute__((deprecated(MSG, FIX)))
|
||||
@@ -178,11 +184,13 @@
|
||||
@@ -197,11 +203,13 @@
|
||||
// more portable solution:
|
||||
// (void)unused_var_name;
|
||||
// Prefer cast-to-void wherever it is sufficient.
|
||||
@@ -64,7 +64,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851
|
||||
|
||||
// FIXME: Provide this for PE/COFF targets.
|
||||
#if __has_attribute(weak) && !defined(__MINGW32__) && !defined(__CYGWIN__) && \
|
||||
@@ -192,6 +200,7 @@
|
||||
@@ -211,6 +219,7 @@
|
||||
#define LLVM_ATTRIBUTE_WEAK
|
||||
#endif
|
||||
|
||||
@@ -72,7 +72,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851
|
||||
// Prior to clang 3.2, clang did not accept any spelling of
|
||||
// __has_attribute(const), so assume it is supported.
|
||||
#if defined(__clang__) || defined(__GNUC__)
|
||||
@@ -200,13 +209,16 @@
|
||||
@@ -219,13 +228,16 @@
|
||||
#else
|
||||
#define LLVM_READNONE
|
||||
#endif
|
||||
@@ -89,7 +89,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851
|
||||
|
||||
#if __has_attribute(minsize)
|
||||
#define LLVM_ATTRIBUTE_MINSIZE __attribute__((minsize))
|
||||
@@ -214,6 +226,7 @@
|
||||
@@ -233,6 +245,7 @@
|
||||
#define LLVM_ATTRIBUTE_MINSIZE
|
||||
#endif
|
||||
|
||||
@@ -97,7 +97,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851
|
||||
#if __has_builtin(__builtin_expect) || defined(__GNUC__)
|
||||
#define LLVM_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true)
|
||||
#define LLVM_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false)
|
||||
@@ -221,9 +234,11 @@
|
||||
@@ -240,9 +253,11 @@
|
||||
#define LLVM_LIKELY(EXPR) (EXPR)
|
||||
#define LLVM_UNLIKELY(EXPR) (EXPR)
|
||||
#endif
|
||||
@@ -109,7 +109,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851
|
||||
#if __has_attribute(noinline)
|
||||
#define LLVM_ATTRIBUTE_NOINLINE __attribute__((noinline))
|
||||
#elif defined(_MSC_VER)
|
||||
@@ -231,9 +246,11 @@
|
||||
@@ -250,9 +265,11 @@
|
||||
#else
|
||||
#define LLVM_ATTRIBUTE_NOINLINE
|
||||
#endif
|
||||
@@ -121,7 +121,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851
|
||||
#if __has_attribute(always_inline)
|
||||
#define LLVM_ATTRIBUTE_ALWAYS_INLINE inline __attribute__((always_inline))
|
||||
#elif defined(_MSC_VER)
|
||||
@@ -241,6 +258,7 @@
|
||||
@@ -260,6 +277,7 @@
|
||||
#else
|
||||
#define LLVM_ATTRIBUTE_ALWAYS_INLINE inline
|
||||
#endif
|
||||
@@ -129,7 +129,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851
|
||||
|
||||
/// LLVM_ATTRIBUTE_NO_DEBUG - On compilers where we have a directive to do
|
||||
/// so, mark a method "no debug" because debug info makes the debugger
|
||||
@@ -251,6 +269,7 @@
|
||||
@@ -270,6 +288,7 @@
|
||||
#define LLVM_ATTRIBUTE_NODEBUG
|
||||
#endif
|
||||
|
||||
@@ -137,7 +137,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851
|
||||
#if __has_attribute(returns_nonnull)
|
||||
#define LLVM_ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull))
|
||||
#elif defined(_MSC_VER)
|
||||
@@ -258,9 +277,11 @@
|
||||
@@ -277,9 +296,11 @@
|
||||
#else
|
||||
#define LLVM_ATTRIBUTE_RETURNS_NONNULL
|
||||
#endif
|
||||
@@ -149,7 +149,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851
|
||||
#ifdef __GNUC__
|
||||
#define LLVM_ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__))
|
||||
#elif defined(_MSC_VER)
|
||||
@@ -268,8 +289,10 @@
|
||||
@@ -287,8 +308,10 @@
|
||||
#else
|
||||
#define LLVM_ATTRIBUTE_RETURNS_NOALIAS
|
||||
#endif
|
||||
@@ -160,7 +160,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851
|
||||
#if defined(__cplusplus) && __cplusplus > 201402L && LLVM_HAS_CPP_ATTRIBUTE(fallthrough)
|
||||
#define LLVM_FALLTHROUGH [[fallthrough]]
|
||||
#elif LLVM_HAS_CPP_ATTRIBUTE(gnu::fallthrough)
|
||||
@@ -281,6 +304,7 @@
|
||||
@@ -300,6 +323,7 @@
|
||||
#else
|
||||
#define LLVM_FALLTHROUGH
|
||||
#endif
|
||||
@@ -168,7 +168,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851
|
||||
|
||||
/// LLVM_REQUIRE_CONSTANT_INITIALIZATION - Apply this to globals to ensure that
|
||||
/// they are constant initialized.
|
||||
@@ -309,11 +333,13 @@
|
||||
@@ -334,11 +358,13 @@
|
||||
|
||||
/// LLVM_EXTENSION - Support compilers where we have a keyword to suppress
|
||||
/// pedantic diagnostics.
|
||||
@@ -182,7 +182,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851
|
||||
|
||||
/// LLVM_BUILTIN_UNREACHABLE - On compilers which support it, expands
|
||||
/// to an expression which states that it is undefined behavior for the
|
||||
@@ -322,14 +348,17 @@
|
||||
@@ -347,14 +373,17 @@
|
||||
/// '#else' is intentionally left out so that other macro logic (e.g.,
|
||||
/// LLVM_ASSUME_ALIGNED and llvm_unreachable()) can detect whether
|
||||
/// LLVM_BUILTIN_UNREACHABLE has a definition.
|
||||
@@ -200,7 +200,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851
|
||||
#if __has_builtin(__builtin_trap) || defined(__GNUC__)
|
||||
# define LLVM_BUILTIN_TRAP __builtin_trap()
|
||||
#elif defined(_MSC_VER)
|
||||
@@ -341,10 +370,12 @@
|
||||
@@ -366,10 +395,12 @@
|
||||
#else
|
||||
# define LLVM_BUILTIN_TRAP *(volatile int*)0x11 = 0
|
||||
#endif
|
||||
@@ -213,7 +213,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851
|
||||
#if __has_builtin(__builtin_debugtrap)
|
||||
# define LLVM_BUILTIN_DEBUGTRAP __builtin_debugtrap()
|
||||
#elif defined(_MSC_VER)
|
||||
@@ -358,9 +389,11 @@
|
||||
@@ -383,9 +414,11 @@
|
||||
// program to abort if encountered.
|
||||
# define LLVM_BUILTIN_DEBUGTRAP
|
||||
#endif
|
||||
@@ -225,7 +225,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851
|
||||
#if __has_builtin(__builtin_assume_aligned) || defined(__GNUC__)
|
||||
# define LLVM_ASSUME_ALIGNED(p, a) __builtin_assume_aligned(p, a)
|
||||
#elif defined(LLVM_BUILTIN_UNREACHABLE)
|
||||
@@ -369,6 +402,7 @@
|
||||
@@ -394,6 +427,7 @@
|
||||
#else
|
||||
# define LLVM_ASSUME_ALIGNED(p, a) (p)
|
||||
#endif
|
||||
@@ -233,7 +233,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851
|
||||
|
||||
/// \macro LLVM_PACKED
|
||||
/// Used to specify a packed structure.
|
||||
@@ -388,6 +422,7 @@
|
||||
@@ -413,6 +447,7 @@
|
||||
/// long long l;
|
||||
/// };
|
||||
/// LLVM_PACKED_END
|
||||
@@ -241,7 +241,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851
|
||||
#ifdef _MSC_VER
|
||||
# define LLVM_PACKED(d) __pragma(pack(push, 1)) d __pragma(pack(pop))
|
||||
# define LLVM_PACKED_START __pragma(pack(push, 1))
|
||||
@@ -397,6 +432,7 @@
|
||||
@@ -422,6 +457,7 @@
|
||||
# define LLVM_PACKED_START _Pragma("pack(push, 1)")
|
||||
# define LLVM_PACKED_END _Pragma("pack(pop)")
|
||||
#endif
|
||||
@@ -249,7 +249,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851
|
||||
|
||||
/// \macro LLVM_MEMORY_SANITIZER_BUILD
|
||||
/// Whether LLVM itself is built with MemorySanitizer instrumentation.
|
||||
@@ -488,11 +524,13 @@ void AnnotateIgnoreWritesEnd(const char *file, int line);
|
||||
@@ -513,11 +549,13 @@ void AnnotateIgnoreWritesEnd(const char *file, int line);
|
||||
|
||||
/// \macro LLVM_NO_SANITIZE
|
||||
/// Disable a particular sanitizer for a function.
|
||||
@@ -263,7 +263,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851
|
||||
|
||||
/// Mark debug helper function definitions like dump() that should not be
|
||||
/// stripped from debug builds.
|
||||
@@ -500,17 +538,20 @@ void AnnotateIgnoreWritesEnd(const char *file, int line);
|
||||
@@ -525,17 +563,20 @@ void AnnotateIgnoreWritesEnd(const char *file, int line);
|
||||
/// `#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)` so they do always
|
||||
/// get stripped in release builds.
|
||||
// FIXME: Move this to a private config.h as it's not usable in public headers.
|
||||
@@ -284,7 +284,7 @@ index 2662839b27bf368cd5da0668099c4b44cbc6435d..ce75702c8c6f99780ecdb6dc77e84851
|
||||
#if defined(_MSC_VER)
|
||||
#define LLVM_PRETTY_FUNCTION __FUNCSIG__
|
||||
#elif defined(__GNUC__) || defined(__clang__)
|
||||
@@ -518,6 +559,7 @@ void AnnotateIgnoreWritesEnd(const char *file, int line);
|
||||
@@ -543,6 +584,7 @@ void AnnotateIgnoreWritesEnd(const char *file, int line);
|
||||
#else
|
||||
#define LLVM_PRETTY_FUNCTION __func__
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sat, 7 May 2022 22:37:34 -0400
|
||||
Subject: [PATCH 06/34] Explicitly use std::
|
||||
Subject: [PATCH 06/35] Explicitly use std::
|
||||
|
||||
---
|
||||
llvm/include/llvm/ADT/SmallSet.h | 2 +-
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sat, 7 May 2022 22:53:50 -0400
|
||||
Subject: [PATCH 07/34] Remove format_provider
|
||||
Subject: [PATCH 07/35] Remove format_provider
|
||||
|
||||
---
|
||||
llvm/include/llvm/Support/Chrono.h | 109 ------------------------
|
||||
llvm/include/llvm/Support/Chrono.h | 114 ------------------------
|
||||
llvm/include/llvm/Support/raw_ostream.h | 6 --
|
||||
llvm/unittests/Support/Chrono.cpp | 67 ---------------
|
||||
3 files changed, 182 deletions(-)
|
||||
llvm/unittests/Support/Chrono.cpp | 67 --------------
|
||||
3 files changed, 187 deletions(-)
|
||||
|
||||
diff --git a/llvm/include/llvm/Support/Chrono.h b/llvm/include/llvm/Support/Chrono.h
|
||||
index a7dea19d9193bcff4bc6b553b80a10b2bc7b64af..9f9a2b5cab270327898cee3f97d9ae7cf77eb564 100644
|
||||
index 9c9ba7002310eba5113c14957f769702c61f4326..b269ff8bb5db7bb3c62c3a87daf255b18ece4cd7 100644
|
||||
--- a/llvm/include/llvm/Support/Chrono.h
|
||||
+++ b/llvm/include/llvm/Support/Chrono.h
|
||||
@@ -10,7 +10,6 @@
|
||||
@@ -21,9 +21,9 @@ index a7dea19d9193bcff4bc6b553b80a10b2bc7b64af..9f9a2b5cab270327898cee3f97d9ae7c
|
||||
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
@@ -59,114 +58,6 @@ toTimePoint(std::time_t T, uint32_t nsec) {
|
||||
|
||||
@@ -80,119 +79,6 @@ toTimePoint(std::time_t T, uint32_t nsec) {
|
||||
raw_ostream &operator<<(raw_ostream &OS, sys::TimePoint<> TP);
|
||||
raw_ostream &operator<<(raw_ostream &OS, sys::UtcTime<> TP);
|
||||
|
||||
-/// Format provider for TimePoint<>
|
||||
-///
|
||||
@@ -39,6 +39,11 @@ index a7dea19d9193bcff4bc6b553b80a10b2bc7b64af..9f9a2b5cab270327898cee3f97d9ae7c
|
||||
- std::string_view Style);
|
||||
-};
|
||||
-
|
||||
-template <> struct format_provider<sys::UtcTime<std::chrono::seconds>> {
|
||||
- static void format(const sys::UtcTime<std::chrono::seconds> &TP,
|
||||
- llvm::raw_ostream &OS, StringRef Style);
|
||||
-};
|
||||
-
|
||||
-namespace detail {
|
||||
-template <typename Period> struct unit { static const char value[]; };
|
||||
-template <typename Period> const char unit<Period>::value[] = "";
|
||||
@@ -137,7 +142,7 @@ index a7dea19d9193bcff4bc6b553b80a10b2bc7b64af..9f9a2b5cab270327898cee3f97d9ae7c
|
||||
|
||||
#endif // LLVM_SUPPORT_CHRONO_H
|
||||
diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h
|
||||
index 2463f1af612a78cafafe3c0e16d496e607cdc322..5d08596b4cf6bf9e9b8e2c2c1aef731bb8832da5 100644
|
||||
index 9345348d9ba555022b31f94299684316ffa15939..862a1db876e9b8467a8839dae8f6632f18d5e7a0 100644
|
||||
--- a/llvm/include/llvm/Support/raw_ostream.h
|
||||
+++ b/llvm/include/llvm/Support/raw_ostream.h
|
||||
@@ -27,12 +27,6 @@
|
||||
@@ -154,10 +159,10 @@ index 2463f1af612a78cafafe3c0e16d496e607cdc322..5d08596b4cf6bf9e9b8e2c2c1aef731b
|
||||
|
||||
namespace sys {
|
||||
diff --git a/llvm/unittests/Support/Chrono.cpp b/llvm/unittests/Support/Chrono.cpp
|
||||
index daf8a8a350f08c748ba05af44f43f3faca8e2c61..3c049de18c0a80465f4b0a8c054df2602d5e9b1c 100644
|
||||
index 7dfc5dd2c29348ea8df9ce87c80f357aaad1a73b..a4d166d435d6d679f773dcf3eab985f0631e12d2 100644
|
||||
--- a/llvm/unittests/Support/Chrono.cpp
|
||||
+++ b/llvm/unittests/Support/Chrono.cpp
|
||||
@@ -30,43 +30,6 @@ TEST(Chrono, TimeTConversion) {
|
||||
@@ -29,43 +29,6 @@ TEST(Chrono, TimeTConversion) {
|
||||
EXPECT_EQ(TP, toTimePoint(toTimeT(TP)));
|
||||
}
|
||||
|
||||
@@ -201,7 +206,7 @@ index daf8a8a350f08c748ba05af44f43f3faca8e2c61..3c049de18c0a80465f4b0a8c054df260
|
||||
// Test that toTimePoint and toTimeT can be called with a arguments with varying
|
||||
// precisions.
|
||||
TEST(Chrono, ImplicitConversions) {
|
||||
@@ -84,34 +47,4 @@ TEST(Chrono, ImplicitConversions) {
|
||||
@@ -83,34 +46,4 @@ TEST(Chrono, ImplicitConversions) {
|
||||
EXPECT_EQ(TimeT, toTimeT(Nano));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sun, 8 May 2022 13:34:07 -0400
|
||||
Subject: [PATCH 08/34] Add compiler warning pragmas
|
||||
Subject: [PATCH 08/35] Add compiler warning pragmas
|
||||
|
||||
---
|
||||
llvm/include/llvm/ADT/FunctionExtras.h | 11 +++++++++++
|
||||
@@ -17,10 +17,10 @@ Subject: [PATCH 08/34] Add compiler warning pragmas
|
||||
10 files changed, 72 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/llvm/include/llvm/ADT/FunctionExtras.h b/llvm/include/llvm/ADT/FunctionExtras.h
|
||||
index 9d10b16e3cbe9c0df818a3254fcd3a6032d54b39..1daeae915eb506b32a2d1296d2f0fe4e6dab606e 100644
|
||||
index 5641a913d0a35ee2911cf872ad90c3dc864f20f5..043d8d90fff03d571a923c264b49be37a5dffa09 100644
|
||||
--- a/llvm/include/llvm/ADT/FunctionExtras.h
|
||||
+++ b/llvm/include/llvm/ADT/FunctionExtras.h
|
||||
@@ -55,6 +55,13 @@ namespace llvm {
|
||||
@@ -56,6 +56,13 @@ namespace llvm {
|
||||
/// It can hold functions with a non-const operator(), like mutable lambdas.
|
||||
template <typename FunctionT> class unique_function;
|
||||
|
||||
@@ -34,7 +34,7 @@ index 9d10b16e3cbe9c0df818a3254fcd3a6032d54b39..1daeae915eb506b32a2d1296d2f0fe4e
|
||||
namespace detail {
|
||||
|
||||
template <typename T>
|
||||
@@ -409,6 +416,10 @@ public:
|
||||
@@ -412,6 +419,10 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
@@ -46,7 +46,7 @@ index 9d10b16e3cbe9c0df818a3254fcd3a6032d54b39..1daeae915eb506b32a2d1296d2f0fe4e
|
||||
|
||||
#endif // LLVM_ADT_FUNCTIONEXTRAS_H
|
||||
diff --git a/llvm/include/llvm/ADT/Hashing.h b/llvm/include/llvm/ADT/Hashing.h
|
||||
index ef983105c7bae67bb2ef832e4473939a0406e0df..781bdb7416392e3f60a1ac3a38fbcf5324b5395f 100644
|
||||
index a5477362a50793985e1e9df9dc77c8a1d5b5846b..08d6edb14eb3cd51405329aae61b9782266a2590 100644
|
||||
--- a/llvm/include/llvm/ADT/Hashing.h
|
||||
+++ b/llvm/include/llvm/ADT/Hashing.h
|
||||
@@ -56,6 +56,11 @@
|
||||
@@ -61,9 +61,9 @@ index ef983105c7bae67bb2ef832e4473939a0406e0df..781bdb7416392e3f60a1ac3a38fbcf53
|
||||
namespace llvm {
|
||||
template <typename T, typename Enable> struct DenseMapInfo;
|
||||
|
||||
@@ -683,4 +688,8 @@ template <> struct DenseMapInfo<hash_code, void> {
|
||||
@@ -697,4 +702,8 @@ struct hash<llvm::hash_code> {
|
||||
|
||||
} // namespace llvm
|
||||
} // namespace std;
|
||||
|
||||
+#ifdef _WIN32
|
||||
+#pragma warning(pop)
|
||||
@@ -71,7 +71,7 @@ index ef983105c7bae67bb2ef832e4473939a0406e0df..781bdb7416392e3f60a1ac3a38fbcf53
|
||||
+
|
||||
#endif
|
||||
diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h
|
||||
index 84f4d0931a30f4be29549354c85cb4c0489e14c9..b42438a9b16c273f9ef5b5cce6192873c78cb964 100644
|
||||
index d7600fe209a58deb07c63e2553f9dad62e06e973..d7788e94b5379f5eba6fbddee50e4b4359da9d80 100644
|
||||
--- a/llvm/include/llvm/ADT/SmallVector.h
|
||||
+++ b/llvm/include/llvm/ADT/SmallVector.h
|
||||
@@ -14,6 +14,14 @@
|
||||
@@ -90,7 +90,7 @@ index 84f4d0931a30f4be29549354c85cb4c0489e14c9..b42438a9b16c273f9ef5b5cce6192873
|
||||
#include "llvm/Support/type_traits.h"
|
||||
#include <algorithm>
|
||||
diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h
|
||||
index 0bd572d07fcbf2ff56998dbf366215068b62f527..cd5a64a746b2eb7491e9b6cf8570bdf436d94a6d 100644
|
||||
index 5cabfdd6493fee33fbc74b831dc1fa3c91ba725d..7541447fa2db5e1634d952b1f39957eb725611f4 100644
|
||||
--- a/llvm/include/llvm/Support/MathExtras.h
|
||||
+++ b/llvm/include/llvm/Support/MathExtras.h
|
||||
@@ -208,6 +208,11 @@ inline uint64_t maxUIntN(uint64_t N) {
|
||||
@@ -117,7 +117,7 @@ index 0bd572d07fcbf2ff56998dbf366215068b62f527..cd5a64a746b2eb7491e9b6cf8570bdf4
|
||||
inline int64_t maxIntN(int64_t N) {
|
||||
assert(N > 0 && N <= 64 && "integer width out of range");
|
||||
diff --git a/llvm/include/llvm/Support/MemAlloc.h b/llvm/include/llvm/Support/MemAlloc.h
|
||||
index d6012bd5a6985d8405136039aa85931605cd8a40..01007deb89bba625b1b3ad3e703d0c16ed6f757b 100644
|
||||
index f3f378b7697a18f57b189c5322b080fe23d45bec..0028e871f6a05baf6172c60c602b8b26e5f116c6 100644
|
||||
--- a/llvm/include/llvm/Support/MemAlloc.h
|
||||
+++ b/llvm/include/llvm/Support/MemAlloc.h
|
||||
@@ -22,6 +22,14 @@
|
||||
@@ -146,7 +146,7 @@ index d6012bd5a6985d8405136039aa85931605cd8a40..01007deb89bba625b1b3ad3e703d0c16
|
||||
+
|
||||
#endif
|
||||
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
|
||||
index 9966a0056ae4f24a7a38346ee1c2f5d83ac20248..a23f567a37abdc199363607446f33f29e021d7ad 100644
|
||||
index 220d850b9bc69f8fc2fba7cd23629eca487cde23..65810ca93fdc1290e3188b5f4fb292a1e1e79b60 100644
|
||||
--- a/llvm/lib/Support/raw_ostream.cpp
|
||||
+++ b/llvm/lib/Support/raw_ostream.cpp
|
||||
@@ -10,6 +10,10 @@
|
||||
@@ -176,7 +176,7 @@ index b710ac07461ba58faa99cedeae7f209dc0f5902b..1f232d3046292c0da940ba4bef7d5060
|
||||
#include "llvm/ADT/DenseMapInfo.h"
|
||||
#include "llvm/ADT/DenseMapInfoVariant.h"
|
||||
diff --git a/llvm/unittests/ADT/MapVectorTest.cpp b/llvm/unittests/ADT/MapVectorTest.cpp
|
||||
index 1a371cbfba81e8ea4b57c4077ca94c86c3db8991..62fafcaf04a67d4c67b98b8f42d837ccca245fe9 100644
|
||||
index e0f11b60a0223da7c00a47c20b61136bd608bae6..9c802ab30721c9ce58ed65052a6ab467039226ff 100644
|
||||
--- a/llvm/unittests/ADT/MapVectorTest.cpp
|
||||
+++ b/llvm/unittests/ADT/MapVectorTest.cpp
|
||||
@@ -6,6 +6,13 @@
|
||||
|
||||
@@ -1,52 +1,50 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sun, 8 May 2022 13:43:50 -0400
|
||||
Subject: [PATCH 09/34] Remove unused functions
|
||||
Subject: [PATCH 09/35] Remove unused functions
|
||||
|
||||
---
|
||||
llvm/include/llvm/ADT/SmallString.h | 85 +-----
|
||||
llvm/include/llvm/ADT/SmallString.h | 79 ------
|
||||
llvm/include/llvm/Support/Errno.h | 9 -
|
||||
llvm/include/llvm/Support/VersionTuple.h | 39 ---
|
||||
llvm/include/llvm/Support/raw_ostream.h | 127 +--------
|
||||
llvm/lib/Support/raw_ostream.cpp | 329 -----------------------
|
||||
5 files changed, 10 insertions(+), 579 deletions(-)
|
||||
llvm/include/llvm/Support/raw_ostream.h | 129 +--------
|
||||
llvm/lib/Support/raw_ostream.cpp | 332 -----------------------
|
||||
5 files changed, 8 insertions(+), 580 deletions(-)
|
||||
|
||||
diff --git a/llvm/include/llvm/ADT/SmallString.h b/llvm/include/llvm/ADT/SmallString.h
|
||||
index 4d673cc8b1c49cf8a3f19653de53881cd12662ee..bfa965fd68a09d7ca3b332e38585ae37a5982ed0 100644
|
||||
index 45fbf13a43a081731186b0f41c553413b0e36e0f..cb6136d8fd1886e8dc444cb807b33a5f1e18aa44 100644
|
||||
--- a/llvm/include/llvm/ADT/SmallString.h
|
||||
+++ b/llvm/include/llvm/ADT/SmallString.h
|
||||
@@ -88,49 +88,12 @@ public:
|
||||
@@ -88,17 +88,6 @@ public:
|
||||
/// @name String Comparison
|
||||
/// @{
|
||||
|
||||
- /// Check for string equality. This is more efficient than compare() when
|
||||
- /// the relative ordering of inequal strings isn't needed.
|
||||
- bool equals(std::string_view RHS) const {
|
||||
- [[nodiscard]] bool equals(std::string_view RHS) const {
|
||||
- return str().equals(RHS);
|
||||
- }
|
||||
-
|
||||
- /// Check for string equality, ignoring case.
|
||||
- bool equals_insensitive(std::string_view RHS) const {
|
||||
- [[nodiscard]] bool equals_insensitive(std::string_view RHS) const {
|
||||
- return str().equals_insensitive(RHS);
|
||||
- }
|
||||
-
|
||||
- /// compare - Compare two strings; the result is negative, zero, or positive
|
||||
- /// if this string is lexicographically less than, equal to, or greater than
|
||||
- /// the \p RHS.
|
||||
+ /// Compare two strings; the result is -1, 0, or 1 if this string is
|
||||
+ /// lexicographically less than, equal to, or greater than the \p RHS.
|
||||
int compare(std::string_view RHS) const {
|
||||
/// compare - Compare two strings; the result is negative, zero, or positive
|
||||
/// if this string is lexicographically less than, equal to, or greater than
|
||||
/// the \p RHS.
|
||||
@@ -106,31 +95,6 @@ public:
|
||||
return str().compare(RHS);
|
||||
}
|
||||
|
||||
- /// compare_insensitive - Compare two strings, ignoring case.
|
||||
- int compare_insensitive(std::string_view RHS) const {
|
||||
- [[nodiscard]] int compare_insensitive(std::string_view RHS) const {
|
||||
- return str().compare_insensitive(RHS);
|
||||
- }
|
||||
-
|
||||
- /// compare_numeric - Compare two strings, treating sequences of digits as
|
||||
- /// numbers.
|
||||
- int compare_numeric(std::string_view RHS) const {
|
||||
- [[nodiscard]] int compare_numeric(std::string_view RHS) const {
|
||||
- return str().compare_numeric(RHS);
|
||||
- }
|
||||
-
|
||||
@@ -55,19 +53,19 @@ index 4d673cc8b1c49cf8a3f19653de53881cd12662ee..bfa965fd68a09d7ca3b332e38585ae37
|
||||
- /// @{
|
||||
-
|
||||
- /// startswith - Check if this string starts with the given \p Prefix.
|
||||
- bool startswith(std::string_view Prefix) const {
|
||||
- [[nodiscard]] bool startswith(std::string_view Prefix) const {
|
||||
- return str().startswith(Prefix);
|
||||
- }
|
||||
-
|
||||
- /// endswith - Check if this string ends with the given \p Suffix.
|
||||
- bool endswith(std::string_view Suffix) const {
|
||||
- [[nodiscard]] bool endswith(std::string_view Suffix) const {
|
||||
- return str().endswith(Suffix);
|
||||
- }
|
||||
-
|
||||
/// @}
|
||||
/// @name String Searching
|
||||
/// @{
|
||||
@@ -211,50 +174,6 @@ public:
|
||||
@@ -215,49 +179,6 @@ public:
|
||||
}
|
||||
|
||||
/// @}
|
||||
@@ -75,13 +73,11 @@ index 4d673cc8b1c49cf8a3f19653de53881cd12662ee..bfa965fd68a09d7ca3b332e38585ae37
|
||||
- /// @{
|
||||
-
|
||||
- /// Return the number of occurrences of \p C in the string.
|
||||
- size_t count(char C) const {
|
||||
- return str().count(C);
|
||||
- }
|
||||
- [[nodiscard]] size_t count(char C) const { return str().count(C); }
|
||||
-
|
||||
- /// Return the number of non-overlapped occurrences of \p Str in the
|
||||
- /// string.
|
||||
- size_t count(std::string_view Str) const {
|
||||
- [[nodiscard]] size_t count(std::string_view Str) const {
|
||||
- return str().count(Str);
|
||||
- }
|
||||
-
|
||||
@@ -98,7 +94,8 @@ index 4d673cc8b1c49cf8a3f19653de53881cd12662ee..bfa965fd68a09d7ca3b332e38585ae37
|
||||
- /// \param N The number of characters to included in the substring. If \p N
|
||||
- /// exceeds the number of characters remaining in the string, the string
|
||||
- /// suffix (starting with \p Start) will be returned.
|
||||
- std::string_view substr(size_t Start, size_t N = std::string_view::npos) const {
|
||||
- [[nodiscard]] std::string_view substr(
|
||||
- size_t Start, size_t N = std::string_view::npos) const {
|
||||
- return str().substr(Start, N);
|
||||
- }
|
||||
-
|
||||
@@ -112,7 +109,7 @@ index 4d673cc8b1c49cf8a3f19653de53881cd12662ee..bfa965fd68a09d7ca3b332e38585ae37
|
||||
- /// substring. If this is npos, or less than \p Start, or exceeds the
|
||||
- /// number of characters remaining in the string, the string suffix
|
||||
- /// (starting with \p Start) will be returned.
|
||||
- std::string_view slice(size_t Start, size_t End) const {
|
||||
- [[nodiscard]] std::string_view slice(size_t Start, size_t End) const {
|
||||
- return str().slice(Start, End);
|
||||
- }
|
||||
|
||||
@@ -139,10 +136,10 @@ index e095c66b90860001d90b5c2eb74f6032de6de454..787805dac6c5e3c8cb85dabeb8025444
|
||||
inline decltype(auto) RetryAfterSignal(const FailT &Fail, const Fun &F,
|
||||
const Args &... As) {
|
||||
diff --git a/llvm/include/llvm/Support/VersionTuple.h b/llvm/include/llvm/Support/VersionTuple.h
|
||||
index 953b40701dc934c1a356b5413c9c6c692d5f5679..30cf717973fb15ff65a47a2d80795c351b0d2768 100644
|
||||
index e1cdce77ce8659305c99a21e01f9b3cc3481a5fd..9102ff063afedc03bd524b2805cba98ea5afeba8 100644
|
||||
--- a/llvm/include/llvm/Support/VersionTuple.h
|
||||
+++ b/llvm/include/llvm/Support/VersionTuple.h
|
||||
@@ -168,45 +168,6 @@ public:
|
||||
@@ -166,45 +166,6 @@ public:
|
||||
friend bool operator>=(const VersionTuple &X, const VersionTuple &Y) {
|
||||
return !(X < Y);
|
||||
}
|
||||
@@ -151,8 +148,8 @@ index 953b40701dc934c1a356b5413c9c6c692d5f5679..30cf717973fb15ff65a47a2d80795c35
|
||||
- return hash_combine(VT.Major, VT.Minor, VT.Subminor, VT.Build);
|
||||
- }
|
||||
-
|
||||
- template <typename HasherT, llvm::support::endianness Endianness>
|
||||
- friend void addHash(HashBuilderImpl<HasherT, Endianness> &HBuilder,
|
||||
- template <typename HasherT, llvm::endianness Endianness>
|
||||
- friend void addHash(HashBuilder<HasherT, Endianness> &HBuilder,
|
||||
- const VersionTuple &VT) {
|
||||
- HBuilder.add(VT.Major, VT.Minor, VT.Subminor, VT.Build);
|
||||
- }
|
||||
@@ -189,7 +186,7 @@ index 953b40701dc934c1a356b5413c9c6c692d5f5679..30cf717973fb15ff65a47a2d80795c35
|
||||
|
||||
} // end namespace llvm
|
||||
diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h
|
||||
index 5d08596b4cf6bf9e9b8e2c2c1aef731bb8832da5..95019180a9deb406ed4f2991c664a4cc4e956dac 100644
|
||||
index 862a1db876e9b8467a8839dae8f6632f18d5e7a0..95019180a9deb406ed4f2991c664a4cc4e956dac 100644
|
||||
--- a/llvm/include/llvm/Support/raw_ostream.h
|
||||
+++ b/llvm/include/llvm/Support/raw_ostream.h
|
||||
@@ -261,32 +261,6 @@ public:
|
||||
@@ -339,10 +336,12 @@ index 5d08596b4cf6bf9e9b8e2c2c1aef731bb8832da5..95019180a9deb406ed4f2991c664a4cc
|
||||
};
|
||||
|
||||
/// This returns a reference to a raw_fd_ostream for standard output. Use it
|
||||
@@ -619,17 +542,6 @@ public:
|
||||
@@ -619,19 +542,6 @@ public:
|
||||
/// immediately destroyed.
|
||||
raw_fd_stream(std::string_view Filename, std::error_code &EC);
|
||||
|
||||
- raw_fd_stream(int fd, bool shouldClose);
|
||||
-
|
||||
- /// This reads the \p Size bytes into a buffer pointed by \p Ptr.
|
||||
- ///
|
||||
- /// \param Ptr The start of the buffer to hold data to be read.
|
||||
@@ -357,7 +356,7 @@ index 5d08596b4cf6bf9e9b8e2c2c1aef731bb8832da5..95019180a9deb406ed4f2991c664a4cc
|
||||
/// Check if \p OS is a pointer of type raw_fd_stream*.
|
||||
static bool classof(const raw_ostream *OS);
|
||||
};
|
||||
@@ -747,29 +659,6 @@ public:
|
||||
@@ -749,29 +659,6 @@ public:
|
||||
~buffer_unique_ostream() override { *OS << str(); }
|
||||
};
|
||||
|
||||
@@ -388,18 +387,18 @@ index 5d08596b4cf6bf9e9b8e2c2c1aef731bb8832da5..95019180a9deb406ed4f2991c664a4cc
|
||||
|
||||
#endif // LLVM_SUPPORT_RAW_OSTREAM_H
|
||||
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
|
||||
index a23f567a37abdc199363607446f33f29e021d7ad..76c32155b4296fbbf3f4b164cd58d63f472ccd5e 100644
|
||||
index 65810ca93fdc1290e3188b5f4fb292a1e1e79b60..c65fb70a4d22db51f4140b910c308333289b6248 100644
|
||||
--- a/llvm/lib/Support/raw_ostream.cpp
|
||||
+++ b/llvm/lib/Support/raw_ostream.cpp
|
||||
@@ -18,7 +18,6 @@
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
@@ -19,7 +19,6 @@
|
||||
#include "llvm/Config/config.h"
|
||||
#include "llvm/Support/AutoConvert.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
-#include "llvm/Support/Duration.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/Format.h"
|
||||
@@ -127,49 +126,6 @@ void raw_ostream::SetBufferAndMode(char *BufferStart, size_t Size,
|
||||
@@ -128,49 +127,6 @@ void raw_ostream::SetBufferAndMode(char *BufferStart, size_t Size,
|
||||
assert(OutBufStart <= OutBufEnd && "Invalid size!");
|
||||
}
|
||||
|
||||
@@ -449,7 +448,7 @@ index a23f567a37abdc199363607446f33f29e021d7ad..76c32155b4296fbbf3f4b164cd58d63f
|
||||
raw_ostream &raw_ostream::write_escaped(std::string_view Str,
|
||||
bool UseHexEscapes) {
|
||||
for (unsigned char c : Str) {
|
||||
@@ -315,173 +271,6 @@ void raw_ostream::flush_tied_then_write(const char *Ptr, size_t Size) {
|
||||
@@ -316,173 +272,6 @@ void raw_ostream::flush_tied_then_write(const char *Ptr, size_t Size) {
|
||||
write_impl(Ptr, Size);
|
||||
}
|
||||
|
||||
@@ -623,7 +622,7 @@ index a23f567a37abdc199363607446f33f29e021d7ad..76c32155b4296fbbf3f4b164cd58d63f
|
||||
template <char C>
|
||||
static raw_ostream &write_padding(raw_ostream &OS, unsigned NumChars) {
|
||||
static const char Chars[] = {C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C,
|
||||
@@ -512,63 +301,8 @@ raw_ostream &raw_ostream::write_zeros(unsigned NumZeros) {
|
||||
@@ -513,63 +302,8 @@ raw_ostream &raw_ostream::write_zeros(unsigned NumZeros) {
|
||||
return write_padding<'\0'>(*this, NumZeros);
|
||||
}
|
||||
|
||||
@@ -687,7 +686,7 @@ index a23f567a37abdc199363607446f33f29e021d7ad..76c32155b4296fbbf3f4b164cd58d63f
|
||||
//===----------------------------------------------------------------------===//
|
||||
// raw_fd_ostream
|
||||
//===----------------------------------------------------------------------===//
|
||||
@@ -867,31 +601,6 @@ size_t raw_fd_ostream::preferred_buffer_size() const {
|
||||
@@ -865,31 +599,6 @@ size_t raw_fd_ostream::preferred_buffer_size() const {
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -719,10 +718,13 @@ index a23f567a37abdc199363607446f33f29e021d7ad..76c32155b4296fbbf3f4b164cd58d63f
|
||||
void raw_fd_ostream::anchor() {}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
@@ -934,16 +643,6 @@ raw_fd_stream::raw_fd_stream(std::string_view Filename, std::error_code &EC)
|
||||
@@ -940,19 +649,6 @@ raw_fd_stream::raw_fd_stream(std::string_view Filename, std::error_code &EC)
|
||||
EC = std::make_error_code(std::errc::invalid_argument);
|
||||
}
|
||||
|
||||
-raw_fd_stream::raw_fd_stream(int fd, bool shouldClose)
|
||||
- : raw_fd_ostream(fd, shouldClose, false, OStreamKind::OK_FDStream) {}
|
||||
-
|
||||
-ssize_t raw_fd_stream::read(char *Ptr, size_t Size) {
|
||||
- assert(get_fd() >= 0 && "File already closed.");
|
||||
- ssize_t Ret = ::read(get_fd(), (void *)Ptr, Size);
|
||||
@@ -736,7 +738,7 @@ index a23f567a37abdc199363607446f33f29e021d7ad..76c32155b4296fbbf3f4b164cd58d63f
|
||||
bool raw_fd_stream::classof(const raw_ostream *OS) {
|
||||
return OS->get_kind() == OStreamKind::OK_FDStream;
|
||||
}
|
||||
@@ -999,31 +698,3 @@ void raw_pwrite_stream::anchor() {}
|
||||
@@ -1000,31 +696,3 @@ void raw_pwrite_stream::anchor() {}
|
||||
void buffer_ostream::anchor() {}
|
||||
|
||||
void buffer_unique_ostream::anchor() {}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Thu, 5 May 2022 23:18:34 -0400
|
||||
Subject: [PATCH 10/34] Detemplatize SmallVectorBase
|
||||
Subject: [PATCH 10/35] Detemplatize SmallVectorBase
|
||||
|
||||
---
|
||||
llvm/include/llvm/ADT/SmallVector.h | 27 +++++++--------------
|
||||
llvm/include/llvm/ADT/SmallVector.h | 35 ++++++++++-----------------
|
||||
llvm/lib/Support/SmallVector.cpp | 37 +++++------------------------
|
||||
2 files changed, 14 insertions(+), 50 deletions(-)
|
||||
2 files changed, 18 insertions(+), 54 deletions(-)
|
||||
|
||||
diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h
|
||||
index b42438a9b16c273f9ef5b5cce6192873c78cb964..7775ed7e8e083908f033529c30b1e4beae91b10a 100644
|
||||
index d7788e94b5379f5eba6fbddee50e4b4359da9d80..b953ae45a34772eb7fd04c3af0275a7d093e1242 100644
|
||||
--- a/llvm/include/llvm/ADT/SmallVector.h
|
||||
+++ b/llvm/include/llvm/ADT/SmallVector.h
|
||||
@@ -56,14 +56,14 @@ using EnableIfConvertibleToInputIterator = std::enable_if_t<std::is_convertible<
|
||||
@@ -56,19 +56,19 @@ using EnableIfConvertibleToInputIterator = std::enable_if_t<std::is_convertible<
|
||||
/// Using 64 bit size is desirable for cases like SmallVector<char>, where a
|
||||
/// 32 bit size would limit the vector to ~4GB. SmallVectors are used for
|
||||
/// buffering bitcode output - which can exceed 4GB.
|
||||
@@ -23,14 +23,35 @@ index b42438a9b16c273f9ef5b5cce6192873c78cb964..7775ed7e8e083908f033529c30b1e4be
|
||||
- Size_T Size = 0, Capacity;
|
||||
+ unsigned Size = 0, Capacity;
|
||||
|
||||
/// The maximum value of the Size_T used.
|
||||
- /// The maximum value of the Size_T used.
|
||||
+ /// The maximum value of the unsigned used.
|
||||
static constexpr size_t SizeTypeMax() {
|
||||
- return (std::numeric_limits<Size_T>::max)();
|
||||
+ return (std::numeric_limits<unsigned>::max)();
|
||||
}
|
||||
|
||||
SmallVectorBase() = delete;
|
||||
@@ -111,15 +111,10 @@ protected:
|
||||
SmallVectorBase(void *FirstEl, size_t TotalCapacity)
|
||||
- : BeginX(FirstEl), Capacity(static_cast<Size_T>(TotalCapacity)) {}
|
||||
+ : BeginX(FirstEl), Capacity(static_cast<unsigned>(TotalCapacity)) {}
|
||||
|
||||
/// This is a helper for \a grow() that's out of line to reduce code
|
||||
/// duplication. This function will report a fatal error if it can't grow at
|
||||
@@ -107,7 +107,7 @@ protected:
|
||||
/// This does not construct or destroy any elements in the vector.
|
||||
void set_size(size_t N) {
|
||||
assert(N <= capacity()); // implies no overflow in assignment
|
||||
- Size = static_cast<Size_T>(N);
|
||||
+ Size = static_cast<unsigned>(N);
|
||||
}
|
||||
|
||||
/// Set the array data pointer to \p Begin and capacity to \p N.
|
||||
@@ -117,19 +117,14 @@ protected:
|
||||
void set_allocation_range(void *Begin, size_t N) {
|
||||
assert(N <= SizeTypeMax());
|
||||
BeginX = Begin;
|
||||
- Capacity = static_cast<Size_T>(N);
|
||||
+ Capacity = static_cast<unsigned>(N);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -48,7 +69,7 @@ index b42438a9b16c273f9ef5b5cce6192873c78cb964..7775ed7e8e083908f033529c30b1e4be
|
||||
alignas(T) char FirstEl[sizeof(T)];
|
||||
};
|
||||
|
||||
@@ -128,8 +123,8 @@ template <class T, typename = void> struct SmallVectorAlignmentAndSize {
|
||||
@@ -138,8 +133,8 @@ template <class T, typename = void> struct SmallVectorAlignmentAndSize {
|
||||
/// to avoid unnecessarily requiring T to be complete.
|
||||
template <typename T, typename = void>
|
||||
class SmallVectorTemplateCommon
|
||||
@@ -59,7 +80,7 @@ index b42438a9b16c273f9ef5b5cce6192873c78cb964..7775ed7e8e083908f033529c30b1e4be
|
||||
|
||||
protected:
|
||||
/// Find the address of the first element. For this pointer math to be valid
|
||||
@@ -451,7 +446,7 @@ template <typename T, bool TriviallyCopyable>
|
||||
@@ -461,7 +456,7 @@ template <typename T, bool TriviallyCopyable>
|
||||
T *SmallVectorTemplateBase<T, TriviallyCopyable>::mallocForGrow(
|
||||
size_t MinSize, size_t &NewCapacity) {
|
||||
return static_cast<T *>(
|
||||
@@ -68,7 +89,7 @@ index b42438a9b16c273f9ef5b5cce6192873c78cb964..7775ed7e8e083908f033529c30b1e4be
|
||||
this->getFirstEl(), MinSize, sizeof(T), NewCapacity));
|
||||
}
|
||||
|
||||
@@ -1324,12 +1319,6 @@ template <typename Out, typename R> SmallVector<Out> to_vector_of(R &&Range) {
|
||||
@@ -1333,12 +1328,6 @@ template <typename Out, typename R> SmallVector<Out> to_vector_of(R &&Range) {
|
||||
return {std::begin(Range), std::end(Range)};
|
||||
}
|
||||
|
||||
@@ -82,7 +103,7 @@ index b42438a9b16c273f9ef5b5cce6192873c78cb964..7775ed7e8e083908f033529c30b1e4be
|
||||
|
||||
namespace std {
|
||||
diff --git a/llvm/lib/Support/SmallVector.cpp b/llvm/lib/Support/SmallVector.cpp
|
||||
index 6cefdff7c28060ca18b522acf5279af3a206e23a..ae64a36dcf4b9ceaf8767adbf8100f164f3738ac 100644
|
||||
index 4f6fee18b659adcbfd79822832f914170cbb1635..7ef023084d791cf746c346cb1655c9da36a6beb5 100644
|
||||
--- a/llvm/lib/Support/SmallVector.cpp
|
||||
+++ b/llvm/lib/Support/SmallVector.cpp
|
||||
@@ -51,10 +51,6 @@ static_assert(sizeof(SmallVector<void *, 1>) ==
|
||||
@@ -144,9 +165,9 @@ index 6cefdff7c28060ca18b522acf5279af3a206e23a..ae64a36dcf4b9ceaf8767adbf8100f16
|
||||
void *NewElts;
|
||||
if (BeginX == FirstEl) {
|
||||
NewElts = llvm::safe_malloc(NewCapacity * TSize);
|
||||
@@ -155,20 +147,3 @@ void SmallVectorBase<Size_T>::grow_pod(void *FirstEl, size_t MinSize,
|
||||
this->BeginX = NewElts;
|
||||
this->Capacity = NewCapacity;
|
||||
@@ -154,20 +146,3 @@ void SmallVectorBase<Size_T>::grow_pod(void *FirstEl, size_t MinSize,
|
||||
|
||||
this->set_allocation_range(NewElts, NewCapacity);
|
||||
}
|
||||
-
|
||||
-template class llvm::SmallVectorBase<uint32_t>;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sun, 8 May 2022 13:48:59 -0400
|
||||
Subject: [PATCH 11/34] Add vectors to raw_ostream
|
||||
Subject: [PATCH 11/35] Add vectors to raw_ostream
|
||||
|
||||
---
|
||||
llvm/include/llvm/Support/raw_ostream.h | 115 ++++++++++++++++++++++++
|
||||
@@ -155,10 +155,10 @@ index 95019180a9deb406ed4f2991c664a4cc4e956dac..e7526e016a858ad728feb7cf1c5014b9
|
||||
class raw_null_ostream : public raw_pwrite_stream {
|
||||
/// See raw_ostream::write_impl.
|
||||
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
|
||||
index 76c32155b4296fbbf3f4b164cd58d63f472ccd5e..dcdfdfd7a8e3fcc4019538a4fc9e158aeda0a8b8 100644
|
||||
index c65fb70a4d22db51f4140b910c308333289b6248..57d3091fd5cc5b416e814f9f33811f0fa7afe9cf 100644
|
||||
--- a/llvm/lib/Support/raw_ostream.cpp
|
||||
+++ b/llvm/lib/Support/raw_ostream.cpp
|
||||
@@ -670,6 +670,53 @@ void raw_svector_ostream::pwrite_impl(const char *Ptr, size_t Size,
|
||||
@@ -668,6 +668,53 @@ void raw_svector_ostream::pwrite_impl(const char *Ptr, size_t Size,
|
||||
memcpy(OS.data() + Offset, Ptr, Size);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Tue, 3 May 2022 22:16:10 -0400
|
||||
Subject: [PATCH 12/34] Extra collections features
|
||||
Subject: [PATCH 12/35] Extra collections features
|
||||
|
||||
---
|
||||
llvm/include/llvm/ADT/StringMap.h | 103 +++++++++++++++++++++++++++++-
|
||||
@@ -142,10 +142,10 @@ index 34dfbf83c681f4e81a9dadd9382ddca6ef8d6c1d..c133e84f9b2e3a225cdac782c011fadb
|
||||
|
||||
#endif // LLVM_ADT_STRINGMAP_H
|
||||
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
|
||||
index dcdfdfd7a8e3fcc4019538a4fc9e158aeda0a8b8..b2a726633b48b179abfd24a5de110a2301e0f877 100644
|
||||
index 57d3091fd5cc5b416e814f9f33811f0fa7afe9cf..5bec803ccc76ce287b7ff3ea037d5e490a7af20c 100644
|
||||
--- a/llvm/lib/Support/raw_ostream.cpp
|
||||
+++ b/llvm/lib/Support/raw_ostream.cpp
|
||||
@@ -76,6 +76,14 @@ constexpr raw_ostream::Colors raw_ostream::WHITE;
|
||||
@@ -77,6 +77,14 @@ constexpr raw_ostream::Colors raw_ostream::WHITE;
|
||||
constexpr raw_ostream::Colors raw_ostream::SAVEDCOLOR;
|
||||
constexpr raw_ostream::Colors raw_ostream::RESET;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Wed, 4 May 2022 00:01:00 -0400
|
||||
Subject: [PATCH 13/34] EpochTracker ABI macro
|
||||
Subject: [PATCH 13/35] EpochTracker ABI macro
|
||||
|
||||
---
|
||||
llvm/include/llvm/ADT/EpochTracker.h | 2 +-
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Thu, 5 May 2022 18:09:45 -0400
|
||||
Subject: [PATCH 14/34] Delete numbers from MathExtras
|
||||
Subject: [PATCH 14/35] Delete numbers from MathExtras
|
||||
|
||||
---
|
||||
llvm/include/llvm/Support/MathExtras.h | 36 --------------------------
|
||||
1 file changed, 36 deletions(-)
|
||||
|
||||
diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h
|
||||
index cd5a64a746b2eb7491e9b6cf8570bdf436d94a6d..cdf859ccfaca22a04b08a351d7c2c9789a70627e 100644
|
||||
index 7541447fa2db5e1634d952b1f39957eb725611f4..60b3b9012a32dda5e7c3ba1dc5923ffa68df8215 100644
|
||||
--- a/llvm/include/llvm/Support/MathExtras.h
|
||||
+++ b/llvm/include/llvm/Support/MathExtras.h
|
||||
@@ -24,42 +24,6 @@
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Tue, 3 May 2022 22:50:24 -0400
|
||||
Subject: [PATCH 15/34] Add lerp and sgn
|
||||
Subject: [PATCH 15/35] Add lerp and sgn
|
||||
|
||||
---
|
||||
llvm/include/llvm/Support/MathExtras.h | 20 ++++++++++++++++++++
|
||||
1 file changed, 20 insertions(+)
|
||||
|
||||
diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h
|
||||
index cdf859ccfaca22a04b08a351d7c2c9789a70627e..b82d9883c41008dcbbd933709c6e854ad74c5b58 100644
|
||||
index 60b3b9012a32dda5e7c3ba1dc5923ffa68df8215..daa79d99578e934ca001d1de5d2772ff961b8fc3 100644
|
||||
--- a/llvm/include/llvm/Support/MathExtras.h
|
||||
+++ b/llvm/include/llvm/Support/MathExtras.h
|
||||
@@ -614,6 +614,26 @@ std::enable_if_t<std::is_signed_v<T>, T> MulOverflow(T X, T Y, T &Result) {
|
||||
@@ -617,6 +617,26 @@ std::enable_if_t<std::is_signed_v<T>, T> MulOverflow(T X, T Y, T &Result) {
|
||||
return UX > (static_cast<U>((std::numeric_limits<T>::max)())) / UY;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sun, 8 May 2022 16:38:11 -0400
|
||||
Subject: [PATCH 16/34] Fixup includes
|
||||
Subject: [PATCH 16/35] Fixup includes
|
||||
|
||||
---
|
||||
llvm/include/llvm/ADT/StringMap.h | 4 ++++
|
||||
@@ -91,7 +91,7 @@ index 0b87b375de67dc18647e3ebe646bf323dd05e8c5..3a88178cfbbcf7062a958c7de820247b
|
||||
|
||||
using namespace llvm;
|
||||
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
|
||||
index b2a726633b48b179abfd24a5de110a2301e0f877..3b7d8d6db5f0df31e18b91be716a4fd21e7e3549 100644
|
||||
index 5bec803ccc76ce287b7ff3ea037d5e490a7af20c..ae5428825f7f62ad8e742490448d40aea7506990 100644
|
||||
--- a/llvm/lib/Support/raw_ostream.cpp
|
||||
+++ b/llvm/lib/Support/raw_ostream.cpp
|
||||
@@ -15,6 +15,8 @@
|
||||
@@ -102,8 +102,8 @@ index b2a726633b48b179abfd24a5de110a2301e0f877..3b7d8d6db5f0df31e18b91be716a4fd2
|
||||
+#include "wpi/SmallVector.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/Config/config.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
@@ -32,12 +34,11 @@
|
||||
#include "llvm/Support/AutoConvert.h"
|
||||
@@ -33,12 +35,11 @@
|
||||
#include <sys/stat.h>
|
||||
|
||||
// <fcntl.h> may provide O_BINARY.
|
||||
@@ -119,7 +119,7 @@ index b2a726633b48b179abfd24a5de110a2301e0f877..3b7d8d6db5f0df31e18b91be716a4fd2
|
||||
#endif
|
||||
|
||||
#if defined(__CYGWIN__)
|
||||
@@ -60,7 +61,7 @@
|
||||
@@ -61,7 +62,7 @@
|
||||
#ifdef _WIN32
|
||||
#include "llvm/Support/ConvertUTF.h"
|
||||
#include "llvm/Support/Signals.h"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sun, 8 May 2022 16:42:09 -0400
|
||||
Subject: [PATCH 17/34] Use std::is_trivially_copy_constructible
|
||||
Subject: [PATCH 17/35] Use std::is_trivially_copy_constructible
|
||||
|
||||
---
|
||||
llvm/include/llvm/Support/type_traits.h | 16 ----------------
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sun, 8 May 2022 16:42:09 -0400
|
||||
Subject: [PATCH 18/31] Use std::is_trivially_copy_constructible
|
||||
|
||||
---
|
||||
llvm/include/llvm/Support/type_traits.h | 37 ++-----------------------
|
||||
1 file changed, 2 insertions(+), 35 deletions(-)
|
||||
|
||||
diff --git a/llvm/include/llvm/Support/type_traits.h b/llvm/include/llvm/Support/type_traits.h
|
||||
index a6046de87d1e3e1264a0040826ea347b870a8f9e..292a2cb78b93717647cf88d00f88c2eec14f52f6 100644
|
||||
--- a/llvm/include/llvm/Support/type_traits.h
|
||||
+++ b/llvm/include/llvm/Support/type_traits.h
|
||||
@@ -92,44 +92,11 @@ union trivial_helper {
|
||||
|
||||
} // end namespace detail
|
||||
|
||||
-/// An implementation of `std::is_trivially_copy_constructible` since we have
|
||||
-/// users with STLs that don't yet include it.
|
||||
template <typename T>
|
||||
-struct is_trivially_copy_constructible
|
||||
- : std::is_copy_constructible<
|
||||
- ::llvm::detail::copy_construction_triviality_helper<T>> {};
|
||||
-template <typename T>
|
||||
-struct is_trivially_copy_constructible<T &> : std::true_type {};
|
||||
-template <typename T>
|
||||
-struct is_trivially_copy_constructible<T &&> : std::false_type {};
|
||||
+using is_trivially_move_constructible = std::is_trivially_move_constructible<T>;
|
||||
|
||||
-/// An implementation of `std::is_trivially_move_constructible` since we have
|
||||
-/// users with STLs that don't yet include it.
|
||||
-template <typename T>
|
||||
-struct is_trivially_move_constructible
|
||||
- : std::is_move_constructible<
|
||||
- ::llvm::detail::move_construction_triviality_helper<T>> {};
|
||||
template <typename T>
|
||||
-struct is_trivially_move_constructible<T &> : std::true_type {};
|
||||
-template <typename T>
|
||||
-struct is_trivially_move_constructible<T &&> : std::true_type {};
|
||||
-
|
||||
-
|
||||
-template <typename T>
|
||||
-struct is_copy_assignable {
|
||||
- template<class F>
|
||||
- static auto get(F*) -> decltype(std::declval<F &>() = std::declval<const F &>(), std::true_type{});
|
||||
- static std::false_type get(...);
|
||||
- static constexpr bool value = decltype(get((T*)nullptr))::value;
|
||||
-};
|
||||
-
|
||||
-template <typename T>
|
||||
-struct is_move_assignable {
|
||||
- template<class F>
|
||||
- static auto get(F*) -> decltype(std::declval<F &>() = std::declval<F &&>(), std::true_type{});
|
||||
- static std::false_type get(...);
|
||||
- static constexpr bool value = decltype(get((T*)nullptr))::value;
|
||||
-};
|
||||
+using is_trivially_copy_constructible = std::is_trivially_copy_constructible<T>;
|
||||
|
||||
} // end namespace llvm
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Tue, 3 May 2022 20:22:38 -0400
|
||||
Subject: [PATCH 18/34] Windows support
|
||||
Subject: [PATCH 18/35] Windows support
|
||||
|
||||
---
|
||||
.../llvm/Support/Windows/WindowsSupport.h | 45 +++++----
|
||||
@@ -204,10 +204,10 @@ index bc04c5ab5113563fb82d7b3b168985369b611f4b..57eb64a6017a6964ab14b40b8c6b3563
|
||||
|
||||
ConvertUTF_RESTORE_WARNINGS
|
||||
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
|
||||
index 3b7d8d6db5f0df31e18b91be716a4fd21e7e3549..4769d34a14f3f2cbaaa4df50ea7111fe9fa2792f 100644
|
||||
index ae5428825f7f62ad8e742490448d40aea7506990..9ea41cad8fed864b53e2e463450c066fb4e00131 100644
|
||||
--- a/llvm/lib/Support/raw_ostream.cpp
|
||||
+++ b/llvm/lib/Support/raw_ostream.cpp
|
||||
@@ -534,7 +534,6 @@ void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) {
|
||||
@@ -535,7 +535,6 @@ void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) {
|
||||
DWORD WinLastError = GetLastError();
|
||||
if (WinLastError == ERROR_BROKEN_PIPE ||
|
||||
(WinLastError == ERROR_NO_DATA && errno == EINVAL)) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sun, 8 May 2022 16:46:20 -0400
|
||||
Subject: [PATCH 19/34] Prefer fmtlib
|
||||
Subject: [PATCH 19/35] Prefer fmtlib
|
||||
|
||||
---
|
||||
llvm/lib/Support/ErrorHandling.cpp | 20 ++++++--------------
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sun, 8 May 2022 16:49:36 -0400
|
||||
Subject: [PATCH 20/34] Prefer wpi's fs.h
|
||||
Subject: [PATCH 20/35] Prefer wpi's fs.h
|
||||
|
||||
---
|
||||
llvm/include/llvm/Support/raw_ostream.h | 7 ++-----
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sun, 8 May 2022 19:16:51 -0400
|
||||
Subject: [PATCH 21/34] Remove unused functions
|
||||
Subject: [PATCH 21/35] Remove unused functions
|
||||
|
||||
---
|
||||
llvm/include/llvm/Support/raw_ostream.h | 5 +-
|
||||
@@ -62,10 +62,10 @@ index 54137a331ca9e752b02c0f16ae996094a6f2fafa..e253d6f7a5ca3aee75823efdb9717dcd
|
||||
|
||||
#include <winerror.h>
|
||||
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
|
||||
index 4769d34a14f3f2cbaaa4df50ea7111fe9fa2792f..f9928ac969932b6baea60a80750477d78b6a5b02 100644
|
||||
index 9ea41cad8fed864b53e2e463450c066fb4e00131..44149e85876f089756dcce151670a6060eadfee1 100644
|
||||
--- a/llvm/lib/Support/raw_ostream.cpp
|
||||
+++ b/llvm/lib/Support/raw_ostream.cpp
|
||||
@@ -175,16 +175,6 @@ raw_ostream &raw_ostream::write_escaped(std::string_view Str,
|
||||
@@ -176,16 +176,6 @@ raw_ostream &raw_ostream::write_escaped(std::string_view Str,
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ index 4769d34a14f3f2cbaaa4df50ea7111fe9fa2792f..f9928ac969932b6baea60a80750477d7
|
||||
void raw_ostream::flush_nonempty() {
|
||||
assert(OutBufCur > OutBufStart && "Invalid call to flush_nonempty.");
|
||||
size_t Length = OutBufCur - OutBufStart;
|
||||
@@ -327,15 +317,22 @@ static int getFD(std::string_view Filename, std::error_code &EC,
|
||||
@@ -328,15 +318,22 @@ static int getFD(std::string_view Filename, std::error_code &EC,
|
||||
if (Filename == "-") {
|
||||
EC = std::error_code();
|
||||
// Change stdout's text/binary mode based on the Flags.
|
||||
@@ -110,7 +110,7 @@ index 4769d34a14f3f2cbaaa4df50ea7111fe9fa2792f..f9928ac969932b6baea60a80750477d7
|
||||
if (EC)
|
||||
return -1;
|
||||
|
||||
@@ -395,12 +392,8 @@ raw_fd_ostream::raw_fd_ostream(int fd, bool shouldClose, bool unbuffered,
|
||||
@@ -396,12 +393,8 @@ raw_fd_ostream::raw_fd_ostream(int fd, bool shouldClose, bool unbuffered,
|
||||
|
||||
// Get the starting position.
|
||||
off_t loc = ::lseek(FD, 0, SEEK_CUR);
|
||||
@@ -124,7 +124,7 @@ index 4769d34a14f3f2cbaaa4df50ea7111fe9fa2792f..f9928ac969932b6baea60a80750477d7
|
||||
#else
|
||||
SupportsSeeking = !EC && loc != (off_t)-1;
|
||||
#endif
|
||||
@@ -413,10 +406,8 @@ raw_fd_ostream::raw_fd_ostream(int fd, bool shouldClose, bool unbuffered,
|
||||
@@ -414,10 +407,8 @@ raw_fd_ostream::raw_fd_ostream(int fd, bool shouldClose, bool unbuffered,
|
||||
raw_fd_ostream::~raw_fd_ostream() {
|
||||
if (FD >= 0) {
|
||||
flush();
|
||||
@@ -137,7 +137,7 @@ index 4769d34a14f3f2cbaaa4df50ea7111fe9fa2792f..f9928ac969932b6baea60a80750477d7
|
||||
}
|
||||
|
||||
#ifdef __MINGW32__
|
||||
@@ -511,7 +502,11 @@ void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) {
|
||||
@@ -512,7 +503,11 @@ void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) {
|
||||
|
||||
do {
|
||||
size_t ChunkSize = std::min(Size, MaxWriteSize);
|
||||
@@ -149,7 +149,7 @@ index 4769d34a14f3f2cbaaa4df50ea7111fe9fa2792f..f9928ac969932b6baea60a80750477d7
|
||||
|
||||
if (ret < 0) {
|
||||
// If it's a recoverable error, swallow it and retry the write.
|
||||
@@ -554,8 +549,8 @@ void raw_fd_ostream::close() {
|
||||
@@ -555,8 +550,8 @@ void raw_fd_ostream::close() {
|
||||
assert(ShouldClose);
|
||||
ShouldClose = false;
|
||||
flush();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Sun, 8 May 2022 19:30:43 -0400
|
||||
Subject: [PATCH 22/34] OS-specific changes
|
||||
Subject: [PATCH 22/35] OS-specific changes
|
||||
|
||||
---
|
||||
llvm/lib/Support/ErrorHandling.cpp | 16 +++++++---------
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Mon, 9 May 2022 00:04:30 -0400
|
||||
Subject: [PATCH 23/34] Use SmallVector for UTF conversion
|
||||
Subject: [PATCH 23/35] Use SmallVector for UTF conversion
|
||||
|
||||
---
|
||||
llvm/include/llvm/Support/ConvertUTF.h | 6 +++---
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Thu, 19 May 2022 00:58:36 -0400
|
||||
Subject: [PATCH 24/34] Prefer to use static pointers in raw_ostream
|
||||
Subject: [PATCH 24/35] Prefer to use static pointers in raw_ostream
|
||||
|
||||
See #1401
|
||||
---
|
||||
@@ -9,13 +9,13 @@ See #1401
|
||||
1 file changed, 4 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
|
||||
index f9928ac969932b6baea60a80750477d78b6a5b02..1de34976844d500970b833fca35324e2948733b7 100644
|
||||
index 44149e85876f089756dcce151670a6060eadfee1..8fe686142b8cdba76287a3b8b97569fde922f2bf 100644
|
||||
--- a/llvm/lib/Support/raw_ostream.cpp
|
||||
+++ b/llvm/lib/Support/raw_ostream.cpp
|
||||
@@ -613,15 +613,15 @@ void raw_fd_ostream::anchor() {}
|
||||
raw_fd_ostream &llvm::outs() {
|
||||
// Set buffer settings to model stdout behavior.
|
||||
std::error_code EC;
|
||||
@@ -615,9 +615,9 @@ raw_fd_ostream &llvm::outs() {
|
||||
EC = enableAutoConversion(STDOUT_FILENO);
|
||||
assert(!EC);
|
||||
#endif
|
||||
- static raw_fd_ostream S("-", EC, sys::fs::OF_None);
|
||||
+ static raw_fd_ostream* S = new raw_fd_ostream("-", EC, sys::fs::OF_None);
|
||||
assert(!EC);
|
||||
@@ -24,7 +24,10 @@ index f9928ac969932b6baea60a80750477d78b6a5b02..1de34976844d500970b833fca35324e2
|
||||
}
|
||||
|
||||
raw_fd_ostream &llvm::errs() {
|
||||
// Set standard error to be unbuffered and tied to outs() by default.
|
||||
@@ -626,8 +626,8 @@ raw_fd_ostream &llvm::errs() {
|
||||
std::error_code EC = enableAutoConversion(STDERR_FILENO);
|
||||
assert(!EC);
|
||||
#endif
|
||||
- static raw_fd_ostream S(STDERR_FILENO, false, true);
|
||||
- return S;
|
||||
+ static raw_fd_ostream* S = new raw_fd_ostream(STDERR_FILENO, false, true);
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: PJ Reiniger <pj.reiniger@gmail.com>
|
||||
Date: Thu, 19 May 2022 01:12:41 -0400
|
||||
Subject: [PATCH 25/34] constexpr endian byte swap
|
||||
Date: Fri, 1 Mar 2024 11:56:17 -0800
|
||||
Subject: [PATCH 25/35] constexpr endian byte swap
|
||||
|
||||
---
|
||||
llvm/include/llvm/Support/Endian.h | 4 +++-
|
||||
1 file changed, 3 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/llvm/include/llvm/Support/Endian.h b/llvm/include/llvm/Support/Endian.h
|
||||
index 5e7c1e961b9d1e0fd6bcd0c923f678a5e1596860..2e883ff05b7e287151b6031f66d3b4aefd1bf297 100644
|
||||
index 4c0405cf1e2f69c6268d708badc2aef6dd968b51..f31fbf70fb723d19634e61ea4f21549fc767e58c 100644
|
||||
--- a/llvm/include/llvm/Support/Endian.h
|
||||
+++ b/llvm/include/llvm/Support/Endian.h
|
||||
@@ -55,7 +55,9 @@ inline value_type byte_swap(value_type value, endianness endian) {
|
||||
@@ -50,7 +50,9 @@ template <typename value_type>
|
||||
/// Swap the bytes of value to match the given endianness.
|
||||
template<typename value_type, endianness endian>
|
||||
inline value_type byte_swap(value_type value) {
|
||||
template <typename value_type, endianness endian>
|
||||
[[nodiscard]] inline value_type byte_swap(value_type value) {
|
||||
- return byte_swap(value, endian);
|
||||
+ if constexpr ((endian != native) && (endian != system_endianness()))
|
||||
+ if constexpr (endian != llvm::endianness::native)
|
||||
+ sys::swapByteOrder(value);
|
||||
+ return value;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Tyler Veness <calcmogul@gmail.com>
|
||||
Date: Wed, 10 Aug 2022 17:07:52 -0700
|
||||
Subject: [PATCH 26/34] Copy type traits from STLExtras.h into PointerUnion.h
|
||||
Subject: [PATCH 26/35] Copy type traits from STLExtras.h into PointerUnion.h
|
||||
|
||||
---
|
||||
llvm/include/llvm/ADT/PointerUnion.h | 46 ++++++++++++++++++++++++++++
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Tyler Veness <calcmogul@gmail.com>
|
||||
Date: Wed, 10 Aug 2022 22:35:00 -0700
|
||||
Subject: [PATCH 27/34] Remove StringMap test for llvm::sort()
|
||||
Subject: [PATCH 27/35] Remove StringMap test for llvm::sort()
|
||||
|
||||
---
|
||||
llvm/unittests/ADT/StringMapTest.cpp | 14 --------------
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Leander Schulten <Leander.Schulten@rwth-aachen.de>
|
||||
Date: Mon, 10 Jul 2023 00:53:43 +0200
|
||||
Subject: [PATCH 28/34] Unused variable in release mode
|
||||
Subject: [PATCH 28/35] Unused variable in release mode
|
||||
|
||||
---
|
||||
llvm/include/llvm/ADT/DenseMap.h | 2 +-
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Tyler Veness <calcmogul@gmail.com>
|
||||
Date: Tue, 11 Jul 2023 22:56:09 -0700
|
||||
Subject: [PATCH 29/34] Use C++20 <bit> header
|
||||
Subject: [PATCH 29/35] Use C++20 <bit> header
|
||||
|
||||
---
|
||||
llvm/include/llvm/ADT/DenseMap.h | 3 +-
|
||||
llvm/include/llvm/ADT/Hashing.h | 35 +--
|
||||
llvm/include/llvm/ADT/bit.h | 287 -------------------------
|
||||
llvm/include/llvm/ADT/bit.h | 313 -------------------------
|
||||
llvm/include/llvm/Support/MathExtras.h | 21 +-
|
||||
4 files changed, 31 insertions(+), 315 deletions(-)
|
||||
4 files changed, 31 insertions(+), 341 deletions(-)
|
||||
|
||||
diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h
|
||||
index e9bd3bfa4a6fe0fa26ff20069bbadc816c8baa65..93b50c9e53af4ea3af5fd0329a8a03bdce659e9d 100644
|
||||
@@ -32,7 +32,7 @@ index e9bd3bfa4a6fe0fa26ff20069bbadc816c8baa65..93b50c9e53af4ea3af5fd0329a8a03bd
|
||||
}
|
||||
|
||||
diff --git a/llvm/include/llvm/ADT/Hashing.h b/llvm/include/llvm/ADT/Hashing.h
|
||||
index 781bdb7416392e3f60a1ac3a38fbcf5324b5395f..28934add722f518ae1e9cb9c4a23d2212a47cbdf 100644
|
||||
index 08d6edb14eb3cd51405329aae61b9782266a2590..e84d53e6bf2f741be562b9d66bf0bdfe4a79f936 100644
|
||||
--- a/llvm/include/llvm/ADT/Hashing.h
|
||||
+++ b/llvm/include/llvm/ADT/Hashing.h
|
||||
@@ -49,6 +49,7 @@
|
||||
@@ -123,13 +123,39 @@ index 781bdb7416392e3f60a1ac3a38fbcf5324b5395f..28934add722f518ae1e9cb9c4a23d221
|
||||
h4 = h0 + h5;
|
||||
mix_32_bytes(s, h3, h4);
|
||||
diff --git a/llvm/include/llvm/ADT/bit.h b/llvm/include/llvm/ADT/bit.h
|
||||
index 2840c5f608d3ea896e1867dd4710685da9572f2d..0a4a3634820efbc0a8ca675e3ad7c98469260d0b 100644
|
||||
index c42b5e686bdc9cf3da71d8edaddc08216fe5fb2a..a19b6a9b80da2965f1308d3e7b0ade593b522a08 100644
|
||||
--- a/llvm/include/llvm/ADT/bit.h
|
||||
+++ b/llvm/include/llvm/ADT/bit.h
|
||||
@@ -27,18 +27,6 @@
|
||||
@@ -27,44 +27,6 @@
|
||||
#include <cstdlib> // for _byteswap_{ushort,ulong,uint64}
|
||||
#endif
|
||||
|
||||
-#if defined(__linux__) || defined(__GNU__) || defined(__HAIKU__) || \
|
||||
- defined(__Fuchsia__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) || \
|
||||
- defined(__OpenBSD__) || defined(__DragonFly__)
|
||||
-#include <endian.h>
|
||||
-#elif defined(_AIX)
|
||||
-#include <sys/machine.h>
|
||||
-#elif defined(__sun)
|
||||
-/* Solaris provides _BIG_ENDIAN/_LITTLE_ENDIAN selector in sys/types.h */
|
||||
-#include <sys/types.h>
|
||||
-#define BIG_ENDIAN 4321
|
||||
-#define LITTLE_ENDIAN 1234
|
||||
-#if defined(_BIG_ENDIAN)
|
||||
-#define BYTE_ORDER BIG_ENDIAN
|
||||
-#else
|
||||
-#define BYTE_ORDER LITTLE_ENDIAN
|
||||
-#endif
|
||||
-#elif defined(__MVS__)
|
||||
-#define BIG_ENDIAN 4321
|
||||
-#define LITTLE_ENDIAN 1234
|
||||
-#define BYTE_ORDER BIG_ENDIAN
|
||||
-#else
|
||||
-#if !defined(BYTE_ORDER) && !defined(_WIN32)
|
||||
-#include <machine/endian.h>
|
||||
-#endif
|
||||
-#endif
|
||||
-
|
||||
-#ifdef _MSC_VER
|
||||
-// Declare these intrinsics manually rather including intrin.h. It's very
|
||||
-// expensive, and bit.h is popular via MathExtras.h.
|
||||
@@ -144,8 +170,8 @@ index 2840c5f608d3ea896e1867dd4710685da9572f2d..0a4a3634820efbc0a8ca675e3ad7c984
|
||||
-
|
||||
namespace llvm {
|
||||
|
||||
// This implementation of bit_cast is different from the C++20 one in two ways:
|
||||
@@ -106,281 +94,6 @@ template <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
|
||||
enum class endianness {
|
||||
@@ -142,281 +104,6 @@ template <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -428,7 +454,7 @@ index 2840c5f608d3ea896e1867dd4710685da9572f2d..0a4a3634820efbc0a8ca675e3ad7c984
|
||||
|
||||
#endif
|
||||
diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h
|
||||
index b82d9883c41008dcbbd933709c6e854ad74c5b58..5f034b694989d8ef24e0b249abd12a5c20146b97 100644
|
||||
index daa79d99578e934ca001d1de5d2772ff961b8fc3..f66e64b601d01f17dc6c7a4e568cc4eb1d9bb985 100644
|
||||
--- a/llvm/include/llvm/Support/MathExtras.h
|
||||
+++ b/llvm/include/llvm/Support/MathExtras.h
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Tyler Veness <calcmogul@gmail.com>
|
||||
Date: Sun, 30 Jul 2023 14:17:37 -0700
|
||||
Subject: [PATCH 30/34] Remove DenseMap GTest printer test
|
||||
Subject: [PATCH 30/35] Remove DenseMap GTest printer test
|
||||
|
||||
LLVM modifies internal GTest headers to support it, which we can't do.
|
||||
---
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Tyler Veness <calcmogul@gmail.com>
|
||||
Date: Fri, 15 Sep 2023 18:26:50 -0700
|
||||
Subject: [PATCH 31/34] Replace deprecated std::aligned_storage_t
|
||||
Subject: [PATCH 31/35] Replace deprecated std::aligned_storage_t
|
||||
|
||||
---
|
||||
llvm/include/llvm/ADT/FunctionExtras.h | 4 ++--
|
||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/llvm/include/llvm/ADT/FunctionExtras.h b/llvm/include/llvm/ADT/FunctionExtras.h
|
||||
index 1daeae915eb506b32a2d1296d2f0fe4e6dab606e..2e60e34d69914bd9b2197fc0a0e75a8e025674b2 100644
|
||||
index 043d8d90fff03d571a923c264b49be37a5dffa09..a62d5ce00d784def5ae21b8d91cea40cee7bf942 100644
|
||||
--- a/llvm/include/llvm/ADT/FunctionExtras.h
|
||||
+++ b/llvm/include/llvm/ADT/FunctionExtras.h
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "llvm/ADT/STLForwardCompat.h"
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "llvm/Support/Compiler.h"
|
||||
#include "llvm/Support/MemAlloc.h"
|
||||
#include "llvm/Support/type_traits.h"
|
||||
+#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
@@ -167,8 +168,7 @@ protected:
|
||||
@@ -168,8 +169,7 @@ protected:
|
||||
// provide four pointers worth of storage here.
|
||||
// This is mutable as an inlined `const unique_function<void() const>` may
|
||||
// still modify its own mutable members.
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Benjamin Hall <bhallctre@gmail.com>
|
||||
Date: Mon, 23 Oct 2023 21:36:40 -0400
|
||||
Subject: [PATCH 32/34] Fix compilation of MathExtras.h on Windows with /sdl
|
||||
|
||||
See https://github.com/llvm/llvm-project/pull/68978
|
||||
---
|
||||
llvm/include/llvm/Support/MathExtras.h | 5 ++++-
|
||||
1 file changed, 4 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h
|
||||
index 5f034b694989d8ef24e0b249abd12a5c20146b97..03db6e4d92cb3b62ac3d8b3cbd97783817c6326b 100644
|
||||
--- a/llvm/include/llvm/Support/MathExtras.h
|
||||
+++ b/llvm/include/llvm/Support/MathExtras.h
|
||||
@@ -356,7 +356,10 @@ inline uint64_t alignTo(uint64_t Value, uint64_t Align) {
|
||||
inline uint64_t alignToPowerOf2(uint64_t Value, uint64_t Align) {
|
||||
assert(Align != 0 && (Align & (Align - 1)) == 0 &&
|
||||
"Align must be a power of 2");
|
||||
- return (Value + Align - 1) & -Align;
|
||||
+ // Replace unary minus to avoid compilation error on Windows:
|
||||
+ // "unary minus operator applied to unsigned type, result still unsigned"
|
||||
+ uint64_t negAlign = (~Align) + 1;
|
||||
+ return (Value + Align - 1) & negAlign;
|
||||
}
|
||||
|
||||
/// If non-zero \p Skew is specified, the return value will be a minimal integer
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Peter Johnson <johnson.peter@gmail.com>
|
||||
Date: Sun, 29 Oct 2023 23:00:08 -0700
|
||||
Subject: [PATCH 33/34] raw_ostream: Add SetNumBytesInBuffer
|
||||
Subject: [PATCH 32/35] raw_ostream: Add SetNumBytesInBuffer
|
||||
|
||||
---
|
||||
llvm/include/llvm/Support/raw_ostream.h | 5 +++++
|
||||
@@ -1,7 +1,7 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Peter Johnson <johnson.peter@gmail.com>
|
||||
Date: Sat, 2 Dec 2023 15:21:32 -0800
|
||||
Subject: [PATCH 34/34] type_traits.h: Add is_constexpr()
|
||||
Subject: [PATCH 33/35] type_traits.h: Add is_constexpr()
|
||||
|
||||
---
|
||||
llvm/include/llvm/Support/type_traits.h | 5 +++++
|
||||
@@ -0,0 +1,28 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Tyler Veness <calcmogul@gmail.com>
|
||||
Date: Fri, 1 Mar 2024 11:37:36 -0800
|
||||
Subject: [PATCH 34/35] Add back removed raw_string_ostream::write_impl()
|
||||
|
||||
---
|
||||
llvm/lib/Support/raw_ostream.cpp | 8 ++++++++
|
||||
1 file changed, 8 insertions(+)
|
||||
|
||||
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
|
||||
index 8fe686142b8cdba76287a3b8b97569fde922f2bf..9134f3d3db220ec5afb87b72cb9aed76c52a80ca 100644
|
||||
--- a/llvm/lib/Support/raw_ostream.cpp
|
||||
+++ b/llvm/lib/Support/raw_ostream.cpp
|
||||
@@ -656,6 +656,14 @@ bool raw_fd_stream::classof(const raw_ostream *OS) {
|
||||
return OS->get_kind() == OStreamKind::OK_FDStream;
|
||||
}
|
||||
|
||||
+//===----------------------------------------------------------------------===//
|
||||
+// raw_string_ostream
|
||||
+//===----------------------------------------------------------------------===//
|
||||
+
|
||||
+void raw_string_ostream::write_impl(const char *Ptr, size_t Size) {
|
||||
+ OS.append(Ptr, Size);
|
||||
+}
|
||||
+
|
||||
//===----------------------------------------------------------------------===//
|
||||
// raw_svector_ostream
|
||||
//===----------------------------------------------------------------------===//
|
||||
@@ -0,0 +1,43 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Tyler Veness <calcmogul@gmail.com>
|
||||
Date: Sun, 17 Mar 2024 14:51:11 -0700
|
||||
Subject: [PATCH 35/35] Remove auto-conversion from raw_ostream
|
||||
|
||||
---
|
||||
llvm/lib/Support/raw_ostream.cpp | 9 ---------
|
||||
1 file changed, 9 deletions(-)
|
||||
|
||||
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
|
||||
index 9134f3d3db220ec5afb87b72cb9aed76c52a80ca..efba615e1b77de335ab343cc56ce9b00ccf3f462 100644
|
||||
--- a/llvm/lib/Support/raw_ostream.cpp
|
||||
+++ b/llvm/lib/Support/raw_ostream.cpp
|
||||
@@ -19,7 +19,6 @@
|
||||
#include "wpi/SmallVector.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/Config/config.h"
|
||||
-#include "llvm/Support/AutoConvert.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
@@ -611,10 +610,6 @@ void raw_fd_ostream::anchor() {}
|
||||
raw_fd_ostream &llvm::outs() {
|
||||
// Set buffer settings to model stdout behavior.
|
||||
std::error_code EC;
|
||||
-#ifdef __MVS__
|
||||
- EC = enableAutoConversion(STDOUT_FILENO);
|
||||
- assert(!EC);
|
||||
-#endif
|
||||
static raw_fd_ostream* S = new raw_fd_ostream("-", EC, sys::fs::OF_None);
|
||||
assert(!EC);
|
||||
return *S;
|
||||
@@ -622,10 +617,6 @@ raw_fd_ostream &llvm::outs() {
|
||||
|
||||
raw_fd_ostream &llvm::errs() {
|
||||
// Set standard error to be unbuffered and tied to outs() by default.
|
||||
-#ifdef __MVS__
|
||||
- std::error_code EC = enableAutoConversion(STDERR_FILENO);
|
||||
- assert(!EC);
|
||||
-#endif
|
||||
static raw_fd_ostream* S = new raw_fd_ostream(STDERR_FILENO, false, true);
|
||||
return *S;
|
||||
}
|
||||
@@ -171,7 +171,7 @@ def overwrite_tests(wpiutil_root, llvm_root):
|
||||
|
||||
|
||||
def main():
|
||||
upstream_root = clone_repo("https://github.com/llvm/llvm-project", "llvmorg-17.0.5")
|
||||
upstream_root = clone_repo("https://github.com/llvm/llvm-project", "llvmorg-18.1.1")
|
||||
wpilib_root = get_repo_root()
|
||||
wpiutil = os.path.join(wpilib_root, "wpiutil")
|
||||
|
||||
@@ -209,9 +209,10 @@ def main():
|
||||
"0029-Use-C-20-bit-header.patch",
|
||||
"0030-Remove-DenseMap-GTest-printer-test.patch",
|
||||
"0031-Replace-deprecated-std-aligned_storage_t.patch",
|
||||
"0032-Fix-compilation-of-MathExtras.h-on-Windows-with-sdl.patch",
|
||||
"0033-raw_ostream-Add-SetNumBytesInBuffer.patch",
|
||||
"0034-type_traits.h-Add-is_constexpr.patch",
|
||||
"0032-raw_ostream-Add-SetNumBytesInBuffer.patch",
|
||||
"0033-type_traits.h-Add-is_constexpr.patch",
|
||||
"0034-Add-back-removed-raw_string_ostream-write_impl.patch",
|
||||
"0035-Remove-auto-conversion-from-raw_ostream.patch",
|
||||
]:
|
||||
git_am(
|
||||
os.path.join(wpilib_root, "upstream_utils/llvm_patches", f),
|
||||
|
||||
@@ -174,8 +174,7 @@ std::optional<std::string> Command::GetPreviousCompositionSite() const {
|
||||
|
||||
void Command::InitSendable(wpi::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Command");
|
||||
builder.AddStringProperty(
|
||||
".name", [this] { return GetName(); }, nullptr);
|
||||
builder.AddStringProperty(".name", [this] { return GetName(); }, nullptr);
|
||||
builder.AddBooleanProperty(
|
||||
"running", [this] { return IsScheduled(); },
|
||||
[this](bool value) {
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <wpi/deprecated.h>
|
||||
|
||||
#include "frc2/command/Command.h"
|
||||
|
||||
namespace frc2 {
|
||||
@@ -19,7 +17,7 @@ namespace frc2 {
|
||||
*/
|
||||
class [[deprecated("Use Command instead")]] CommandBase : public Command {
|
||||
protected:
|
||||
WPI_DEPRECATED("Use Command instead")
|
||||
[[deprecated("Use Command instead")]]
|
||||
CommandBase();
|
||||
};
|
||||
} // namespace frc2
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include <wpi/deprecated.h>
|
||||
|
||||
#include "frc2/command/Command.h"
|
||||
#include "frc2/command/CommandPtr.h"
|
||||
|
||||
@@ -36,8 +34,9 @@ class CommandHelper : public Base {
|
||||
}
|
||||
|
||||
protected:
|
||||
WPI_DEPRECATED("Use ToPtr() instead")
|
||||
std::unique_ptr<Command> TransferOwnership() && override {
|
||||
[[deprecated("Use ToPtr() instead")]]
|
||||
std::unique_ptr<Command> TransferOwnership() &&
|
||||
override {
|
||||
return std::make_unique<CRTP>(std::move(*static_cast<CRTP*>(this)));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/deprecated.h>
|
||||
#include <wpi/sendable/SendableBuilder.h>
|
||||
|
||||
#include "frc2/command/Command.h"
|
||||
@@ -135,8 +134,9 @@ class SelectCommand : public CommandHelper<Command, SelectCommand<Key>> {
|
||||
}
|
||||
|
||||
protected:
|
||||
WPI_DEPRECATED("Use ToPtr() instead")
|
||||
std::unique_ptr<Command> TransferOwnership() && override {
|
||||
[[deprecated("Use ToPtr() instead")]]
|
||||
std::unique_ptr<Command> TransferOwnership() &&
|
||||
override {
|
||||
return std::make_unique<SelectCommand>(std::move(*this));
|
||||
}
|
||||
|
||||
|
||||
@@ -65,9 +65,9 @@ class TrapezoidProfileCommand
|
||||
* @deprecated The new constructor allows you to pass in a supplier for
|
||||
* desired and current state. This allows you to change goals at runtime.
|
||||
*/
|
||||
WPI_DEPRECATED(
|
||||
[[deprecated(
|
||||
"The new constructor allows you to pass in a supplier for desired and "
|
||||
"current state. This allows you to change goals at runtime.")
|
||||
"current state. This allows you to change goals at runtime.")]]
|
||||
TrapezoidProfileCommand(frc::TrapezoidProfile<Distance> profile,
|
||||
std::function<void(State)> output,
|
||||
Requirements requirements = {})
|
||||
|
||||
@@ -24,8 +24,8 @@ std::vector<CommonType> make_vector(Args&&... args) {
|
||||
vec.reserve(sizeof...(Args));
|
||||
|
||||
using arr_t = int[];
|
||||
[[maybe_unused]] arr_t arr{
|
||||
0, (vec.emplace_back(std::forward<Args>(args)), 0)...};
|
||||
[[maybe_unused]]
|
||||
arr_t arr{0, (vec.emplace_back(std::forward<Args>(args)), 0)...};
|
||||
|
||||
return vec;
|
||||
}
|
||||
|
||||
@@ -150,6 +150,5 @@ int ADXRS450_Gyro::GetPort() const {
|
||||
|
||||
void ADXRS450_Gyro::InitSendable(wpi::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Gyro");
|
||||
builder.AddDoubleProperty(
|
||||
"Value", [=, this] { return GetAngle(); }, nullptr);
|
||||
builder.AddDoubleProperty("Value", [=, this] { return GetAngle(); }, nullptr);
|
||||
}
|
||||
|
||||
@@ -143,6 +143,5 @@ std::shared_ptr<AnalogInput> AnalogGyro::GetAnalogInput() const {
|
||||
|
||||
void AnalogGyro::InitSendable(wpi::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Gyro");
|
||||
builder.AddDoubleProperty(
|
||||
"Value", [=, this] { return GetAngle(); }, nullptr);
|
||||
builder.AddDoubleProperty("Value", [=, this] { return GetAngle(); }, nullptr);
|
||||
}
|
||||
|
||||
@@ -45,6 +45,5 @@ double AnalogPotentiometer::Get() const {
|
||||
|
||||
void AnalogPotentiometer::InitSendable(wpi::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Analog Input");
|
||||
builder.AddDoubleProperty(
|
||||
"Value", [=, this] { return Get(); }, nullptr);
|
||||
builder.AddDoubleProperty("Value", [=, this] { return Get(); }, nullptr);
|
||||
}
|
||||
|
||||
@@ -41,10 +41,7 @@ double BuiltInAccelerometer::GetZ() {
|
||||
|
||||
void BuiltInAccelerometer::InitSendable(wpi::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("3AxisAccelerometer");
|
||||
builder.AddDoubleProperty(
|
||||
"X", [=, this] { return GetX(); }, nullptr);
|
||||
builder.AddDoubleProperty(
|
||||
"Y", [=, this] { return GetY(); }, nullptr);
|
||||
builder.AddDoubleProperty(
|
||||
"Z", [=, this] { return GetZ(); }, nullptr);
|
||||
builder.AddDoubleProperty("X", [=, this] { return GetX(); }, nullptr);
|
||||
builder.AddDoubleProperty("Y", [=, this] { return GetY(); }, nullptr);
|
||||
builder.AddDoubleProperty("Z", [=, this] { return GetZ(); }, nullptr);
|
||||
}
|
||||
|
||||
@@ -320,6 +320,5 @@ bool Counter::GetDirection() const {
|
||||
|
||||
void Counter::InitSendable(wpi::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Counter");
|
||||
builder.AddDoubleProperty(
|
||||
"Value", [=, this] { return Get(); }, nullptr);
|
||||
builder.AddDoubleProperty("Value", [=, this] { return Get(); }, nullptr);
|
||||
}
|
||||
|
||||
@@ -68,6 +68,5 @@ int DigitalInput::GetChannel() const {
|
||||
|
||||
void DigitalInput::InitSendable(wpi::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Digital Input");
|
||||
builder.AddBooleanProperty(
|
||||
"Value", [=, this] { return Get(); }, nullptr);
|
||||
builder.AddBooleanProperty("Value", [=, this] { return Get(); }, nullptr);
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user