Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
c3908a7f
Commit
c3908a7f
authored
May 11, 2006
by
osku
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add mem_heap_printf() and mem_heap_cat().
parent
896e890f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
193 additions
and
0 deletions
+193
-0
include/mem0mem.h
include/mem0mem.h
+27
-0
mem/mem0mem.c
mem/mem0mem.c
+166
-0
No files found.
include/mem0mem.h
View file @
c3908a7f
...
...
@@ -333,6 +333,33 @@ mem_heap_dup(
const
void
*
data
,
/* in: data to be copied */
ulint
len
);
/* in: length of data, in bytes */
/**************************************************************************
Concatenate two memory blocks and return the result, using a memory heap. */
void
*
mem_heap_cat
(
/*=========*/
/* out, own: the result */
mem_heap_t
*
heap
,
/* in: memory heap where result is allocated */
const
void
*
b1
,
/* in: block 1 */
ulint
len1
,
/* in: length of b1, in bytes */
const
void
*
b2
,
/* in: block 2 */
ulint
len2
);
/* in: length of b2, in bytes */
/********************************************************************
A simple (s)printf replacement that dynamically allocates the space for the
formatted string from the given heap. This supports a very limited set of
the printf syntax: types 's' and 'u' and length modifier 'l' (which is
required for the 'u' type). */
char
*
mem_heap_printf
(
/*============*/
/* out: heap-allocated formatted string */
mem_heap_t
*
heap
,
/* in: memory heap */
const
char
*
format
,
/* in: format string */
...)
__attribute__
((
format
(
printf
,
2
,
3
)));
#ifdef MEM_PERIODIC_CHECK
/**********************************************************************
Goes through the list of all allocated mem blocks, checks their magic
...
...
mem/mem0mem.c
View file @
c3908a7f
...
...
@@ -17,6 +17,7 @@ Created 6/9/1994 Heikki Tuuri
#include "btr0sea.h"
#include "srv0srv.h"
#include "mem0dbg.c"
#include <stdarg.h>
/*
THE MEMORY MANAGEMENT
...
...
@@ -127,6 +128,27 @@ mem_heap_dup(
return
(
memcpy
(
mem_heap_alloc
(
heap
,
len
),
data
,
len
));
}
/**************************************************************************
Concatenate two memory blocks and return the result, using a memory heap. */
void
*
mem_heap_cat
(
/*=========*/
/* out, own: the result */
mem_heap_t
*
heap
,
/* in: memory heap where result is allocated */
const
void
*
b1
,
/* in: block 1 */
ulint
len1
,
/* in: length of b1, in bytes */
const
void
*
b2
,
/* in: block 2 */
ulint
len2
)
/* in: length of b2, in bytes */
{
void
*
res
=
mem_heap_alloc
(
heap
,
len1
+
len2
);
memcpy
(
res
,
b1
,
len1
);
memcpy
(
res
+
len1
,
b2
,
len2
);
return
(
res
);
}
/**************************************************************************
Concatenate two strings and return the result, using a memory heap. */
...
...
@@ -152,6 +174,150 @@ mem_heap_strcat(
return
(
s
);
}
/********************************************************************
Helper function for mem_heap_printf. */
static
ulint
mem_heap_printf_low
(
/*================*/
/* out: length of formatted string,
including terminating NUL */
char
*
buf
,
/* in/out: buffer to store formatted string
in, or NULL to just calculate length */
const
char
*
format
,
/* in: format string */
va_list
ap
)
/* in: arguments */
{
ulint
len
=
0
;
while
(
*
format
)
{
/* Does this format specifier have the 'l' length modifier. */
ibool
is_long
=
FALSE
;
/* Length of one parameter. */
size_t
plen
;
if
(
*
format
++
!=
'%'
)
{
/* Non-format character. */
len
++
;
if
(
buf
)
{
*
buf
++
=
*
(
format
-
1
);
}
continue
;
}
if
(
*
format
==
'l'
)
{
is_long
=
TRUE
;
format
++
;
}
switch
(
*
format
++
)
{
case
's'
:
/* string */
{
char
*
s
=
va_arg
(
ap
,
char
*
);
/* "%ls" is a non-sensical format specifier. */
ut_a
(
!
is_long
);
plen
=
strlen
(
s
);
len
+=
plen
;
if
(
buf
)
{
memcpy
(
buf
,
s
,
plen
);
buf
+=
plen
;
}
}
break
;
case
'u'
:
/* unsigned int */
{
char
tmp
[
32
];
unsigned
long
val
;
/* We only support 'long' values for now. */
ut_a
(
is_long
);
val
=
va_arg
(
ap
,
unsigned
long
);
plen
=
sprintf
(
tmp
,
"%lu"
,
val
);
len
+=
plen
;
if
(
buf
)
{
memcpy
(
buf
,
tmp
,
plen
);
buf
+=
plen
;
}
}
break
;
case
'%'
:
/* "%l%" is a non-sensical format specifier. */
ut_a
(
!
is_long
);
len
++
;
if
(
buf
)
{
*
buf
++
=
'%'
;
}
break
;
default:
ut_error
;
}
}
/* For the NUL character. */
len
++
;
if
(
buf
)
{
*
buf
=
'\0'
;
}
return
(
len
);
}
/********************************************************************
A simple (s)printf replacement that dynamically allocates the space for the
formatted string from the given heap. This supports a very limited set of
the printf syntax: types 's' and 'u' and length modifier 'l' (which is
required for the 'u' type). */
char
*
mem_heap_printf
(
/*============*/
/* out: heap-allocated formatted string */
mem_heap_t
*
heap
,
/* in: memory heap */
const
char
*
format
,
/* in: format string */
...)
{
va_list
ap
;
char
*
str
;
ulint
len
;
/* Calculate length of string */
len
=
0
;
va_start
(
ap
,
format
);
len
=
mem_heap_printf_low
(
NULL
,
format
,
ap
);
va_end
(
ap
);
/* Now create it for real. */
str
=
mem_heap_alloc
(
heap
,
len
);
va_start
(
ap
,
format
);
mem_heap_printf_low
(
str
,
format
,
ap
);
va_end
(
ap
);
return
(
str
);
}
/*******************************************************************
Creates a memory heap block where data can be allocated. */
...
...
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