Skip to content

Commit

Permalink
Modernize remaining uses of 0/NULL instead of nullptr (C++11)
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga committed May 14, 2020
1 parent 5f5f53e commit 1a81678
Show file tree
Hide file tree
Showing 21 changed files with 37 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
Checks: 'clang-diagnostic-*,clang-analyzer-*,-*,modernize-use-default-member-init'
Checks: 'clang-diagnostic-*,clang-analyzer-*,-*,modernize-use-default-member-init,modernize-use-nullptr'
WarningsAsErrors: ''
HeaderFilterRegex: '.*'
AnalyzeTemporaryDtors: false
Expand Down
2 changes: 1 addition & 1 deletion core/callable.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Callable {
return method == StringName() && object == 0;
}
_FORCE_INLINE_ bool is_custom() const {
return method == StringName() && custom != 0;
return method == StringName() && custom != nullptr;
}
_FORCE_INLINE_ bool is_standard() const {
return method != StringName();
Expand Down
2 changes: 1 addition & 1 deletion core/cowdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class CowData {
}

_FORCE_INLINE_ void clear() { resize(0); }
_FORCE_INLINE_ bool empty() const { return _ptr == 0; }
_FORCE_INLINE_ bool empty() const { return _ptr == nullptr; }

_FORCE_INLINE_ void set(int p_index, const T &p_elem) {

Expand Down
8 changes: 4 additions & 4 deletions core/hash_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ class HashMap {
hash_table_power = MIN_HASH_TABLE_POWER;
elements = 0;
for (int i = 0; i < (1 << MIN_HASH_TABLE_POWER); i++)
hash_table[i] = 0;
hash_table[i] = nullptr;
}

void erase_hash_table() {

ERR_FAIL_COND_MSG(elements, "Cannot erase hash table if there are still elements inside.");

memdelete_arr(hash_table);
hash_table = 0;
hash_table = nullptr;
hash_table_power = 0;
elements = 0;
}
Expand Down Expand Up @@ -155,7 +155,7 @@ class HashMap {

for (int i = 0; i < (1 << new_hash_table_power); i++) {

new_hash_table[i] = 0;
new_hash_table[i] = nullptr;
}

if (hash_table) {
Expand Down Expand Up @@ -541,7 +541,7 @@ class HashMap {
memdelete_arr(hash_table);
}

hash_table = 0;
hash_table = nullptr;
hash_table_power = 0;
elements = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion core/io/file_access_buffered.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class FileAccessBuffered : public FileAccess {
int offset;
} cache;

virtual int read_data_block(int p_offset, int p_size, uint8_t *p_dest = 0) const = 0;
virtual int read_data_block(int p_offset, int p_size, uint8_t *p_dest = nullptr) const = 0;

void set_cache_size(int p_size);
int get_cache_size();
Expand Down
12 changes: 6 additions & 6 deletions core/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,30 +182,30 @@ class List {
*/
_FORCE_INLINE_ const Element *front() const {

return _data ? _data->first : 0;
return _data ? _data->first : nullptr;
};

/**
* return an iterator to the beginning of the list.
*/
_FORCE_INLINE_ Element *front() {
return _data ? _data->first : 0;
return _data ? _data->first : nullptr;
};

/**
* return a const iterator to the last member of the list.
*/
_FORCE_INLINE_ const Element *back() const {

return _data ? _data->last : 0;
return _data ? _data->last : nullptr;
};

/**
* return an iterator to the last member of the list.
*/
_FORCE_INLINE_ Element *back() {

return _data ? _data->last : 0;
return _data ? _data->last : nullptr;
};

/**
Expand All @@ -225,7 +225,7 @@ class List {
n->value = (T &)value;

n->prev_ptr = _data->last;
n->next_ptr = 0;
n->next_ptr = nullptr;
n->data = _data;

if (_data->last) {
Expand Down Expand Up @@ -264,7 +264,7 @@ class List {

Element *n = memnew_allocator(Element, A);
n->value = (T &)value;
n->prev_ptr = 0;
n->prev_ptr = nullptr;
n->next_ptr = _data->first;
n->data = _data;

Expand Down
4 changes: 2 additions & 2 deletions core/math/face3.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ class Face3 {
Vector3 get_median_point() const;
Vector3 get_closest_point_to(const Vector3 &p_point) const;

bool intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *p_intersection = 0) const;
bool intersects_segment(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *p_intersection = 0) const;
bool intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *p_intersection = nullptr) const;
bool intersects_segment(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *p_intersection = nullptr) const;

ClockDirection get_clock_dir() const; ///< todo, test if this is returning the proper clockwisity

Expand Down
8 changes: 4 additions & 4 deletions core/math/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class Geometry {
return dP.length(); // Return the closest distance.
}

static inline bool ray_intersects_triangle(const Vector3 &p_from, const Vector3 &p_dir, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2, Vector3 *r_res = 0) {
static inline bool ray_intersects_triangle(const Vector3 &p_from, const Vector3 &p_dir, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2, Vector3 *r_res = nullptr) {
Vector3 e1 = p_v1 - p_v0;
Vector3 e2 = p_v2 - p_v0;
Vector3 h = p_dir.cross(e2);
Expand Down Expand Up @@ -225,7 +225,7 @@ class Geometry {
return false;
}

static inline bool segment_intersects_triangle(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2, Vector3 *r_res = 0) {
static inline bool segment_intersects_triangle(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2, Vector3 *r_res = nullptr) {

Vector3 rel = p_to - p_from;
Vector3 e1 = p_v1 - p_v0;
Expand Down Expand Up @@ -262,7 +262,7 @@ class Geometry {
return false;
}

static inline bool segment_intersects_sphere(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_sphere_pos, real_t p_sphere_radius, Vector3 *r_res = 0, Vector3 *r_norm = 0) {
static inline bool segment_intersects_sphere(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_sphere_pos, real_t p_sphere_radius, Vector3 *r_res = nullptr, Vector3 *r_norm = nullptr) {

Vector3 sphere_pos = p_sphere_pos - p_from;
Vector3 rel = (p_to - p_from);
Expand Down Expand Up @@ -298,7 +298,7 @@ class Geometry {
return true;
}

static inline bool segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, real_t p_height, real_t p_radius, Vector3 *r_res = 0, Vector3 *r_norm = 0) {
static inline bool segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, real_t p_height, real_t p_radius, Vector3 *r_res = nullptr, Vector3 *r_norm = nullptr) {

Vector3 rel = (p_to - p_from);
real_t rel_l = rel.length();
Expand Down
2 changes: 1 addition & 1 deletion core/math/plane.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Plane {

/* intersections */

bool intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r_result = 0) const;
bool intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r_result = nullptr) const;
bool intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *p_intersection) const;
bool intersects_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 *p_intersection) const;

Expand Down
4 changes: 2 additions & 2 deletions core/os/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ template <typename T>
T *memnew_arr_template(size_t p_elements, const char *p_descr = "") {

if (p_elements == 0)
return 0;
return nullptr;
/** overloading operator new[] cannot be done , because it may not return the real allocated address (it may pad the 'element count' before the actual array). Because of that, it must be done by hand. This is the
same strategy used by std::vector, and the Vector class, so it should be safe.*/

size_t len = sizeof(T) * p_elements;
uint64_t *mem = (uint64_t *)Memory::alloc_static(len, true);
T *failptr = 0; //get rid of a warning
T *failptr = nullptr; //get rid of a warning
ERR_FAIL_COND_V(!mem, failptr);
*(mem - 1) = p_elements;

Expand Down
2 changes: 1 addition & 1 deletion core/string_name.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class StringName {
StringName(_Data *p_data) { _data = p_data; }

public:
operator const void *() const { return (_data && (_data->cname || !_data->name.empty())) ? (void *)1 : 0; }
operator const void *() const { return (_data && (_data->cname || !_data->name.empty())) ? (void *)1 : nullptr; }

bool operator==(const String &p_name) const;
bool operator==(const char *p_name) const;
Expand Down
2 changes: 1 addition & 1 deletion editor/shader_globals_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,6 @@ ShaderGlobalsEditor::ShaderGlobalsEditor() {
interface->connect("var_changed", Callable(this, "_changed"));
}
ShaderGlobalsEditor::~ShaderGlobalsEditor() {
inspector->edit(NULL);
inspector->edit(nullptr);
memdelete(interface);
}
2 changes: 1 addition & 1 deletion main/tests/test_shader_lang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ MainLoop *test() {
Set<String> types;
types.insert("spatial");

Error err = sl.compile(code, dt, rm, types, NULL);
Error err = sl.compile(code, dt, rm, types, nullptr);

if (err) {

Expand Down
2 changes: 1 addition & 1 deletion modules/gdscript/gdscript_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
gdfs->state.instance = p_instance;
p_instance->pending_func_states.add(&gdfs->instances_list);
} else {
gdfs->state.instance = NULL;
gdfs->state.instance = nullptr;
}
}
#ifdef DEBUG_ENABLED
Expand Down
2 changes: 1 addition & 1 deletion modules/mono/csharp_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ void CSharpLanguage::get_reserved_words(List<String> *p_words) const {
"when",
"where",
"yield",
0
nullptr
};

const char **w = _reserved_words;
Expand Down
2 changes: 1 addition & 1 deletion modules/mono/editor/godotsharp_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Error get_assembly_dependencies(GDMonoAssembly *p_assembly, const Vector<String>
if (r_assembly_dependencies.has(ref_name))
continue;

GDMonoAssembly *ref_assembly = NULL;
GDMonoAssembly *ref_assembly = nullptr;

{
MonoAssemblyName *ref_aname = mono_assembly_name_new("A"); // We can't allocate an empty MonoAssemblyName, hence "A"
Expand Down
2 changes: 1 addition & 1 deletion modules/websocket/editor_debugger_server_websocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ EditorDebuggerServerWebSocket::~EditorDebuggerServerWebSocket() {
}

EditorDebuggerServer *EditorDebuggerServerWebSocket::create(const String &p_protocol) {
ERR_FAIL_COND_V(p_protocol != "ws://", NULL);
ERR_FAIL_COND_V(p_protocol != "ws://", nullptr);
return memnew(EditorDebuggerServerWebSocket);
}
4 changes: 2 additions & 2 deletions modules/websocket/remote_debugger_peer_websocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ RemoteDebuggerPeerWebSocket::RemoteDebuggerPeerWebSocket(Ref<WebSocketPeer> p_pe
}

RemoteDebuggerPeer *RemoteDebuggerPeerWebSocket::create(const String &p_uri) {
ERR_FAIL_COND_V(!p_uri.begins_with("ws://") && !p_uri.begins_with("wss://"), NULL);
ERR_FAIL_COND_V(!p_uri.begins_with("ws://") && !p_uri.begins_with("wss://"), nullptr);
RemoteDebuggerPeerWebSocket *peer = memnew(RemoteDebuggerPeerWebSocket);
Error err = peer->connect_to_host(p_uri);
if (err != OK) {
memdelete(peer);
return NULL;
return nullptr;
}
return peer;
}
2 changes: 1 addition & 1 deletion scene/gui/tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ class Tree : public Control {

void clear();

TreeItem *create_item(TreeItem *p_parent = 0, int p_idx = -1);
TreeItem *create_item(TreeItem *p_parent = nullptr, int p_idx = -1);
TreeItem *get_root();
TreeItem *get_last_item();

Expand Down
2 changes: 1 addition & 1 deletion scene/main/shader_globals_override.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void ShaderGlobalsOverride::_get_property_list(List<PropertyInfo> *p_list) const
Override o;
o.in_use = false;
Callable::CallError ce;
o.override = Variant::construct(pinfo.type, NULL, 0, ce);
o.override = Variant::construct(pinfo.type, nullptr, 0, ce);
overrides[variables[i]] = o;
}

Expand Down
6 changes: 3 additions & 3 deletions servers/rendering/rasterizer_rd/rasterizer_storage_rd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4896,7 +4896,7 @@ void RasterizerStorageRD::_update_decal_atlas() {
Vector<DecalAtlas::SortItem> itemsv;
itemsv.resize(decal_atlas.textures.size());
int base_size = 8;
const RID *K = NULL;
const RID *K = nullptr;

int idx = 0;
while ((K = decal_atlas.textures.next(K))) {
Expand Down Expand Up @@ -5050,7 +5050,7 @@ void RasterizerStorageRD::_update_decal_atlas() {

RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(mm.fb, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_DROP, RD::FINAL_ACTION_DISCARD, cc);

const RID *K = NULL;
const RID *K = nullptr;
while ((K = decal_atlas.textures.next(K))) {
DecalAtlas::Texture *t = decal_atlas.textures.getptr(*K);
Texture *src_tex = texture_owner.getornull(*K);
Expand Down Expand Up @@ -5459,7 +5459,7 @@ Vector<StringName> RasterizerStorageRD::global_variable_get_list() const {
ERR_FAIL_V_MSG(Vector<StringName>(), "This function should never be used outside the editor, it can severely damage performance.");
}

const StringName *K = NULL;
const StringName *K = nullptr;
Vector<StringName> names;
while ((K = global_variables.variables.next(K))) {
names.push_back(*K);
Expand Down

0 comments on commit 1a81678

Please sign in to comment.