loader

package
v0.11.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package loader opens speech.cpp's shared library, libspeech, at run time and checks that its C API is one this module was written against.

It does not use cgo: the library is opened with dlopen (purego) on Unix and LoadLibrary on Windows, from a path the caller gives.

Index

Constants

View Source
const (
	RequiredMajor = 4
	RequiredMinor = 3
)

The C API version this module binds: speech.h of speech.cpp 0.11.3. A library of the same major version and a minor version of at least RequiredMinor is accepted.

Variables

View Source
var ErrIncompatibleVersion = errors.New("loader: incompatible libspeech API version")

ErrIncompatibleVersion is the sentinel every *VersionError matches with errors.Is.

View Source
var ErrNoLibrary = errors.New("loader: no libspeech in directory")

ErrNoLibrary is returned when a directory holds no file with one of LibraryFilenames' names.

Functions

func CheckVersion

func CheckVersion(path string, major, minor int) error

CheckVersion returns a *VersionError when major.minor is not compatible with RequiredMajor.RequiredMinor: another major version, or a lower minor one. path only names the library in the error.

func LibraryFilenames

func LibraryFilenames(goos string) []string

LibraryFilenames returns the file names libspeech has on goos, the versioned name (its SOVERSION) first.

func Resolve

func Resolve(path string) (string, error)

Resolve returns the library file that path names: path itself when it is a file, or the first of LibraryFilenames(runtime.GOOS) present in it when it is a directory.

Types

type Library

type Library struct {
	// contains filtered or unexported fields
}

Library is an open libspeech whose C API version has been checked. Nothing a library hands out may outlive it, so one whose functions are in use stays open for the life of the process; Close is for one that is not.

func Open

func Open(path string) (*Library, error)

Open opens libspeech at path, a file or a directory holding it, reads speech_api_version_major() and speech_api_version_minor(), and refuses a library whose version CheckVersion refuses, with a *VersionError.

func (*Library) APIVersion

func (l *Library) APIVersion() (major, minor int)

APIVersion is the C API version the library reported.

func (*Library) Close

func (l *Library) Close() error

Close closes the library (dlclose, FreeLibrary). It is only for a library none of whose functions or objects are in use, such as one whose symbols could not all be bound. A second Close does nothing. It is not safe to call while another goroutine uses the Library.

func (*Library) Handle

func (l *Library) Handle() uintptr

Handle is the native handle (dlopen's or LoadLibrary's).

func (*Library) Path

func (l *Library) Path() string

Path is the file that was opened.

func (*Library) Symbol

func (l *Library) Symbol(name string) (uintptr, error)

Symbol returns the address of the exported function name.

type VersionError

type VersionError struct {
	Path          string
	FoundMajor    int
	FoundMinor    int
	RequiredMajor int
	RequiredMinor int
}

VersionError says that the library's C API version is not one this module runs against.

func (*VersionError) Error

func (e *VersionError) Error() string

func (*VersionError) Unwrap

func (e *VersionError) Unwrap() error

Unwrap makes errors.Is(err, ErrIncompatibleVersion) true.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL