libzypp 17.38.15
curl_dl.cc File Reference

Load libcurl with dlopen() on first use instead of a DT_NEEDED entry. More...

#include <curl/curl.h>
#include <dlfcn.h>
#include <pthread.h>
#include <stdarg.h>
#include <stdio.h>
Include dependency graph for curl_dl.cc:

Go to the source code of this file.

Macros

#define CURL_DL_FN(ret, name, proto, args, errret)
#define CURL_DL_FN_VOID(name, proto, args)

Functions

 CURL_DL_FN (CURLcode, curl_global_init,(long flags),(flags), CURLE_FAILED_INIT) CURL_DL_FN(CURL *
nullptr CURL_DL_FN_VOID (curl_easy_cleanup,(CURL *handle),(handle)) CURL_DL_FN_VOID(curl_easy_reset
nullptr CURL handle CURL_DL_FN (const char *, curl_easy_strerror,(CURLcode code),(code), "libcurl is not available") CURL_DL_FN_VOID(curl_free
nullptr CURL handle void p CURL_DL_FN (char *, curl_unescape,(const char *str, int length),(str, length), nullptr) CURL_DL_FN(curl_version_info_data *
nullptr CURL handle void p CURLversion nullptr CURL_DL_FN (struct curl_slist *, curl_slist_append,(struct curl_slist *list, const char *str),(list, str), nullptr) CURL_DL_FN_VOID(curl_slist_free_all
nullptr CURL handle void p CURLversion nullptr struct curl_slist list CURL_DL_FN (CURLM *, curl_multi_init,(void),(), nullptr) CURL_DL_FN(CURLMcode
nullptr CURL handle void p CURLversion nullptr struct curl_slist list CURLM CURLM_INTERNAL_ERROR CURL_DL_FN (CURLMcode, curl_multi_add_handle,(CURLM *multi, CURL *handle),(multi, handle), CURLM_INTERNAL_ERROR) CURL_DL_FN(CURLMcode
nullptr CURL handle void p CURLversion nullptr struct curl_slist list CURLM CURLM_INTERNAL_ERROR CURLM CURL CURLM_INTERNAL_ERROR CURL_DL_FN (CURLMsg *, curl_multi_info_read,(CURLM *multi, int *msgs_in_queue),(multi, msgs_in_queue), nullptr) CURL_DL_FN(CURLMcode
nullptr CURL handle void p CURLversion nullptr struct curl_slist list CURLM CURLM_INTERNAL_ERROR CURLM CURL CURLM_INTERNAL_ERROR CURLM curl_socket_t int int CURLM_INTERNAL_ERROR CURL_DL_FN (const char *, curl_multi_strerror,(CURLMcode code),(code), "libcurl is not available") CURLcode curl_easy_getinfo(CURL *handle
 if (!fn) *(void **) &fn
 if (!fn) return CURLE_FAILED_INIT
 va_start (ap, info)
 va_end (ap)
return fn (handle, info, arg)
CURLcode curl_easy_setopt (CURL *handle, CURLoption option,...)
CURLMcode curl_multi_setopt (CURLM *multi, CURLMoption option,...)

Variables

 curl_easy_init
 void
nullptr CURL * handle
nullptr CURL handle voidp
nullptr CURL handle void p curl_version_info
nullptr CURL handle void p CURLversion age
nullptr CURL handle void p CURLversion nullptr struct curl_slist * list
nullptr CURL handle void p CURLversion nullptr struct curl_slist list curl_multi_cleanup
nullptr CURL handle void p CURLversion nullptr struct curl_slist list CURLM * multi
nullptr CURL handle void p CURLversion nullptr struct curl_slist list CURLM CURLM_INTERNAL_ERROR curl_multi_remove_handle
nullptr CURL handle void p CURLversion nullptr struct curl_slist list CURLM CURLM_INTERNAL_ERROR CURLM CURL CURLM_INTERNAL_ERROR curl_multi_socket_action
nullptr CURL handle void p CURLversion nullptr struct curl_slist list CURLM CURLM_INTERNAL_ERROR CURLM CURL CURLM_INTERNAL_ERROR CURLM curl_socket_t s
nullptr CURL handle void p CURLversion nullptr struct curl_slist list CURLM CURLM_INTERNAL_ERROR CURLM CURL CURLM_INTERNAL_ERROR CURLM curl_socket_t int ev_bitmask
nullptr CURL handle void p CURLversion nullptr struct curl_slist list CURLM CURLM_INTERNAL_ERROR CURLM CURL CURLM_INTERNAL_ERROR CURLM curl_socket_t int int * running_handles
nullptr CURL handle void p CURLversion nullptr struct curl_slist list CURLM CURLM_INTERNAL_ERROR CURLM CURL CURLM_INTERNAL_ERROR CURLM curl_socket_t int int CURLM_INTERNAL_ERROR CURLINFO info
nullptr CURL handle void p CURLversion nullptr struct curl_slist list CURLM CURLM_INTERNAL_ERROR CURLM CURL CURLM_INTERNAL_ERROR CURLM curl_socket_t int int CURLM_INTERNAL_ERROR CURLINFO va_list ap
voidarg = va_arg( ap, void * )

Detailed Description

Load libcurl with dlopen() on first use instead of a DT_NEEDED entry.

The distro libcurl pulls ~30 shared objects (TLS, ssh, ldap, idn, kerberos, ...) into every process that links it, costing ~2ms of startup per exec - paid even by runs that never touch the network (zypper –help, cached info/search).

This file defines every libcurl symbol libzypp references. Each wrapper resolves the real function from libcurl.so.4 on first call, so the library and its dependency closure are only mapped when a download actually happens. All other code keeps calling plain curl_* functions and stays oblivious.

Keep the list in sync with the real usage: nm -D –undefined-only libzypp.so | grep ' curl_' A missing wrapper resurfaces as a DT_NEEDED on libcurl again (the linker pulls it from CURL_LIBRARIES if someone re-adds it) or as a link error, never as silent misbehavior.

curl_easy_setopt, curl_multi_setopt and curl_easy_getinfo are variadic in the libcurl ABI. getinfo always takes one pointer; the setopt argument class is defined by the CURLOPTTYPE_* range of the option id, exactly the rule libcurl documents for bindings.

Definition in file curl_dl.cc.

Macro Definition Documentation

◆ CURL_DL_FN

#define CURL_DL_FN ( ret,
name,
proto,
args,
errret )
Value:
ret name proto \
{ \
static ret (*fn) proto; \
if ( !fn ) \
*(void **)&fn = curl_dl_sym( #name ); \
if ( !fn ) \
return errret; \
return fn args; \
}
return fn(handle, info, arg)

Definition at line 70 of file curl_dl.cc.

◆ CURL_DL_FN_VOID

#define CURL_DL_FN_VOID ( name,
proto,
args )
Value:
void name proto \
{ \
static void (*fn) proto; \
if ( !fn ) \
*(void **)&fn = curl_dl_sym( #name ); \
if ( fn ) \
fn args; \
}
void
Definition curl_dl.cc:94

Definition at line 82 of file curl_dl.cc.

Function Documentation

◆ CURL_DL_FN() [1/8]

CURL_DL_FN ( CURLcode ,
curl_global_init ,
(long flags) ,
(flags) ,
CURLE_FAILED_INIT  )

◆ CURL_DL_FN_VOID()

nullptr CURL_DL_FN_VOID ( curl_easy_cleanup ,
(CURL *handle) ,
(handle)  )

◆ CURL_DL_FN() [2/8]

nullptr CURL handle CURL_DL_FN ( const char * ,
curl_easy_strerror ,
(CURLcode code) ,
(code) ,
"libcurl is not available"  )

◆ CURL_DL_FN() [3/8]

nullptr CURL handle void p CURL_DL_FN ( char * ,
curl_unescape ,
(const char *str, int length) ,
(str, length) ,
nullptr  )

◆ CURL_DL_FN() [4/8]

nullptr CURL handle void p CURLversion nullptr CURL_DL_FN ( struct curl_slist * ,
curl_slist_append ,
(struct curl_slist *list, const char *str) ,
(list, str) ,
nullptr  )

◆ CURL_DL_FN() [5/8]

nullptr CURL handle void p CURLversion nullptr struct curl_slist list CURL_DL_FN ( CURLM * ,
curl_multi_init ,
(void) ,
() ,
nullptr  )

◆ CURL_DL_FN() [6/8]

nullptr CURL handle void p CURLversion nullptr struct curl_slist list CURLM CURLM_INTERNAL_ERROR CURL_DL_FN ( CURLMcode ,
curl_multi_add_handle ,
(CURLM *multi, CURL *handle) ,
(multi, handle) ,
CURLM_INTERNAL_ERROR  )

◆ CURL_DL_FN() [7/8]

nullptr CURL handle void p CURLversion nullptr struct curl_slist list CURLM CURLM_INTERNAL_ERROR CURLM CURL CURLM_INTERNAL_ERROR CURL_DL_FN ( CURLMsg * ,
curl_multi_info_read ,
(CURLM *multi, int *msgs_in_queue) ,
(multi, msgs_in_queue) ,
nullptr  )

◆ CURL_DL_FN() [8/8]

nullptr CURL handle void p CURLversion nullptr struct curl_slist list CURLM CURLM_INTERNAL_ERROR CURLM CURL CURLM_INTERNAL_ERROR CURLM curl_socket_t int int CURLM_INTERNAL_ERROR CURL_DL_FN ( const char * ,
curl_multi_strerror ,
(CURLMcode code) ,
(code) ,
"libcurl is not available"  )

◆ if() [1/2]

if ( ! fn) &

◆ if() [2/2]

if ( ! fn)

◆ va_start()

va_start ( ap ,
info  )

◆ va_end()

va_end ( ap )

◆ fn()

return fn ( handle ,
info ,
arg  )

◆ curl_easy_setopt()

CURLcode curl_easy_setopt ( CURL * handle,
CURLoption option,
... )

Definition at line 132 of file curl_dl.cc.

◆ curl_multi_setopt()

CURLMcode curl_multi_setopt ( CURLM * multi,
CURLMoption option,
... )

Definition at line 154 of file curl_dl.cc.

Variable Documentation

◆ curl_easy_init

curl_easy_init

Definition at line 94 of file curl_dl.cc.

◆ void

void

Definition at line 94 of file curl_dl.cc.

◆ handle

nullptr CURL handle void p CURLversion nullptr struct curl_slist list CURLM CURLM_INTERNAL_ERROR CURLM CURL handle

Definition at line 96 of file curl_dl.cc.

◆ p

nullptr CURL handle void* p

Definition at line 99 of file curl_dl.cc.

◆ curl_version_info

nullptr CURL handle void p curl_version_info

Definition at line 101 of file curl_dl.cc.

◆ age

nullptr CURL handle void p CURLversion age

Definition at line 101 of file curl_dl.cc.

◆ list

nullptr CURL handle void p CURLversion nullptr struct curl_slist* list

Definition at line 104 of file curl_dl.cc.

◆ curl_multi_cleanup

nullptr CURL handle void p CURLversion nullptr struct curl_slist list curl_multi_cleanup

Definition at line 107 of file curl_dl.cc.

◆ multi

nullptr CURL handle void p CURLversion nullptr struct curl_slist list CURLM CURLM_INTERNAL_ERROR CURLM CURL CURLM_INTERNAL_ERROR CURLM curl_socket_t int int multi

Definition at line 107 of file curl_dl.cc.

◆ curl_multi_remove_handle

nullptr CURL handle void p CURLversion nullptr struct curl_slist list CURLM CURLM_INTERNAL_ERROR curl_multi_remove_handle

Definition at line 109 of file curl_dl.cc.

◆ curl_multi_socket_action

nullptr CURL handle void p CURLversion nullptr struct curl_slist list CURLM CURLM_INTERNAL_ERROR CURLM CURL CURLM_INTERNAL_ERROR curl_multi_socket_action

Definition at line 111 of file curl_dl.cc.

◆ s

nullptr CURL handle void p CURLversion nullptr struct curl_slist list CURLM CURLM_INTERNAL_ERROR CURLM CURL CURLM_INTERNAL_ERROR CURLM curl_socket_t int int s

Definition at line 111 of file curl_dl.cc.

◆ ev_bitmask

nullptr CURL handle void p CURLversion nullptr struct curl_slist list CURLM CURLM_INTERNAL_ERROR CURLM CURL CURLM_INTERNAL_ERROR CURLM curl_socket_t int int ev_bitmask

Definition at line 111 of file curl_dl.cc.

◆ running_handles

nullptr CURL handle void p CURLversion nullptr struct curl_slist list CURLM CURLM_INTERNAL_ERROR CURLM CURL CURLM_INTERNAL_ERROR CURLM curl_socket_t int int running_handles

Definition at line 111 of file curl_dl.cc.

◆ info

nullptr CURL handle void p CURLversion nullptr struct curl_slist list CURLM CURLM_INTERNAL_ERROR CURLM CURL CURLM_INTERNAL_ERROR CURLM curl_socket_t int int CURLM_INTERNAL_ERROR CURLINFO info

Definition at line 117 of file curl_dl.cc.

◆ ap

nullptr CURL handle void p CURLversion nullptr struct curl_slist list CURLM CURLM_INTERNAL_ERROR CURLM CURL CURLM_INTERNAL_ERROR CURLM curl_socket_t int int CURLM_INTERNAL_ERROR CURLINFO va_list ap
Initial value:
{
static CURLcode (*fn)( CURL *, CURLINFO, ... )

Definition at line 120 of file curl_dl.cc.

◆ arg

arg = va_arg( ap, void * )

Definition at line 121 of file curl_dl.cc.