libxl: mark internal functions hidden
PATCH 1/1 libxl: mark internal functions hidden
# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1334219369 -3600
# Node ID ce1c73db77fb1264de40a9253371158e9c9ae71c # Parent 14cac8170e122115ef090cb390775b8c356ae643
libxl: mark internal functions hidden
tools/libxl/gentypes.py +8 -8
@@ -280,22 +280,22 @@ if __name__ == '__main__': for ty in types: f.write(libxl_C_type_define(ty) + ";\n") if ty.dispose_fn is not None: - f.write("void %s(%s);\n" % (ty.dispose_fn, ty.make_arg("p"))) + f.write("%svoid %s(%s);\n" % (ty.hidden(), ty.dispose_fn, ty.make_arg("p"))) if ty.init_fn is not None: - f.write("void %s(%s);\n" % (ty.init_fn, ty.make_arg("p"))) + f.write("%svoid %s(%s);\n" % (ty.hidden(), ty.init_fn, ty.make_arg("p"))) for field in libxl_init_members(ty): if not isinstance(field.type, idl.KeyedUnion): raise Exception("Only KeyedUnion is supported for member init") ku = field.type - f.write("void %s(%s, %s);\n" % (ty.init_fn + "_" + ku.keyvar.name, + f.write("%svoid %s(%s, %s);\n" % (ty.hidden(), ty.init_fn + "_" + ku.keyvar.name, ty.make_arg("p"), ku.keyvar.type.make_arg(ku.keyvar.name))) if ty.json_fn is not None: - f.write("char *%s_to_json(libxl_ctx *ctx, %s);\n" % (ty.typename, ty.make_arg("p"))) + f.write("%schar *%s_to_json(libxl_ctx *ctx, %s);\n" % (ty.hidden(), ty.typename, ty.make_arg("p"))) if isinstance(ty, idl.Enumeration): - f.write("const char *%s_to_string(%s);\n" % (ty.typename, ty.make_arg("p"))) - f.write("int %s_from_string(const char *s, %s);\n" % (ty.typename, ty.make_arg("e", passby=idl.PASS_BY_REFERENCE))) - f.write("extern libxl_enum_string_table %s_string_table[];\n" % (ty.typename)) + f.write("%sconst char *%s_to_string(%s);\n" % (ty.hidden(), ty.typename, ty.make_arg("p"))) + f.write("%sint %s_from_string(const char *s, %s);\n" % (ty.hidden(), ty.typename, ty.make_arg("e", passby=idl.PASS_BY_REFERENCE))) + f.write("%sextern libxl_enum_string_table %s_string_table[];\n" % (ty.hidden(), ty.typename)) f.write("\n") f.write("""#endif /* %s */\n""" % (header_define))
@@ -319,7 +319,7 @@ if __name__ == '__main__': """ % (header_json_define, header_json_define, " ".join(sys.argv))) for ty in [ty for ty in types if ty.json_fn is not None]: - f.write("yajl_gen_status %s_gen_json(yajl_gen hand, %s);\n" % (ty.typename, ty.make_arg("p", passby=idl.PASS_BY_REFERENCE))) + f.write("%syajl_gen_status %s_gen_json(yajl_gen hand, %s);\n" % (ty.hidden(), ty.typename, ty.make_arg("p", passby=idl.PASS_BY_REFERENCE))) f.write("\n") f.write("""#endif /* %s */\n""" % header_json_define)
tools/libxl/idl.py +16 -1
@@ -19,11 +19,20 @@ def _get_default_namespace(): global _default_namespace return _default_namespace +_default_hidden = False +def hidden(b): + global _default_hidden + _default_hidden = b + +def _get_default_hidden(): + global _default_hidden + return _default_hidden class Type(object): def __init__(self, typename, **kwargs): self.namespace = kwargs.setdefault('namespace', _get_default_namespace()) + self._hidden = kwargs.setdefault('hidden', _get_default_hidden()) self.dir = kwargs.setdefault('dir', DIR_BOTH) if self.dir not in [DIR_NONE, DIR_IN, DIR_OUT, DIR_BOTH]: raise ValueError
@@ -67,6 +76,12 @@ class Type(object): def marshal_out(self): return self.dir in [DIR_OUT, DIR_BOTH] + def hidden(self): + if self._hidden: + return "_hidden " + else: + return "" + def make_arg(self, n, passby=None): if passby is None: passby = self.passby
@@ -289,7 +304,7 @@ def parse(f): globs[n] = t elif n in ['PASS_BY_REFERENCE', 'PASS_BY_VALUE', 'DIR_NONE', 'DIR_IN', 'DIR_OUT', 'DIR_BOTH', - 'namespace']: + 'namespace', 'hidden']: globs[n] = t try:
tools/libxl/libxl_internal.h +15 -14
@@ -118,7 +118,7 @@ typedef struct libxl__gc libxl__gc;typedef struct libxl__egc libxl__egc ;typedef struct libxl__ao libxl__ao ; -void libxl__alloc_failed (libxl_ctx *,const char *func, +_hidden void libxl__alloc_failed(libxl_ctx *, const char *func,size_t nmemb,size_t size) __attribute__((noreturn));/* func, size and nmemb are used only in the log message. * You may pass size==0 if size and nmemb are not meaningful
@@ -184,7 +184,8 @@ typedef struct libxl__ev_watch_slot {LIBXL_SLIST_ENTRY (struct libxl__ev_watch_slot ) empty; } libxl__ev_watch_slot; -libxl__ev_xswatch *libxl__watch_slot_contents (libxl__gc *gc,int slotnum); +_hidden libxl__ev_xswatch *libxl__watch_slot_contents(libxl__gc *gc, +int slotnum);/*
@@ -597,21 +598,21 @@ _hidden void libxl__event_disaster(libxl/* Fills in, or disposes of, the resources held by, a poller whose * space the caller has allocated. ctx must be locked. */ -int libxl__poller_init (libxl_ctx *ctx,libxl__poller *p); -void libxl__poller_dispose (libxl__poller *p); +_hidden int libxl__poller_init(libxl_ctx *ctx, libxl__poller *p); +_hidden void libxl__poller_dispose(libxl__poller *p);/* Obtain a fresh poller from malloc or the idle list, and put it * away again afterwards. _get can fail, returning NULL. * ctx must be locked. */ -libxl__poller *libxl__poller_get (libxl_ctx *ctx); -void libxl__poller_put (libxl_ctx *ctx,libxl__poller *p); +_hidden libxl__poller *libxl__poller_get(libxl_ctx *ctx); +_hidden void libxl__poller_put(libxl_ctx *ctx, libxl__poller *p);/* Notifies whoever is polling using p that they should wake up. * ctx must be locked. */ -void libxl__poller_wakeup (libxl__egc *egc,libxl__poller *p); +_hidden void libxl__poller_wakeup(libxl__egc *egc, libxl__poller *p); -int libxl__atfork_init (libxl_ctx *ctx); +_hidden int libxl__atfork_init(libxl_ctx *ctx);/* from xl_dom */
@@ -1356,23 +1357,23 @@ _hidden void libxl__ao__destroy(libxl_ct*/ typedef struct libxl__carefd libxl__carefd ; -void libxl__carefd_begin (void ); -void libxl__carefd_unlock (void ); +_hidden void libxl__carefd_begin(void); +_hidden void libxl__carefd_unlock(void);/* fd may be -1, in which case this returns a dummy libxl__fd_record * on which it _carefd_close is a no-op. Cannot fail. */ -libxl__carefd *libxl__carefd_record (libxl_ctx *ctx,int fd); +_hidden libxl__carefd *libxl__carefd_record(libxl_ctx *ctx, int fd);/* Combines _record and _unlock in a single call. If fd==-1, * still does the unlock, but returns 0. Cannot fail. */ -libxl__carefd *libxl__carefd_opened (libxl_ctx *ctx,int fd); +_hidden libxl__carefd *libxl__carefd_opened(libxl_ctx *ctx, int fd);/* Works just like close(2). You may pass NULL, in which case it's * a successful no-op. */ -int libxl__carefd_close (libxl__carefd *); +_hidden int libxl__carefd_close(libxl__carefd*);/* You may pass NULL in which case the answer is -1. */ -int libxl__carefd_fd (const libxl__carefd *); +_hidden int libxl__carefd_fd(const libxl__carefd*);/* common paths */ _hidden const char *libxl__libexec_path(void);
tools/libxl/libxl_types_internal.idl +1 -0
@@ -1,4 +1,5 @@ namespace("libxl__") +hidden(True) libxl_domid = Builtin("domid", namespace="libxl_", json_fn = "yajl_gen_integer")
tools/libxl/libxl_internal.h _hidden void libxl__event_disaster(libxl · line 602
Quoted 8 lines · Ian Campbell
tools/libxl/libxl_internal.h +2
-2@@ -597,21 +598,21 @@ _hidden void libxl__event_disaster(libxl/* Fills in, or disposes of, the resources held by, a poller whose * space the caller has allocated. ctx must be locked. */ -int libxl__poller_init (libxl_ctx *ctx,libxl__poller *p); -void libxl__poller_dispose (libxl__poller *p); +_hidden int libxl__poller_init(libxl_ctx *ctx, libxl__poller *p); +_hidden void libxl__poller_dispose(libxl__poller *p);
BTW, I noticed a bunch of libxl__ functions which take a ctx instead of a gc while doing this.
$ grep libxl_ctx tools/libxl/libxl_internal.h
_hidden void libxl__logv(libxl_ctx *ctx, xentoollog_level msglevel, int errnoval,
_hidden void libxl__log(libxl_ctx *ctx, xentoollog_level msglevel, int errnoval,
_hidden void libxl__alloc_failed(libxl_ctx *, const char *func,
[...]
_hidden int libxl__poller_init(libxl_ctx *ctx, libxl__poller *p);
_hidden libxl__poller *libxl__poller_get(libxl_ctx *ctx);
_hidden void libxl__poller_put(libxl_ctx *ctx, libxl__poller *p);
_hidden int libxl__atfork_init(libxl_ctx *ctx);
_hidden char *libxl__object_to_json(libxl_ctx *ctx, const char *type,
_hidden int libxl__init_recursive_mutex(libxl_ctx *ctx, pthread_mutex_t *lock);
[...]
_hidden libxl__ao *libxl__ao_create(libxl_ctx*, uint32_t domid,
_hidden void libxl__ao__destroy(libxl_ctx*, libxl__ao *ao);
_hidden libxl__carefd *libxl__carefd_record(libxl_ctx *ctx, int fd);
_hidden libxl__carefd *libxl__carefd_opened(libxl_ctx *ctx, int fd);
static inline void libxl__ctx_lock(libxl_ctx *ctx) {
static inline void libxl__ctx_unlock(libxl_ctx *ctx) {libxl__log*, libxl__alloc_failed and libxl__ctx_{un}lock are probably fine, libxl__object_to_json probably is too, but the others ought to take a gc? Something to be left for 4.3 IMHO but I thought I'd mention it.
Ian.
Ian Campbell writes ("Re: [Xen-devel] [PATCH] libxl: mark internal functions hidden"):
Quoted 2 lines
BTW, I noticed a bunch of
libxl__functions which take a ctx instead of a gc while doing this.
Yes, there are a few.
In some cases this is to make it easier to call them from infrastructure or macros which doesn't necessarily have a gc, eg the logging functions, and the way that libxl__ao_create obviously is _creating_ the gc (as well as the ao) for its caller.
In other cases it's just to avoid needlessly pratting about with GC_INIT. (Note that in the past, that pratting about was considerably more verbose.)
It isn't in general a bug to have nested calls to GC_INIT.
Ian.
Ian Campbell writes ("[Xen-devel] [PATCH] libxl: mark internal functions hidden"):
Quoted 3 lines
libxl: mark internal functions hidden
Signed-off-by Ian Campbell <[email protected]>