Skip to content

Commit 35d8e80

Browse files
committed
Structure sourceFile is now copied instead of passed-by-pointer
1 parent 1c57270 commit 35d8e80

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

internal/arduino/builder/internal/detector/cache.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type detectorCache struct {
3030

3131
type detectorCacheEntry struct {
3232
AddedIncludePath *paths.Path `json:"added_include_path,omitempty"`
33-
Compile *sourceFile `json:"compile,omitempty"`
33+
Compile sourceFile `json:"compile,omitempty"`
3434
CompileTask *runner.Task `json:"compile_task,omitempty"`
3535
MissingIncludeH *string `json:"missing_include_h,omitempty"`
3636
}
@@ -39,7 +39,7 @@ func (e *detectorCacheEntry) String() string {
3939
if e.AddedIncludePath != nil {
4040
return "Added include path: " + e.AddedIncludePath.String()
4141
}
42-
if e.Compile != nil && e.CompileTask != nil {
42+
if e.CompileTask != nil {
4343
return "Compiling: " + e.Compile.String() + " / " + e.CompileTask.String()
4444
}
4545
if e.MissingIncludeH != nil {

internal/arduino/builder/internal/detector/detector.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ func (l *SketchLibrariesDetector) findIncludes(
272272
// Pre-run cache entries
273273
l.preRunner = runner.New(ctx, jobs)
274274
for _, entry := range l.cache.EntriesAhead() {
275-
if entry.Compile != nil && entry.CompileTask != nil {
275+
if entry.CompileTask != nil {
276276
upToDate, _ := entry.Compile.ObjFileIsUpToDate()
277277
if !upToDate {
278278
_ = entry.Compile.PrepareBuildPath()
@@ -351,7 +351,7 @@ func (l *SketchLibrariesDetector) findIncludes(
351351
return nil
352352
}
353353

354-
func (l *SketchLibrariesDetector) gccPreprocessTask(sourceFile *sourceFile, buildProperties *properties.Map) *runner.Task {
354+
func (l *SketchLibrariesDetector) gccPreprocessTask(sourceFile sourceFile, buildProperties *properties.Map) *runner.Task {
355355
// Libraries may require the "utility" directory to be added to the include
356356
// search path, but only for the source code of the library, so we temporary
357357
// copy the current search path list and add the library' utility directory
@@ -517,7 +517,7 @@ func (l *SketchLibrariesDetector) queueSourceFilesFromFolder(
517517

518518
// makeSourceFile create a sourceFile object for the given source file path.
519519
// The given sourceFilePath can be absolute, or relative within the sourceRoot root folder.
520-
func (l *SketchLibrariesDetector) makeSourceFile(sourceRoot, buildRoot, sourceFilePath *paths.Path, extraIncludePaths ...*paths.Path) (*sourceFile, error) {
520+
func (l *SketchLibrariesDetector) makeSourceFile(sourceRoot, buildRoot, sourceFilePath *paths.Path, extraIncludePaths ...*paths.Path) (sourceFile, error) {
521521
if len(extraIncludePaths) > 1 {
522522
panic("only one extra include path allowed")
523523
}
@@ -530,15 +530,14 @@ func (l *SketchLibrariesDetector) makeSourceFile(sourceRoot, buildRoot, sourceFi
530530
var err error
531531
sourceFilePath, err = sourceRoot.RelTo(sourceFilePath)
532532
if err != nil {
533-
return nil, err
533+
return sourceFile{}, err
534534
}
535535
}
536-
res := &sourceFile{
536+
return sourceFile{
537537
SourcePath: sourceRoot.JoinPath(sourceFilePath),
538538
DepfilePath: buildRoot.Join(fmt.Sprintf("%s.libsdetect.d", sourceFilePath)),
539539
ExtraIncludePath: extraIncludePath,
540-
}
541-
return res, nil
540+
}, nil
542541
}
543542

544543
func (l *SketchLibrariesDetector) failIfImportedLibraryIsWrong() error {

internal/arduino/builder/internal/detector/source_file.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (f *sourceFile) String() string {
4646
}
4747

4848
// Equals checks if a sourceFile is equal to another.
49-
func (f *sourceFile) Equals(g *sourceFile) bool {
49+
func (f *sourceFile) Equals(g sourceFile) bool {
5050
return f.SourcePath.EqualsTo(g.SourcePath) &&
5151
f.DepfilePath.EqualsTo(g.DepfilePath) &&
5252
((f.ExtraIncludePath == nil && g.ExtraIncludePath == nil) ||
@@ -120,22 +120,22 @@ func (f *sourceFile) ObjFileIsUpToDate() (unchanged bool, err error) {
120120
}
121121

122122
// uniqueSourceFileQueue is a queue of source files that does not allow duplicates.
123-
type uniqueSourceFileQueue []*sourceFile
123+
type uniqueSourceFileQueue []sourceFile
124124

125125
// Push adds a source file to the queue if it is not already present.
126-
func (queue *uniqueSourceFileQueue) Push(value *sourceFile) {
126+
func (queue *uniqueSourceFileQueue) Push(value sourceFile) {
127127
if !queue.Contains(value) {
128128
*queue = append(*queue, value)
129129
}
130130
}
131131

132132
// Contains checks if the queue Contains a source file.
133-
func (queue uniqueSourceFileQueue) Contains(target *sourceFile) bool {
133+
func (queue uniqueSourceFileQueue) Contains(target sourceFile) bool {
134134
return slices.ContainsFunc(queue, target.Equals)
135135
}
136136

137137
// Pop removes and returns the first element of the queue.
138-
func (queue *uniqueSourceFileQueue) Pop() *sourceFile {
138+
func (queue *uniqueSourceFileQueue) Pop() sourceFile {
139139
old := *queue
140140
x := old[0]
141141
*queue = old[1:]

0 commit comments

Comments
 (0)