Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
d3416dfe
Commit
d3416dfe
authored
9 years ago
by
Vicent Marti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pool: Dot not assume mallocs are zeroed out
parent
66eb7660
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
24 deletions
+23
-24
src/commit_list.c
+1
-1
src/merge.c
+4
-4
src/pool.c
+17
-7
src/pool.h
+1
-12
No files found.
src/commit_list.c
View file @
d3416dfe
...
...
@@ -47,7 +47,7 @@ git_commit_list *git_commit_list_insert_by_date(git_commit_list_node *item, git_
git_commit_list_node
*
git_commit_list_alloc_node
(
git_revwalk
*
walk
)
{
return
(
git_commit_list_node
*
)
git_pool_malloc
(
&
walk
->
commit_pool
,
COMMIT_ALLOC
);
return
(
git_commit_list_node
*
)
git_pool_malloc
z
(
&
walk
->
commit_pool
,
1
);
}
static
int
commit_error
(
git_commit_list_node
*
commit
,
const
char
*
msg
)
...
...
This diff is collapsed.
Click to expand it.
src/merge.c
View file @
d3416dfe
...
...
@@ -626,7 +626,7 @@ static int merge_conflict_resolve_one_renamed(
git_oid__cmp
(
&
conflict
->
our_entry
.
id
,
&
conflict
->
their_entry
.
id
)
!=
0
)
return
0
;
if
((
merged
=
git_pool_malloc
(
&
diff_list
->
pool
,
sizeof
(
git_index_entry
)))
==
NULL
)
if
((
merged
=
git_pool_malloc
z
(
&
diff_list
->
pool
,
sizeof
(
git_index_entry
)))
==
NULL
)
return
-
1
;
if
(
ours_changed
)
...
...
@@ -711,7 +711,7 @@ static int merge_conflict_resolve_automerge(
(
error
=
git_odb_write
(
&
automerge_oid
,
odb
,
result
.
ptr
,
result
.
len
,
GIT_OBJ_BLOB
))
<
0
)
goto
done
;
if
((
index_entry
=
git_pool_malloc
(
&
diff_list
->
pool
,
sizeof
(
git_index_entry
)))
==
NULL
)
if
((
index_entry
=
git_pool_malloc
z
(
&
diff_list
->
pool
,
sizeof
(
git_index_entry
)))
==
NULL
)
GITERR_CHECK_ALLOC
(
index_entry
);
index_entry
->
path
=
git_pool_strdup
(
&
diff_list
->
pool
,
result
.
path
);
...
...
@@ -1342,7 +1342,7 @@ static git_merge_diff *merge_diff_from_index_entries(
git_merge_diff
*
conflict
;
git_pool
*
pool
=
&
diff_list
->
pool
;
if
((
conflict
=
git_pool_malloc
(
pool
,
sizeof
(
git_merge_diff
)))
==
NULL
)
if
((
conflict
=
git_pool_malloc
z
(
pool
,
sizeof
(
git_merge_diff
)))
==
NULL
)
return
NULL
;
if
(
index_entry_dup_pool
(
&
conflict
->
ancestor_entry
,
pool
,
entries
[
TREE_IDX_ANCESTOR
])
<
0
||
...
...
@@ -1383,7 +1383,7 @@ static int merge_diff_list_insert_unmodified(
int
error
=
0
;
git_index_entry
*
entry
;
entry
=
git_pool_malloc
(
&
diff_list
->
pool
,
sizeof
(
git_index_entry
));
entry
=
git_pool_malloc
z
(
&
diff_list
->
pool
,
sizeof
(
git_index_entry
));
GITERR_CHECK_ALLOC
(
entry
);
if
((
error
=
index_entry_dup_pool
(
entry
,
&
diff_list
->
pool
,
tree_items
[
0
]))
>=
0
)
...
...
This diff is collapsed.
Click to expand it.
src/pool.c
View file @
d3416dfe
...
...
@@ -51,7 +51,6 @@ void git_pool_clear(git_pool *pool)
}
pool
->
pages
=
NULL
;
pool
->
items
=
0
;
}
void
git_pool_swap
(
git_pool
*
a
,
git_pool
*
b
)
...
...
@@ -73,7 +72,7 @@ static void *pool_alloc_page(git_pool *pool, uint32_t size)
size_t
alloc_size
;
if
(
GIT_ADD_SIZET_OVERFLOW
(
&
alloc_size
,
new_page_size
,
sizeof
(
git_pool_page
))
||
!
(
page
=
git__
calloc
(
1
,
alloc_size
)))
!
(
page
=
git__
malloc
(
alloc_size
)))
return
NULL
;
page
->
size
=
new_page_size
;
...
...
@@ -81,15 +80,12 @@ static void *pool_alloc_page(git_pool *pool, uint32_t size)
page
->
next
=
pool
->
pages
;
pool
->
pages
=
page
;
pool
->
items
++
;
return
page
->
data
;
}
void
*
git_pool_malloc
(
git_pool
*
pool
,
uint32_t
items
)
static
void
*
pool_alloc
(
git_pool
*
pool
,
uint32_t
size
)
{
const
uint32_t
size
=
items
*
pool
->
item_size
;
git_pool_page
*
page
=
pool
->
pages
;
void
*
ptr
=
NULL
;
...
...
@@ -98,11 +94,25 @@ void *git_pool_malloc(git_pool *pool, uint32_t items)
ptr
=
&
page
->
data
[
page
->
size
-
page
->
avail
];
page
->
avail
-=
size
;
pool
->
items
++
;
return
ptr
;
}
void
*
git_pool_malloc
(
git_pool
*
pool
,
uint32_t
items
)
{
const
uint32_t
size
=
items
*
pool
->
item_size
;
return
pool_alloc
(
pool
,
size
);
}
void
*
git_pool_mallocz
(
git_pool
*
pool
,
uint32_t
items
)
{
const
uint32_t
size
=
items
*
pool
->
item_size
;
void
*
ptr
=
pool_alloc
(
pool
,
size
);
if
(
ptr
)
memset
(
ptr
,
0x0
,
size
);
return
ptr
;
}
char
*
git_pool_strndup
(
git_pool
*
pool
,
const
char
*
str
,
size_t
n
)
{
char
*
ptr
=
NULL
;
...
...
This diff is collapsed.
Click to expand it.
src/pool.h
View file @
d3416dfe
...
...
@@ -31,7 +31,6 @@ typedef struct {
git_pool_page
*
pages
;
/* pages with space left */
uint32_t
item_size
;
/* size of single alloc unit in bytes */
uint32_t
page_size
;
/* size of page in bytes */
uint32_t
items
;
}
git_pool
;
/**
...
...
@@ -66,17 +65,7 @@ extern void git_pool_swap(git_pool *a, git_pool *b);
* Allocate space for one or more items from a pool.
*/
extern
void
*
git_pool_malloc
(
git_pool
*
pool
,
uint32_t
items
);
/**
* Allocate space and zero it out.
*/
GIT_INLINE
(
void
*
)
git_pool_mallocz
(
git_pool
*
pool
,
uint32_t
items
)
{
void
*
ptr
=
git_pool_malloc
(
pool
,
items
);
if
(
ptr
)
memset
(
ptr
,
0
,
(
size_t
)
items
*
(
size_t
)
pool
->
item_size
);
return
ptr
;
}
extern
void
*
git_pool_mallocz
(
git_pool
*
pool
,
uint32_t
items
);
/**
* Allocate space and duplicate string data into it.
...
...
This diff is collapsed.
Click to expand it.
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