Can't createCollation

Open
#1,321 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
sqlite, swift
Domain
databases

Research direction

Start with Sources/SQLite/Core/Connection.swift at the createCollation implementation around line 659, then reproduce the crash with the minimal Swift example from the issue. Check the documented collation syntax against the current API usage. Done means the example creates a collation without crashing and the supported ordering syntax is clarified or covered by a test.

Written by the indexing model from the issue text.

Description

Hello, I'm doing my first steps with Swift so I hope that I'm not doing things wrong but rather reporting an actual bug.

platform: Linux

I'm trying to create a collation and get a crash with this minimal example:

import SQLite

let db = try Connection(.inMemory);
try db.createCollation("NOTHING_SPECIAL") { lhs, rhs in
  return lhs.compare(rhs)
}

Crash log:

💣 Program crashed: Bad pointer dereference at 0x0000000000000040

Thread 0 "test" crashed:

0 0x00007f828e0de8d7 swift_initEnumMetadataSinglePayload + 23 in libswiftCore.so
1 0x00007f828df57c0c type metadata completion function for ClosedRange<>.Index + 59 in libswiftCore.so
2 0x00007f828e1038bf swift::MetadataCacheEntryBase<(anonymous namespace)::GenericCacheEntry, void const*>::doInitialization(swift::MetadataWaitQueue::Worker&, swift::MetadataRequest) + 270 in libswiftCore.so
3 0x00007f828e0f4144 _swift_getGenericMetadata(swift::MetadataRequest, void const* const*, swift::TargetTypeContextDescriptor<swift::InProcess> const*) + 2755 in libswiftCore.so
4 0x00007f828df692b3 __swift_instantiateCanonicalPrespecializedGenericMetadata + 34 in libswiftCore.so
5 0x00007f828dfa75fe Dictionary.subscript.setter + 45 in libswiftCore.so
6 Connection.createCollation(_:_:) + 851 in test at ..../.build/checkouts/SQLite.swift/Sources/SQLite/Core/Connection.swift:659:31

   657│             }
   658│         }, nil /* xDestroy */))
   659│         collations[collation] = box
      │                               ▲
   660│     }
   661│     fileprivate typealias Collation = @convention(block) (UnsafeRawPointer, UnsafeRawPointer) -> Int32

7 test_main + 140 in test at .../Test/test.swift:4:8

     2│
     3│ let db = try Connection(.inMemory);
     4│ try db.createCollation("NOTHING_SPECIAL") { lhs, rhs in
      │        ▲
     5│   return lhs.compare(rhs)
     6│ }

8 0x00007f828c95c6b5 <unknown> in libc.so.6
9 0x00007f828c95c769 <unknown> in libc.so.6

By the way, I've found the syntax .order(collate(.custom("NODIACRITIC"), name)) in the docs but couldn't get it to work. Isn't it .order(name.collate(.custom("NODIACRITIC"))) now ?

Dominant language
Swift
Stars
10.2k
Forks
1.6k
Avg merge
6d 2h
Merged PRs (30d)
2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stephencelis/SQLite.swift

All issues in stephencelis/SQLite.swift

Similar issues

More Swift issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.