64 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto f2d43069f0 mruby-socet: add socket constants
Introduced in Ruby3.2:

- SO_INCOMING_CPU
- SO_INCOMING_NAPI_ID
- SO_RTABLE
- SO_SETFIB
- SO_USER_COOKIE
- TCP_KEEPALIVE
- TCP_CONNECTION_INFO
2022-12-19 18:59:10 +09:00
Yukihiro "Matz" Matsumoto b99c389ec3 internal.h: aggregate internal functions.
Internal functions can only be called from within the library.
Functions listed in `mruby/internal.h` can be called from:

* core (src/*.c)
* gems (mrbgems/**/*.c)

But not from the application linked with `libmruby`.
2022-04-02 18:25:13 +09:00
dearblue f9d72908ca Remove old compatibility code
The `mrb_voidp()` related macros have been removed in mruby-1.1.0.
2022-03-27 11:26:43 +09:00
Yukihiro "Matz" Matsumoto 6fa5aaf694 socket.c: unify error handling code. 2022-03-09 15:21:14 +09:00
Yukihiro "Matz" Matsumoto 2cb82803b3 socket.c: reorganize error condition in mrb_ipsocket_ntop(). 2022-03-09 15:21:14 +09:00
Yukihiro "Matz" Matsumoto a4f740ff9a string.c: use mrb_int instead of size_t. 2022-03-03 08:08:02 +09:00
Yukihiro "Matz" Matsumoto 80b44c6ade socket.c: avoid mrb_funcall_id() to retrieve file descriptor. 2022-02-22 11:46:02 +09:00
dearblue 621cafde68 Need to check the type of the method return value 2022-02-19 15:01:46 +09:00
mimaki 1f3a385ec5 Fix build error and refine definition of ssize_t on MSVC. 2021-12-28 17:18:59 +09:00
Yukihiro "Matz" Matsumoto d6dd6f0e7b Update struct initializer to work with relatively older C++. 2021-09-20 19:13:17 +09:00
Yukihiro "Matz" Matsumoto 8619ba6a38 Use struct initializer instead of memset. 2021-09-15 13:02:15 +09:00
Yukihiro "Matz" Matsumoto 5c804cf68f Remove redundant include headers.
- stdlib.h
- stddef.h
- stdint.h
- stdarg.h
- limits.h
- float.h
2021-07-25 13:07:10 +09:00
Yukihiro "Matz" Matsumoto ea7f1953c3 Rename mrb_fixnum_to_str to mrb_integer_to_str. 2021-05-17 13:59:01 +09:00
dearblue 6fc5dc986a Extend the tab with 8 whitespace
This work was done as follows:
- check:   `git grep $'\011' -- :^oss-fuzz`
- convert: `ruby -pi -e 'nil while $_.sub!(/^(.*?)\t/) { $1 + " " * (8 - $1.size % 8) }'`

The `doc/guide/{compile,mrbgems}.md` file adds and removes whitespace to make the directory tree look the same.
In `mrbgems/mruby-socket/src/socket.c`, there is a part where the indent is changed from 4 to 2 at the same time as the tab is changed.
2021-05-05 22:16:03 +09:00
Yukihiro "Matz" Matsumoto 17ecf14511 Revert "Minimize the changes in #5277"
This reverts commit dc51d89ac2.
2021-01-26 10:57:07 +09:00
Yukihiro "Matz" Matsumoto dc51d89ac2 Minimize the changes in #5277
Instead of including `mruby/presym.h` everywhere, we provided the
fallback `mruby/presym.inc` under `include/mruby` directory, and specify
`-I<build-dir>/include` before `-I<top-dir>/include` in `presym.rake`.
So even when someone drops `-I<build-dir>/include` in compiler options,
it just compiles without failure.
2021-01-22 18:38:53 +09:00
KOBAYASHI Shuji 90b53f4c29 Avoid including presym.inc in existing header files
Addressed an issue where existing programs linking `libmruby.a` could only
be built by adding `<build-dir>/include` to compiler's include path.
2021-01-11 09:21:07 +09:00
Yukihiro "Matz" Matsumoto 39a11f323e Remove mrb_str_buf_new() and MRB_STR_BUF_MIN_SIZE; close #5171 2020-11-22 22:54:21 +09:00
KOBAYASHI Shuji 89f591485b Change name and usage of presym macros
To be also able to build mruby without presym in the future. However,
`MRB_QSYM` has been removed and changed as follows:

### Example

