This is the mail archive of the mailing list for the newlib project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH]Introducing small foot-print implementation for non-wide-char formatted IO


This is the second try to merge our work of formatted IO for small systems
originated from Newlib-nano library, in project "GNU Tools for ARM Embedded
Processors".  For the first time try, please refer to archived message at:

Since Newlib-nano in our project has been adopted/verified by many ARM
embedded developers and is relatively stable as far as I can see, here I am
trying again to upstream it.  In this patch I rebased/refactored code
against the latest trunk.  I also introduced a new configuration option
"--enable-newlib-nano-formatted-io" to control this small foot-print
implementation of formatted IO.  The new option can be used just like other
code size saving ones, and there is some straightforward description I added
for it in newlib/README, which is quoted here:

+     NEWLIB has a special implementation for formatted IO functions, it has
+     below features:
+      1) It only supports C89 standard and would never include other
+      2) It removes direct dependency on floating-point IO handling code.
+	 Programs that need to handle floating-point IO must now explicitly
+	 request the feature by providing options "-u _printf_float" or
+	 "-u _scanf_float" at linking command line.
+      3) It removes now redundant integer-only implementation of the
+	 printf/scanf family of routines (iprintf/iscanf, etc.).  These
+	 functions now alias the standard routines.  This avoids the risk
+	 of getting duplicated functionality when these operations are
+	 needed.  The affected functions are:
+	  diprintf vdiprintf
+	  siprintf fiprintf iprintf sniprintf asiprintf asniprintf
+	  siscanf fiscanf iscanf
+	  viprintf vfiprintf vsiprintf vsniprintf vasiprintf vasniprintf
+	  viscanf vfiscanf vsiscanf
+	  _diprintf_r _vdiprintf_r
+	  _siprintf_r _fiprintf_r _iprintf_r _sniprintf_r _asiprintf_r
+	  _asniprintf_r
+	  _siscanf_r _fiscanf_r _iscanf_r
+	  _viprintf_r _vfiprintf_r _vsiprintf_r _asniprintf_r _vasiprintf_r
+	  _vasniprintf_r
+	  _viscanf_r _vfiscanf_r _vsiscanf_r
+     With this implementation, the following newlib configuration options
+     are no longer available for non-wide-char formatted IO:
+       enable-newlib-io-pos-args
+       enable-newlib-io-c99-formats
+       enable-newlib-io-long-long
+       enable-newlib-io-long-double
+     Additionally, "enable-newlib-io-float" is no longer needed because of
+     changes to the handling of floating-point formatted IO.
+     This option enables the nano-formatted-IO implementation, and should
+     be used for small systems with very limited memory.
+     Disabled by default.

I know there are concerns about maintenance burden of keeping two
implementations of formatted IO, which I hope can be addressed by below
1) The two implementations are totally independent to each other, in other
words, there is no shared code which need to be dealt with in future
2) The nano version of implementation is designed for small systems with
very limited resources only, so it is restricted to C89 standard.  I think
it's reasonable to setup a rule after merging that we will never include
features outside of C89.
3) The nano version of implementation is quite modularized, with most codes
added by several new files.   Other than that, it's just like other code
size saving options.
4) The nano version of implementation has been widely used since it was
first introduced in 2012.  Because it's very simple, there is not many
issues reported so far, and I don't expect there will be many issues after

With these considerations, I guess it's not inappropriate for it to be
included in Newlib.  So any comments?

BTW, I compressed the patch since it exceeds size limitation of newlib
mailing list.


2014-06-20  Bin Cheng  <>

	* README (--enable-newlib-nano-formatted-io): Describe.
	* acconfig.h (_NANO_FORMATTED_IO): Undef.
	* newlib.hin (_NANO_FORMATTED_IO): Undef.
	* (--enable-newlib-nano-formatted-io): New option.
	* configure: Regenerated.
	* libc/ (--enable-newlib-nano-formatted-io): New option.
	* libc/configure: Regenerated.
	* libc/stdio/ (NEWLIB_NANO_FORMATTED_IO): Support new
	configuration option.
	* libc/stdio/ Regenerated.
	* libc/stdio/asnprintf.c (_asniprintf_r, asniprintf): Use
	_NANO_FORMATTED_IO to declare alias prototypes.
	* libc/stdio/asprintf.c (_asiprintf_r, asiprintf): Ditto.
	* libc/stdio/dprintf.c (_diprintf_r, diprintf): Ditto.
	* libc/stdio/fprintf.c (_fiprintf_r, fiprintf): Ditto.
	* libc/stdio/fscanf.c (fiscanf, _fiscanf_r): Ditto.
	* libc/stdio/printf.c (_iprintf_r, iprintf): Ditto.
	* libc/stdio/scanf.c (iscanf, _iscanf_r): Ditto.
	* libc/stdio/snprintf.c (_sniprintf_r, sniprintf): Ditto.
	* libc/stdio/sprintf.c (_siprintf_r, siprintf): Ditto.
	* libc/stdio/sscanf.c (siscanf, _siscanf_r): Ditto.
	* libc/stdio/vasnprintf.c (_vasniprintf_r, vasniprintf): Ditto.
	* libc/stdio/vasprintf.c (vasiprintf, _vasiprintf_r): Ditto.
	* libc/stdio/vdprintf.c (_vdiprintf_r, vdiprintf): Ditto.
	* libc/stdio/vprintf.c (viprintf, _viprintf_r): Ditto.
	* libc/stdio/vscanf.c (viscanf, _viscanf_r): Ditto.
	* libc/stdio/vsnprintf.c (vsniprintf, _vsniprintf_r): Ditto.
	* libc/stdio/vsprintf.c (vsiprintf, _vsiprintf_r): Ditto.
	* libc/stdio/vsscanf.c (vsiscanf, _vsiscanf_r): Ditto.
	* libc/stdio/nano-vfprintf.c: New file.
	* libc/stdio/nano-vfprintf_float.c: New file.
	* libc/stdio/nano-vfprintf_i.c: New file.
	* libc/stdio/nano-vfprintf_local.h: New file.
	* libc/stdio/nano-vfscanf.c: New file.
	* libc/stdio/nano-vfscanf_float.c: New file.
	* libc/stdio/nano-vfscanf_i.c: New file.
	* libc/stdio/nano-vfscanf_local.h: New file.

Attachment: newlib-nano-formatted-io-20140611.txt.tar.bz2
Description: Binary data

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]