IT戦記

プログラミング、起業などについて書いているプログラマーのブログです😚

C++

gdb で swig 内部の値を見る

C++

きっといつか誰かのためになると信じて残しておきます。 swig では doh というライブラリを使っていて、 gdb にはほとんどのオブジェクトが void* に見えてしまう。(おそろしい子) で、文字列の値を見たい場合は以下のようにすれば見れます。 (gdb) p (cha…

Twitter の半径数クリック以内の情報収集

ちょっと 現実頭皮的に自己満足的プログラムを書きたくなったので Twitter のクローラーを書いてみた。 C++ にしては、割とすっきり書けて満足。 使ったライブラリ soci データベースライブラリ picojson json パーサー boost.asio ネットワークライブラリ b…

new と delete と throw で気をつけること(自分用メモ)

C++

delete する変数が未初期化になっている可能性を考えろ コンストラクタの初期化子リストで throw とか 初期化子リストで throw する可能性のある式を評価するな。 0 を入れておいて、コンストラクタ内で評価しろ または、ポインタラッパー的なものを使え。(…

Visual Studio で exe を ldd する(依存する dll を調べる)方法

C++

今日、教えていただいた方法。 Visual Studio には dumpbin.exe というコマンドラインツールがついているので、それを使う。 C:\bin> dumpbin /DEPENDENTS hoge.exe Microsoft (R) COFF/PE Dumper Version 9.00.30729.01 Copyright (C) Microsoft Corporatio…

Amino というライブラリを使ってみた

C++

これ CBBs - Concurrent Building Blocks via:http://secure.ddo.jp/~kaku/tdiary/20090710.html 内容 スレッド 1 で入力を Shift_JIS -> UTF-16 変換して、 UTF-16 のデータをキューに入れる。 スレッド 2 でキューから UTF-16 のデータを取り出して、 UTF-…

boost::is_convertible はどうやってるか

C++

概ね以下のような感じ template <typename From, typename To> struct is_convertible_basic_impl { // 2 つの同名関数を作って static no_type _m_check(...); static yes_type _m_check(To); // 関数の戻り値の型を見る(どっちの関数が使われるかを見る) static bool value = sizeof(</typename>…

C++ で Buzztter を Growl する

C++

はじめに Buzztter の RSS を持ってきて、新しいキーワードを Growl に表示するものを作ってみた。 C++ でも boost::asio とか、 libxml2 とかを使うとけっこうサクっと書ける。ってこともないか。。 必要なもの boost libxml2 Growl SDK ソース #include <libxml/xmlreader.h> #</libxml/xmlreader.h>…

libxml2 内のメモリの解放

C++

ちょっとメモ 今日も valgrind 使ってます libxml2 を使って以下のような XML のパース処理を書く #include <iostream> #include <sstream> #include <boost/shared_ptr.hpp> #include <libxml/xmlreader.h> static int read(void* in, char* buf, int len) { return static_cast<std::istream*>(in)->readsome(buf, len); } int main() { </std::istream*></libxml/xmlreader.h></boost/shared_ptr.hpp></sstream></iostream>…

ICU の解放順序でハマった

C++

ちょっとメモ 以下のようなコードを書いて失敗した。 #include <boost/shared_ptr.hpp> #include <unicode/uclean.h> #include <unicode/ucnv.h> int main() { UErrorCode status = U_ZERO_ERROR; u_init(&status); // (snip) boost::shared_ptr<UConverter> ucnv(ucnv_open("Shift_JIS", &status), ucnv_close); // (snip) u_clea</uconverter></unicode/ucnv.h></unicode/uclean.h></boost/shared_ptr.hpp>…

XMPP ライブラリ Gloox のトランスポート層を触る(2)

C++

SASL → Resource Bind → Create Session まで #include <cassert> #include <iostream> #include <boost/make_shared.hpp> #include <gloox/iq.h> #include <gloox/parser.h> #include <gloox/base64.h> #include <gloox/connectiontcpclient.h> #include <gloox/connectiontls.h> class Bot : public gloox::ConnectionDataH…</gloox/connectiontls.h></gloox/connectiontcpclient.h></gloox/base64.h></gloox/parser.h></gloox/iq.h></boost/make_shared.hpp></iostream></cassert>

XMPP ライブラリ Gloox のトランスポート層を触る(1)

C++

一日一回 XMPP 勉強中 とりあえず、 TLS のコネクション貼るところまでできた #include <cassert> #include <iostream> #include <boost/make_shared.hpp> #include <gloox/parser.h> #include <gloox/connectiontcpclient.h> #include <gloox/connectiontls.h> class Bot : public gloox::ConnectionDataHandler, gloox::TagHandler, gloox::TLSHandler {…</gloox/connectiontls.h></gloox/connectiontcpclient.h></gloox/parser.h></boost/make_shared.hpp></iostream></cassert>

XMPP クライアント Psi で XML のトレース

C++

一日、数十分ずつ XMPP を勉強 Psi というクライアントを使うと XML の生のメッセージが確認できる Psi - The cross-platform XMPP client for power users やり方は簡単 Tools メニューの XML Console を選択するだけ 以下は実際にトレースしたところ これ…

Gloox で XMPP を書いてみた

C++

camaya.net | Home of gloox – The Portable XMPP Engine ちなみに 1.0 beta を使った Gtalk に Hello! #include <iostream> #include <gloox/client.h> #include <gloox/connectionlistener.h> #include <gloox/messagesession.h> class Bot : public gloox::ConnectionListener { public: Bot() : client_(gloox::JID("USER@gmail.…</gloox/messagesession.h></gloox/connectionlistener.h></gloox/client.h></iostream>

double が IEEE 754 かどうか

C++

double をシリアライズするときとかは、 std::numeric_limit< double >::is_iec559 を assert しておけばいいのかなー。 #include <cassert> #include <limits> #include <boost/cstdint.hpp> template<class Itr> void serialize(Itr it, const double d) { // ↓ こんな感じ assert(sizeof(double) == sizeo</class></boost/cstdint.hpp></limits></cassert>…

C++ の型変換

C++

http://www.kuzbass.ru:8086/docs/isocpp/special.html#class.convクラスの型変換はコンストラクタと型変換関数を使って定義できる。これらの型変換は、ユーザー定義型変換と呼ばれ、暗黙的型変換、変数初期化子、明示的型変換に使われる。 ユーザー定義型変…

POSIX と Windows でのファイルオープン方法

C++

各プラットフォームでのファイルオープンの仕方のメモ たぶん、あってると思ってる 有ったら失敗、無かったら作る // POSIX open(name, O_RDWR | O_EXCL | O_CREAT, 0666); // Win CreateFileA(name, GENERIC_READ | GENERIC_WRITE, FILE_SHARED_READ | FILE…

iostream の状態について

C++

書いとかないと忘れそうなのでメモ gcc の basic_ios は以下のような operator void* と operator! を持っているので //@{ /** * @brief The quick-and-easy status check. * * This allows you to write constructs such as * "if (!a_stream) ..." and "wh…

Boost.Integer で signed な変数を unsigned に変換する

C++

boost::uint_t を使うと出来るみたい #include <boost/integer.hpp> template <class T> struct add_unsigned { typedef typename boost::uint_t<sizeof(T) * 8>::least type; }; /************/ #include <iostream> #include <typeinfo> int main() { std::cout << typeid(unsigned int).name() << std::endl; std::cout <<</typeinfo></iostream></sizeof(t)></class></boost/integer.hpp>…

テンプレートを使って数値をリトルエンディアン形式のバイト列に変換する

C++

boost/spirit/home/support/detail/integer/endian.hpp を参考に書いてみた 以下のような感じで定義しておいて template <class T, std::size_t S> struct little_endian { static inline void set(char* const buf, const T &t) { *buf = t & 0xff; little_endian<T, S - 1>::set(buf + 1, t ></t,></class>…

boost::serialization の Dataflow Iterators で base64 生成

C++

はじめに base64 を作りたいと思って調べたら boost::serialization の Dataflow Iterators が便利そう。 Serialization - Dataflow Iterators 実際に書いてみた #include <iostream> #include <boost/pfto.hpp> #include <boost/archive/iterators/base64_from_binary.hpp> #include <boost/archive/iterators/transform_width.hpp> int main() { using nam…</boost/archive/iterators/transform_width.hpp></boost/archive/iterators/base64_from_binary.hpp></boost/pfto.hpp></iostream>

std::string まとめ

C++

注意 gcc version 4.3.2 の std::string 私的まとめ 実装 クラス std::basic_string::_Rep は以下の情報を持つ 文字列長 _M_length 確保された容量 _M_capacity 参照カウンタ _M_refcount アロケータ(std::basic_string::_Alloc)の派生クラス(std::basic_…

FastCGI のプロセスを strace する

C++

メモしておきます。 1. プロセスマネージャに以下のように attach する(-ff は fork したプロセスにも自動で attach してくれる) $ sudo strace -ff -o fastcgi_strace_log -p <fcgi プロセスマネージャの PID>2. fcgi サーバーのプロセスを殺す $ sudo pkill application.fcgi3. すると、</fcgi>…

私的 Win32 API メモ

いろいろ勉強した 忘れてしまいそうなので書き下しておく 雰囲気的なこと ウィンドウ 俗にいうウィンドウではなく、 GUI の部品全般(ボタンとか、ツールバー)も含む 俗にいうウィンドウは、フレームとか言う ハンドル ポインタみたいなもん HWND ウィンド…

ブラウザで X86 のマシン語を動かす! Google 謹製 Native Client をさっそく試してみる

C++

はじめに Google から、非常に面白そうなソフトウェアがリリースされました! その名も Native Client なんとブラウザ上で X86 のバイナリを動かしてしまうそうです。 これはすごい! さっそく試してみたいと思います。その過程を逐次更新していきます。 自…

質問した

複数の C++ のソースファイルに対して、一度にシンボルの置換を… - 人力検索はてな もし良かったら、教えてください><

C/C++ のコードを Flash Player で動かす! Alchemy を速攻試してみる。

はじめに Adobe から C/C++ で書いたコードを Flash や AIR で動かす Alchemy というものがリリースされましたね! Alchemy - Adobe Labs これはすごい!ということで、少し試してみたいと思います。 その様子をリアルタイムに書いていきます。ちゃんと出来…

Firefox メモ

alert の位置を知る dom/src/base/nsGlobalWindow.cpp 4035 行目 nsGlobalWindow::Alert JavaScript を書く alert(0); var img = document.createElement('img'); img.onload = function() { alert(1) }; alert(2); img.src = 'http://www.hatena.ne.jp/imag…

1000 万行のソースコード

Linuxカーネルのコード行数、1000万行を上回る | スラド 1 日 1000 行読んだとしても 30 年かかるのかあ。 桁が違いすぎる。 その間もソースコードは増え続ける。 やがて、誰も保守することができなくなったソースコードの山。 人類はソースコードを解析する…

JavaScript はどのように実行されるか

JavaScript はどのように実行されるか Safari*1 の実装を例に JavaScript はどのようにして実行されているかを書く。自分用のメモ。日本語の出来は気にしない 1. ブラウザを起動して以下のようなページを開いたとする <html> <head> <script> var a = 1; var b = 2; alert(a + b)</script></head></html>…

scons で msvc と gcc の差を吸収できるかどうかを考えるときに見るべきファイル

C++

この辺 http://scons.tigris.org/source/browse/scons/trunk/src/engine/SCons/Tool/