Hi,
During the development for AtariST, I found that there
are 2 generic implementations of zcalloc() & zcfree() in
zutil.c and ftgzip.c.
Tracking the CVS history, originally zutil.c had the
implementations, and ftgzip.c didn't have. zutil.c had
3 implementations in it:
A) Intel 8086, (MS-)DOS and Turbo-C implementation
B) Intel 8086, (MS-)DOS and MS-C implementation
C) generic implementation calling system calloc() & free()
The macro MY_ZALLOC was designed to enable C) when A) nor
B) is enabled. Thus, the conditional to enable A) or B)
does not check MY_ZCALLOC. All of them are derived from
original zlib.
On 2002-11-05, another implementation D) was introduced to
ftgzip.c.
D) generic implementation calling FT_ALLOC() & FT_FREE()
At the same time, to avoid the conflict of C) & D),
ftgzip.c defines MY_ZCALLOC before the inclusion of
zutil.c. Differently from other modules, ftgzip.c
includes all files even in multi build, therefore,
now A), B) or D) can be enabled, but C) is never
enabled.
During the development for AtariST, I'm afraid that
the building on Intel 8086 with Turbo-C or MS-C fails,
by following scenario.
* The cpp conditionals in zutil.c to enable A) & B)
does not check MY_ZCALLOC. Their design seems to
assume that MY_ZCALLOC is undefined.
* Thus, on Intel 8086 with Turbo-C or MS-C, A) or B)
is enabled, for first.
* Afterwards, on Intel 8086, ftgzip.c enables D) as
far as the system has no existing zlib.
* As a result, there might be a conflict between A)
and D), or, a conflict between B) and D).
So I have 2 questions:
Q1) the implementation C) in zutil.c is still required?
I think following modification can solve bad scenario
in above.
F1) Remove the implementation C) from zutil.c.
F2) Remove the definition of MY_ZCALLOC from ftgzip.c,
or undefine it before the inclusion of zutils.
Thus, zutil.c defines it when A) or B) is enabled.
F3) If MY_ZALLOC is undefined and no system zlib, D) is
enabled as fallback.
Attached mps-ftgzip_pt1.c is a patch to apply this
modification.
Q2) the comment in D) tells:
/* it is better to use FreeType memory routines instead of raw
'malloc/free' */
It makes me think using A) or B) in FT2 is worse.
I'm not sure if this is true on Intel 8086, but,
I think there are 2 disadvantages to use A) & B).
* Other modules in FT2 cannot use A) & B).
* FT2 memory debugger cannot trace A) & B).
So, I think it is worthful to consider dropping
A) & B) from zutil.c (and use D) always).
Attached mps-ftgzip_pt2.c is a patch to do this,
after mps-ftgzip_pt1.c.
I want to hear the comments, especially from FT2
developers on (MS-)DOS.
Regards,
mpsuzuki
? mps-ftgzip_pt1.diff
Index: src/gzip/ftgzip.c
===================================================================
RCS file: /sources/freetype/freetype2/src/gzip/ftgzip.c,v
retrieving revision 1.25
diff -u -r1.25 ftgzip.c
--- src/gzip/ftgzip.c 13 Jan 2009 17:34:47 -0000 1.25
+++ src/gzip/ftgzip.c 2 Feb 2009 14:12:41 -0000
@@ -54,7 +54,6 @@
/* original ZLib. */
#define NO_DUMMY_DECL
-#define MY_ZCALLOC
#include "zlib.h"
@@ -117,7 +116,8 @@
}
-#ifndef FT_CONFIG_OPTION_SYSTEM_ZLIB
+ /* zutil.c has several system-specific zcalloc */
+#if !defined( FT_CONFIG_OPTION_SYSTEM_ZLIB ) && !defined( MY_ZCALLOC )
local voidpf
zcalloc ( voidpf opaque,
@@ -134,7 +134,7 @@
ft_gzip_free( (FT_Memory)opaque, ptr );
}
-#endif /* !SYSTEM_ZLIB */
+#endif /* !SYSTEM_ZLIB && !MY_ZCALLOC */
/***************************************************************************/
Index: src/gzip/zutil.c
===================================================================
RCS file: /sources/freetype/freetype2/src/gzip/zutil.c,v
retrieving revision 1.3
diff -u -r1.3 zutil.c
--- src/gzip/zutil.c 29 Apr 2006 07:31:16 -0000 1.3
+++ src/gzip/zutil.c 2 Feb 2009 14:12:42 -0000
@@ -152,30 +152,3 @@
}
#endif /* MSC */
-
-
-#ifndef MY_ZCALLOC /* Any system without a special alloc function */
-
-#ifndef STDC
-extern voidp ft_scalloc OF((uInt items, uInt size));
-extern void ft_sfree OF((voidpf ptr));
-#endif
-
-voidpf zcalloc (opaque, items, size)
- voidpf opaque;
- unsigned items;
- unsigned size;
-{
- if (opaque) items += size - size; /* make compiler happy */
- return (voidpf)ft_scalloc(items, size);
-}
-
-void zcfree (opaque, ptr)
- voidpf opaque;
- voidpf ptr;
-{
- ft_sfree(ptr);
- if (opaque) return; /* make compiler happy */
-}
-
-#endif /* MY_ZCALLOC */
diff -u src/gzip/ftgzip.c src/gzip/ftgzip.c
--- src/gzip/ftgzip.c 2 Feb 2009 14:12:41 -0000
+++ src/gzip/ftgzip.c 2 Feb 2009 14:15:44 -0000
@@ -116,8 +116,7 @@
}
- /* zutil.c has several system-specific zcalloc */
-#if !defined( FT_CONFIG_OPTION_SYSTEM_ZLIB ) && !defined( MY_ZCALLOC )
+#ifndef FT_CONFIG_OPTION_SYSTEM_ZLIB
local voidpf
zcalloc ( voidpf opaque,
@@ -134,7 +133,7 @@
ft_gzip_free( (FT_Memory)opaque, ptr );
}
-#endif /* !SYSTEM_ZLIB && !MY_ZCALLOC */
+#endif /* !SYSTEM_ZLIB */
/***************************************************************************/
diff -u src/gzip/zutil.c src/gzip/zutil.c
--- src/gzip/zutil.c 2 Feb 2009 14:12:42 -0000
+++ src/gzip/zutil.c 2 Feb 2009 14:15:44 -0000
@@ -51,104 +50,0 @@
-
-#ifdef __TURBOC__
-#if (defined( __BORLANDC__) || !defined(SMALL_MEDIUM)) && !defined(__32BIT__)
-/* Small and medium model in Turbo C are for now limited to near allocation
- * with reduced MAX_WBITS and MAX_MEM_LEVEL
- */
-# define MY_ZCALLOC
-
-/* Turbo C malloc() does not allow dynamic allocation of 64K bytes
- * and farmalloc(64K) returns a pointer with an offset of 8, so we
- * must fix the pointer. Warning: the pointer must be put back to its
- * original form in order to free it, use zcfree().
- */
-
-#define MAX_PTR 10
-/* 10*64K = 640K */
-
-local int next_ptr = 0;
-
-typedef struct ptr_table_s {
- voidpf org_ptr;
- voidpf new_ptr;
-} ptr_table;
-
-local ptr_table table[MAX_PTR];
-/* This table is used to remember the original form of pointers
- * to large buffers (64K). Such pointers are normalized with a zero offset.
- * Since MSDOS is not a preemptive multitasking OS, this table is not
- * protected from concurrent access. This hack doesn't work anyway on
- * a protected system like OS/2. Use Microsoft C instead.
- */
-
-voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
-{
- voidpf buf = opaque; /* just to make some compilers happy */
- ulg bsize = (ulg)items*size;
-
- /* If we allocate less than 65520 bytes, we assume that farmalloc
- * will return a usable pointer which doesn't have to be normalized.
- */
- if (bsize < 65520L) {
- buf = farmalloc(bsize);
- if (*(ush*)&buf != 0) return buf;
- } else {
- buf = farmalloc(bsize + 16L);
- }
- if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
- table[next_ptr].org_ptr = buf;
-
- /* Normalize the pointer to seg:0 */
- *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
- *(ush*)&buf = 0;
- table[next_ptr++].new_ptr = buf;
- return buf;
-}
-
-void zcfree (voidpf opaque, voidpf ptr)
-{
- int n;
- if (*(ush*)&ptr != 0) { /* object < 64K */
- farfree(ptr);
- return;
- }
- /* Find the original pointer */
- for (n = 0; n < next_ptr; n++) {
- if (ptr != table[n].new_ptr) continue;
-
- farfree(table[n].org_ptr);
- while (++n < next_ptr) {
- table[n-1] = table[n];
- }
- next_ptr--;
- return;
- }
- ptr = opaque; /* just to make some compilers happy */
- Assert(0, "zcfree: ptr not found");
-}
-#endif
-#endif /* __TURBOC__ */
-
-
-#if defined(M_I86) && !defined(__32BIT__)
-/* Microsoft C in 16-bit mode */
-
-# define MY_ZCALLOC
-
-#if (!defined(_MSC_VER) || (_MSC_VER <= 600))
-# define _halloc halloc
-# define _hfree hfree
-#endif
-
-voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
-{
- if (opaque) opaque = 0; /* to make compiler happy */
- return _halloc((long)items, size);
-}
-
-void zcfree (voidpf opaque, voidpf ptr)
-{
- if (opaque) opaque = 0; /* to make compiler happy */
- _hfree(ptr);
-}
-
-#endif /* MSC */
_______________________________________________
Freetype-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/freetype-devel