Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
_harness
.vscode
.vscode
12 changes: 10 additions & 2 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,6 @@ type Index struct {
// Collation allows users to specify language-specific rules for string comparison,
// such as rules for lettercase and accent marks.
type Collation struct {

// Locale defines the collation locale.
Locale string `bson:"locale"`

Expand Down Expand Up @@ -4274,10 +4273,19 @@ func (iter *Iter) Next(result interface{}) bool {
//
func (iter *Iter) All(result interface{}) error {
resultv := reflect.ValueOf(result)
if resultv.Kind() != reflect.Ptr || resultv.Elem().Kind() != reflect.Slice {
if resultv.Kind() != reflect.Ptr {
panic("result argument must be a slice address")
}

slicev := resultv.Elem()

if slicev.Kind() == reflect.Interface {
slicev = slicev.Elem()
}
if slicev.Kind() != reflect.Slice {
panic("result argument must be a slice address")
}

slicev = slicev.Slice(0, slicev.Cap())
elemt := slicev.Type().Elem()
i := 0
Expand Down
12 changes: 12 additions & 0 deletions session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,18 @@ func (s *S) TestInsertFindAll(c *C) {
// Ensure result is backed by the originally allocated array
c.Assert(&result[0], Equals, &allocd[0])

// Re-run test destination as a pointer to interface{}
var resultInterface interface{}

anotherslice := make([]R, 5)
resultInterface = anotherslice
err = coll.Find(nil).Sort("a").All(&resultInterface)
c.Assert(err, IsNil)
assertResult()

// Ensure result is backed by the originally allocated array
c.Assert(&result[0], Equals, &allocd[0])

// Non-pointer slice error
f := func() { coll.Find(nil).All(result) }
c.Assert(f, Panics, "result argument must be a slice address")
Expand Down