Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
9703c6cd
Commit
9703c6cd
authored
Sep 06, 2021
by
Dridi Boukelmoune
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ws: Move common code to a new cache_ws_common.c
parent
9a0a613c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
195 additions
and
268 deletions
+195
-268
Makefile.am
bin/varnishd/Makefile.am
+1
-0
cache.h
bin/varnishd/cache/cache.h
+17
-8
cache_varnishd.h
bin/varnishd/cache/cache_varnishd.h
+4
-2
cache_ws.c
bin/varnishd/cache/cache_ws.c
+2
-140
cache_ws_common.c
bin/varnishd/cache/cache_ws_common.c
+171
-0
cache_ws_emu.c
bin/varnishd/cache/cache_ws_emu.c
+0
-118
No files found.
bin/varnishd/Makefile.am
View file @
9703c6cd
...
@@ -53,6 +53,7 @@ varnishd_SOURCES = \
...
@@ -53,6 +53,7 @@ varnishd_SOURCES = \
cache/cache_vrt_vcl.c
\
cache/cache_vrt_vcl.c
\
cache/cache_vrt_vmod.c
\
cache/cache_vrt_vmod.c
\
cache/cache_wrk.c
\
cache/cache_wrk.c
\
cache/cache_ws_common.c
\
common/common_vsc.c
\
common/common_vsc.c
\
common/common_vsmw.c
\
common/common_vsmw.c
\
hash
/hash_classic.c
\
hash
/hash_classic.c
\
...
...
bin/varnishd/cache/cache.h
View file @
9703c6cd
...
@@ -780,13 +780,10 @@ void WRK_BgThread(pthread_t *thr, const char *name, bgthread_t *func,
...
@@ -780,13 +780,10 @@ void WRK_BgThread(pthread_t *thr, const char *name, bgthread_t *func,
void
*
priv
);
void
*
priv
);
/* cache_ws.c */
/* cache_ws.c */
void
WS_Init
(
struct
ws
*
ws
,
const
char
*
id
,
void
*
space
,
unsigned
len
);
void
WS_Init
(
struct
ws
*
ws
,
const
char
*
id
,
void
*
space
,
unsigned
len
);
unsigned
WS_ReserveSize
(
struct
ws
*
,
unsigned
);
unsigned
WS_ReserveSize
(
struct
ws
*
,
unsigned
);
unsigned
WS_ReserveAll
(
struct
ws
*
);
unsigned
WS_ReserveAll
(
struct
ws
*
);
unsigned
WS_ReserveLumps
(
struct
ws
*
ws
,
size_t
sz
);
void
WS_MarkOverflow
(
struct
ws
*
ws
);
void
WS_Release
(
struct
ws
*
ws
,
unsigned
bytes
);
void
WS_Release
(
struct
ws
*
ws
,
unsigned
bytes
);
void
WS_ReleaseP
(
struct
ws
*
ws
,
const
char
*
ptr
);
void
WS_ReleaseP
(
struct
ws
*
ws
,
const
char
*
ptr
);
void
WS_Assert
(
const
struct
ws
*
ws
);
void
WS_Assert
(
const
struct
ws
*
ws
);
...
@@ -794,14 +791,9 @@ void WS_Reset(struct ws *ws, uintptr_t);
...
@@ -794,14 +791,9 @@ void WS_Reset(struct ws *ws, uintptr_t);
void
*
WS_Alloc
(
struct
ws
*
ws
,
unsigned
bytes
);
void
*
WS_Alloc
(
struct
ws
*
ws
,
unsigned
bytes
);
void
*
WS_Copy
(
struct
ws
*
ws
,
const
void
*
str
,
int
len
);
void
*
WS_Copy
(
struct
ws
*
ws
,
const
void
*
str
,
int
len
);
uintptr_t
WS_Snapshot
(
struct
ws
*
ws
);
uintptr_t
WS_Snapshot
(
struct
ws
*
ws
);
int
WS_Overflowed
(
const
struct
ws
*
ws
);
const
char
*
WS_Printf
(
struct
ws
*
ws
,
const
char
*
fmt
,
...)
v_printflike_
(
2
,
3
);
int
WS_Allocated
(
const
struct
ws
*
ws
,
const
void
*
ptr
,
ssize_t
len
);
int
WS_Allocated
(
const
struct
ws
*
ws
,
const
void
*
ptr
,
ssize_t
len
);
unsigned
WS_Dump
(
const
struct
ws
*
ws
,
char
,
size_t
off
,
void
*
buf
,
size_t
len
);
unsigned
WS_Dump
(
const
struct
ws
*
ws
,
char
,
size_t
off
,
void
*
buf
,
size_t
len
);
void
WS_VSB_new
(
struct
vsb
*
,
struct
ws
*
);
char
*
WS_VSB_finish
(
struct
vsb
*
,
struct
ws
*
,
size_t
*
);
static
inline
void
*
static
inline
void
*
WS_Reservation
(
const
struct
ws
*
ws
)
WS_Reservation
(
const
struct
ws
*
ws
)
{
{
...
@@ -820,6 +812,23 @@ WS_ReservationSize(const struct ws *ws)
...
@@ -820,6 +812,23 @@ WS_ReservationSize(const struct ws *ws)
return
(
ws
->
r
-
ws
->
f
);
return
(
ws
->
r
-
ws
->
f
);
}
}
static
inline
unsigned
WS_ReserveLumps
(
struct
ws
*
ws
,
size_t
sz
)
{
AN
(
sz
);
return
(
WS_ReserveAll
(
ws
)
/
sz
);
}
/* cache_ws_common.c */
void
WS_MarkOverflow
(
struct
ws
*
ws
);
int
WS_Overflowed
(
const
struct
ws
*
ws
);
const
char
*
WS_Printf
(
struct
ws
*
ws
,
const
char
*
fmt
,
...)
v_printflike_
(
2
,
3
);
void
WS_VSB_new
(
struct
vsb
*
,
struct
ws
*
);
char
*
WS_VSB_finish
(
struct
vsb
*
,
struct
ws
*
,
size_t
*
);
/* cache_rfc2616.c */
/* cache_rfc2616.c */
void
RFC2616_Ttl
(
struct
busyobj
*
,
vtim_real
now
,
vtim_real
*
t_origin
,
void
RFC2616_Ttl
(
struct
busyobj
*
,
vtim_real
now
,
vtim_real
*
t_origin
,
float
*
ttl
,
float
*
grace
,
float
*
keep
);
float
*
ttl
,
float
*
grace
,
float
*
keep
);
...
...
bin/varnishd/cache/cache_varnishd.h
View file @
9703c6cd
...
@@ -527,7 +527,6 @@ void WRK_Init(void);
...
@@ -527,7 +527,6 @@ void WRK_Init(void);
void
WRK_AddStat
(
const
struct
worker
*
);
void
WRK_AddStat
(
const
struct
worker
*
);
/* cache_ws.c */
/* cache_ws.c */
void
WS_Id
(
const
struct
ws
*
ws
,
char
*
id
);
void
WS_Panic
(
struct
vsb
*
,
const
struct
ws
*
);
void
WS_Panic
(
struct
vsb
*
,
const
struct
ws
*
);
static
inline
int
static
inline
int
WS_IsReserved
(
const
struct
ws
*
ws
)
WS_IsReserved
(
const
struct
ws
*
ws
)
...
@@ -536,11 +535,14 @@ WS_IsReserved(const struct ws *ws)
...
@@ -536,11 +535,14 @@ WS_IsReserved(const struct ws *ws)
return
(
ws
->
r
!=
NULL
);
return
(
ws
->
r
!=
NULL
);
}
}
void
WS_Rollback
(
struct
ws
*
,
uintptr_t
);
void
*
WS_AtOffset
(
const
struct
ws
*
ws
,
unsigned
off
,
unsigned
len
);
void
*
WS_AtOffset
(
const
struct
ws
*
ws
,
unsigned
off
,
unsigned
len
);
unsigned
WS_ReservationOffset
(
const
struct
ws
*
ws
);
unsigned
WS_ReservationOffset
(
const
struct
ws
*
ws
);
unsigned
WS_ReqPipeline
(
struct
ws
*
,
const
void
*
b
,
const
void
*
e
);
unsigned
WS_ReqPipeline
(
struct
ws
*
,
const
void
*
b
,
const
void
*
e
);
/* cache_ws_common.c */
void
WS_Id
(
const
struct
ws
*
ws
,
char
*
id
);
void
WS_Rollback
(
struct
ws
*
,
uintptr_t
);
/* http1/cache_http1_pipe.c */
/* http1/cache_http1_pipe.c */
void
V1P_Init
(
void
);
void
V1P_Init
(
void
);
...
...
bin/varnishd/cache/cache_ws.c
View file @
9703c6cd
/*-
/*-
* Copyright (c) 2006 Verdens Gang AS
* Copyright (c) 2006 Verdens Gang AS
* Copyright (c) 2006-20
1
1 Varnish Software AS
* Copyright (c) 2006-20
2
1 Varnish Software AS
* All rights reserved.
* All rights reserved.
*
*
* Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
* Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
* Author: Dridi Boukelmoune <dridi.boukelmoune@gmail.com>
*
*
* SPDX-License-Identifier: BSD-2-Clause
* SPDX-License-Identifier: BSD-2-Clause
*
*
...
@@ -34,8 +35,6 @@
...
@@ -34,8 +35,6 @@
#include "cache_varnishd.h"
#include "cache_varnishd.h"
#include <stdio.h>
#define WS_REDZONE_END '\x15'
#define WS_REDZONE_END '\x15'
static
const
uintptr_t
snap_overflowed
=
(
uintptr_t
)
&
snap_overflowed
;
static
const
uintptr_t
snap_overflowed
=
(
uintptr_t
)
&
snap_overflowed
;
...
@@ -100,32 +99,6 @@ WS_Init(struct ws *ws, const char *id, void *space, unsigned len)
...
@@ -100,32 +99,6 @@ WS_Init(struct ws *ws, const char *id, void *space, unsigned len)
WS_Assert
(
ws
);
WS_Assert
(
ws
);
}
}
void
WS_Id
(
const
struct
ws
*
ws
,
char
*
id
)
{
WS_Assert
(
ws
);
AN
(
id
);
memcpy
(
id
,
ws
->
id
,
WS_ID_SIZE
);
id
[
0
]
|=
0x20
;
// cheesy tolower()
}
void
WS_MarkOverflow
(
struct
ws
*
ws
)
{
CHECK_OBJ_NOTNULL
(
ws
,
WS_MAGIC
);
ws
->
id
[
0
]
&=
~
0x20
;
// cheesy toupper()
}
static
void
ws_ClearOverflow
(
struct
ws
*
ws
)
{
CHECK_OBJ_NOTNULL
(
ws
,
WS_MAGIC
);
ws
->
id
[
0
]
|=
0x20
;
// cheesy tolower()
}
/*
/*
* Reset a WS to a cookie from WS_Snapshot
* Reset a WS to a cookie from WS_Snapshot
*
*
...
@@ -156,24 +129,6 @@ WS_Reset(struct ws *ws, uintptr_t pp)
...
@@ -156,24 +129,6 @@ WS_Reset(struct ws *ws, uintptr_t pp)
WS_Assert
(
ws
);
WS_Assert
(
ws
);
}
}
/*
* Reset the WS to a cookie or its start and clears any overflow
*
* for varnishd internal use only
*/
void
WS_Rollback
(
struct
ws
*
ws
,
uintptr_t
pp
)
{
WS_Assert
(
ws
);
if
(
pp
==
0
)
pp
=
(
uintptr_t
)
ws
->
s
;
ws_ClearOverflow
(
ws
);
WS_Reset
(
ws
,
pp
);
}
/*
/*
* Make a reservation and optionally pipeline a memory region that may or
* Make a reservation and optionally pipeline a memory region that may or
* may not originate from the same workspace.
* may not originate from the same workspace.
...
@@ -252,28 +207,6 @@ WS_Copy(struct ws *ws, const void *str, int len)
...
@@ -252,28 +207,6 @@ WS_Copy(struct ws *ws, const void *str, int len)
return
(
r
);
return
(
r
);
}
}
const
char
*
WS_Printf
(
struct
ws
*
ws
,
const
char
*
fmt
,
...)
{
unsigned
u
,
v
;
va_list
ap
;
char
*
p
;
u
=
WS_ReserveAll
(
ws
);
p
=
ws
->
f
;
va_start
(
ap
,
fmt
);
v
=
vsnprintf
(
p
,
u
,
fmt
,
ap
);
va_end
(
ap
);
if
(
v
>=
u
)
{
WS_Release
(
ws
,
0
);
WS_MarkOverflow
(
ws
);
p
=
NULL
;
}
else
{
WS_Release
(
ws
,
v
+
1
);
}
return
(
p
);
}
uintptr_t
uintptr_t
WS_Snapshot
(
struct
ws
*
ws
)
WS_Snapshot
(
struct
ws
*
ws
)
{
{
...
@@ -332,12 +265,6 @@ WS_ReserveSize(struct ws *ws, unsigned bytes)
...
@@ -332,12 +265,6 @@ WS_ReserveSize(struct ws *ws, unsigned bytes)
return
(
bytes
);
return
(
bytes
);
}
}
unsigned
WS_ReserveLumps
(
struct
ws
*
ws
,
size_t
sz
)
{
return
(
WS_ReserveAll
(
ws
)
/
sz
);
}
void
void
WS_Release
(
struct
ws
*
ws
,
unsigned
bytes
)
WS_Release
(
struct
ws
*
ws
,
unsigned
bytes
)
{
{
...
@@ -364,17 +291,6 @@ WS_ReleaseP(struct ws *ws, const char *ptr)
...
@@ -364,17 +291,6 @@ WS_ReleaseP(struct ws *ws, const char *ptr)
WS_Assert
(
ws
);
WS_Assert
(
ws
);
}
}
int
WS_Overflowed
(
const
struct
ws
*
ws
)
{
CHECK_OBJ_NOTNULL
(
ws
,
WS_MAGIC
);
AN
(
ws
->
id
[
0
]);
if
(
ws
->
id
[
0
]
&
0x20
)
// cheesy islower()
return
(
0
);
return
(
1
);
}
void
*
void
*
WS_AtOffset
(
const
struct
ws
*
ws
,
unsigned
off
,
unsigned
len
)
WS_AtOffset
(
const
struct
ws
*
ws
,
unsigned
off
,
unsigned
len
)
{
{
...
@@ -394,60 +310,6 @@ WS_ReservationOffset(const struct ws *ws)
...
@@ -394,60 +310,6 @@ WS_ReservationOffset(const struct ws *ws)
return
(
ws
->
f
-
ws
->
s
);
return
(
ws
->
f
-
ws
->
s
);
}
}
/*---------------------------------------------------------------------
* Build a VSB on a workspace.
* Usage pattern:
*
* struct vsb vsb[1];
* char *p;
*
* WS_VSB_new(vsb, ctx->ws);
* VSB_printf(vsb, "blablabla");
* p = WS_VSB_finish(vsb, ctx->ws, NULL);
* if (p == NULL)
* return (FAILURE);
*/
void
WS_VSB_new
(
struct
vsb
*
vsb
,
struct
ws
*
ws
)
{
unsigned
u
;
static
char
bogus
[
2
];
// Smallest possible vsb
AN
(
vsb
);
WS_Assert
(
ws
);
u
=
WS_ReserveAll
(
ws
);
if
(
WS_Overflowed
(
ws
)
||
u
<
2
)
AN
(
VSB_init
(
vsb
,
bogus
,
sizeof
bogus
));
else
AN
(
VSB_init
(
vsb
,
WS_Reservation
(
ws
),
u
));
}
char
*
WS_VSB_finish
(
struct
vsb
*
vsb
,
struct
ws
*
ws
,
size_t
*
szp
)
{
char
*
p
;
AN
(
vsb
);
WS_Assert
(
ws
);
if
(
!
VSB_finish
(
vsb
))
{
p
=
VSB_data
(
vsb
);
if
(
p
==
ws
->
f
)
{
WS_Release
(
ws
,
VSB_len
(
vsb
)
+
1
);
if
(
szp
!=
NULL
)
*
szp
=
VSB_len
(
vsb
);
VSB_fini
(
vsb
);
return
(
p
);
}
}
WS_MarkOverflow
(
ws
);
VSB_fini
(
vsb
);
WS_Release
(
ws
,
0
);
if
(
szp
)
*
szp
=
0
;
return
(
NULL
);
}
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
unsigned
unsigned
...
...
bin/varnishd/cache/cache_ws_common.c
0 → 100644
View file @
9703c6cd
/*-
* Copyright (c) 2006 Verdens Gang AS
* Copyright (c) 2006-2021 Varnish Software AS
* All rights reserved.
*
* Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
* Author: Dridi Boukelmoune <dridi.boukelmoune@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#include "config.h"
#include <stdio.h>
#include "cache_varnishd.h"
void
WS_Id
(
const
struct
ws
*
ws
,
char
*
id
)
{
WS_Assert
(
ws
);
AN
(
id
);
memcpy
(
id
,
ws
->
id
,
WS_ID_SIZE
);
id
[
0
]
|=
0x20
;
// cheesy tolower()
}
void
WS_MarkOverflow
(
struct
ws
*
ws
)
{
CHECK_OBJ_NOTNULL
(
ws
,
WS_MAGIC
);
ws
->
id
[
0
]
&=
~
0x20
;
// cheesy toupper()
}
static
void
ws_ClearOverflow
(
struct
ws
*
ws
)
{
CHECK_OBJ_NOTNULL
(
ws
,
WS_MAGIC
);
ws
->
id
[
0
]
|=
0x20
;
// cheesy tolower()
}
int
WS_Overflowed
(
const
struct
ws
*
ws
)
{
CHECK_OBJ_NOTNULL
(
ws
,
WS_MAGIC
);
AN
(
ws
->
id
[
0
]);
if
(
ws
->
id
[
0
]
&
0x20
)
// cheesy islower()
return
(
0
);
return
(
1
);
}
/*
* Reset the WS to a cookie or its start and clears any overflow
*
* for varnishd internal use only
*/
void
WS_Rollback
(
struct
ws
*
ws
,
uintptr_t
pp
)
{
WS_Assert
(
ws
);
if
(
pp
==
0
)
pp
=
(
uintptr_t
)
ws
->
s
;
ws_ClearOverflow
(
ws
);
WS_Reset
(
ws
,
pp
);
}
/*--------------------------------------------------------------------*/
const
char
*
WS_Printf
(
struct
ws
*
ws
,
const
char
*
fmt
,
...)
{
unsigned
u
,
v
;
va_list
ap
;
char
*
p
;
u
=
WS_ReserveAll
(
ws
);
p
=
ws
->
f
;
va_start
(
ap
,
fmt
);
v
=
vsnprintf
(
p
,
u
,
fmt
,
ap
);
va_end
(
ap
);
if
(
v
>=
u
)
{
WS_Release
(
ws
,
0
);
WS_MarkOverflow
(
ws
);
p
=
NULL
;
}
else
{
WS_Release
(
ws
,
v
+
1
);
}
return
(
p
);
}
/*---------------------------------------------------------------------
* Build a VSB on a workspace.
* Usage pattern:
*
* struct vsb vsb[1];
* char *p;
*
* WS_VSB_new(vsb, ctx->ws);
* VSB_printf(vsb, "blablabla");
* p = WS_VSB_finish(vsb, ctx->ws, NULL);
* if (p == NULL)
* return (FAILURE);
*/
void
WS_VSB_new
(
struct
vsb
*
vsb
,
struct
ws
*
ws
)
{
unsigned
u
;
static
char
bogus
[
2
];
// Smallest possible vsb
AN
(
vsb
);
WS_Assert
(
ws
);
u
=
WS_ReserveAll
(
ws
);
if
(
WS_Overflowed
(
ws
)
||
u
<
2
)
AN
(
VSB_init
(
vsb
,
bogus
,
sizeof
bogus
));
else
AN
(
VSB_init
(
vsb
,
WS_Reservation
(
ws
),
u
));
}
char
*
WS_VSB_finish
(
struct
vsb
*
vsb
,
struct
ws
*
ws
,
size_t
*
szp
)
{
char
*
p
;
AN
(
vsb
);
WS_Assert
(
ws
);
if
(
!
VSB_finish
(
vsb
))
{
p
=
VSB_data
(
vsb
);
if
(
p
==
ws
->
f
)
{
WS_Release
(
ws
,
VSB_len
(
vsb
)
+
1
);
if
(
szp
!=
NULL
)
*
szp
=
VSB_len
(
vsb
);
VSB_fini
(
vsb
);
return
(
p
);
}
}
WS_MarkOverflow
(
ws
);
VSB_fini
(
vsb
);
WS_Release
(
ws
,
0
);
if
(
szp
)
*
szp
=
0
;
return
(
NULL
);
}
bin/varnishd/cache/cache_ws_emu.c
View file @
9703c6cd
...
@@ -39,7 +39,6 @@
...
@@ -39,7 +39,6 @@
#include "cache_varnishd.h"
#include "cache_varnishd.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
struct
ws_alloc
{
struct
ws_alloc
{
...
@@ -182,32 +181,6 @@ WS_Init(struct ws *ws, const char *id, void *space, unsigned len)
...
@@ -182,32 +181,6 @@ WS_Init(struct ws *ws, const char *id, void *space, unsigned len)
WS_Assert
(
ws
);
WS_Assert
(
ws
);
}
}
void
WS_Id
(
const
struct
ws
*
ws
,
char
*
id
)
{
WS_Assert
(
ws
);
AN
(
id
);
memcpy
(
id
,
ws
->
id
,
WS_ID_SIZE
);
id
[
0
]
|=
0x20
;
// cheesy tolower()
}
void
WS_MarkOverflow
(
struct
ws
*
ws
)
{
CHECK_OBJ_NOTNULL
(
ws
,
WS_MAGIC
);
ws
->
id
[
0
]
&=
~
0x20
;
// cheesy toupper()
}
static
void
ws_ClearOverflow
(
struct
ws
*
ws
)
{
CHECK_OBJ_NOTNULL
(
ws
,
WS_MAGIC
);
ws
->
id
[
0
]
|=
0x20
;
// cheesy tolower()
}
static
void
static
void
ws_alloc_free
(
struct
ws_emu
*
we
,
struct
ws_alloc
**
wap
)
ws_alloc_free
(
struct
ws_emu
*
we
,
struct
ws_alloc
**
wap
)
{
{
...
@@ -248,18 +221,6 @@ WS_Reset(struct ws *ws, uintptr_t pp)
...
@@ -248,18 +221,6 @@ WS_Reset(struct ws *ws, uintptr_t pp)
WS_Assert
(
ws
);
WS_Assert
(
ws
);
}
}
void
WS_Rollback
(
struct
ws
*
ws
,
uintptr_t
pp
)
{
WS_Assert
(
ws
);
if
(
pp
==
0
)
pp
=
(
uintptr_t
)
ws
->
s
;
ws_ClearOverflow
(
ws
);
WS_Reset
(
ws
,
pp
);
}
unsigned
unsigned
WS_ReqPipeline
(
struct
ws
*
ws
,
const
void
*
b
,
const
void
*
e
)
WS_ReqPipeline
(
struct
ws
*
ws
,
const
void
*
b
,
const
void
*
e
)
{
{
...
@@ -375,28 +336,6 @@ WS_Copy(struct ws *ws, const void *str, int len)
...
@@ -375,28 +336,6 @@ WS_Copy(struct ws *ws, const void *str, int len)
return
(
NULL
);
return
(
NULL
);
}
}
const
char
*
WS_Printf
(
struct
ws
*
ws
,
const
char
*
fmt
,
...)
{
unsigned
u
,
v
;
va_list
ap
;
char
*
p
;
u
=
WS_ReserveAll
(
ws
);
p
=
ws
->
f
;
va_start
(
ap
,
fmt
);
v
=
vsnprintf
(
p
,
u
,
fmt
,
ap
);
va_end
(
ap
);
if
(
v
>=
u
)
{
WS_Release
(
ws
,
0
);
WS_MarkOverflow
(
ws
);
p
=
NULL
;
}
else
{
WS_Release
(
ws
,
v
+
1
);
}
return
(
p
);
}
uintptr_t
uintptr_t
WS_Snapshot
(
struct
ws
*
ws
)
WS_Snapshot
(
struct
ws
*
ws
)
{
{
...
@@ -464,12 +403,6 @@ WS_ReserveSize(struct ws *ws, unsigned bytes)
...
@@ -464,12 +403,6 @@ WS_ReserveSize(struct ws *ws, unsigned bytes)
return
(
bytes
);
return
(
bytes
);
}
}
unsigned
WS_ReserveLumps
(
struct
ws
*
ws
,
size_t
sz
)
{
return
(
WS_ReserveAll
(
ws
)
/
sz
);
}
static
void
static
void
ws_release
(
struct
ws
*
ws
,
unsigned
bytes
)
ws_release
(
struct
ws
*
ws
,
unsigned
bytes
)
{
{
...
@@ -520,17 +453,6 @@ WS_ReleaseP(struct ws *ws, const char *ptr)
...
@@ -520,17 +453,6 @@ WS_ReleaseP(struct ws *ws, const char *ptr)
DSL
(
DBG_WORKSPACE
,
0
,
"WS_ReleaseP(%p, %p (%u))"
,
ws
,
ptr
,
l
);
DSL
(
DBG_WORKSPACE
,
0
,
"WS_ReleaseP(%p, %p (%u))"
,
ws
,
ptr
,
l
);
}
}
int
WS_Overflowed
(
const
struct
ws
*
ws
)
{
CHECK_OBJ_NOTNULL
(
ws
,
WS_MAGIC
);
AN
(
ws
->
id
[
0
]);
if
(
ws
->
id
[
0
]
&
0x20
)
// cheesy islower()
return
(
0
);
return
(
1
);
}
void
*
void
*
WS_AtOffset
(
const
struct
ws
*
ws
,
unsigned
off
,
unsigned
len
)
WS_AtOffset
(
const
struct
ws
*
ws
,
unsigned
off
,
unsigned
len
)
{
{
...
@@ -566,46 +488,6 @@ WS_ReservationOffset(const struct ws *ws)
...
@@ -566,46 +488,6 @@ WS_ReservationOffset(const struct ws *ws)
return
(
wa
->
off
);
return
(
wa
->
off
);
}
}
void
WS_VSB_new
(
struct
vsb
*
vsb
,
struct
ws
*
ws
)
{
unsigned
u
;
static
char
bogus
[
2
];
// Smallest possible vsb
AN
(
vsb
);
WS_Assert
(
ws
);
u
=
WS_ReserveAll
(
ws
);
if
(
WS_Overflowed
(
ws
)
||
u
<
2
)
AN
(
VSB_init
(
vsb
,
bogus
,
sizeof
bogus
));
else
AN
(
VSB_init
(
vsb
,
WS_Reservation
(
ws
),
u
));
}
char
*
WS_VSB_finish
(
struct
vsb
*
vsb
,
struct
ws
*
ws
,
size_t
*
szp
)
{
char
*
p
;
AN
(
vsb
);
WS_Assert
(
ws
);
if
(
!
VSB_finish
(
vsb
))
{
p
=
VSB_data
(
vsb
);
if
(
p
==
ws
->
f
)
{
WS_Release
(
ws
,
VSB_len
(
vsb
)
+
1
);
if
(
szp
!=
NULL
)
*
szp
=
VSB_len
(
vsb
);
VSB_fini
(
vsb
);
return
(
p
);
}
}
WS_MarkOverflow
(
ws
);
VSB_fini
(
vsb
);
WS_Release
(
ws
,
0
);
if
(
szp
)
*
szp
=
0
;
return
(
NULL
);
}
unsigned
unsigned
WS_Dump
(
const
struct
ws
*
ws
,
char
where
,
size_t
off
,
void
*
buf
,
size_t
len
)
WS_Dump
(
const
struct
ws
*
ws
,
char
where
,
size_t
off
,
void
*
buf
,
size_t
len
)
{
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment