save the library (make it work on latest zig)
This commit is contained in:
parent
b14ed1f61e
commit
c9b3166ace
@ -16,10 +16,6 @@ pub fn build(b: *std.Build) void {
|
||||
|
||||
const zlib = b.dependency("zlib", .{});
|
||||
|
||||
const deque = b.dependency("zig-deque", .{
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
|
||||
const dzig = b.addModule("discord.zig", .{
|
||||
.root_source_file = b.path("src/discord.zig"),
|
||||
@ -28,7 +24,6 @@ pub fn build(b: *std.Build) void {
|
||||
|
||||
dzig.addImport("ws", websocket.module("websocket"));
|
||||
dzig.addImport("zlib", zlib.module("zlib"));
|
||||
dzig.addImport("deque", deque.module("zig-deque"));
|
||||
|
||||
const marin = b.addExecutable(.{
|
||||
.name = "marin",
|
||||
@ -41,7 +36,6 @@ pub fn build(b: *std.Build) void {
|
||||
marin.root_module.addImport("discord", dzig);
|
||||
marin.root_module.addImport("ws", websocket.module("websocket"));
|
||||
marin.root_module.addImport("zlib", zlib.module("zlib"));
|
||||
marin.root_module.addImport("deque", deque.module("zig-deque"));
|
||||
|
||||
//b.installArtifact(marin);
|
||||
|
||||
@ -61,7 +55,6 @@ pub fn build(b: *std.Build) void {
|
||||
|
||||
lib.root_module.addImport("ws", websocket.module("websocket"));
|
||||
lib.root_module.addImport("zlib", zlib.module("zlib"));
|
||||
lib.root_module.addImport("deque", deque.module("zig-deque"));
|
||||
|
||||
// docs
|
||||
const docs_step = b.step("docs", "Generate documentation");
|
||||
|
@ -6,7 +6,8 @@
|
||||
//
|
||||
// It is redundant to include "zig" in this name because it is already
|
||||
// within the Zig package namespace.
|
||||
.name = "discord.zig",
|
||||
.name = .discordzig,
|
||||
.fingerprint = 0xa3bc9c6f53658b29,
|
||||
|
||||
// This is a [Semantic Version](https://semver.org/).
|
||||
// In a future version of Zig it will be used for package deduplication.
|
||||
@ -23,17 +24,13 @@
|
||||
// Once all dependencies are fetched, `zig build` no longer requires
|
||||
// internet connectivity.
|
||||
.dependencies = .{
|
||||
.@"zig-deque" = .{
|
||||
.url = "https://github.com/magurotuna/zig-deque/archive/refs/heads/main.zip",
|
||||
.hash = "1220d1bedf7d5cfc7475842b3d4e8f03f1308be2e724a036677cceb5c4db13c3da3d",
|
||||
},
|
||||
.zlib = .{
|
||||
.url = "https://github.com/yuzudev/zig-zlib/archive/refs/heads/main.zip",
|
||||
.hash = "1220cd041e8d04f1da9d6f46d0438f4e6809b113ba3454fffdaae96b59d2b35a6b2b",
|
||||
.hash = "zlib-0.1.0-AAAAAKm6QADNBB6NBPHanW9G0EOPTmgJsRO6NFT__arp",
|
||||
},
|
||||
.websocket = .{
|
||||
.url = "https://github.com/yuzudev/websocket.zig/archive/refs/heads/master.zip",
|
||||
.hash = "12207c03624f9f5a1c444bde3d484a9b1e927a902067fded98364b714de412d318e0",
|
||||
.url = "https://github.com/karlseguin/websocket.zig/archive/refs/heads/master.zip",
|
||||
.hash = "websocket-0.1.0-ZPISdYBIAwB1yO6AFDHRHLaZSmpdh4Bz4dCmaQUqNNWh"
|
||||
},
|
||||
},
|
||||
.paths = .{
|
||||
|
@ -16,7 +16,6 @@
|
||||
|
||||
const std = @import("std");
|
||||
const mem = std.mem;
|
||||
const Deque = @import("deque").Deque;
|
||||
const builtin = @import("builtin");
|
||||
const Types = @import("./structures/types.zig");
|
||||
|
||||
@ -104,7 +103,13 @@ pub fn ConnectQueue(comptime T: type) type {
|
||||
shard: T,
|
||||
};
|
||||
|
||||
dequeue: Deque(RequestWithShard),
|
||||
// ignore this function
|
||||
// so it becomes a regular dequeue
|
||||
fn eq(_: void, _: RequestWithShard, _: RequestWithShard) std.math.Order {
|
||||
return std.math.Order.eq;
|
||||
}
|
||||
|
||||
dequeue: std.PriorityDequeue(RequestWithShard, void, eq),
|
||||
allocator: mem.Allocator,
|
||||
remaining: usize,
|
||||
interval_time: u64 = 5000,
|
||||
@ -114,7 +119,7 @@ pub fn ConnectQueue(comptime T: type) type {
|
||||
pub fn init(allocator: mem.Allocator, concurrency: usize, interval_time: u64) !ConnectQueue(T) {
|
||||
return .{
|
||||
.allocator = allocator,
|
||||
.dequeue = try Deque(RequestWithShard).init(allocator),
|
||||
.dequeue = std.PriorityDequeue(RequestWithShard, void, eq).init(allocator, {}),
|
||||
.remaining = concurrency,
|
||||
.interval_time = interval_time,
|
||||
.concurrency = concurrency,
|
||||
@ -127,7 +132,7 @@ pub fn ConnectQueue(comptime T: type) type {
|
||||
|
||||
pub fn push(self: *ConnectQueue(T), req: RequestWithShard) !void {
|
||||
if (self.remaining == 0) {
|
||||
return self.dequeue.pushBack(req);
|
||||
return self.dequeue.add(req);
|
||||
}
|
||||
self.remaining -= 1;
|
||||
|
||||
@ -136,7 +141,7 @@ pub fn ConnectQueue(comptime T: type) type {
|
||||
self.running = true;
|
||||
}
|
||||
|
||||
if (self.dequeue.len() < self.concurrency) {
|
||||
if (self.dequeue.count() < self.concurrency) {
|
||||
// perhaps store this?
|
||||
const ptr = try self.allocator.create(RequestWithShard);
|
||||
ptr.* = req;
|
||||
@ -144,15 +149,15 @@ pub fn ConnectQueue(comptime T: type) type {
|
||||
return;
|
||||
}
|
||||
|
||||
return self.dequeue.pushBack(req);
|
||||
return self.dequeue.add(req);
|
||||
}
|
||||
|
||||
fn startInterval(self: *ConnectQueue(T)) !void {
|
||||
while (self.running) {
|
||||
std.Thread.sleep(std.time.ns_per_ms * (self.interval_time / self.concurrency));
|
||||
const req: ?RequestWithShard = self.dequeue.popFront();
|
||||
const req: ?RequestWithShard = self.dequeue.removeMin(); // pop front
|
||||
|
||||
while (self.dequeue.len() == 0 and req == null) {}
|
||||
while (self.dequeue.count() == 0 and req == null) {}
|
||||
|
||||
if (req) |r| {
|
||||
const ptr = try self.allocator.create(RequestWithShard);
|
||||
@ -165,7 +170,7 @@ pub fn ConnectQueue(comptime T: type) type {
|
||||
self.remaining += 1;
|
||||
}
|
||||
|
||||
if (self.dequeue.len() == 0) {
|
||||
if (self.dequeue.count() == 0) {
|
||||
self.running = false;
|
||||
}
|
||||
}
|
||||
|
10
src/json.zig
10
src/json.zig
@ -884,7 +884,7 @@ pub const BailingAllocator = struct {
|
||||
fn bail(self: *BailingAllocator) void {
|
||||
for (0..self.responsibilities.len) |i| {
|
||||
const memory = self.responsibilities.get(i);
|
||||
self.child_allocator.rawFree(memory.ptr[0..memory.len], memory.ptr_align, 0);
|
||||
self.child_allocator.rawFree(memory.ptr[0..memory.len], .fromByteUnits(memory.ptr_align), 0);
|
||||
}
|
||||
self.responsibilities.deinit(self.child_allocator);
|
||||
}
|
||||
@ -1132,13 +1132,13 @@ pub fn parseInto(comptime T: type, allocator: mem.Allocator, value: JsonType) Er
|
||||
}
|
||||
},
|
||||
.pointer => |ptrInfo| switch (ptrInfo.size) {
|
||||
.One => {
|
||||
.one => {
|
||||
// we simply allocate the type and return an address instead of just returning the type
|
||||
const r: *ptrInfo.child = try allocator.create(ptrInfo.child);
|
||||
r.* = try parseInto(ptrInfo.child, allocator, value);
|
||||
return r;
|
||||
},
|
||||
.Slice => switch (value) {
|
||||
.slice => switch (value) {
|
||||
.array => |array| {
|
||||
var arraylist: std.ArrayList(ptrInfo.child) = .init(allocator);
|
||||
try arraylist.ensureUnusedCapacity(array.len);
|
||||
@ -1146,7 +1146,7 @@ pub fn parseInto(comptime T: type, allocator: mem.Allocator, value: JsonType) Er
|
||||
const item = try parseInto(ptrInfo.child, allocator, jsonval);
|
||||
arraylist.appendAssumeCapacity(item);
|
||||
}
|
||||
if (ptrInfo.sentinel) |some| {
|
||||
if (ptrInfo.sentinel()) |some| {
|
||||
const sentinel = @as(*align(1) const ptrInfo.child, @ptrCast(some)).*;
|
||||
return try arraylist.toOwnedSliceSentinel(sentinel);
|
||||
}
|
||||
@ -1160,7 +1160,7 @@ pub fn parseInto(comptime T: type, allocator: mem.Allocator, value: JsonType) Er
|
||||
for (string) |char|
|
||||
arraylist.appendAssumeCapacity(char);
|
||||
|
||||
if (ptrInfo.sentinel) |some| {
|
||||
if (ptrInfo.sentinel_ptr) |some| {
|
||||
const sentinel = @as(*align(1) const ptrInfo.child, @ptrCast(some)).*;
|
||||
return try arraylist.toOwnedSliceSentinel(sentinel);
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ pub fn Partial(comptime T: type) type {
|
||||
const aligned_ptr: *align(field.alignment) const anyopaque = @alignCast(@ptrCast(&default_value));
|
||||
const optional_field: [1]std.builtin.Type.StructField = [_]std.builtin.Type.StructField{.{
|
||||
.alignment = field.alignment,
|
||||
.default_value = aligned_ptr,
|
||||
.default_value_ptr = aligned_ptr,
|
||||
.is_comptime = false,
|
||||
.name = field.name,
|
||||
.type = optional_type,
|
||||
|
Loading…
x
Reference in New Issue
Block a user