History

[array] split out arrayadd

Noam Preil committed 5 years ago

Commit b0515391 parent ee088482 files · +15 −5Browse files

Showing the changes to array.c (1 of 2 files). Show all

Unified · Split

array.c+14−5
@@ -8,7 +8,6 @@ Object * · 7 unmodified lines
8pdfarray(Pdf *pdf, Stream *s)8pdfarray(Pdf *pdf, Stream *s)
9{9{
10 Object *o, *m;10 Object *o, *m;
11 Object **a;
12 int c, noel;11 int c, noel;
13 12
14 o = calloc(1, sizeof(*o));13 o = calloc(1, sizeof(*o));
@@ -30,13 +29,10 @@ pdfarray(Pdf *pdf, Stream *s) · 15 unmodified lines
30 continue;29 continue;
31 }30 }
32 31
33 if((a = realloc(o->array.e, (o->array.ne+1)*sizeof(Object*))) == nil){32 if(!arrayadd(o, m)){
34 pdfobjfree(m);33 pdfobjfree(m);
35 goto err;34 goto err;
36 }35 }
37
38 o->array.e = a;
39 a[o->array.ne++] = m;
40 }36 }
41 37
42 if(c != ']'){38 if(c != ']'){
@@ -51,6 +47,19 @@ err: · 8 unmodified lines
51 return nil;47 return nil;
52}48}
53 49
50int
51arrayadd(Object *arr, Object *o)
52{
53 Object **a;
54 a = realloc(arr->array.e, (arr->array.ne+1)*sizeof(Object*));
55 if(a == nil)
56 return 0;
57 arr->array.e = a;
58 a[arr->array.ne] = o;
59 arr->array.ne += 1;
60 return 1;
61}
62
54int63int
55arraylen(Object *o)64arraylen(Object *o)
56{65{

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t