|       Type                | Symbol |  Previous Style  |   New Style    |
|---------------------------|--------|------------------|----------------|
| Operator                  | &      | MRB_QSYM(and)    | MRB_OPSYM(and) |
| Class Variable            | @@foo  | MRB_QSYM(00_foo) | MRB_CVSYM(foo) |
| Instance Variable         | @foo   | MRB_QSYM(0_foo)  | MRB_IVSYM(foo) |
| Method with Bang          | foo!   | MRB_QSYM(foo_b)  | MRB_SYM_B(foo) |
| Method with Question mark | foo?   | MRB_QSYM(foo_p)  | MRB_SYM_Q(foo) |
| Mmethod with Equal        | foo=   | MRB_QSYM(foo_e)  | MRB_SYM_E(foo) |

This change makes it possible to define, for example, `MRB_IVSYM(foo)` as
`mrb_intern_lit(mrb, "@" "foo")`, which is useful if we support building
without presym in the future.
2020-11-13 13:41:20 +09:00
Yukihiro "Matz" Matsumoto 5134031e18 Use mrb_int_value() instead of mrb_fixnum_value().
Where fixnum overflow can happen.
2020-10-12 18:20:05 +09:00
Yukihiro "Matz" Matsumoto 2b188ed8a1 Reorganize Integer system.
- Integrate `Fixnum` and `Integer`
- Remove `Integral`
- `int / int -> int`
- Replace `mrb_fixnum()` to `mrb_int()`
- Replace `mrb_fixnum_value()` to `mrb_int_value()`.
- Use `mrb_integer_p()` instead of `mrb_fixnum_p()`
2020-10-12 18:19:54 +09:00
dearblue 80fe9838d2 Integrate Fixnum class into Integer class
* The `Fixnum` constant is now an alias for the `Integer` class.
* Remove `struct mrb_state::fixnum_class` member.
  If necessary, use `struct mrb_state::integer_class` instead.
2020-10-12 16:21:44 +09:00
Yukihiro "Matz" Matsumoto 52507b1083 Generate C struct from irep instead of binary dump. 2020-10-12 16:21:10 +09:00
Yukihiro "Matz" Matsumoto 2a366ffba8 Use functions that take symbols to reduce string litrals in C. 2020-10-12 16:20:59 +09:00
Yukihiro "Matz" Matsumoto 00f5ddc9ae Use mrb_funcall_id() extensively.
Except for support files e.g. `mruby-test/driver.c`, which are not
target of symbol collection via `rake gensym`.
2020-10-12 16:20:58 +09:00
Yukihiro "Matz" Matsumoto eddd324979 Add MRB_SYM() for inline symbols. 2020-10-12 16:20:41 +09:00
dearblue 57611240a9 Prohibit string changes by "s"/"z" specifier of mrb_get_args()
- The `s` specifier is a string pointer obtained without performing `mrb_str_modify()`, so it cannot be changed.
- The `z` specifier cannot be changed because it is a string pointer obtained by `RSTRING_CSTR()` which returns `const char *`.
2020-09-25 21:02:58 +09:00
Yukihiro "Matz" Matsumoto 55482063a7 Remove duplicated definition of E_EOF_ERROR. 2020-08-09 21:57:41 +09:00
Yukihiro "Matz" Matsumoto 9174b18f34 Rename mrb_num_args_error to mrb_argnum_error; ref #4863 2020-01-01 22:37:14 +09:00
KOBAYASHI Shuji 81de1f159c Add mrb_num_args_error() for "wrong number of arguments" error
To unify the style of messages.
2019-12-12 11:45:58 +09:00
KOBAYASHI Shuji feaf80d899 Use type predicate macros instead of mrb_type if possible
For efficiency with `MRB_WORD_BOXING` (implement type predicate macros for
all `enum mrb_vtype`).
2019-09-26 22:23:27 +09:00
Yukihiro "Matz" Matsumoto 98fc887cb3 Reorganize mrb_string_value_cstr and related functions.
`mrb_string_value_cstr` and `mrb_string_value_len`: obsolete
`mrb_string_cstr`: new function to retrieve NULL terminated C string
`RSTRING_CSTR`: wrapper macro of `mrb_string_cstr`
2019-08-07 15:52:10 +09:00
KOBAYASHI Shuji 334afb167c Use new specifiers/modifiers of mrb_vfromat()
The binary sizes (gems are only `mruby-bin-mruby`) are reduced slightly in
my environment than before the introduction of new specifiers/modifiers
(5116789a) with this change.

  ------------+-------------------+-------------------+--------
   BINARY     | BEFORE (5116789a) |   AFTER (This PR) |  RATIO
  ------------+-------------------+-------------------+--------
   mruby      |      593416 bytes |      593208 bytes | -0.04%
   libmruby.a |      769048 bytes |      767264 bytes | -0.23%
  ------------+-------------------+-------------------+--------

