Skip to content

Commit

Permalink
Fix - Warning: implicit conversion to 'cstring' from a non-const loca…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
zqqw committed Nov 13, 2021
1 parent 334e09a commit a1c22c6
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 37 deletions.
2 changes: 1 addition & 1 deletion lib/bisect.nim
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ proc handleBisect*(params: seq[string]): int =

# this output is required by main program
echo(version)
if vercmp(compareVersion, version) > 0: 0 else: 1
if vercmp(cstring(compareVersion), cstring(version)) > 0: 0 else: 1
4 changes: 2 additions & 2 deletions lib/install.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ proc splitCommands(params: seq[string], index: int, res: seq[seq[string]]): seq[
res

proc perror*(s: cstring): void {.importc, header: "<stdio.h>".}
template perror*: void = perror(paramStr(0))
template perror*: void = perror(cstring(paramStr(0)))

proc runCommand(params: seq[string], inputOutput: bool): int =
if params.len > 0:
Expand Down Expand Up @@ -67,7 +67,7 @@ proc handleInstall*(params: seq[string]): int =
let name = if index >= 0: pkg.file[index + 1 .. ^1] else: pkg.file
let dest = destination & "/" & name
copyFile(pkg.file, dest)
discard chown(dest, (Uid) uid, (Gid) gid)
discard chown(cstring(dest), (Uid) uid, (Gid) gid)
except:
discard

Expand Down
12 changes: 6 additions & 6 deletions src/common.nim
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ proc findSyncTargets*(handle: ptr AlpmHandle, dbs: seq[ptr AlpmDatabase],

if dbTable.hasKey(repo):
let db = dbTable[repo]
let pkg = db[target.reference.name]
let pkg = db[cstring(target.reference.name)]

if pkg != nil and target.reference.isProvidedBy(pkg.toPackageReference, true):
let base = if pkg.base == nil: target.reference.name else: $pkg.base
Expand All @@ -164,7 +164,7 @@ proc findSyncTargets*(handle: ptr AlpmHandle, dbs: seq[ptr AlpmDatabase],

let directResults = dbs
.map(db => (block:
let pkg = db[target.reference.name]
let pkg = db[cstring(target.reference.name)]
if pkg != nil and target.reference.isProvidedBy(pkg.toPackageReference, true):
let base = if pkg.base == nil: target.reference.name else: $pkg.base
some(($db.name, some((base, $pkg.version, some($pkg.arch)))))
Expand Down Expand Up @@ -318,7 +318,7 @@ proc createDirRecursive(dir: string, chownUser: Option[User]): bool =
try:
let exists = path.existsOrCreateDir()
if chownUser.isSome and (not exists or index == segments.len - 1):
discard chown(path, (Uid) chownUser.unsafeGet.uid, (Gid) chownUser.unsafeGet.gid)
discard chown(cstring(path), (Uid) chownUser.unsafeGet.uid, (Gid) chownUser.unsafeGet.gid)
createDirIndex(index + 1)
except:
false
Expand Down Expand Up @@ -626,7 +626,7 @@ proc obtainBuildPkgInfosInternal(config: Config, bases: seq[LookupBaseGroup],
dropPrivileges)

if berrors.len > 0:
discard rmdir(config.tmpRoot(dropPrivileges))
discard rmdir(cstring(config.tmpRoot(dropPrivileges)))
(newSeq[PackageInfo](), newSeq[string](), berrors)
else:
proc findCommitAndGetSrcInfo(base: string, version: string,
Expand Down Expand Up @@ -673,7 +673,7 @@ proc obtainBuildPkgInfosInternal(config: Config, bases: seq[LookupBaseGroup],
if errorMessages.len > 0:
for path in paths:
removeDirQuiet(path)
discard rmdir(config.tmpRoot(dropPrivileges))
discard rmdir(cstring(config.tmpRoot(dropPrivileges)))
(foundPkgInfos, paths, errorMessages)

proc obtainBuildPkgInfos*(config: Config, pacmanTargets: seq[FullPackageTarget],
Expand Down Expand Up @@ -783,5 +783,5 @@ proc cloneAurReposWithPackageInfos*(config: Config, rpcInfos: seq[RpcPackageInfo
let names = rpcInfos.map(i => i.name).toHashSet
let additionalPkgInfos = fullPkgInfos.filter(i => not (i.rpc.name in names))

discard rmdir(config.tmpRoot(dropPrivileges))
discard rmdir(cstring(config.tmpRoot(dropPrivileges)))
(resultPkgInfos, additionalPkgInfos, paths, errors)
4 changes: 2 additions & 2 deletions src/config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,5 @@ proc obtainConfig*(config: PacmanConfig): Config =

template withAlpmConfig*(config: Config, passDbs: bool,
handle: untyped, alpmDbs: untyped, errors: untyped, body: untyped): untyped =
withAlpm(config.root, config.db, if passDbs: config.common.dbs else: @[],
config.common.arch, handle, alpmDbs, errors, body)
withAlpm(cstring(config.root), config.db, if passDbs: config.common.dbs
else: @[], cstring(config.common.arch), handle, alpmDbs, errors, body)
6 changes: 3 additions & 3 deletions src/feature/syncclean.nim
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ proc handleSyncClean*(args: seq[Argument], config: Config): int =
let index = file.path.rfind('/')
let dirName = if index >= 0: file.path[index + 1 .. ^1] else: file.path
for name in bareFullNameDeconstruct(BareKind.pkg, dirName):
if cleanCount >= 2 or local[name] == nil:
if cleanCount >= 2 or local[cstring(name)] == nil:
removeDirQuiet(file.path)

discard rmdir(reposCacheDir)
discard rmdir(config.userCacheCurrent)
discard rmdir(cstring(reposCacheDir))
discard rmdir(cstring(config.userCacheCurrent))

0
18 changes: 9 additions & 9 deletions src/feature/syncinstall.nim
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ proc findDependencies(config: Config, handle: ptr AlpmHandle,
template clearPaths(paths: untyped) =
for path in paths:
removeDirQuiet(path)
discard rmdir(config.tmpRootInitial)
discard rmdir(cstring(config.tmpRootInitial))

proc printUnsatisfied(config: Config,
satisfied: Table[PackageReference, SatisfyResult], unsatisfied: seq[PackageReference]) =
Expand All @@ -296,7 +296,7 @@ proc printUnsatisfied(config: Config,

template dropPrivilegesAndChdir(path: Option[string], body: untyped): int =
if dropPrivileges():
if path.isNone or chdir(path.unsafeGet) == 0:
if path.isNone or chdir(cstring(path.unsafeGet)) == 0:
body
else:
printError(config.color, tr"chdir failed: $#" % [path.unsafeGet])
Expand All @@ -307,7 +307,7 @@ template dropPrivilegesAndChdir(path: Option[string], body: untyped): int =

template dropPrivRedirectAndChdir(path: Option[string], body: untyped): int =
if dropPrivRedirect():
if path.isNone or chdir(path.unsafeGet) == 0:
if path.isNone or chdir(cstring(path.unsafeGet)) == 0:
body
else:
printError(config.color, tr"chdir failed: $#" % [path.unsafeGet])
Expand Down Expand Up @@ -437,7 +437,7 @@ proc buildLoop(config: Config, pkgInfos: seq[PackageInfo], skipDeps: bool,
file.close()
true
except:
discard unlink(workConfFile)
discard unlink(cstring(workConfFile))
false

if not workConfFileCopySuccess:
Expand Down Expand Up @@ -472,7 +472,7 @@ proc buildLoop(config: Config, pkgInfos: seq[PackageInfo], skipDeps: bool,
execResult(@[makepkgCmd, "--config", workConfFile, "--force"] &
optional.filter(o => o.cond).map(o => o.arg)))

discard unlink(workConfFile)
discard unlink(cstring(workConfFile))

if interrupted:
(none(BuildResult), buildCode, interrupted)
Expand Down Expand Up @@ -627,7 +627,7 @@ proc installGroupFromSources(config: Config, commonArgs: seq[Argument],
let local = handle.local
install.map(proc (pkg: auto): tuple[name: string, file: string, mode: string] =
let explicit = pkg.name in explicits
let package = local[pkg.name]
let package = local[cstring(pkg.name)]
let mode = if package != nil: (block:
let installedExplicitly = package.reason == AlpmReason.explicit
if explicit == installedExplicitly:
Expand Down Expand Up @@ -918,7 +918,7 @@ proc printAllWarnings(config: Config, installed: seq[Installed], rpcInfos: seq[R
installedTable.hasKey(pkgInfo.rpc.name):
let installedVersion = installedTable[pkgInfo.rpc.name].version
let newVersion = pkgInfo.rpc.version
if vercmp(newVersion, installedVersion) < 0:
if vercmp(cstring(newVersion), cstring(installedVersion)) < 0:
printWarning(config.color, tra("%s: ignoring package downgrade (%s => %s)\n") %
[pkgInfo.rpc.name, installedVersion, newVersion])
else:
Expand All @@ -932,7 +932,7 @@ proc printAllWarnings(config: Config, installed: seq[Installed], rpcInfos: seq[R
if installedTable.hasKey(pkgInfo.rpc.name):
let installedVersion = installedTable[pkgInfo.rpc.name].version
let newVersion = pkgInfo.rpc.version
if vercmp(newVersion, installedVersion) < 0 and not pkgInfo.rpc.name.isVcs:
if vercmp(cstring(newVersion), cstring(installedVersion)) < 0 and not pkgInfo.rpc.name.isVcs:
printWarning(config.color,
tra("%s: downgrading from version %s to version %s\n") %
[pkgInfo.rpc.name, installedVersion, newVersion])
Expand Down Expand Up @@ -991,7 +991,7 @@ proc checkNeeded(installed: Table[string, Installed],
name: string, version: string, downgrade: bool): tuple[needed: bool, vercmp: int] =
if installed.hasKey(name):
let i = installed[name]
let vercmp = vercmp(version, i.version)
let vercmp = vercmp(version, cstring(i.version))
let needed = if downgrade: vercmp != 0 else: vercmp > 0
(needed, vercmp.int)
else:
Expand Down
2 changes: 1 addition & 1 deletion src/feature/syncsearch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ proc handleSyncSearch*(args: seq[Argument], config: Config): int =
for e in errors: printError(config.color, e)

aurPackages.map(proc (rpcInfo: RpcPackageInfo): Package =
let pkg = handle.local[rpcInfo.name]
let pkg = handle.local[cstring(rpcInfo.name)]
if pkg != nil:
(rpcInfo, some($pkg.version))
else:
Expand Down
4 changes: 2 additions & 2 deletions src/feature/syncsource.nim
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ proc copyFiles(config: Config, quiet: bool, results: seq[CloneResult]): List[str
messages.reversed
else:
let res = results[index]
discard mkdir(res.destination, 0o755)
discard mkdir(cstring(res.destination), 0o755)

let error = try:
for f in res.files:
Expand Down Expand Up @@ -144,7 +144,7 @@ proc cloneAndCopy(config: Config, quiet: bool, fullTargets: seq[FullPackageTarge

for result in results:
removeDirQuiet(result.path)
discard rmdir(config.tmpRootCurrent)
discard rmdir(cstring(config.tmpRootCurrent))

if rerrors.len > 0 or cerrors != nil:
1
Expand Down
2 changes: 1 addition & 1 deletion src/package.nim
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ proc isProvidedBy*(package: PackageReference, by: PackageReference, checkVersion
else:
let lcon = package.constraint.unsafeGet
let rcon = by.constraint.unsafeGet
let cmp = vercmp(lcon.version, rcon.version)
let cmp = vercmp(cstring(lcon.version), cstring(rcon.version))
checkConstraints(lcon.operation, rcon.operation, cmp)
else:
false
Expand Down
14 changes: 7 additions & 7 deletions src/utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ proc groupBy*[T, X](s: seq[T], callback: T -> X): seq[tuple[key: X, values: seq[
result &= (key, values[])

proc perror*(s: cstring): void {.importc, header: "<stdio.h>".}
template perror*: void = perror(getAppFilename())
template perror*: void = perror(cstring(getAppFilename()))

proc execResult*(args: varargs[string]): int =
let cexec = allocCStringArray(args)
Expand Down Expand Up @@ -319,15 +319,15 @@ proc dropPrivileges*(): bool =
if setuid((Uid) user.uid) != 0:
return false

template replaceExisting(name: string, value: string) =
template replaceExisting(name: string, value: cstring) =
if cgetenv(name) != nil:
discard csetenv(name, value, 1)

replaceExisting("USER", user.name)
replaceExisting("USERNAME", user.name)
replaceExisting("LOGNAME", user.name)
replaceExisting("HOME", user.home)
replaceExisting("SHELL", user.shell)
replaceExisting("USER", cstring(user.name))
replaceExisting("USERNAME", cstring(user.name))
replaceExisting("LOGNAME", cstring(user.name))
replaceExisting("HOME", cstring(user.home))
replaceExisting("SHELL", cstring(user.shell))

discard cunsetenv("SUDO_COMMAND")
discard cunsetenv("SUDO_USER")
Expand Down
6 changes: 3 additions & 3 deletions src/wrapper/alpm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ proc freeListFull*[T](list: ptr AlpmList[T]) =
list.freeListInner(cfree)
list.freeList()

template withAlpm*(root: string, db: string, dbs: seq[string], arch: string,
template withAlpm*(root: cstring, db: string, dbs: seq[string], arch: cstring,
handle: untyped, alpmDbs: untyped, errors: untyped, body: untyped): untyped =
block:
var errno: cint = 0
let handle = newAlpmHandle(root, db, errno)
let handle = newAlpmHandle(root, cstring(db), errno)

if handle == nil:
raise commandError(trp("failed to initialize alpm library\n(%s: %s)\n").strip
Expand All @@ -129,7 +129,7 @@ template withAlpm*(root: string, db: string, dbs: seq[string], arch: string,
var alpmDbs = newSeq[ptr AlpmDatabase]()
var errors = newSeq[string]()
for dbName in dbs:
let alpmDb = handle.register(dbName, 1 shl 30)
let alpmDb = handle.register(cstring(dbName), 1 shl 30)
if alpmDb != nil:
alpmDbs &= alpmDb
else:
Expand Down

0 comments on commit a1c22c6

Please sign in to comment.