Skip to content

Instantly share code, notes, and snippets.

View hnakamur's full-sized avatar

Hiroaki Nakamura hnakamur

View GitHub Profile
@hnakamur
hnakamur / gist:3708248
Created September 12, 2012 17:13
working version
static int fs_open(lua_State* L) {
int mode;
uv_fs_cb cb;
uv_loop_t *loop = luv_get_loop(L);
int arg_n = lua_gettop(L);
fs_req_holder *holder = (fs_req_holder *)create_obj_init_ref(L,
sizeof(fs_req_holder), "lev.fs");
/* NOTE: set_call needs "object" to be stack at index 1 */
lua_insert(L, 1);
@hnakamur
hnakamur / gist:3708688
Created September 12, 2012 18:05
fs.open using macros
#define SETUP_REQ \
uv_fs_cb cb = NULL; \
uv_loop_t *loop = luv_get_loop(L); \
fs_req_holder *holder = (fs_req_holder *)create_obj_init_ref(L, \
sizeof(fs_req_holder), "lev.fs"); \
/* NOTE: set_call needs "object" to be stack at index 1 */ \
lua_insert(L, 1); \
uv_fs_t *req = &holder->req;
#define SET_OPT_CB(index, c_callback) \
@hnakamur
hnakamur / gist:3709211
Created September 12, 2012 19:14
struct stat on OSX
struct stat {
dev_t st_dev; /* [XSI] ID of device containing file */
ino_t st_ino; /* [XSI] File serial number */
mode_t st_mode; /* [XSI] Mode of file (see below) */
nlink_t st_nlink; /* [XSI] Number of hard links */
uid_t st_uid; /* [XSI] User ID of the file */
gid_t st_gid; /* [XSI] Group ID of the file */
dev_t st_rdev; /* [XSI] Device ID */
#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
struct timespec st_atimespec; /* time of last access */
@hnakamur
hnakamur / gist:3713361
Created September 13, 2012 10:10
segfault on Ubuntu
hnakamur@ubuntu:~/lev$ build/lev -g tools/checkit tests/*.lua
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
@hnakamur
hnakamur / gist:3713365
Created September 13, 2012 10:11
git submoduleの結果
$ git submodule
8bec3ea459fe2369a1e7d4d08f1ac598eb877247 deps/http-parser (v0.1-244-g8bec3ea)
9b1a6844ad6af2973a9ff427415d9bae679f1b79 deps/luacrypto (heads/luvit-dev)
dd9e7a4608413d25b85336030ad268fcce25e23e deps/luajit (v2.0.0-beta10-62-gdd9e7a4)
5e9b32e8c505ac145b2a734584263df65fe105cd deps/openssl (heads/master)
dfb6be0e07f298fb6def24078ca6ed5bb3a0eba3 deps/uv (node-v0.7.11-66-gdfb6be0)
8b48967c74e9b16c07f120b71598f5e5269e8f57 deps/yajl (2.0.4-1-g8b48967)
89c3db5f341a1875c08ff18b8a70a8b17623345c deps/zlib (v1.2.6-3-g89c3db5)
66665cc0f78933a7a118603928be059fed23f673 tools/gyp (heads/luvit-dev)
@hnakamur
hnakamur / gist:3713374
Created September 13, 2012 10:14
segfault gdb
hnakamur@ubuntu:~/lev$ build/lev -g tools/checkit tests/*.lua
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
@hnakamur
hnakamur / gist:3713595
Created September 13, 2012 11:02
sometime error "attempt to compare two table values" occurs
```
hnakamur@ubuntu:~/lev$ make test
./build/lev ./tools/checkit tests/*.lua
*lev core started: 14365
✔ tcp_timer_again_error: 1/1 within 0.011 ms
✔ tcp_timer_stop: 1/1 within 0.058 ms
✔ tcp_timer_once: 2/2 within 99.097 ms
✔ tcp_timer_again: 10/10 within 501.955 ms
✔ tcp_timer_repeat: 10/10 within 601.988 ms
✔ fs_sync_test: 10/10 within 0.144 ms
@hnakamur
hnakamur / gist:3713944
Created September 13, 2012 12:15
"attempt to compare two %s values" in luajit
nakamur@ubuntu:~/lev$ grep -r 'compare two' .
./include/lev/lj_errmsg.h:ERRDEF(BADCMPV, "attempt to compare two %s values")
./include/lev/host/minilua.c:luaG_runerror(L,"attempt to compare two %s values",t1);
./deps/luajit/src/lj_errmsg.h:ERRDEF(BADCMPV, "attempt to compare two %s values")
./deps/luajit/src/host/minilua.c:luaG_runerror(L,"attempt to compare two %s values",t1);
./deps/openssl/openssl/CHANGES: to compare two certificates. We do this by working out the SHA1
./deps/openssl/openssl/crypto/x509/x509_vfy.c: * 3. Both are full names and compare two GENERAL_NAMES.
@hnakamur
hnakamur / env_copy_test.c
Created September 16, 2012 21:53
test on how to copy worker env for spawning
/*
gcc env_copy_test.c; ./a.out
*/
#include <stdio.h>
#include <time.h> /* clock */
#include <stdlib.h> /* free */
#include <string.h> /* sprintf */
@hnakamur
hnakamur / env_copy_test.bench
Created September 17, 2012 02:18 — forked from kristate/env_copy_test.bench
test on how to copy worker env for spawning
hnakamur@ubuntu:~/execve_env_copy$ gcc -O3 env_copy_test.c
hnakamur@ubuntu:~/execve_env_copy$ rm env_copy_test
hnakamur@ubuntu:~/execve_env_copy$ ./a.out
type_a: 0.750000 seconds
type_b: 0.730000 seconds
type_c: 0.640000 seconds
type_d: 0.860000 seconds
type_e: 0.760000 seconds
hnakamur@ubuntu:~/execve_env_copy$ ./a.out
type_a: 0.750000 seconds