BTW, I accidentally changed `tasks/toolchains/visualcpp.rake` at #4613,
so I put it back.
2019-08-05 13:18:50 +09:00
Hiroshi Mimaki b630bf59ef Fix path of error.h. 2019-06-18 13:27:16 +09:00
KOBAYASHI Shuji e2604c1550 Avoid using mrb_str_to_cstr if possible
Because it always allocate new string. Replace with the followings:

- Use `RSRING_PTR` if string is guaranteed to be null-terminated.
- Use `mrb_string_value_cstr` or `mrb_get_args("z")` if return value isn't
  modified.
2019-05-06 23:32:53 +09:00
KOBAYASHI Shuji 0ccb058b90 Use mrb_fixnum_to_str() instead of Fixnum#to_s 2019-05-05 20:31:12 +09:00
Hiroshi Mimaki 0711c861ca Fix mruby-socket test failure on MinGW. 2018-11-22 09:49:00 +09:00
Kazuhiro Sera b03f1f78e3 Fix misspelling words in comments 2018-08-11 00:28:32 +09:00
Yukihiro "Matz" Matsumoto a9abf65f03 Fixed wrong usages of mrb_raisef(); ref #4043
`mrb_raisef()` only takes `%S` specifier. If you don't have extra
arguments, use `mrb_raise()`.
2018-06-15 07:47:18 +09:00
Yukihiro "Matz" Matsumoto 70600c3ba8 Resolve sign comparison warning; ref #4044 2018-06-14 14:16:04 +09:00
Tomoyuki Sahara af8020e7fd sa_family_t is not defined on windows. 2018-06-14 13:52:37 +09:00
Tomoyuki Sahara 2eeac91098 set sockaddr_un.sun_len on the systems that have sockaddr.sa_len.
If your system has sa_len but is not BSD-derived, define HAVE_SA_LEN=1
on mrbgem.rake or build_config.rb.
2018-06-14 13:36:01 +09:00
Tomoyuki Sahara 5013d2b20f struct sockaddr_un can be truncated.
When we have "struct sockaddr_un *s_un", we could not assume *s_un
points to a memory region which size is at least sizeof(*s_un).
Even worse, it may be shorter than sizeof(struct sockaddr) on some
systems.
2018-06-14 13:28:32 +09:00
Tomoyuki Sahara 3618556a95 struct sockaddr_un can be shorter than struct sockaddr.
ref: https://github.com/iij/mruby-socket/issues/45
2018-06-14 13:25:57 +09:00
Sebastián Katzer e7a4699135 Declare inet_ntop and inet_pton as static
To avoid conflicts with multiple definitions of inet_ntop and inet_pton if compiled with # define _WIN32_WINNT _WIN32_WINNT_VISTA

C:/mingw-w64/x86_64-7.2.0-posix-seh-rt_v5-rev1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libWs2_32.a(dghfs00169.o):(.text+0x0): multiple definition of `inet_pton'
722C:/projects/iss/mruby/build/host/lib/libmruby.a(socket.o):C:/projects/iss/mruby/mrbgems/mruby-socket/src/socket.c:80: first defined here

define _WIN32_WINNT _WIN32_WINNT_VISTA
2018-06-05 15:59:12 +02:00
Yukihiro "Matz" Matsumoto 0866fa38b0 Avoid unnecessary object allocation (addrinfo) in _accept; ref #3999 2018-04-18 00:18:03 +09:00
Yukihiro "Matz" Matsumoto 66b1695ba9 Define SOL_IP and SOL_TCP; ref #3999 2018-04-17 12:01:32 +09:00
Takeshi Watanabe baff7c63ee Revert #3984 . 2018-03-26 11:02:05 +09:00
Takeshi Watanabe 306cb99b10 Merge commit '36d016afd663d34607c843d03371bedb71efa34e' 2018-03-25 21:10:11 +09:00
Yukihiro "Matz" Matsumoto f0379c8c45 Merge pull request #3892 from mimaki/ipproto-winsock
Use IPPROTO enum values on WinSock.
2017-12-14 00:09:45 +09:00