Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix variadic arglist to enable native backend
  • Loading branch information
carlosrogue committed Feb 21, 2020
1 parent 9d0f30f commit 93593ec
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Expand Up @@ -22,5 +22,9 @@ project/plugins/project/

core/native/local.sbt

.metals/
.bloop/
project/metals.sbt

# scala-native
lowered.hnir
lowered.hnir
4 changes: 2 additions & 2 deletions build.sbt
Expand Up @@ -181,8 +181,8 @@ def dependenciesFor(version: String)(deps: (Option[(Long, Long)] => ModuleID)*):
deps.map(_.apply(CrossVersion.partialVersion(version)))

lazy val rootProjectAggregates: Seq[ProjectReference] = if (sys.env.isDefinedAt("STTP_NATIVE")) {
println("[info] STTP_NATIVE defined, including sttp-native in the aggregate projects [temporarily disabled]")
//List(rootJVM, rootJS, rootNative)
println("[info] STTP_NATIVE defined, including sttp-native in the aggregate projects")
List(rootJVM, rootJS, rootNative)
List(rootJVM, rootJS)
} else {
println("[info] STTP_NATIVE *not* defined, *not* including sttp-native in the aggregate projects")
Expand Down
7 changes: 5 additions & 2 deletions core/native/src/main/scala/sttp/client/curl/CCurl.scala
Expand Up @@ -20,13 +20,16 @@ private[curl] object CCurl {
def cleanup(handle: Ptr[Curl]): Unit = extern

@name("curl_easy_setopt")
def setopt(handle: Ptr[Curl], option: CInt, parameter: Any): CInt = extern
def setopt(handle: Ptr[Curl], option: CInt, parameter: Ptr[_]): CInt = extern

@name("curl_easy_setopt")
def setopt(handle: Ptr[Curl], option: CInt, parameter: CVarArgList): CInt = extern

@name("curl_easy_perform")
def perform(easy_handle: Ptr[Curl]): CInt = extern

@name("curl_easy_getinfo")
def getInfo(handle: Ptr[Curl], info: CInt, parameter: Any): CInt = extern
def getInfo(handle: Ptr[Curl], info: CInt, parameter: Ptr[_]): CInt = extern

@name("curl_mime_init")
def mimeInit(easy: Ptr[Curl]): Ptr[Mime] = extern
Expand Down
31 changes: 19 additions & 12 deletions core/native/src/main/scala/sttp/client/curl/CurlApi.scala
Expand Up @@ -4,6 +4,7 @@ import sttp.client.curl.CurlCode.CurlCode
import sttp.client.curl.CurlInfo.CurlInfo
import sttp.client.curl.CurlOption.CurlOption

import scala.scalanative.runtime.Boxes
import scala.scalanative.unsafe.{Ptr, _}

private[client] object CurlApi {
Expand All @@ -25,47 +26,53 @@ private[client] object CurlApi {
def cleanup(): Unit = CCurl.cleanup(handle)

def option(option: CurlOption, parameter: String)(implicit z: Zone): CurlCode = {
setopt(handle, option, toCString(parameter)(z))
setopt(handle, option, toCString(parameter))
}

def option(option: CurlOption, parameter: Long): CurlCode = {
def option(option: CurlOption, parameter: Long)(implicit z: Zone): CurlCode = {
setopt(handle, option, parameter)
}

def option(option: CurlOption, parameter: Int): CurlCode = {
def option(option: CurlOption, parameter: Int)(implicit z: Zone): CurlCode = {
setopt(handle, option, parameter)
}

def option(option: CurlOption, parameter: Boolean): CurlCode = {
def option(option: CurlOption, parameter: Boolean)(implicit z: Zone): CurlCode = {
setopt(handle, option, if (parameter) 1L else 0L)
}

def option(option: CurlOption, parameter: Ptr[_]): CurlCode = {
setopt(handle, option, parameter)
}

def option[FuncPtr >: CFuncPtr](option: CurlOption, parameter: FuncPtr): CurlCode = {
setopt(handle, option, parameter)
def option[FuncPtr <: CFuncPtr](option: CurlOption, parameter: FuncPtr)(implicit z: Zone): CurlCode = {
setopt(handle, option, Boxes.boxToPtr[Byte](Boxes.unboxToCFuncRawPtr(parameter)))
}

def info(curlInfo: CurlInfo, parameter: Long): CurlCode = {
getInfo(handle, curlInfo, parameter)
def info(curlInfo: CurlInfo, parameter: Long)(implicit z: Zone): CurlCode = {
val lPtr = alloc[Long](sizeof[Long])
!lPtr = parameter
getInfo(handle, curlInfo, lPtr)
}

def info(curlInfo: CurlInfo, parameter: String): CurlCode = {
getInfo(handle, curlInfo, parameter)
def info(curlInfo: CurlInfo, parameter: String)(implicit z: Zone): CurlCode = {
getInfo(handle, curlInfo, toCString(parameter))
}

def info(curlInfo: CurlInfo, parameter: Ptr[_]): CurlCode = {
getInfo(handle, curlInfo, parameter)
}
}

private def setopt(handle: CurlHandle, option: CurlOption, parameter: Any): CurlCode = {
private def setopt(handle: CurlHandle, option: CurlOption, parameter: Ptr[_]): CurlCode = {
CurlCode(CCurl.setopt(handle, option.id, parameter))
}

private def getInfo(handle: CurlHandle, curlInfo: CurlInfo, parameter: Any): CurlCode = {
private def setopt(handle: CurlHandle, option: CurlOption, parameter: CVarArg)(implicit z: Zone): CurlCode = {
CurlCode(CCurl.setopt(handle, option.id, toCVarArgList(Seq(parameter))))
}

private def getInfo(handle: CurlHandle, curlInfo: CurlInfo, parameter: Ptr[_]): CurlCode = {
CurlCode(CCurl.getInfo(handle, curlInfo.id, parameter))
}

Expand Down

0 comments on commit 93593ec

Please sign in to comment.