-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: un-revert registration of db.sql
metrics
#2373
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
package reflect | ||
|
||
import ( | ||
"container/list" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's roll these reflection changes back, we shouldn't be copying a db.DB in the first place. I'll send a PR to rectify that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Excellent, thank you! Done |
||
"fmt" | ||
"reflect" | ||
"strings" | ||
|
@@ -131,6 +132,11 @@ func copyAny(src any, ptrs map[uintptr]any, copyConf *copyConfig) (dst any) { | |
return src | ||
} | ||
|
||
// Special case list.List to handle its internal structure | ||
if reflect.TypeOf(src) == reflect.TypeFor[*list.List]() { | ||
return copyList(src.(*list.List), ptrs, copyConf) | ||
} | ||
|
||
// Look up the corresponding copy function. | ||
switch v.Kind() { | ||
case reflect.Bool, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, | ||
|
@@ -146,7 +152,7 @@ func copyAny(src any, ptrs map[uintptr]any, copyConf *copyConfig) (dst any) { | |
dst = copyArray(src, ptrs, copyConf) | ||
case reflect.Map: | ||
dst = copyMap(src, ptrs, copyConf) | ||
case reflect.Ptr, reflect.UnsafePointer: | ||
case reflect.Pointer, reflect.UnsafePointer: | ||
dst = copyPointer(src, ptrs, copyConf) | ||
case reflect.Struct: | ||
dst = copyStruct(src, ptrs, copyConf) | ||
|
@@ -160,10 +166,22 @@ func copyAny(src any, ptrs map[uintptr]any, copyConf *copyConfig) (dst any) { | |
return | ||
} | ||
|
||
func copyList(src *list.List, ptrs map[uintptr]any, copyConf *copyConfig) *list.List { | ||
if src == nil { | ||
return nil | ||
} | ||
dst := list.New() | ||
for e := src.Front(); e != nil; e = e.Next() { | ||
copiedValue := copyAny(e.Value, ptrs, copyConf) | ||
dst.PushBack(copiedValue) | ||
} | ||
return dst | ||
} | ||
|
||
func copyPremitive(src any, ptr map[uintptr]any, copyConf *copyConfig) (dst any) { | ||
kind := reflect.ValueOf(src).Kind() | ||
switch kind { | ||
case reflect.Array, reflect.Chan, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice, reflect.Struct, reflect.UnsafePointer: | ||
case reflect.Array, reflect.Chan, reflect.Interface, reflect.Map, reflect.Pointer, reflect.Slice, reflect.Struct, reflect.UnsafePointer: | ||
panic(fmt.Sprintf("reflect: internal error: type %v is not a primitive", kind)) | ||
} | ||
dst = src | ||
|
@@ -225,7 +243,7 @@ func copyPointer(x any, ptrs map[uintptr]any, copyConf *copyConfig) any { | |
t := reflect.TypeOf(x) | ||
|
||
if v.Kind() != reflect.Pointer { | ||
panic(fmt.Errorf("reflect: internal error: must be a Pointer or Ptr; got %v", v.Kind())) | ||
panic(fmt.Errorf("reflect: internal error: must be a Pointer; got %v", v.Kind())) | ||
} | ||
|
||
if v.IsNil() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we create a helper function that opens + instruments in one, and use that function in all these locations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great idea - done