mirror of
				https://github.com/tailix/libkernaux.git
				synced 2025-10-30 23:47:50 -04:00 
			
		
		
		
	Conditional compilation
This commit is contained in:
		
							parent
							
								
									d1105f1cc6
								
							
						
					
					
						commit
						edf40ddb83
					
				
					 4 changed files with 94 additions and 76 deletions
				
			
		|  | @ -2,9 +2,9 @@ | |||
| 
 | ||||
| require 'mkmf' | ||||
| 
 | ||||
| have_library 'kernaux' | ||||
| raise 'libkernaux not found' unless have_library 'kernaux' | ||||
| 
 | ||||
| have_func 'kernaux_utoa10' | ||||
| have_func 'kernaux_itoa10' | ||||
| 
 | ||||
| create_makefile 'kernaux/default' | ||||
| raise 'can\'t create Makefile' unless create_makefile 'kernaux/default' | ||||
|  |  | |||
|  | @ -5,16 +5,25 @@ | |||
| 
 | ||||
| static VALUE rb_KernAux = Qnil; | ||||
| 
 | ||||
| #ifdef HAVE_KERNAUX_UTOA10 | ||||
| static VALUE rb_KernAux_utoa10(VALUE self, VALUE number); | ||||
| #endif | ||||
| #ifdef HAVE_KERNAUX_ITOA10 | ||||
| static VALUE rb_KernAux_itoa10(VALUE self, VALUE number); | ||||
| #endif | ||||
| 
 | ||||
| void Init_default() | ||||
| { | ||||
|     rb_KernAux = rb_define_module("KernAux"); | ||||
| #ifdef HAVE_KERNAUX_UTOA10 | ||||
|     rb_define_singleton_method(rb_KernAux, "utoa10", rb_KernAux_utoa10, 1); | ||||
| #endif | ||||
| #ifdef HAVE_KERNAUX_ITOA10 | ||||
|     rb_define_singleton_method(rb_KernAux, "itoa10", rb_KernAux_itoa10, 1); | ||||
| #endif | ||||
| } | ||||
| 
 | ||||
| #ifdef HAVE_KERNAUX_UTOA10 | ||||
| VALUE rb_KernAux_utoa10( | ||||
|     const VALUE self_rb __attribute__((unused)), | ||||
|     const VALUE number_rb | ||||
|  | @ -27,7 +36,9 @@ VALUE rb_KernAux_utoa10( | |||
|     kernaux_utoa10(NUM2ULL(number_rb), buffer); | ||||
|     return rb_funcall(rb_str_new2(buffer), rb_intern("freeze"), 0); | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| #ifdef HAVE_KERNAUX_ITOA10 | ||||
| VALUE rb_KernAux_itoa10( | ||||
|     const VALUE self_rb __attribute__((unused)), | ||||
|     const VALUE number_rb | ||||
|  | @ -37,3 +48,4 @@ VALUE rb_KernAux_itoa10( | |||
|     kernaux_itoa10(NUM2LL(number_rb), buffer); | ||||
|     return rb_funcall(rb_str_new2(buffer), rb_intern("freeze"), 0); | ||||
| } | ||||
| #endif | ||||
|  |  | |||
|  | @ -9,6 +9,7 @@ RSpec.describe KernAux do | |||
|     end | ||||
|   end | ||||
| 
 | ||||
|   if described_class.singleton_class.method_defined? :utoa10 | ||||
|     describe '.utoa10' do | ||||
|       subject(:utoa10) { described_class.utoa10 number } | ||||
| 
 | ||||
|  | @ -48,7 +49,9 @@ RSpec.describe KernAux do | |||
|         end | ||||
|       end | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
|   if described_class.singleton_class.method_defined? :itoa10 | ||||
|     describe '.itoa10' do | ||||
|       subject(:itoa10) { described_class.itoa10 number } | ||||
| 
 | ||||
|  | @ -92,8 +95,8 @@ RSpec.describe KernAux do | |||
|         let(:number) { -2**63 - 1 } | ||||
| 
 | ||||
|         specify do | ||||
|         expect { itoa10 }.to \ | ||||
|           raise_error RangeError, 'bignum too big to convert into `long long\'' | ||||
|           expect { itoa10 }.to raise_error \ | ||||
|             RangeError, 'bignum too big to convert into `long long\'' | ||||
|         end | ||||
|       end | ||||
| 
 | ||||
|  | @ -101,8 +104,9 @@ RSpec.describe KernAux do | |||
|         let(:number) { 2**63 } | ||||
| 
 | ||||
|         specify do | ||||
|         expect { itoa10 }.to \ | ||||
|           raise_error RangeError, 'bignum too big to convert into `long long\'' | ||||
|           expect { itoa10 }.to raise_error \ | ||||
|             RangeError, 'bignum too big to convert into `long long\'' | ||||
|         end | ||||
|       end | ||||
|     end | ||||
|   end | ||||
|  |  | |||
|  | @ -17,12 +17,14 @@ | |||
| 
 | ||||
| #include <stddef.h> | ||||
| 
 | ||||
| #ifdef WITH_PRINTF | ||||
| static void kernaux_console_printf_putc( | ||||
|     const char c, | ||||
|     void *const arg __attribute__((unused)) | ||||
| ) { | ||||
|     kernaux_console_putc(c); | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| void kernaux_console_putc(const char c __attribute__((unused))) | ||||
| { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Alex Kotov
						Alex Kotov