Skip to content

Commit

Permalink
Fix compatibility with latest Odin master
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarnp committed Apr 30, 2021
1 parent 6b9ba38 commit 5a7e677
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 33 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Tracy profiler bindings/wrapper for the Odin programming language.

## 0. Prerequisites
This assumes you are using the latest nightly build or GitHub master of the Odin compiler. Since Odin is still under development this means these bindings might break in the future. Please create an issue or PR if that happens.
Last verified against: odin version dev-2021-04:5f617c56

## 1. Cloning the sources
```sh
Expand Down
65 changes: 34 additions & 31 deletions allocator.odin
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,46 @@ TrackedAllocator :: proc(
self.backing_allocator = backing_allocator;
self.tracked_allocator = mem.Allocator{
data = self,
procedure = proc(allocator_data : rawptr, mode : mem.Allocator_Mode, size, alignment : int, old_memory : rawptr, old_size : int, flags : u64, location := #caller_location) -> rawptr {
procedure = proc(allocator_data : rawptr, mode : mem.Allocator_Mode, size, alignment : int, old_memory :
rawptr, old_size : int, location := #caller_location) -> ([]byte, mem.Allocator_Error) {
self := cast(^TrackedAllocatorData) allocator_data;
new_memory := self.backing_allocator.procedure(self.backing_allocator.data, mode, size, alignment, old_memory, old_size, flags, location);
switch mode {
case .Alloc:
if new_memory != nil {
if self.callstack_enable {
___tracy_emit_memory_alloc_callstack(new_memory, c.size_t(size), self.callstack_size, 1);
} else {
___tracy_emit_memory_alloc(new_memory, c.size_t(size), 1);
new_memory, error := self.backing_allocator.procedure(self.backing_allocator.data, mode, size, alignment, old_memory, old_size, location);
if error == .None {
switch mode {
case .Alloc:
if new_memory != nil {
if self.callstack_enable {
___tracy_emit_memory_alloc_callstack(raw_data(new_memory), c.size_t(size), self.callstack_size, 1);
} else {
___tracy_emit_memory_alloc(raw_data(new_memory), c.size_t(size), 1);
}
}
}
case .Free:
if old_memory != nil {
___tracy_emit_memory_free(old_memory, 1);
}
case .Free_All:
// NOTE: Free_All not supported by this allocator
case .Resize:
if old_memory != nil {
___tracy_emit_memory_free(old_memory, 1);
}
if new_memory != nil {
if self.callstack_enable {
___tracy_emit_memory_alloc_callstack(new_memory, c.size_t(size), self.callstack_size, 1);
case .Free:
if old_memory != nil {
___tracy_emit_memory_free(old_memory, 1);
}
case .Free_All:
// NOTE: Free_All not supported by this allocator
case .Resize:
if old_memory != nil {
___tracy_emit_memory_free(old_memory, 1);
}
else {
___tracy_emit_memory_alloc(new_memory, c.size_t(size), 1);
if new_memory != nil {
if self.callstack_enable {
___tracy_emit_memory_alloc_callstack(raw_data(new_memory), c.size_t(size), self.callstack_size, 1);
}
else {
___tracy_emit_memory_alloc(raw_data(new_memory), c.size_t(size), 1);
}
}
case .Query_Info:
// TODO
case .Query_Features:
// TODO
}
case .Query_Info:
// TODO
case .Query_Features:
// TODO
}
return new_memory;
}
return new_memory, error;
},
};
return self.tracked_allocator;
}
4 changes: 2 additions & 2 deletions demo/demo.odin
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ main :: proc() {
self = &tracy.TrackedAllocatorData{},
callstack_enable = true,
callstack_size = 5,
backing_allocator = context.allocator
backing_allocator = context.allocator,
);

for {
Expand Down Expand Up @@ -100,4 +100,4 @@ random_sleep :: proc (r : ^rand.Rand) {

random_alloc :: proc (r : ^rand.Rand) -> rawptr {
return mem.alloc(1 + rand.int_max(1024, r));
}
}

0 comments on commit 5a7e677

Please sign in to comment.