[gjs: 7/21] maint: Remove C-style NULLs from some files
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 7/21] maint: Remove C-style NULLs from some files
- Date: Sun, 9 Jun 2019 17:02:45 +0000 (UTC)
commit 916677785ed17dc5dde965113820c695c95d936d
Author: Philip Chimento <philip chimento gmail com>
Date: Fri May 31 22:16:53 2019 -0700
maint: Remove C-style NULLs from some files
In files where the IWYU tool would recommend including <stddef.h> only
for the symbol NULL, we instead remove usage of NULL in favour of
C++-style nullptr, or implicit conversion to bool.
gi/closure.cpp | 18 ++++++------
gi/fundamental.cpp | 18 ++++++------
gi/gerror.cpp | 28 +++++++++++--------
gi/interface.cpp | 6 ++--
gi/ns.cpp | 8 +++---
gi/param.cpp | 59 +++++++++++++++------------------------
gi/private.cpp | 2 +-
gi/union.cpp | 15 +++++-----
gi/wrapperutils.cpp | 6 ++--
gjs/jsapi-util-args.h | 8 +++---
gjs/jsapi-util-error.cpp | 2 +-
modules/cairo-context.cpp | 46 +++++++++++++++---------------
modules/cairo-image-surface.cpp | 9 +++---
modules/cairo-linear-gradient.cpp | 9 +++---
modules/cairo-path.cpp | 18 ++++++------
modules/cairo-pattern.cpp | 28 +++++++++----------
modules/cairo-pdf-surface.cpp | 11 ++++----
modules/cairo-ps-surface.cpp | 11 ++++----
modules/cairo-radial-gradient.cpp | 9 +++---
modules/cairo-region.cpp | 12 ++++----
modules/cairo-solid-pattern.cpp | 9 +++---
modules/cairo-surface-pattern.cpp | 9 +++---
modules/cairo-surface.cpp | 28 +++++++++----------
modules/cairo-svg-surface.cpp | 11 ++++----
test/gjs-test-rooting.cpp | 5 ++--
util/glib.cpp | 11 ++++----
util/misc.cpp | 2 +-
27 files changed, 198 insertions(+), 200 deletions(-)
---
diff --git a/gi/closure.cpp b/gi/closure.cpp
index 9d48e830..a952a14f 100644
--- a/gi/closure.cpp
+++ b/gi/closure.cpp
@@ -90,7 +90,7 @@ invalidate_js_pointers(GjsClosure *gc)
return;
c->func.reset();
- c->context = NULL;
+ c->context = nullptr;
/* Notify any closure reference holders they
* may want to drop references.
@@ -188,7 +188,7 @@ gjs_closure_invoke(GClosure *closure,
if (!c->func) {
/* We were destroyed; become a no-op */
- c->context = NULL;
+ c->context = nullptr;
return false;
}
@@ -243,7 +243,7 @@ gjs_closure_is_valid(GClosure *closure)
c = &((GjsClosure*) closure)->priv;
- return c->context != NULL;
+ return !!c->context;
}
JSContext*
@@ -281,10 +281,10 @@ gjs_closure_trace(GClosure *closure,
GClosure* gjs_closure_new(JSContext* context, JSFunction* callable,
const char* description GJS_USED_VERBOSE_GCLOSURE,
bool root_function) {
- GjsClosure *gc;
Closure *c;
- gc = (GjsClosure*) g_closure_new_simple(sizeof(GjsClosure), NULL);
+ auto* gc = reinterpret_cast<GjsClosure*>(
+ g_closure_new_simple(sizeof(GjsClosure), nullptr));
c = new (&gc->priv) Closure();
/* The saved context is used for lifetime management, so that the closure will
@@ -301,15 +301,17 @@ GClosure* gjs_closure_new(JSContext* context, JSFunction* callable,
/* Fully manage closure lifetime if so asked */
c->func.root(context, callable, global_context_finalized, gc);
- g_closure_add_invalidate_notifier(&gc->base, NULL, closure_invalidated);
+ g_closure_add_invalidate_notifier(&gc->base, nullptr,
+ closure_invalidated);
} else {
c->func = callable;
/* Only mark the closure as invalid if memory is managed
outside (i.e. by object.c for signals) */
- g_closure_add_invalidate_notifier(&gc->base, NULL, closure_set_invalid);
+ g_closure_add_invalidate_notifier(&gc->base, nullptr,
+ closure_set_invalid);
}
- g_closure_add_finalize_notifier(&gc->base, NULL, closure_finalize);
+ g_closure_add_finalize_notifier(&gc->base, nullptr, closure_finalize);
gjs_debug_closure("Create closure %p which calls function %p '%s'", gc,
c->func.debug_addr(), description);
diff --git a/gi/fundamental.cpp b/gi/fundamental.cpp
index 8cac0901..35791309 100644
--- a/gi/fundamental.cpp
+++ b/gi/fundamental.cpp
@@ -197,7 +197,7 @@ bool FundamentalInstance::invoke_constructor(JSContext* context,
JS::RootedId constructor_name(context, get_prototype()->constructor_name());
const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
- if (!gjs_object_require_property(context, obj, NULL, atoms.constructor(),
+ if (!gjs_object_require_property(context, obj, nullptr, atoms.constructor(),
&js_constructor) ||
constructor_name == JSID_VOID) {
gjs_throw(context, "Couldn't find a constructor for type %s.%s", ns(),
@@ -206,7 +206,7 @@ bool FundamentalInstance::invoke_constructor(JSContext* context,
}
JS::RootedObject constructor(context);
- if (!gjs_object_require_property(context, js_constructor, NULL,
+ if (!gjs_object_require_property(context, js_constructor, nullptr,
constructor_name, &constructor)) {
gjs_throw(context, "Couldn't find a constructor for type %s.%s", ns(),
name());
@@ -320,11 +320,11 @@ gjs_lookup_fundamental_prototype(JSContext *context,
}
if (G_UNLIKELY (!in_object))
- return NULL;
+ return nullptr;
JS::RootedValue value(context);
if (!JS_GetProperty(context, in_object, constructor_name, &value))
- return NULL;
+ return nullptr;
JS::RootedObject constructor(context);
if (value.isUndefined()) {
@@ -339,7 +339,7 @@ gjs_lookup_fundamental_prototype(JSContext *context,
gjs_throw(context,
"Fundamental constructor was not an object, it was a %s",
JS::InformalValueTypeName(value));
- return NULL;
+ return nullptr;
}
constructor = &value.toObject();
@@ -351,7 +351,7 @@ gjs_lookup_fundamental_prototype(JSContext *context,
JS::RootedObject prototype(context);
if (!gjs_object_require_property(context, constructor, "constructor object",
atoms.prototype(), &prototype))
- return NULL;
+ return nullptr;
return prototype;
}
@@ -435,7 +435,7 @@ JSObject* FundamentalInstance::object_for_c_ptr(JSContext* context,
void* gfundamental) {
if (!gfundamental) {
gjs_throw(context, "Cannot get JSObject for null fundamental pointer");
- return NULL;
+ return nullptr;
}
GjsContextPrivate* gjs = GjsContextPrivate::from_cx(context);
@@ -450,7 +450,7 @@ JSObject* FundamentalInstance::object_for_c_ptr(JSContext* context,
gjs_lookup_fundamental_prototype_from_gtype(context,
G_TYPE_FROM_INSTANCE(gfundamental)));
if (!proto)
- return NULL;
+ return nullptr;
JS::RootedObject object(context, JS_NewObjectWithGivenProto(
context, JS_GetClass(proto), proto));
@@ -489,7 +489,7 @@ JSObject* FundamentalInstance::object_for_gvalue(JSContext* cx,
void* fobj = proto_priv->call_get_value_function(value);
if (!fobj) {
gjs_throw(cx, "Failed to convert GValue to a fundamental instance");
- return NULL;
+ return nullptr;
}
return FundamentalInstance::object_for_c_ptr(cx, fobj);
diff --git a/gi/gerror.cpp b/gi/gerror.cpp
index 00c20cea..366e42aa 100644
--- a/gi/gerror.cpp
+++ b/gi/gerror.cpp
@@ -144,7 +144,7 @@ bool ErrorBase::to_string(JSContext* context, unsigned argc, JS::Value* vp) {
}
ErrorBase* priv = ErrorBase::for_js_typecheck(context, self, rec);
- if (priv == NULL)
+ if (!priv)
return false;
/* We follow the same pattern as standard JS errors, at the expense of
@@ -176,7 +176,7 @@ bool ErrorBase::value_of(JSContext* context, unsigned argc, JS::Value* vp) {
}
ErrorBase* priv = ErrorBase::for_js_typecheck(context, prototype, rec);
- if (priv == NULL)
+ if (!priv)
return false;
rec.rval().setInt32(priv->domain());
@@ -251,22 +251,26 @@ find_error_domain_info(GQuark domain)
GIEnumInfo *info;
/* first an attempt without loading extra libraries */
- info = g_irepository_find_by_error_domain(NULL, domain);
+ info = g_irepository_find_by_error_domain(nullptr, domain);
if (info)
return info;
/* load standard stuff */
- g_irepository_require(NULL, "GLib", "2.0", (GIRepositoryLoadFlags) 0, NULL);
- g_irepository_require(NULL, "GObject", "2.0", (GIRepositoryLoadFlags) 0, NULL);
- g_irepository_require(NULL, "Gio", "2.0", (GIRepositoryLoadFlags) 0, NULL);
- info = g_irepository_find_by_error_domain(NULL, domain);
+ g_irepository_require(nullptr, "GLib", "2.0", GIRepositoryLoadFlags(0),
+ nullptr);
+ g_irepository_require(nullptr, "GObject", "2.0", GIRepositoryLoadFlags(0),
+ nullptr);
+ g_irepository_require(nullptr, "Gio", "2.0", GIRepositoryLoadFlags(0),
+ nullptr);
+ info = g_irepository_find_by_error_domain(nullptr, domain);
if (info)
return info;
/* last attempt: load GIRepository (for invoke errors, rarely
needed) */
- g_irepository_require(NULL, "GIRepository", "1.0", (GIRepositoryLoadFlags) 0, NULL);
- info = g_irepository_find_by_error_domain(NULL, domain);
+ g_irepository_require(nullptr, "GIRepository", "1.0",
+ GIRepositoryLoadFlags(0), nullptr);
+ info = g_irepository_find_by_error_domain(nullptr, domain);
return info;
}
@@ -349,8 +353,8 @@ gjs_error_from_js_gerror(JSContext *cx,
JSObject* ErrorInstance::object_for_c_ptr(JSContext* context, GError* gerror) {
GIEnumInfo *info;
- if (gerror == NULL)
- return NULL;
+ if (!gerror)
+ return nullptr;
if (gerror->domain == GJS_JS_ERROR)
return gjs_error_from_js_gerror(context, gerror);
@@ -363,7 +367,7 @@ JSObject* ErrorInstance::object_for_c_ptr(JSContext* context, GError* gerror) {
GIBaseInfo *glib_boxed;
JSObject *retval;
- glib_boxed = g_irepository_find_by_name(NULL, "GLib", "Error");
+ glib_boxed = g_irepository_find_by_name(nullptr, "GLib", "Error");
retval = BoxedInstance::new_for_c_struct(context, glib_boxed, gerror);
g_base_info_unref(glib_boxed);
diff --git a/gi/interface.cpp b/gi/interface.cpp
index 3bae1280..90ca2066 100644
--- a/gi/interface.cpp
+++ b/gi/interface.cpp
@@ -148,9 +148,9 @@ gjs_lookup_interface_constructor(JSContext *context,
JSObject *constructor;
GIBaseInfo *interface_info;
- interface_info = g_irepository_find_by_gtype(NULL, gtype);
+ interface_info = g_irepository_find_by_gtype(nullptr, gtype);
- if (interface_info == NULL) {
+ if (!interface_info) {
gjs_throw(context, "Cannot expose non introspectable interface %s",
g_type_name(gtype));
return false;
@@ -160,7 +160,7 @@ gjs_lookup_interface_constructor(JSContext *context,
GI_INFO_TYPE_INTERFACE);
constructor = gjs_lookup_generic_constructor(context, interface_info);
- if (G_UNLIKELY (constructor == NULL))
+ if (G_UNLIKELY(!constructor))
return false;
g_base_info_unref(interface_info);
diff --git a/gi/ns.cpp b/gi/ns.cpp
index 5148aaf0..241573ac 100644
--- a/gi/ns.cpp
+++ b/gi/ns.cpp
@@ -72,7 +72,7 @@ ns_resolve(JSContext *context,
"Resolve prop '%s' hook, obj %s, priv %p",
gjs_debug_id(id).c_str(), gjs_debug_object(obj).c_str(), priv);
- if (priv == NULL) {
+ if (!priv) {
*resolved = false; /* we are the prototype, or have the wrong class */
return true;
}
@@ -117,7 +117,7 @@ get_name (JSContext *context,
{
GJS_GET_PRIV(context, argc, vp, args, obj, Ns, priv);
- if (priv == NULL)
+ if (!priv)
return false;
return gjs_string_from_utf8(context, priv->gi_namespace, args.rval());
@@ -131,7 +131,7 @@ static void ns_finalize(JSFreeOp*, JSObject* obj) {
priv = (Ns *)JS_GetPrivate(obj);
gjs_debug_lifecycle(GJS_DEBUG_GNAMESPACE,
"finalize, obj %p priv %p", obj, priv);
- if (priv == NULL)
+ if (!priv)
return; /* we are the prototype, not a real instance */
if (priv->gi_namespace)
@@ -190,7 +190,7 @@ ns_new(JSContext *context,
GJS_INC_COUNTER(ns);
- g_assert(priv_from_js(context, ns) == NULL);
+ g_assert(!priv_from_js(context, ns));
JS_SetPrivate(ns, priv);
gjs_debug_lifecycle(GJS_DEBUG_GNAMESPACE, "ns constructor, obj %p priv %p",
diff --git a/gi/param.cpp b/gi/param.cpp
index c5272916..b47eae42 100644
--- a/gi/param.cpp
+++ b/gi/param.cpp
@@ -38,7 +38,7 @@
#include <util/log.h>
typedef struct {
- GParamSpec *gparam; /* NULL if we are the prototype and not an instance */
+ GParamSpec* gparam; // nullptr if we are the prototype and not an instance
} Param;
extern struct JSClass gjs_param_class;
@@ -57,7 +57,7 @@ param_resolve(JSContext *context,
bool *resolved)
{
Param* priv = priv_from_js(context, obj);
- if (priv != NULL) {
+ if (!priv) {
/* instance, not prototype */
*resolved = false;
return true;
@@ -112,13 +112,10 @@ static void param_finalize(JSFreeOp*, JSObject* obj) {
priv = (Param*) JS_GetPrivate(obj);
gjs_debug_lifecycle(GJS_DEBUG_GPARAM,
"finalize, obj %p priv %p", obj, priv);
- if (priv == NULL)
+ if (!priv)
return; /* wrong class? */
- if (priv->gparam) {
- g_param_spec_unref(priv->gparam);
- priv->gparam = NULL;
- }
+ g_clear_pointer(&priv->gparam, g_param_spec_unref);
GJS_DEC_COUNTER(param);
g_slice_free(Param, priv);
@@ -165,23 +162,19 @@ gjs_lookup_param_prototype(JSContext *context)
context, gjs_lookup_namespace_object_by_name(context, atoms.gobject()));
if (G_UNLIKELY (!in_object))
- return NULL;
+ return nullptr;
JS::RootedValue value(context);
- if (!JS_GetPropertyById(context, in_object, atoms.param_spec(), &value))
- return NULL;
-
- if (G_UNLIKELY (!value.isObject()))
- return NULL;
+ if (!JS_GetPropertyById(context, in_object, atoms.param_spec(), &value) ||
+ G_UNLIKELY(!value.isObject()))
+ return nullptr;
JS::RootedObject constructor(context, &value.toObject());
g_assert(constructor);
- if (!JS_GetPropertyById(context, constructor, atoms.prototype(), &value))
- return NULL;
-
- if (G_UNLIKELY (!value.isObjectOrNull()))
- return NULL;
+ if (!JS_GetPropertyById(context, constructor, atoms.prototype(), &value) ||
+ G_UNLIKELY(!value.isObjectOrNull()))
+ return nullptr;
return value.toObjectOrNull();
}
@@ -195,20 +188,14 @@ gjs_define_param_class(JSContext *context,
constructor_name = "ParamSpec";
- if (!gjs_init_class_dynamic(context, in_object, nullptr, "GObject",
- constructor_name,
- &gjs_param_class,
- gjs_param_constructor, 0,
- /* props of prototype */
- &gjs_param_proto_props[0],
- /* funcs of prototype */
- &gjs_param_proto_funcs[0],
- /* props of constructor, MyConstructor.myprop */
- NULL,
- /* funcs of constructor, MyConstructor.myfunc() */
- gjs_param_constructor_funcs,
- &prototype,
- &constructor))
+ if (!gjs_init_class_dynamic(
+ context, in_object, nullptr, "GObject", constructor_name,
+ &gjs_param_class, gjs_param_constructor, 0,
+ gjs_param_proto_props, // props of prototype
+ gjs_param_proto_funcs, // funcs of prototype
+ nullptr, // props of constructor, MyConstructor.myprop
+ gjs_param_constructor_funcs, // funcs of constructor
+ &prototype, &constructor))
return false;
if (!gjs_wrapper_define_gtype_prop(context, constructor, G_TYPE_PARAM))
@@ -232,8 +219,8 @@ gjs_param_from_g_param(JSContext *context,
JSObject *obj;
Param *priv;
- if (gparam == NULL)
- return NULL;
+ if (!gparam)
+ return nullptr;
gjs_debug(GJS_DEBUG_GPARAM,
"Wrapping %s '%s' on %s with JSObject",
@@ -265,7 +252,7 @@ gjs_g_param_from_param(JSContext *context,
Param *priv;
if (!obj)
- return NULL;
+ return nullptr;
priv = priv_from_js(context, obj);
@@ -286,7 +273,7 @@ gjs_typecheck_param(JSContext *context,
priv = priv_from_js(context, object);
- if (priv->gparam == NULL) {
+ if (!priv->gparam) {
if (throw_error) {
gjs_throw_custom(context, JSProto_TypeError, nullptr,
"Object is GObject.ParamSpec.prototype, not an object instance - "
diff --git a/gi/private.cpp b/gi/private.cpp
index 8125ac9e..b2060e58 100644
--- a/gi/private.cpp
+++ b/gi/private.cpp
@@ -355,7 +355,7 @@ static bool gjs_signal_new(JSContext* cx, unsigned argc, JS::Value* vp) {
break;
case 0:
default:
- accumulator = NULL;
+ accumulator = nullptr;
}
GType return_type;
diff --git a/gi/union.cpp b/gi/union.cpp
index 87a16bf5..f0f5bec3 100644
--- a/gi/union.cpp
+++ b/gi/union.cpp
@@ -131,9 +131,9 @@ union_new(JSContext *context,
if (rval.isNull()) {
gjs_throw(context,
"Unable to construct union type %s as its"
- "constructor function returned NULL",
+ "constructor function returned null",
g_base_info_get_name(info));
- return NULL;
+ return nullptr;
} else {
JS::RootedObject rval_obj(context, &rval.toObject());
return UnionBase::to_c_ptr(context, rval_obj);
@@ -144,7 +144,7 @@ union_new(JSContext *context,
gjs_throw(context, "Unable to construct union type %s since it has no zero-args <constructor>, can only
wrap an existing one",
g_base_info_get_name((GIBaseInfo*) info));
- return NULL;
+ return nullptr;
}
// See GIWrapperBase::constructor().
@@ -162,9 +162,8 @@ bool UnionInstance::constructor_impl(JSContext* context,
*/
void* gboxed = union_new(context, object, info());
- if (gboxed == NULL) {
+ if (!gboxed)
return false;
- }
/* Because "gboxed" is owned by a JS::Value and will
* be garbage collected, we make a copy here to be
@@ -221,8 +220,8 @@ gjs_union_from_c_union(JSContext *context,
{
GType gtype;
- if (gboxed == NULL)
- return NULL;
+ if (!gboxed)
+ return nullptr;
/* For certain unions, we may be able to relax this in the future by
* directly allocating union memory, as we do for structures in boxed.c
@@ -230,7 +229,7 @@ gjs_union_from_c_union(JSContext *context,
gtype = g_registered_type_info_get_g_type( (GIRegisteredTypeInfo*) info);
if (gtype == G_TYPE_NONE) {
gjs_throw(context, "Unions must currently be registered as boxed types");
- return NULL;
+ return nullptr;
}
gjs_debug_marshal(GJS_DEBUG_GBOXED,
diff --git a/gi/wrapperutils.cpp b/gi/wrapperutils.cpp
index c62292c1..d5bb72ba 100644
--- a/gi/wrapperutils.cpp
+++ b/gi/wrapperutils.cpp
@@ -43,12 +43,12 @@ bool gjs_wrapper_to_string_func(JSContext* context, JSObject* this_obj,
buf = g_string_new("");
g_string_append_c(buf, '[');
g_string_append(buf, objtype);
- if (native_address == NULL)
+ if (!native_address)
g_string_append(buf, " prototype of");
else
g_string_append(buf, " instance wrapper");
- if (info != NULL) {
+ if (info) {
g_string_append_printf(buf, " GIName:%s.%s",
g_base_info_get_namespace(info),
g_base_info_get_name(info));
@@ -58,7 +58,7 @@ bool gjs_wrapper_to_string_func(JSContext* context, JSObject* this_obj,
}
g_string_append_printf(buf, " jsobj@%p", this_obj);
- if (native_address != NULL)
+ if (native_address)
g_string_append_printf(buf, " native@%p", native_address);
g_string_append_c(buf, ']');
diff --git a/gjs/jsapi-util-args.h b/gjs/jsapi-util-args.h
index 2fd52684..de51d14f 100644
--- a/gjs/jsapi-util-args.h
+++ b/gjs/jsapi-util-args.h
@@ -64,7 +64,7 @@ static inline void assign(JSContext*, char c, bool nullable,
if (c != 'o')
throw g_strdup_printf("Wrong type for %c, got JS::MutableHandleObject", c);
if (nullable && value.isNull()) {
- ref.set(NULL);
+ ref.set(nullptr);
return;
}
if (!value.isObject())
@@ -209,7 +209,7 @@ free_if_necessary(JS::MutableHandleObject param_ref)
/* This is not exactly right, since before we consumed a JS::ObjectValue
* there may have been something different inside the handle. But it has
* already been clobbered at this point anyhow */
- param_ref.set(NULL);
+ param_ref.set(nullptr);
}
template <typename T>
@@ -220,7 +220,7 @@ GJS_JSAPI_RETURN_CONVENTION static bool parse_call_args_helper(
bool nullable = false;
const char *fchar = fmt_required;
- g_return_val_if_fail (param_name != NULL, false);
+ g_return_val_if_fail(param_name, false);
if (*fchar != '\0') {
nullable = check_nullable(fchar, fmt_required);
@@ -383,7 +383,7 @@ GJS_JSAPI_RETURN_CONVENTION static bool gjs_parse_call_args(
GjsAutoStrv parts = g_strsplit(format, "|", 2);
fmt_required = parts.get()[0];
- fmt_optional = parts.get()[1]; // may be NULL
+ fmt_optional = parts.get()[1]; // may be null
return parse_call_args_helper(cx, function_name, args, fmt_required,
fmt_optional, 0, params...);
diff --git a/gjs/jsapi-util-error.cpp b/gjs/jsapi-util-error.cpp
index 71c046f0..dcd9d78d 100644
--- a/gjs/jsapi-util-error.cpp
+++ b/gjs/jsapi-util-error.cpp
@@ -95,7 +95,7 @@ gjs_throw_valist(JSContext *context,
if (!new_exc)
goto out;
- if (error_name != NULL) {
+ if (error_name) {
const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
JS::RootedValue name_value(context);
if (!gjs_string_from_utf8(context, error_name, &name_value) ||
diff --git a/modules/cairo-context.cpp b/modules/cairo-context.cpp
index caeffeae..2d54228d 100644
--- a/modules/cairo-context.cpp
+++ b/modules/cairo-context.cpp
@@ -254,7 +254,7 @@ _gjs_cairo_context_construct_internal(JSContext *context,
priv = g_slice_new0(GjsCairoContext);
- g_assert(priv_from_js(context, obj) == NULL);
+ g_assert(!priv_from_js(context, obj));
JS_SetPrivate(obj, priv);
priv->context = context;
@@ -297,10 +297,10 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(cairo_context)
static void gjs_cairo_context_finalize(JSFreeOp*, JSObject* obj) {
GjsCairoContext *priv;
priv = (GjsCairoContext*) JS_GetPrivate(obj);
- if (priv == NULL)
+ if (!priv)
return;
- if (priv->cr != NULL)
+ if (priv->cr)
cairo_destroy(priv->cr);
g_slice_free(GjsCairoContext, priv);
@@ -398,10 +398,8 @@ dispose_func(JSContext *context,
{
GJS_GET_PRIV(context, argc, vp, rec, obj, GjsCairoContext, priv);
- if (priv->cr != NULL) {
- cairo_destroy(priv->cr);
- priv->cr = NULL;
- }
+ g_clear_pointer(&priv->cr, cairo_destroy);
+
rec.rval().setUndefined();
return true;
}
@@ -415,7 +413,7 @@ appendPath_func(JSContext *context,
GJS_GET_PRIV(context, argc, vp, argv, obj, GjsCairoContext, priv);
JS::RootedObject path_wrapper(context);
cairo_path_t *path;
- cairo_t *cr = priv ? priv->cr : NULL;
+ cairo_t* cr = priv ? priv->cr : nullptr;
if (!gjs_parse_call_args(context, "path", argv, "o",
"path", &path_wrapper))
@@ -440,7 +438,7 @@ copyPath_func(JSContext *context,
{
GJS_GET_PRIV(context, argc, vp, argv, obj, GjsCairoContext, priv);
cairo_path_t *path;
- cairo_t *cr = priv ? priv->cr : NULL;
+ cairo_t* cr = priv ? priv->cr : nullptr;
if (!gjs_parse_call_args(context, "", argv, ""))
return false;
@@ -458,7 +456,7 @@ copyPathFlat_func(JSContext *context,
{
GJS_GET_PRIV(context, argc, vp, argv, obj, GjsCairoContext, priv);
cairo_path_t *path;
- cairo_t *cr = priv ? priv->cr : NULL;
+ cairo_t* cr = priv ? priv->cr : nullptr;
if (!gjs_parse_call_args(context, "", argv, ""))
return false;
@@ -477,7 +475,7 @@ mask_func(JSContext *context,
GJS_GET_PRIV(context, argc, vp, argv, obj, GjsCairoContext, priv);
JS::RootedObject pattern_wrapper(context);
cairo_pattern_t *pattern;
- cairo_t *cr = priv ? priv->cr : NULL;
+ cairo_t* cr = priv ? priv->cr : nullptr;
if (!gjs_parse_call_args(context, "mask", argv, "o",
"pattern", &pattern_wrapper))
@@ -508,7 +506,7 @@ maskSurface_func(JSContext *context,
JS::RootedObject surface_wrapper(context);
double x, y;
cairo_surface_t *surface;
- cairo_t *cr = priv ? priv->cr : NULL;
+ cairo_t* cr = priv ? priv->cr : nullptr;
if (!gjs_parse_call_args(context, "maskSurface", argv, "off",
"surface", &surface_wrapper,
@@ -539,7 +537,7 @@ setDash_func(JSContext *context,
{
GJS_GET_PRIV(context, argc, vp, argv, obj, GjsCairoContext, priv);
guint i;
- cairo_t *cr = priv ? priv->cr : NULL;
+ cairo_t* cr = priv ? priv->cr : nullptr;
JS::RootedObject dashes(context);
double offset;
guint len;
@@ -599,7 +597,7 @@ setSource_func(JSContext *context,
GJS_GET_PRIV(context, argc, vp, argv, obj, GjsCairoContext, priv);
JS::RootedObject pattern_wrapper(context);
cairo_pattern_t *pattern;
- cairo_t *cr = priv ? priv->cr : NULL;
+ cairo_t* cr = priv ? priv->cr : nullptr;
if (!gjs_parse_call_args(context, "setSource", argv, "o",
"pattern", &pattern_wrapper))
@@ -631,7 +629,7 @@ setSourceSurface_func(JSContext *context,
JS::RootedObject surface_wrapper(context);
double x, y;
cairo_surface_t *surface;
- cairo_t *cr = priv ? priv->cr : NULL;
+ cairo_t* cr = priv ? priv->cr : nullptr;
if (!gjs_parse_call_args(context, "setSourceSurface", argv, "off",
"surface", &surface_wrapper,
@@ -663,7 +661,7 @@ showText_func(JSContext *context,
{
GJS_GET_PRIV(context, argc, vp, argv, obj, GjsCairoContext, priv);
JS::UniqueChars utf8;
- cairo_t *cr = priv ? priv->cr : NULL;
+ cairo_t* cr = priv ? priv->cr : nullptr;
if (!gjs_parse_call_args(context, "showText", argv, "s",
"utf8", &utf8))
@@ -689,7 +687,7 @@ selectFontFace_func(JSContext *context,
JS::UniqueChars family;
cairo_font_slant_t slant;
cairo_font_weight_t weight;
- cairo_t *cr = priv ? priv->cr : NULL;
+ cairo_t* cr = priv ? priv->cr : nullptr;
if (!gjs_parse_call_args(context, "selectFontFace", argv, "sii",
"family", &family,
@@ -713,7 +711,7 @@ popGroup_func(JSContext *context,
JS::Value *vp)
{
GJS_GET_PRIV(context, argc, vp, rec, obj, GjsCairoContext, priv);
- cairo_t *cr = priv ? priv->cr : NULL;
+ cairo_t* cr = priv ? priv->cr : nullptr;
cairo_pattern_t *pattern;
JSObject *pattern_wrapper;
@@ -744,7 +742,7 @@ getSource_func(JSContext *context,
JS::Value *vp)
{
GJS_GET_PRIV(context, argc, vp, rec, obj, GjsCairoContext, priv);
- cairo_t *cr = priv ? priv->cr : NULL;
+ cairo_t* cr = priv ? priv->cr : nullptr;
cairo_pattern_t *pattern;
JSObject *pattern_wrapper;
@@ -776,7 +774,7 @@ getTarget_func(JSContext *context,
JS::Value *vp)
{
GJS_GET_PRIV(context, argc, vp, rec, obj, GjsCairoContext, priv);
- cairo_t *cr = priv ? priv->cr : NULL;
+ cairo_t* cr = priv ? priv->cr : nullptr;
cairo_surface_t *surface;
JSObject *surface_wrapper;
@@ -808,7 +806,7 @@ getGroupTarget_func(JSContext *context,
JS::Value *vp)
{
GJS_GET_PRIV(context, argc, vp, rec, obj, GjsCairoContext, priv);
- cairo_t *cr = priv ? priv->cr : NULL;
+ cairo_t* cr = priv ? priv->cr : nullptr;
cairo_surface_t *surface;
JSObject *surface_wrapper;
@@ -944,7 +942,7 @@ gjs_cairo_context_from_context(JSContext *context,
JS::RootedObject object(context,
JS_NewObjectWithGivenProto(context, &gjs_cairo_context_class, proto));
if (!object)
- return NULL;
+ return nullptr;
_gjs_cairo_context_construct_internal(context, object, cr);
@@ -957,8 +955,8 @@ gjs_cairo_context_get_context(JSContext *context,
{
GjsCairoContext *priv;
priv = priv_from_js(context, object);
- if (priv == NULL)
- return NULL;
+ if (!priv)
+ return nullptr;
return priv->cr;
}
diff --git a/modules/cairo-image-surface.cpp b/modules/cairo-image-surface.cpp
index a0c89278..ee463426 100644
--- a/modules/cairo-image-surface.cpp
+++ b/modules/cairo-image-surface.cpp
@@ -225,9 +225,10 @@ JSObject *
gjs_cairo_image_surface_from_surface(JSContext *context,
cairo_surface_t *surface)
{
- g_return_val_if_fail(context != NULL, NULL);
- g_return_val_if_fail(surface != NULL, NULL);
- g_return_val_if_fail(cairo_surface_get_type(surface) == CAIRO_SURFACE_TYPE_IMAGE, NULL);
+ g_return_val_if_fail(context, nullptr);
+ g_return_val_if_fail(surface, nullptr);
+ g_return_val_if_fail(
+ cairo_surface_get_type(surface) == CAIRO_SURFACE_TYPE_IMAGE, nullptr);
JS::RootedObject proto(context, gjs_cairo_image_surface_get_proto(context));
JS::RootedObject object(context,
@@ -235,7 +236,7 @@ gjs_cairo_image_surface_from_surface(JSContext *context,
proto));
if (!object) {
gjs_throw(context, "failed to create image surface");
- return NULL;
+ return nullptr;
}
gjs_cairo_surface_construct(context, object, surface);
diff --git a/modules/cairo-linear-gradient.cpp b/modules/cairo-linear-gradient.cpp
index 0fb89d19..7892a1c4 100644
--- a/modules/cairo-linear-gradient.cpp
+++ b/modules/cairo-linear-gradient.cpp
@@ -84,9 +84,10 @@ JSObject *
gjs_cairo_linear_gradient_from_pattern(JSContext *context,
cairo_pattern_t *pattern)
{
- g_return_val_if_fail(context != NULL, NULL);
- g_return_val_if_fail(pattern != NULL, NULL);
- g_return_val_if_fail(cairo_pattern_get_type(pattern) == CAIRO_PATTERN_TYPE_LINEAR, NULL);
+ g_return_val_if_fail(context, nullptr);
+ g_return_val_if_fail(pattern, nullptr);
+ g_return_val_if_fail(
+ cairo_pattern_get_type(pattern) == CAIRO_PATTERN_TYPE_LINEAR, nullptr);
JS::RootedObject proto(context,
gjs_cairo_linear_gradient_get_proto(context));
@@ -95,7 +96,7 @@ gjs_cairo_linear_gradient_from_pattern(JSContext *context,
proto));
if (!object) {
gjs_throw(context, "failed to create linear gradient pattern");
- return NULL;
+ return nullptr;
}
gjs_cairo_pattern_construct(context, object, pattern);
diff --git a/modules/cairo-path.cpp b/modules/cairo-path.cpp
index 9b3b85b0..46cb905e 100644
--- a/modules/cairo-path.cpp
+++ b/modules/cairo-path.cpp
@@ -43,7 +43,7 @@ GJS_DEFINE_PRIV_FROM_JS(GjsCairoPath, gjs_cairo_path_class)
static void gjs_cairo_path_finalize(JSFreeOp*, JSObject* obj) {
GjsCairoPath *priv;
priv = (GjsCairoPath*) JS_GetPrivate(obj);
- if (priv == NULL)
+ if (!priv)
return;
cairo_path_destroy(priv->path);
g_slice_free(GjsCairoPath, priv);
@@ -74,20 +74,20 @@ gjs_cairo_path_from_path(JSContext *context,
{
GjsCairoPath *priv;
- g_return_val_if_fail(context != NULL, NULL);
- g_return_val_if_fail(path != NULL, NULL);
+ g_return_val_if_fail(context, nullptr);
+ g_return_val_if_fail(path, nullptr);
JS::RootedObject proto(context, gjs_cairo_path_get_proto(context));
JS::RootedObject object(context,
JS_NewObjectWithGivenProto(context, &gjs_cairo_path_class, proto));
if (!object) {
gjs_throw(context, "failed to create path");
- return NULL;
+ return nullptr;
}
priv = g_slice_new0(GjsCairoPath);
- g_assert(priv_from_js(context, object) == NULL);
+ g_assert(!priv_from_js(context, object));
JS_SetPrivate(object, priv);
priv->context = context;
@@ -112,11 +112,11 @@ gjs_cairo_path_get_path(JSContext *context,
{
GjsCairoPath *priv;
- g_return_val_if_fail(context != NULL, NULL);
- g_return_val_if_fail(object != NULL, NULL);
+ g_return_val_if_fail(context, nullptr);
+ g_return_val_if_fail(object, nullptr);
priv = (GjsCairoPath*) JS_GetPrivate(object);
- if (priv == NULL)
- return NULL;
+ if (!priv)
+ return nullptr;
return priv->path;
}
diff --git a/modules/cairo-pattern.cpp b/modules/cairo-pattern.cpp
index 78d2d0f0..008f49b1 100644
--- a/modules/cairo-pattern.cpp
+++ b/modules/cairo-pattern.cpp
@@ -44,7 +44,7 @@ GJS_DEFINE_PRIV_FROM_JS(GjsCairoPattern, gjs_cairo_pattern_class)
static void gjs_cairo_pattern_finalize(JSFreeOp*, JSObject* obj) {
GjsCairoPattern *priv;
priv = (GjsCairoPattern*) JS_GetPrivate(obj);
- if (priv == NULL)
+ if (!priv)
return;
cairo_pattern_destroy(priv->pattern);
g_slice_free(GjsCairoPattern, priv);
@@ -110,13 +110,13 @@ gjs_cairo_pattern_construct(JSContext *context,
{
GjsCairoPattern *priv;
- g_return_if_fail(context != NULL);
- g_return_if_fail(object != nullptr);
- g_return_if_fail(pattern != NULL);
+ g_return_if_fail(context);
+ g_return_if_fail(object);
+ g_return_if_fail(pattern);
priv = g_slice_new0(GjsCairoPattern);
- g_assert(priv_from_js(context, object) == NULL);
+ g_assert(!priv_from_js(context, object));
JS_SetPrivate(object, priv);
priv->context = context;
@@ -138,8 +138,8 @@ void
gjs_cairo_pattern_finalize_pattern(JSFreeOp *fop,
JSObject *object)
{
- g_return_if_fail(fop != NULL);
- g_return_if_fail(object != NULL);
+ g_return_if_fail(fop);
+ g_return_if_fail(object);
gjs_cairo_pattern_finalize(fop, object);
}
@@ -157,8 +157,8 @@ JSObject *
gjs_cairo_pattern_from_pattern(JSContext *context,
cairo_pattern_t *pattern)
{
- g_return_val_if_fail(context != NULL, NULL);
- g_return_val_if_fail(pattern != NULL, NULL);
+ g_return_val_if_fail(context, nullptr);
+ g_return_val_if_fail(pattern, nullptr);
switch (cairo_pattern_get_type(pattern)) {
case CAIRO_PATTERN_TYPE_SOLID:
@@ -175,7 +175,7 @@ gjs_cairo_pattern_from_pattern(JSContext *context,
gjs_throw(context,
"failed to create pattern, unsupported pattern type %d",
cairo_pattern_get_type(pattern));
- return NULL;
+ return nullptr;
}
}
@@ -193,12 +193,12 @@ gjs_cairo_pattern_get_pattern(JSContext *context,
{
GjsCairoPattern *priv;
- g_return_val_if_fail(context != NULL, NULL);
- g_return_val_if_fail(object != NULL, NULL);
+ g_return_val_if_fail(context, nullptr);
+ g_return_val_if_fail(object, nullptr);
priv = (GjsCairoPattern*) JS_GetPrivate(object);
- if (priv == NULL)
- return NULL;
+ if (!priv)
+ return nullptr;
return priv->pattern;
}
diff --git a/modules/cairo-pdf-surface.cpp b/modules/cairo-pdf-surface.cpp
index 46b60a03..78d430ee 100644
--- a/modules/cairo-pdf-surface.cpp
+++ b/modules/cairo-pdf-surface.cpp
@@ -87,9 +87,10 @@ JSObject *
gjs_cairo_pdf_surface_from_surface(JSContext *context,
cairo_surface_t *surface)
{
- g_return_val_if_fail(context != NULL, NULL);
- g_return_val_if_fail(surface != NULL, NULL);
- g_return_val_if_fail(cairo_surface_get_type(surface) == CAIRO_SURFACE_TYPE_PDF, NULL);
+ g_return_val_if_fail(context, nullptr);
+ g_return_val_if_fail(surface, nullptr);
+ g_return_val_if_fail(
+ cairo_surface_get_type(surface) == CAIRO_SURFACE_TYPE_PDF, nullptr);
JS::RootedObject proto(context, gjs_cairo_pdf_surface_get_proto(context));
JS::RootedObject object(context,
@@ -97,7 +98,7 @@ gjs_cairo_pdf_surface_from_surface(JSContext *context,
proto));
if (!object) {
gjs_throw(context, "failed to create pdf surface");
- return NULL;
+ return nullptr;
}
gjs_cairo_surface_construct(context, object, surface);
@@ -112,6 +113,6 @@ gjs_cairo_pdf_surface_from_surface(JSContext *context,
gjs_throw(context,
"could not create PDF surface, recompile cairo and gjs with "
"PDF support.");
- return NULL;
+ return nullptr;
}
#endif /* CAIRO_HAS_PDF_SURFACE */
diff --git a/modules/cairo-ps-surface.cpp b/modules/cairo-ps-surface.cpp
index 3401052f..863beb71 100644
--- a/modules/cairo-ps-surface.cpp
+++ b/modules/cairo-ps-surface.cpp
@@ -96,16 +96,17 @@ JSObject *
gjs_cairo_ps_surface_from_surface(JSContext *context,
cairo_surface_t *surface)
{
- g_return_val_if_fail(context != NULL, NULL);
- g_return_val_if_fail(surface != NULL, NULL);
- g_return_val_if_fail(cairo_surface_get_type(surface) == CAIRO_SURFACE_TYPE_PS, NULL);
+ g_return_val_if_fail(context, nullptr);
+ g_return_val_if_fail(surface, nullptr);
+ g_return_val_if_fail(
+ cairo_surface_get_type(surface) == CAIRO_SURFACE_TYPE_PS, nullptr);
JS::RootedObject proto(context, gjs_cairo_ps_surface_get_proto(context));
JS::RootedObject object(context,
JS_NewObjectWithGivenProto(context, &gjs_cairo_ps_surface_class, proto));
if (!object) {
gjs_throw(context, "failed to create ps surface");
- return NULL;
+ return nullptr;
}
gjs_cairo_surface_construct(context, object, surface);
@@ -120,6 +121,6 @@ gjs_cairo_ps_surface_from_surface(JSContext *context,
gjs_throw(context,
"could not create PS surface, recompile cairo and gjs with "
"PS support.");
- return NULL;
+ return nullptr;
}
#endif /* CAIRO_HAS_PS_SURFACE */
diff --git a/modules/cairo-radial-gradient.cpp b/modules/cairo-radial-gradient.cpp
index 7aa2dcb3..e2db7417 100644
--- a/modules/cairo-radial-gradient.cpp
+++ b/modules/cairo-radial-gradient.cpp
@@ -86,9 +86,10 @@ JSObject *
gjs_cairo_radial_gradient_from_pattern(JSContext *context,
cairo_pattern_t *pattern)
{
- g_return_val_if_fail(context != NULL, NULL);
- g_return_val_if_fail(pattern != NULL, NULL);
- g_return_val_if_fail(cairo_pattern_get_type(pattern) == CAIRO_PATTERN_TYPE_RADIAL, NULL);
+ g_return_val_if_fail(context, nullptr);
+ g_return_val_if_fail(pattern, nullptr);
+ g_return_val_if_fail(
+ cairo_pattern_get_type(pattern) == CAIRO_PATTERN_TYPE_RADIAL, nullptr);
JS::RootedObject proto(context,
gjs_cairo_radial_gradient_get_proto(context));
@@ -97,7 +98,7 @@ gjs_cairo_radial_gradient_from_pattern(JSContext *context,
proto));
if (!object) {
gjs_throw(context, "failed to create radial gradient pattern");
- return NULL;
+ return nullptr;
}
gjs_cairo_pattern_construct(context, object, pattern);
diff --git a/modules/cairo-region.cpp b/modules/cairo-region.cpp
index 3767ab5d..9ebcfc0b 100644
--- a/modules/cairo-region.cpp
+++ b/modules/cairo-region.cpp
@@ -51,8 +51,8 @@ get_region(JSContext *context,
JS::HandleObject obj)
{
GjsCairoRegion *priv = priv_from_js(context, obj);
- if (priv == NULL)
- return NULL;
+ if (!priv)
+ return nullptr;
else
return priv->region;
}
@@ -65,7 +65,7 @@ fill_rectangle(JSContext *context,
#define PRELUDE \
GJS_GET_PRIV(context, argc, vp, argv, obj, GjsCairoRegion, priv); \
- cairo_region_t *this_region = priv ? priv->region : NULL;
+ cairo_region_t* this_region = priv ? priv->region : nullptr;
#define RETURN_STATUS \
return gjs_cairo_check_status(context, cairo_region_status(this_region), "region");
@@ -247,7 +247,7 @@ _gjs_cairo_region_construct_internal(JSContext *context,
priv = g_slice_new0(GjsCairoRegion);
- g_assert(priv_from_js(context, obj) == NULL);
+ g_assert(!priv_from_js(context, obj));
JS_SetPrivate(obj, priv);
priv->context = context;
@@ -278,7 +278,7 @@ GJS_NATIVE_CONSTRUCTOR_DECLARE(cairo_region)
static void gjs_cairo_region_finalize(JSFreeOp*, JSObject* obj) {
GjsCairoRegion *priv;
priv = (GjsCairoRegion*) JS_GetPrivate(obj);
- if (priv == NULL)
+ if (!priv)
return;
cairo_region_destroy(priv->region);
@@ -294,7 +294,7 @@ gjs_cairo_region_from_region(JSContext *context,
JS::RootedObject object(context,
JS_NewObjectWithGivenProto(context, &gjs_cairo_region_class, proto));
if (!object)
- return NULL;
+ return nullptr;
_gjs_cairo_region_construct_internal(context, object, region);
diff --git a/modules/cairo-solid-pattern.cpp b/modules/cairo-solid-pattern.cpp
index 89066687..ab66265a 100644
--- a/modules/cairo-solid-pattern.cpp
+++ b/modules/cairo-solid-pattern.cpp
@@ -116,9 +116,10 @@ JSObject *
gjs_cairo_solid_pattern_from_pattern(JSContext *context,
cairo_pattern_t *pattern)
{
- g_return_val_if_fail(context != NULL, NULL);
- g_return_val_if_fail(pattern != NULL, NULL);
- g_return_val_if_fail(cairo_pattern_get_type(pattern) == CAIRO_PATTERN_TYPE_SOLID, NULL);
+ g_return_val_if_fail(context, nullptr);
+ g_return_val_if_fail(pattern, nullptr);
+ g_return_val_if_fail(
+ cairo_pattern_get_type(pattern) == CAIRO_PATTERN_TYPE_SOLID, nullptr);
JS::RootedObject proto(context, gjs_cairo_solid_pattern_get_proto(context));
JS::RootedObject object(context,
@@ -126,7 +127,7 @@ gjs_cairo_solid_pattern_from_pattern(JSContext *context,
proto));
if (!object) {
gjs_throw(context, "failed to create solid pattern");
- return NULL;
+ return nullptr;
}
gjs_cairo_pattern_construct(context, object, pattern);
diff --git a/modules/cairo-surface-pattern.cpp b/modules/cairo-surface-pattern.cpp
index 48fd2cfe..ba7dccd5 100644
--- a/modules/cairo-surface-pattern.cpp
+++ b/modules/cairo-surface-pattern.cpp
@@ -191,9 +191,10 @@ JSObject *
gjs_cairo_surface_pattern_from_pattern(JSContext *context,
cairo_pattern_t *pattern)
{
- g_return_val_if_fail(context != NULL, NULL);
- g_return_val_if_fail(pattern != NULL, NULL);
- g_return_val_if_fail(cairo_pattern_get_type(pattern) == CAIRO_PATTERN_TYPE_SURFACE, NULL);
+ g_return_val_if_fail(context, nullptr);
+ g_return_val_if_fail(pattern, nullptr);
+ g_return_val_if_fail(
+ cairo_pattern_get_type(pattern) == CAIRO_PATTERN_TYPE_SURFACE, nullptr);
JS::RootedObject proto(context,
gjs_cairo_surface_pattern_get_proto(context));
@@ -202,7 +203,7 @@ gjs_cairo_surface_pattern_from_pattern(JSContext *context,
proto));
if (!object) {
gjs_throw(context, "failed to create surface pattern");
- return NULL;
+ return nullptr;
}
gjs_cairo_pattern_construct(context, object, pattern);
diff --git a/modules/cairo-surface.cpp b/modules/cairo-surface.cpp
index b6130e0f..a1e0e8d5 100644
--- a/modules/cairo-surface.cpp
+++ b/modules/cairo-surface.cpp
@@ -45,7 +45,7 @@ GJS_DEFINE_PRIV_FROM_JS(GjsCairoSurface, gjs_cairo_surface_class)
static void gjs_cairo_surface_finalize(JSFreeOp*, JSObject* obj) {
GjsCairoSurface *priv;
priv = (GjsCairoSurface*) JS_GetPrivate(obj);
- if (priv == NULL)
+ if (!priv)
return;
cairo_surface_destroy(priv->surface);
g_slice_free(GjsCairoSurface, priv);
@@ -147,13 +147,13 @@ gjs_cairo_surface_construct(JSContext *context,
{
GjsCairoSurface *priv;
- g_return_if_fail(context != NULL);
- g_return_if_fail(object != nullptr);
- g_return_if_fail(surface != NULL);
+ g_return_if_fail(context);
+ g_return_if_fail(object);
+ g_return_if_fail(surface);
priv = g_slice_new0(GjsCairoSurface);
- g_assert(priv_from_js(context, object) == NULL);
+ g_assert(!priv_from_js(context, object));
JS_SetPrivate(object, priv);
priv->context = context;
@@ -174,8 +174,8 @@ void
gjs_cairo_surface_finalize_surface(JSFreeOp *fop,
JSObject *object)
{
- g_return_if_fail(fop != NULL);
- g_return_if_fail(object != NULL);
+ g_return_if_fail(fop);
+ g_return_if_fail(object);
gjs_cairo_surface_finalize(fop, object);
}
@@ -193,8 +193,8 @@ JSObject *
gjs_cairo_surface_from_surface(JSContext *context,
cairo_surface_t *surface)
{
- g_return_val_if_fail(context != NULL, NULL);
- g_return_val_if_fail(surface != NULL, NULL);
+ g_return_val_if_fail(context, nullptr);
+ g_return_val_if_fail(surface, nullptr);
cairo_surface_type_t type = cairo_surface_get_type(surface);
if (type == CAIRO_SURFACE_TYPE_IMAGE)
@@ -211,7 +211,7 @@ gjs_cairo_surface_from_surface(JSContext *context,
JS_NewObjectWithGivenProto(context, &gjs_cairo_surface_class, proto));
if (!object) {
gjs_throw(context, "failed to create surface");
- return NULL;
+ return nullptr;
}
gjs_cairo_surface_construct(context, object, surface);
@@ -233,12 +233,12 @@ gjs_cairo_surface_get_surface(JSContext *context,
{
GjsCairoSurface *priv;
- g_return_val_if_fail(context != NULL, NULL);
- g_return_val_if_fail(object != NULL, NULL);
+ g_return_val_if_fail(context, nullptr);
+ g_return_val_if_fail(object, nullptr);
priv = (GjsCairoSurface*) JS_GetPrivate(object);
- if (priv == NULL)
- return NULL;
+ if (!priv)
+ return nullptr;
return priv->surface;
}
diff --git a/modules/cairo-svg-surface.cpp b/modules/cairo-svg-surface.cpp
index 9dabb07d..601dca94 100644
--- a/modules/cairo-svg-surface.cpp
+++ b/modules/cairo-svg-surface.cpp
@@ -87,9 +87,10 @@ JSObject *
gjs_cairo_svg_surface_from_surface(JSContext *context,
cairo_surface_t *surface)
{
- g_return_val_if_fail(context != NULL, NULL);
- g_return_val_if_fail(surface != NULL, NULL);
- g_return_val_if_fail(cairo_surface_get_type(surface) == CAIRO_SURFACE_TYPE_SVG, NULL);
+ g_return_val_if_fail(context, nullptr);
+ g_return_val_if_fail(surface, nullptr);
+ g_return_val_if_fail(
+ cairo_surface_get_type(surface) == CAIRO_SURFACE_TYPE_SVG, nullptr);
JS::RootedObject proto(context, gjs_cairo_svg_surface_get_proto(context));
JS::RootedObject object(context,
@@ -97,7 +98,7 @@ gjs_cairo_svg_surface_from_surface(JSContext *context,
proto));
if (!object) {
gjs_throw(context, "failed to create svg surface");
- return NULL;
+ return nullptr;
}
gjs_cairo_surface_construct(context, object, surface);
@@ -112,6 +113,6 @@ gjs_cairo_svg_surface_from_surface(JSContext *context,
gjs_throw(context,
"could not create SVG surface, recompile cairo and gjs with "
"SVG support.");
- return NULL;
+ return nullptr;
}
#endif /* CAIRO_HAS_SVG_SURFACE */
diff --git a/test/gjs-test-rooting.cpp b/test/gjs-test-rooting.cpp
index 0ba02bbb..75bb76da 100644
--- a/test/gjs-test-rooting.cpp
+++ b/test/gjs-test-rooting.cpp
@@ -222,8 +222,9 @@ static void test_maybe_owned_object_destroyed_after_notify(
void
gjs_test_add_tests_for_rooting(void)
{
-#define ADD_ROOTING_TEST(path, f) \
- g_test_add("/rooting/" path, GjsRootingFixture, NULL, setup, f, teardown);
+#define ADD_ROOTING_TEST(path, f) \
+ g_test_add("/rooting/" path, GjsRootingFixture, nullptr, setup, f, \
+ teardown);
ADD_ROOTING_TEST("maybe-owned/rooted-flag-set-when-rooted",
test_maybe_owned_rooted_flag_set_when_rooted);
diff --git a/util/glib.cpp b/util/glib.cpp
index 0c9af7f7..1acd2eaf 100644
--- a/util/glib.cpp
+++ b/util/glib.cpp
@@ -30,12 +30,11 @@
* Concate an array of string arrays to one string array. The strings in each
* array is copied to the resulting array.
*
- * @strv_array: array of NULL-terminated arrays of strings. NULL elements are
+ * @strv_array: array of 0-terminated arrays of strings. Null elements are
* allowed.
* @len: number of arrays in @strv_array
*
- * @return: a newly allocated NULL-terminated array of strings. Use
- * g_strfreev() to free it
+ * Returns: (transfer full): a newly allocated 0-terminated array of strings.
*/
char**
gjs_g_strv_concat(char ***strv_array, int len)
@@ -50,14 +49,14 @@ gjs_g_strv_concat(char ***strv_array, int len)
int j;
strv = strv_array[i];
- if (strv == NULL)
+ if (!strv)
continue;
- for (j = 0; strv[j] != NULL; ++j)
+ for (j = 0; strv[j]; ++j)
g_ptr_array_add(array, g_strdup(strv[j]));
}
- g_ptr_array_add(array, NULL);
+ g_ptr_array_add(array, nullptr);
return (char**)g_ptr_array_free(array, false);
}
diff --git a/util/misc.cpp b/util/misc.cpp
index c28b9b10..464f23b6 100644
--- a/util/misc.cpp
+++ b/util/misc.cpp
@@ -30,7 +30,7 @@ gjs_environment_variable_is_set(const char *env_variable_name)
const char *s;
s = g_getenv(env_variable_name);
- if (s == NULL)
+ if (!s)
return false;
if (*s == '\0')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]