Corruption of strings #269
Unanswered
earthboundkid
asked this question in
Q&A
Replies: 1 comment 9 replies
-
This is the code snippet: func buildName(path string) (string, error) {
ppath := strings.Clone(path)
// fmt.Println("*", path, ppath) // ← if I uncomment this, I don't get corruption!!
dateAdded, err := getDateAdded(ppath)
fmt.Println("*", path, ppath)
if err != nil {
return "", err
}
kind := getKind(path)
name := filepath.Base(path)
return fmt.Sprintf("%d/%02d/%s/%s", dateAdded.Year(), dateAdded.Month(), kind, name), nil
}
func getDateAdded(path string) (time.Time, error) {
var dateAdded foundation.Date
defer dateAdded.Release()
var err foundation.Error
defer err.Release()
s := strings.Clone(path) // Apparently, Foundation breaks strings sometimes!!
url := foundation.URL_FileURLWithPath(s)
defer url.Release()
if ok := url.GetResourceValueForKeyError(
unsafe.Pointer(&dateAdded),
foundation.URLAddedToDirectoryDateKey,
unsafe.Pointer(&err),
); !ok {
return time.Time{}, fmt.Errorf("could not read %q", path)
}
unixTimestamp := dateAdded.TimeIntervalSince1970()
seconds := math.Floor(float64(unixTimestamp))
nanoseconds := (float64(unixTimestamp) - seconds) * 1e9
return time.Unix(int64(seconds), int64(nanoseconds)), nil
} |
Beta Was this translation helpful? Give feedback.
9 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm seeing an issue where a Go string is sometimes corrupted when passed to darwinkit. Is there some magic thing I should do first to ensure the string isn't overwritten? I don't understand how they are supposed to interact. I tried just doing a defense strings.Clone, but somehow it didn't help and I still got corrupted memory.
Beta Was this translation helpful? Give feedback.
All reactions